From 84c8953ddb0e55bdb1d5f85d85f854fa08a31e05 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Sat, 22 May 2004 01:32:13 +0000 Subject: [PATCH] patch from Steven Mueller for using more than 4 joystick devices in linux (d1x r1.3, r1.3, r1.3) --- ChangeLog | 6 ++++++ arch/include/joy.h | 4 +++- arch/linux/include/joystick.h | 4 ++-- arch/linux/joydefs.c | 4 ++-- arch/linux/joystick.c | 37 ++++++++++++++++++++++++++--------- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 46dca40c..5397bc6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-05-21 Steven Mueller + + * arch/include/joy.h, arch/linux/joydefs.c, arch/linux/joystick.c, + arch/linux/include/joystick.h: patch from Steven Mueller for using + more than 4 joystick devices in linux (d1x r1.3, r1.3, r1.3) + 2004-05-21 Victor Rachels * main/fvi.c, main/gameseg.c, main/gameseg.h, main/object.c, diff --git a/arch/include/joy.h b/arch/include/joy.h index 56bd3c76..92508a45 100644 --- a/arch/include/joy.h +++ b/arch/include/joy.h @@ -1,4 +1,4 @@ -/* $Id: joy.h,v 1.6 2003-12-18 09:56:13 btb Exp $ */ +/* $Id: joy.h,v 1.7 2004-05-22 01:32:09 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -84,6 +84,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "pstypes.h" #include "fix.h" +// added October 24, 2000 20:40 Steven Mueller: more than 4 joysticks now +#define MAX_JOY_DEVS 8 #define JOY_1_BUTTON_A 1 #define JOY_1_BUTTON_B 2 #define JOY_2_BUTTON_A 4 diff --git a/arch/linux/include/joystick.h b/arch/linux/include/joystick.h index 412284c4..184db9b1 100644 --- a/arch/linux/include/joystick.h +++ b/arch/linux/include/joystick.h @@ -1,4 +1,4 @@ -/* $Id: joystick.h,v 1.2 2003-03-13 00:20:21 btb Exp $ */ +/* $Id: joystick.h,v 1.3 2004-05-22 01:32:13 btb Exp $ */ #define MAX_AXES 32 @@ -32,7 +32,7 @@ typedef struct joystick_button { extern int j_num_axes; extern int j_num_buttons; -extern joystick_device j_joystick[4]; +extern joystick_device j_joystick[MAX_JOY_DEVS]; extern joystick_axis j_axis[MAX_AXES]; extern joystick_button j_button[MAX_BUTTONS]; diff --git a/arch/linux/joydefs.c b/arch/linux/joydefs.c index 85b02773..4e0538da 100644 --- a/arch/linux/joydefs.c +++ b/arch/linux/joydefs.c @@ -1,4 +1,4 @@ -/* $Id: joydefs.c,v 1.2 2003-03-13 00:20:21 btb Exp $ */ +/* $Id: joydefs.c,v 1.3 2004-05-22 01:32:11 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -82,7 +82,7 @@ int joycal_message( char * title, char * text ) extern int WriteConfigFile(); -extern joystick_device j_joystick[4]; +extern joystick_device j_joystick[MAX_JOY_DEVS]; extern joystick_axis j_axis[MAX_AXES]; extern joystick_button j_button[MAX_BUTTONS]; diff --git a/arch/linux/joystick.c b/arch/linux/joystick.c index c4f2b9ab..9a353201 100644 --- a/arch/linux/joystick.c +++ b/arch/linux/joystick.c @@ -1,4 +1,4 @@ -/* $Id: joystick.c,v 1.2 2003-01-01 00:55:03 btb Exp $ */ +/* $Id: joystick.c,v 1.3 2004-05-22 01:32:12 btb Exp $ */ /* * * Linux joystick support @@ -26,15 +26,15 @@ char joy_installed = 0; char joy_present = 0; -joystick_device j_joystick[4]; +joystick_device j_joystick[MAX_JOY_DEVS]; joystick_axis j_axis[MAX_AXES]; joystick_button j_button[MAX_BUTTONS]; int j_num_axes = 0, j_num_buttons = 0; int timer_rate; -int j_axes_in_sticks[4]; /* number of axes in the first [x] sticks */ -int j_buttons_in_sticks[4]; /* number of buttons in the first [x] sticks */ +int j_axes_in_sticks[MAX_JOY_DEVS]; /* number of axes in the first [x] sticks */ +int j_buttons_in_sticks[MAX_JOY_DEVS]; /* number of buttons in the first [x] sticks */ int joy_deadzone = 0; @@ -77,7 +77,8 @@ int j_Update_state () { j_button[i].last_state = j_button[i].state; } - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_JOY_DEVS; i++) + { if (j_joystick[i].buffer >= 0) { if (j_joystick[i].version) { while (read (j_joystick[i].buffer, ¤t_event, sizeof (struct js_event)) > 0) { @@ -194,6 +195,7 @@ ubyte joystick_read_raw_axis (ubyte mask, int *axes) { int joy_init () { int i, j; + int joystick_found; if (joy_installed) return 0; joy_flush (); @@ -206,11 +208,27 @@ int joy_init () { j_joystick[1].buffer = open ("/dev/js1", O_NONBLOCK); j_joystick[2].buffer = open ("/dev/js2", O_NONBLOCK); j_joystick[3].buffer = open ("/dev/js3", O_NONBLOCK); - - if (j_joystick[0].buffer >= 0 || j_joystick[1].buffer >= 0 || j_joystick[2].buffer >= 0 || j_joystick[3].buffer >= 0) { + j_joystick[0].buffer = open("/dev/input/js0", O_NONBLOCK); + j_joystick[1].buffer = open("/dev/input/js1", O_NONBLOCK); + j_joystick[2].buffer = open("/dev/input/js2", O_NONBLOCK); + j_joystick[3].buffer = open("/dev/input/js3", O_NONBLOCK); + + // Determine whether any sticks were found + joystick_found = 0; + for (i = 0; i < MAX_JOY_DEVS; i++) + { + if (j_joystick[i].buffer >= 0) + { + joystick_found = 1; + break; + } + } + if (joystick_found) + { printf ("found: "); - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_JOY_DEVS; i++) + { if (j_joystick[i].buffer >= 0) { ioctl (j_joystick[i].buffer, JSIOCGAXES, &j_joystick[i].num_axes); ioctl (j_joystick[i].buffer, JSIOCGBUTTONS, &j_joystick[i].num_buttons); @@ -278,7 +296,8 @@ void joy_close() { if (!joy_installed) return; - for (i = 0; i < 4; i++) { + for (i = 0; i < MAX_JOY_DEVS; i++) + { if (j_joystick[i].buffer>=0) { printf ("closing js%d\n", i); close (j_joystick[i].buffer); -- 2.39.2