[VM][ENH][UNIX] Linux/Intel VM Joystick Support

Joern Eyrich jeyrich at swol.de
Thu Jan 13 22:02:55 UTC 2000


This is a sqUnixJoystickAndTablet.c that implements the VM hook functions for joysticks under Linux/i386.

It uses Vojtech Pavlik's Linux Joystick driver's (deprecated V0.x driver compatibility) polling interface as opposed to the newer event-driven interface.

It works for me with a Gravis Blackhawk Joystick and SuSE Linux 6.3 on a Gigabyte BX2000 board with a Soundblaster PCI 128 card.

Two buglets in sqMacJoystickAndTablet.c's comment in joystickRead():

1) it says the return value is formatted as this:
     <onFlag (1 bit)><buttonFlags (5 bits)><x-value (11 bits)><y-value (11 bits)>
   sctually, the x and y values are swapped
2) it says "The x and y values are 11-bit signed values in the range [-1024..1023] representing the raw (unencoded) joystick position.", but actually the values are unsigned 11-bit values (zero being left/top)

Have Fun!
-------------- next part --------------
/* This file is a heavily modified version of the file "sqMacJoystick.c".
 *
 * Modifications by: Ian Piumarta (ian.piumarta at inria.fr)
 *
 * Support for Linux/i386 joysticks contributed by:
 *	J"orn Eyrich <jeyrich at brokat.com>
 *
 * The original version of this file can be regenerated from the Squeak
 * image by executing:
 *
 * 	InterpreterSupportCode writeMacSourceFiles
 */

#include "sq.h"

#if defined(__linux__) && defined(__i386__)

#include <linux/joystick.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#define FILENAMEBUFLEN 16
#define FILENAMEPREFIX "/dev/js"

static int  joyFileDes  [JS_MAX];
static char filenameBuf [FILENAMEBUFLEN];

static char filenamePrefix[]=FILENAMEPREFIX;

int joystickInit(void)
{
  int i;

  for (i=0; i < JS_MAX; i++)
  {
     sprintf(filenameBuf,"%.16s%d",filenamePrefix,i);
     joyFileDes[i] = open(filenameBuf,O_RDONLY);
  }

  /* exit() will close the file descriptors for us */

  return 0; /* nobody seems to care about our return value */
}

static struct JS_DATA_TYPE joyStruct;

int joystickRead(int index)
{
  if (index < 0 || index >= JS_MAX || joyFileDes[index-1] == -1)
  {
puts("no");
     return 0;
  }

  if (read(joyFileDes[index-1], &joyStruct, JS_RETURN) == -1)
  {
puts("no read");
    return 0;
  }

  /* x/y are 0..255, convert to 0..2047 by shifting left 3 bits */
  return    (                1 << 27)
          | ((joyStruct.buttons & 0x1F) << 22)
          | ((joyStruct.y       & 0xFF) << 14)
          | ((joyStruct.x       & 0xFF) <<  3);

  /*
     the comments in sqMacJoystickAndTablet.c are wrong on two counts:

     1: x and y components in the return word format are switched
     2: x and y values are not -1024..1023, but 0..2047

     (see InputSensor>>joystickXY:)
  */
}

#else

int joystickInit(void)		{ return 0; }
int joystickRead(int index)	{ return 0; }

#endif

/* we don't have any tablets */

int tabletInit(void)
{
  return 0;
}

int tabletGetParameters(int cursorIndex, int result[])
{
  return 0;
}

int tabletRead(int cursorIndex, int result[])
{
  return 0;
}

int tabletResultSize(void)
{
  return 0;
}


More information about the Squeak-dev mailing list