diff -Naur src.orig/Makefile src/Makefile --- src.orig/Makefile Mon Jan 17 21:38:09 2000 +++ src/Makefile Fri Mar 14 13:06:39 2003 @@ -2,7 +2,7 @@ TARGET= go SRC= main.cc win.cc image.cc game.cc joystick.cc OBJ= $(SRC:%.cc=%.o) -LIB=-L/usr/X11/lib -lXpm -lX11 +LIB=-L/usr/X11/lib -L/usr/X11R6/lib -lXpm -lX11 INC=-I/usr/include/X11 DEF= @@ -16,5 +16,5 @@ $(CPP) -o $@ $(OBJ) $(LIB) clean: - rm -f *.o $(TARGET) core + rm -f *.o $(TARGET) core *~ diff -Naur src.orig/README src/README --- src.orig/README Thu Jan 1 01:00:00 1970 +++ src/README Fri Mar 14 13:11:36 2003 @@ -0,0 +1,18 @@ + +Joystick demo +by Paul Coates +and patched by Hans Schou 2003 + +Original source: +http://game.ncl.ac.uk/00602/src/ + + +To get my Logitech Wingman Rumblepad to work +with Mandrake 8.2 Linux , I did: + rmmod hid + modprobe joydev + modprobe hid + +To compile you need at least to have libxmp4-devel installed. +Otherwise gcc can not find xpm.h + diff -Naur src.orig/game.cc src/game.cc --- src.orig/game.cc Mon Jan 17 22:07:07 2000 +++ src/game.cc Fri Mar 14 15:56:28 2003 @@ -4,6 +4,8 @@ #include "game.h" #include "man.xpm" +#define JDIV 4 + void Game::init(Main *m) { main = m; @@ -30,10 +32,12 @@ sprintf(buf, "%d, %d %d, %d", x, y, jx, jy); main->win.DrawText(20, 20, buf, "#0000ff", FONT_SMALL); - sprintf(buf, "Button 1 %s", jb1 ? "pressed" : "released"); + sprintf(buf, "Button 1 %s", jb & 1 ? "pressed" : "released"); main->win.DrawText(20, 40, buf, "#0000ff", FONT_SMALL); - sprintf(buf, "Button 2 %s", jb2 ? "pressed" : "released"); + sprintf(buf, "Button 2 %s", jb & 2 ? "pressed" : "released"); main->win.DrawText(20, 60, buf, "#0000ff", FONT_SMALL); + sprintf(buf, "Buttons 0x%04x", jb ); + main->win.DrawText(20, 80, buf, "#0000ff", FONT_SMALL); main->win.DrawImage(x, y, img); main->win.DrawWindow(); } @@ -59,18 +63,16 @@ { } -void Game::ProcessJoystick(int x, int y, int button1, int button2) +void Game::ProcessJoystick(int x, int y, int buttons) { jx = x; jy = y; - jb1 = button1; - jb2 = button2; + jb = buttons; + + dx = (jx-128)/JDIV; + dy = (jy-128)/JDIV; - if (jx<64) { dx=-5; } else - if (jx>196) { dx=5; } else - dx=0; - - if (jy<64) { dy=-5; } else - if (jy>196) { dy=5; } else - dy=0; + /* Press button 1 while move to upper left corner */ + if (buttons & 1 == (x | y)) + main->quit = 1; } diff -Naur src.orig/game.h src/game.h --- src.orig/game.h Mon Jan 17 22:04:07 2000 +++ src/game.h Fri Mar 14 14:31:19 2003 @@ -9,11 +9,11 @@ void draw(); void ProcessKey(int key, int action); void ProcessMouse(int button, int action, int x, int y); - void ProcessJoystick(int x, int y, int button1, int button2); + void ProcessJoystick(int x, int y, int buttons); int x, y; int dx, dy; - int jx, jy, jb1, jb2; + int jx, jy, jb; int img; Main *main; }; diff -Naur src.orig/joystick.cc src/joystick.cc --- src.orig/joystick.cc Mon Jan 17 22:17:17 2000 +++ src/joystick.cc Fri Mar 14 17:26:46 2003 @@ -2,20 +2,44 @@ #include #include #include +#include #include "joystick.h" +#define JOYSTICK_DEVFS "/dev/input/js0" /* devfs */ #define JOYSTICK "/dev/js0" +#define NAMESIZE 100 int Joystick::create() { - fd = open(JOYSTICK, O_RDONLY); - if (!fd) return 0; + char c_num_axis; + char c_num_buttons; + unsigned long ver = 0; + + name = NULL; + + if (!(fd = open(JOYSTICK_DEVFS, O_RDONLY))) + fd = open(JOYSTICK, O_RDONLY); + + if (fd) { + if (!ioctl(fd,JSIOCGVERSION,&ver)) + printf("JSIOCGVERSION %d\n", ver); + if (ioctl(fd,JSIOCGAXES,&c_num_axis)) + c_num_axis = 0; + if (ioctl(fd,JSIOCGBUTTONS,&c_num_buttons)) + c_num_buttons = 0; + name = (char *)malloc(NAMESIZE); + sprintf(name,"%dbt %dax ", c_num_buttons, c_num_axis); + if (ioctl(fd,JSIOCGNAME(NAMESIZE-strlen(name)),name+strlen(name))>=0) + printf("ioctl(JSIOCGNAME) %s\n", name); + } - return 1; + return fd; } void Joystick::finish() { + if (name) + free(name); close(fd); } @@ -25,6 +49,7 @@ status = read(fd, &js, JS_RETURN); if (status != JS_RETURN) return 0; + /* print(); */ return 1; } diff -Naur src.orig/joystick.h src/joystick.h --- src.orig/joystick.h Mon Jan 17 22:17:24 2000 +++ src/joystick.h Fri Mar 14 16:26:52 2003 @@ -13,6 +13,7 @@ int fd; struct JS_DATA_TYPE js; + char *name; }; #endif diff -Naur src.orig/main.cc src/main.cc --- src.orig/main.cc Mon Jan 17 22:16:15 2000 +++ src/main.cc Fri Mar 14 14:29:23 2003 @@ -13,9 +13,9 @@ ((Game*)data)->ProcessKey(key, action); } -void joystick_callback(void *data, int x, int y, int button1, int button2) +void joystick_callback(void *data, int x, int y, int buttons) { - ((Game*)data)->ProcessJoystick(x, y, button1, button2); + ((Game*)data)->ProcessJoystick(x, y, buttons); } int main(int argc, char *argv[]) diff -Naur src.orig/main.h src/main.h --- src.orig/main.h Mon Jan 17 21:55:41 2000 +++ src/main.h Fri Mar 14 14:32:35 2003 @@ -10,7 +10,7 @@ Main(int argc, char *argv[]); void ProcessMouse(int button, int action, int x, int y); void ProcessKey(int key, int action); - void ProcessJoystick(int x, int y, int button1, int button2); + void ProcessJoystick(int x, int y, int buttons); int quit; Win win; diff -Naur src.orig/win.cc src/win.cc --- src.orig/win.cc Mon Jan 17 22:17:36 2000 +++ src/win.cc Fri Mar 14 17:29:41 2003 @@ -1,5 +1,6 @@ #include #include +#include #include "input.h" #include "image.h" #include "main.h" @@ -21,7 +22,7 @@ int Win::create() { - char *window_name = "Simple Window"; + char *window_name = "** could not get joy-driver name **"; char *icon_name = "window"; static XSizeHints size_hints; Window rootwin; @@ -41,6 +42,8 @@ joystickcb = NULL; joy.create(); + if (joy.name) + window_name = joy.name; width=WINDOW_WIDTH; height=WINDOW_HEIGHT; @@ -220,7 +223,7 @@ joy.status(); if (joystickcb != NULL) joystickcb(joystickcallback, joy.js.x, joy.js.y, - (joy.js.buttons & 1), (joy.js.buttons & 2)); + joy.js.buttons); } void Win::process_event(XEvent report) diff -Naur src.orig/win.h src/win.h --- src.orig/win.h Mon Jan 17 22:00:46 2000 +++ src/win.h Fri Mar 14 14:30:41 2003 @@ -16,7 +16,7 @@ typedef void (*MouseCB) (void *data, int button, int action, int x, int y); typedef void (*KeyCB) (void *data, int key, int action); -typedef void (*JoystickCB) (void *data, int x, int y, int button1, int button2); +typedef void (*JoystickCB) (void *data, int x, int y, int buttons); typedef struct {