diff -bur uae-0.8.15/src/od-linux/joystick.c uae-0.8.15.mod/src/od-linux/joystick.c --- uae-0.8.15/src/od-linux/joystick.c Wed Apr 15 21:30:16 1998 +++ uae-0.8.15.mod/src/od-linux/joystick.c Sat Nov 10 19:15:49 2001 @@ -1,4 +1,4 @@ - /* +/* * UAE - The Un*x Amiga Emulator * * Joystick emulation for Linux and BSD. They share too much code to @@ -8,6 +8,9 @@ * Copyright 1998 Krister Walfridsson */ +#include +#include + #include "sysconfig.h" #include "sysdeps.h" @@ -48,43 +51,111 @@ static int js0, js1; +#define BUTTONPRESSED(buffer, n) ((buffer & (1 << n)) >> n) + +#define BUTTON_REPEAT_TIME 30 + void read_joystick(int nr, unsigned int *dir, int *button) { - static int minx = INT_MAX, maxx = INT_MIN; - static int miny = INT_MAX, maxy = INT_MIN; - int left = 0, right = 0, top = 0, bot = 0; uae_joystick_t buffer; int len; int fd = nr == 0 ? js0 : js1; + int left = 0, right = 0, top = 0, bot = 0; + int button1 = 0; + int button2 = 0; + + int pause = 0; + static int ignore_press = 0; + *dir = 0; *button = 0; if (nr >= nr_joysticks) return; + // Pause implementation (FIXME: A bit lame) + do { + // Read the joystick state len = read(fd, &buffer, sizeof(buffer)); if (len != sizeof(buffer)) return; - if (buffer.x < minx) minx = buffer.x; - if (buffer.y < miny) miny = buffer.y; - if (buffer.x > maxx) maxx = buffer.x; - if (buffer.y > maxy) maxy = buffer.y; + if (BUTTONPRESSED(buffer.buttons, 9) && ignore_press == 0) { + puts ("Toggling pause"); + ignore_press = 1; + pause = !pause; + } else if (!BUTTONPRESSED(buffer.buttons, 9)) { + ignore_press = 0; + } + + if (pause) + usleep(1000); + } while (pause); - if (buffer.x < (minx + (maxx-minx)/3)) + // Convert joystick struct values to top,bot,left,right + if (buffer.x < 128) left = 1; - else if (buffer.x > (minx + 2*(maxx-minx)/3)) + else if (buffer.x > 128) right = 1; - if (buffer.y < (miny + (maxy-miny)/3)) - top = 1; - else if (buffer.y > (miny + 2*(maxy-miny)/3)) + if (buffer.y > 128) bot = 1; + else if (buffer.y < 128) + top = 1; + + // We map a button to the top direction, this has the advantage + // that when you play with a gamepad you get a more console like + // feeling. + if (BUTTONPRESSED(buffer.buttons, 1)) + { + top = 1; + bot = 0; + } + + button1 = BUTTONPRESSED(buffer.buttons, 5); + button2 = BUTTONPRESSED(buffer.buttons, 2); + // Here we start to convert the values into their internal format, + // better don't touch this + + // Reverse top/buttom formats if (left) top = !top; if (right) bot = !bot; + + // Autofire + { + static long lasttime = 0; + static int button_pressed = 0; + if (BUTTONPRESSED(buffer.buttons, 4)) + { + struct timeval tv; + long t; + gettimeofday(&tv, NULL); + t = (long) tv.tv_sec*(long) 1000 + (long) tv.tv_usec/(long) 1000; + + if (lasttime == 0) + { + button_pressed = 1; + lasttime = t; + } + else if (lasttime + BUTTON_REPEAT_TIME < t) + { + button_pressed = !button_pressed; + lasttime = t; + } + + button1 = button_pressed; + } + else + { + lasttime = 0; + button_pressed = 0; + } + } + + // Encode the booleon values into the right format + *button = button1 | (button2 << 1); *dir = bot | (right << 1) | (top << 8) | (left << 9); - *button = buffer.buttons & 3; } void init_joystick(void)