diff --git a/ChangeLog b/ChangeLog index d8f119228..81f2cef66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-11-22 Bradley Bell + + * configure.ac, arch/include/joy.h, arch/linux/joydefs.c, + arch/linux/joystick.c, arch/linux/include/joystick.h, + arch/sdl/joy.c, main/kconfig.c: Fix sdl joystick axis problem, all + arch use global variable joy_num_axes + 2004-11-19 Chris Taylor * main/gamemine.c, main/piggy.c: compile again on older C compilers diff --git a/arch/include/joy.h b/arch/include/joy.h index 31bb44a76..dc6f7b21e 100644 --- a/arch/include/joy.h +++ b/arch/include/joy.h @@ -1,4 +1,4 @@ -/* $Id: joy.h,v 1.8 2004-08-28 23:17:45 schaffner Exp $ */ +/* $Id: joy.h,v 1.9 2004-11-22 23:32:54 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -39,6 +39,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define JOY_1_U_AXIS 32 #define JOY_1_V_AXIS 64 +#define JOY_MAX_AXES 32 + #if defined WINDOWS #define JOY_NUM_AXES 7 #elif defined USE_LINUX_JOY @@ -89,6 +91,13 @@ extern void joy_close(); extern char joy_installed; extern char joy_present; + +//========================================================================== +// The actual number of available axes. If the arch can't set this +// properly, it should set joy_num_axes=JOY_NUM_AXES; +extern int joy_num_axes; + + //========================================================================== // The following 3 routines can be used to zero in on better joy // calibration factors. To use them, ask the user to hold the stick diff --git a/arch/linux/include/joystick.h b/arch/linux/include/joystick.h index 184db9b16..03203fb6d 100644 --- a/arch/linux/include/joystick.h +++ b/arch/linux/include/joystick.h @@ -1,6 +1,4 @@ -/* $Id: joystick.h,v 1.3 2004-05-22 01:32:13 btb Exp $ */ - -#define MAX_AXES 32 +/* $Id: joystick.h,v 1.4 2004-11-22 23:32:54 btb Exp $ */ typedef struct joystick_device { int device_number; @@ -33,7 +31,7 @@ extern int j_num_axes; extern int j_num_buttons; extern joystick_device j_joystick[MAX_JOY_DEVS]; -extern joystick_axis j_axis[MAX_AXES]; +extern joystick_axis j_axis[JOY_MAX_AXES]; extern joystick_button j_button[MAX_BUTTONS]; extern int j_Update_state (); diff --git a/arch/linux/joydefs.c b/arch/linux/joydefs.c index 4e0538dad..1a6b43918 100644 --- a/arch/linux/joydefs.c +++ b/arch/linux/joydefs.c @@ -1,4 +1,4 @@ -/* $Id: joydefs.c,v 1.3 2004-05-22 01:32:11 btb Exp $ */ +/* $Id: joydefs.c,v 1.4 2004-11-22 23:32:54 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -83,14 +83,14 @@ int joycal_message( char * title, char * text ) extern int WriteConfigFile(); extern joystick_device j_joystick[MAX_JOY_DEVS]; -extern joystick_axis j_axis[MAX_AXES]; +extern joystick_axis j_axis[JOY_MAX_AXES]; extern joystick_button j_button[MAX_BUTTONS]; void joydefs_calibrate() { int i; - int temp_values[MAX_AXES]; + int temp_values[JOY_MAX_AXES]; char title[50]; char text[256]; //added/killed on 10/17/98 by Hans de Goede for joystick/mouse # fix @@ -108,8 +108,9 @@ void joydefs_calibrate() joycal_message ("No Calibration", "calibration not required for\njoystick v1.x"); return; } - - for (i = 0; i < j_num_axes; i += 2) { + + for (i = 0; i < joy_num_axes; i += 2) + { sprintf (title, "js%d Calibration", j_axis[i].joydev); sprintf (text, "center joystick %d", j_axis[i].joydev); diff --git a/arch/linux/joystick.c b/arch/linux/joystick.c index b76203bfe..8bef9b253 100644 --- a/arch/linux/joystick.c +++ b/arch/linux/joystick.c @@ -1,4 +1,4 @@ -/* $Id: joystick.c,v 1.5 2004-05-22 07:31:38 btb Exp $ */ +/* $Id: joystick.c,v 1.6 2004-11-22 23:32:54 btb Exp $ */ /* * * Linux joystick support @@ -27,10 +27,10 @@ char joy_installed = 0; char joy_present = 0; joystick_device j_joystick[MAX_JOY_DEVS]; -joystick_axis j_axis[MAX_AXES]; +joystick_axis j_axis[JOY_MAX_AXES]; joystick_button j_button[MAX_BUTTONS]; -int j_num_axes = 0, j_num_buttons = 0; +int joy_num_axes = 0, j_num_buttons = 0; int timer_rate; int j_axes_in_sticks[MAX_JOY_DEVS]; /* number of axes in the first [x] sticks */ @@ -125,7 +125,7 @@ void joy_set_cal_vals(int *axis_min, int *axis_center, int *axis_max) void joy_get_cal_vals(int *axis_min, int *axis_center, int *axis_max) { int i; - //edited 05/18/99 Matt Mueller - we should return all axes instead of j_num_axes, since they are all given to us in joy_set_cal_vals ( and because checker complains :) + //edited 05/18/99 Matt Mueller - we should return all axes instead of joy_num_axes, since they are all given to us in joy_set_cal_vals ( and because checker complains :) for (i = 0; i < JOY_NUM_AXES; i++) { //end edit -MM @@ -186,7 +186,8 @@ ubyte joystick_read_raw_axis (ubyte mask, int *axes) { return 0; j_Update_state(); - for (i = 0; i < j_num_axes; i++) { + for (i = 0; i < joy_num_axes; i++) + { axes[i] = j_axis[i].value; } @@ -249,7 +250,8 @@ int joy_init () { j_joystick[i].version & 0xff); } - for (j = j_num_axes; j < (j_num_axes + j_joystick[i].num_axes); j++) { + for (j = joy_num_axes; j < (joy_num_axes + j_joystick[i].num_axes); j++) + { j_axis[j].joydev = i; if (j_joystick[i].version) { j_axis[j].center_val = 0; @@ -261,7 +263,7 @@ int joy_init () { j_button[j].joydev = i; } - j_num_axes += j_joystick[i].num_axes; + joy_num_axes += j_joystick[i].num_axes; j_num_buttons += j_joystick[i].num_buttons; } else { @@ -281,8 +283,8 @@ int joy_init () { printf ("\n"); - if (j_num_axes > MAX_AXES) - j_num_axes = MAX_AXES; + if (joy_num_axes > JOY_MAX_AXES) + joy_num_axes = JOY_MAX_AXES; if (j_num_buttons > MAX_BUTTONS) j_num_buttons = MAX_BUTTONS; @@ -351,8 +353,9 @@ int joy_get_scaled_reading(int raw, int axis_num) } -void joy_get_pos(int *x, int *y) { - int axis[MAX_AXES]; +void joy_get_pos(int *x, int *y) +{ + int axis[JOY_MAX_AXES]; if ((!joy_installed)||(!joy_present)) { *x=*y=0; return; } diff --git a/arch/sdl/joy.c b/arch/sdl/joy.c index e06f82ec4..0b1e0fe83 100644 --- a/arch/sdl/joy.c +++ b/arch/sdl/joy.c @@ -1,4 +1,4 @@ -/* $Id: joy.c,v 1.13 2004-05-15 16:25:35 schaffner Exp $ */ +/* $Id: joy.c,v 1.14 2004-11-22 23:32:54 btb Exp $ */ /* * * SDL joystick support @@ -21,7 +21,6 @@ #include "text.h" #define MAX_JOYSTICKS 16 -#define MAX_AXES 32 #define MAX_AXES_PER_JOYSTICK 8 #define MAX_BUTTONS_PER_JOYSTICK 16 @@ -34,6 +33,8 @@ int num_joysticks = 0; int joy_deadzone = 0; +int joy_num_axes = 0; + struct joybutton { int state; int last_state; @@ -49,13 +50,19 @@ struct joyaxis { int max_val; }; +/* This struct is a "virtual" joystick, which includes all the axes + * and buttons of every joystick found. + */ static struct joyinfo { int n_axes; int n_buttons; - struct joyaxis axes[MAX_AXES]; + struct joyaxis axes[JOY_MAX_AXES]; struct joybutton buttons[MAX_BUTTONS]; } Joystick; +/* This struct is an array, with one entry for each physical joystick + * found. + */ static struct { SDL_Joystick *handle; int n_axes; @@ -202,6 +209,8 @@ int joy_init() con_printf(CON_VERBOSE, "sdl-joystick: %d buttons (total)\n", Joystick.n_buttons); } + joy_num_axes = Joystick.n_axes; + return joy_present; } @@ -213,7 +222,7 @@ void joy_close() void joy_get_pos(int *x, int *y) { - int axis[MAX_AXES]; + int axis[JOY_MAX_AXES]; if (!num_joysticks) { *x=*y=0; @@ -292,7 +301,7 @@ ubyte joystick_read_raw_axis( ubyte mask, int * axis ) event_poll(); - for (i = 0; i < JOY_NUM_AXES; i++) { + for (i = 0; i < Joystick.n_axes; i++) { if ((axis[i] = Joystick.axes[i].value)) channel_masks |= 1 << i; } @@ -331,7 +340,7 @@ void joy_get_cal_vals(int *axis_min, int *axis_center, int *axis_max) { int i; - for (i = 0; i < JOY_NUM_AXES; i++) { + for (i = 0; i < Joystick.n_axes; i++) { axis_center[i] = Joystick.axes[i].center_val; axis_min[i] = Joystick.axes[i].min_val; axis_max[i] = Joystick.axes[i].max_val; @@ -342,7 +351,7 @@ void joy_set_cal_vals(int *axis_min, int *axis_center, int *axis_max) { int i; - for (i = 0; i < JOY_NUM_AXES; i++) { + for (i = 0; i < Joystick.n_axes; i++) { Joystick.axes[i].center_val = axis_center[i]; Joystick.axes[i].min_val = axis_min[i]; Joystick.axes[i].max_val = axis_max[i]; diff --git a/configure.ac b/configure.ac index 84dcc3089..1f82d60be 100644 --- a/configure.ac +++ b/configure.ac @@ -129,6 +129,7 @@ AC_ARG_ENABLE(linuxjoy, [ --enable-linuxjoy do not use the SDL Joystick. (eg for MS Sidewinder)],,) if test x$enable_linuxjoy = xyes; then AC_DEFINE(USE_LINUX_JOY,,[define to not use the SDL_Joystick routines.]) + D2X_FEATURES="linuxjoy ${D2X_FEATURES}" fi AM_CONDITIONAL(USE_LINUX_JOY, test x$enable_linuxjoy = xyes) diff --git a/main/kconfig.c b/main/kconfig.c index ca02cbf75..3c55218cf 100644 --- a/main/kconfig.c +++ b/main/kconfig.c @@ -1,4 +1,4 @@ -/* $Id: kconfig.c,v 1.32 2004-08-28 23:17:45 schaffner Exp $ */ +/* $Id: kconfig.c,v 1.33 2004-11-22 23:32:54 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -23,7 +23,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: kconfig.c,v 1.32 2004-08-28 23:17:45 schaffner Exp $"; +static char rcsid[] = "$Id: kconfig.c,v 1.33 2004-11-22 23:32:54 btb Exp $"; #endif #ifdef WINDOWS @@ -1694,11 +1694,7 @@ void kc_next_joyaxis(kc_item *item) // I modelled this ifdef after the code in the kc_change_joyaxis method. // So, if somethin's not workin here, it might not be workin there either. -#ifdef USE_LINUX_JOY - max = 32; -#else - max = JOY_NUM_AXES; -#endif + max = JOY_MAX_AXES; tries = 1; code = (item->value + 1) % max; @@ -1729,15 +1725,9 @@ void kc_next_joyaxis(kc_item *item) void kc_change_joyaxis( kc_item * item ) { -#ifdef USE_LINUX_JOY - int axis[MAX_AXES]; - int old_axis[MAX_AXES]; - int numaxis = j_num_axes; -#else - int axis[JOY_NUM_AXES]; - int old_axis[JOY_NUM_AXES]; - int numaxis = JOY_NUM_AXES; -#endif + int axis[JOY_MAX_AXES]; + int old_axis[JOY_MAX_AXES]; + int numaxis = joy_num_axes; int n,i,k; ubyte code; @@ -2104,11 +2094,7 @@ read_head_tracker() fix LastReadTime = 0; -#ifdef USE_LINUX_JOY -fix joy_axis[MAX_AXES]; -#else -fix joy_axis[JOY_NUM_AXES]; -#endif +fix joy_axis[JOY_MAX_AXES]; ubyte kc_use_external_control = 0; ubyte kc_enable_external_control = 0; @@ -2909,11 +2895,7 @@ void controls_read_all() int idx, idy; fix ctime; fix mouse_axis[3] = {0,0,0}; -#ifdef USE_LINUX_JOY - int raw_joy_axis[MAX_AXES]; -#else - int raw_joy_axis[JOY_NUM_AXES]; -#endif + int raw_joy_axis[JOY_MAX_AXES]; int mouse_buttons; fix k0, k1, k2, k3, kp; fix k4, k5, k6, k7, kh; @@ -2952,12 +2934,8 @@ void controls_read_all() } else if ((Config_control_type>0) && (Config_control_type<5) ) { LastReadTime = ctime; channel_masks = joystick_read_raw_axis( JOY_ALL_AXIS, raw_joy_axis ); - -# ifdef USE_LINUX_JOY - for (i = 0; i < j_num_axes; i++) -# else - for (i = 0; i < JOY_NUM_AXES; i++) -# endif + + for (i = 0; i < joy_num_axes; i++) { #ifndef SDL_INPUT if (channel_masks&(1<