From 80e7237ae7ed2a228cb9d7eed00ddc6381cf00c8 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Wed, 10 Oct 2001 03:01:30 +0000 Subject: [PATCH] Replacing win32 joystick (broken) with SDL joystick (stubs) --- input/Makefile.am | 10 +- input/sdl_joy.c | 109 +++++++ input/sdl_joydefs.c | 31 ++ input/win32_joydefs.c | 149 ---------- input/win32_joyhh.c | 667 ------------------------------------------ 5 files changed, 144 insertions(+), 822 deletions(-) create mode 100644 input/sdl_joy.c create mode 100644 input/sdl_joydefs.c delete mode 100644 input/win32_joydefs.c delete mode 100644 input/win32_joyhh.c diff --git a/input/Makefile.am b/input/Makefile.am index a2909e63..eae74938 100644 --- a/input/Makefile.am +++ b/input/Makefile.am @@ -16,8 +16,7 @@ libinput_a_SOURCES = linux_joydefs.c linux_joystick.c \ svgalib_event.c svgalib_key.c svgalib_mouse.c svgalib_init.c else if ENV_CYGWIN -libinput_a_SOURCES = sdl_event.c sdl_key.c sdl_mouse.c \ -win32_joydefs.c win32_joyhh.c +libinput_a_SOURCES = sdl_event.c sdl_key.c sdl_mouse.c sdl_joy.c sdl_joydefs.c else libinput_a_SOURCES = linux_joydefs.c linux_joystick.c \ sdl_event.c sdl_key.c sdl_mouse.c @@ -30,16 +29,15 @@ EXTRA_libinput_a_SOURCES = \ dos_key.c dos_joyc.c dos_joydefs.c dos_mouse.c \ ggi_event.c ggi_key.c ggi_mouse.c \ linux_joydefs.c linux_joystick.c \ -sdl_event.c sdl_key.c sdl_mouse.c \ -svgalib_event.c svgalib_key.c svgalib_mouse.c svgalib_init.c \ -win32_joydefs.c win32_joyhh.c +sdl_event.c sdl_key.c sdl_mouse.c sdl_joy.c sdl_joydefs.c \ +svgalib_event.c svgalib_key.c svgalib_mouse.c svgalib_init.c SUFFIXES = .asm %.o: %.asm $(NASM) $(NASMFLAGS) $< -o $@ if ENV_DJGPP -libinput_a_LIBADD += dos_joy2.o +libinput_a_LIBADD = dos_joy2.o endif EXTRA_DIST = \ diff --git a/input/sdl_joy.c b/input/sdl_joy.c new file mode 100644 index 00000000..076ac43e --- /dev/null +++ b/input/sdl_joy.c @@ -0,0 +1,109 @@ +/* + * $Source: /cvs/cvsroot/d2x/input/sdl_joy.c,v $ + * $Revision: 1.1 $ + * $Author: bradleyb $ + * $Date: 2001-10-10 03:01:29 $ + * + * SDL joystick support + * + * $Log: not supported by cvs2svn $ + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "joy.h" +#include "error.h" + +char joy_present = 0; + +int +joy_init() +{ + if (SDL_Init( SDL_INIT_JOYSTICK ) < 0) + { + Warning("SDL library initialisation failed: %s.", SDL_GetError()); + return 0; + } + + + + return 1; +} + +void +joy_close() +{ + return; +} + +void +joy_get_pos(int *x, int *y) +{ + *x = *y = 0; + return; +} + +int +joy_get_btns() +{ + return 0; +} + +int +joy_get_button_down_cnt(int btn) +{ + return 0; +} + +fix +joy_get_button_down_time(int btn) +{ + return 0; +} + +ubyte +joystick_read_raw_axis(ubyte mask, int *axis) +{ + return 0; +} + +void +joy_flush() +{ + return; +} + +int +joy_get_button_state(int btn) +{ + return 0; +} + +void +joy_get_cal_vals(int *axis_min, int *axis_center, int *axis_max) +{ + return; +} + +void +joy_set_cal_vals(int *axis_min, int *axis_center, int *axis_max) +{ + return; +} + +int +joy_get_scaled_reading(int raw, int axn) +{ + return 0; +} + +void +joy_set_slow_reading(int flag) +{ + return; +} diff --git a/input/sdl_joydefs.c b/input/sdl_joydefs.c new file mode 100644 index 00000000..5f48a00e --- /dev/null +++ b/input/sdl_joydefs.c @@ -0,0 +1,31 @@ +/* + * $Source: /cvs/cvsroot/d2x/input/sdl_joydefs.c,v $ + * $Revision: 1.1 $ + * $Author: bradleyb $ + * $Date: 2001-10-10 03:01:29 $ + * + * SDL joystick support + * + * $Log: not supported by cvs2svn $ + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "joydefs.h" + +int joydefs_calibrate_flag = 0; + +void +joydefs_calibrate() +{ + return; +} + +void +joydefs_config() +{ + return; +} diff --git a/input/win32_joydefs.c b/input/win32_joydefs.c deleted file mode 100644 index 2cd9ea4c..00000000 --- a/input/win32_joydefs.c +++ /dev/null @@ -1,149 +0,0 @@ -/* -THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include "mono.h" -#include "key.h" -#include "joy.h" -#include "timer.h" -#include "error.h" - -#include "inferno.h" -#include "game.h" -#include "object.h" -#include "player.h" - -#include "controls.h" -#include "joydefs.h" -#include "render.h" -#include "palette.h" -#include "newmenu.h" -#include "args.h" -#include "text.h" -#include "kconfig.h" -#include "digi.h" -#include "playsave.h" - -int joydefs_calibrate_flag=0; - -int Joy_is_Sidewinder=0; //not needed, but lots of main/* stuff use it - -void joy_delay() -{ - -} - -int joycal_message( char * title, char * text ) -{ - int i; - newmenu_item m[2]; - m[0].type = NM_TYPE_TEXT; m[0].text = text; - m[1].type = NM_TYPE_MENU; m[1].text = TXT_OK; - i = newmenu_do( title, NULL, 2, m, NULL ); - if ( i < 0 ) - return 1; - return 0; -} - -void joydefs_calibrate() -{ - joycal_message("No Calibration", "calibration should be performed\nthrough windows"); - return; -} - -void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem ) -{ - int i; - int oc_type = Config_control_type; - - nitems = nitems; - last_key = last_key; - citem = citem; - - for (i=0; i<3; i++ ) - if (items[i].value) Config_control_type = i; - - if (Config_control_type == 2) Config_control_type = CONTROL_MOUSE; - - if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) ) { - nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS ); - } - - if (oc_type != Config_control_type) { - switch (Config_control_type) { - // case CONTROL_NONE: - case CONTROL_JOYSTICK: - case CONTROL_FLIGHTSTICK_PRO: - case CONTROL_THRUSTMASTER_FCS: - case CONTROL_GRAVIS_GAMEPAD: - // case CONTROL_MOUSE: - // case CONTROL_CYBERMAN: - joydefs_calibrate_flag = 1; - } - kc_set_controls(); - } - -} - -extern ubyte kc_use_external_control; -extern ubyte kc_enable_external_control; -extern ubyte *kc_external_name; - -void joydefs_config() -{ - newmenu_item m[13]; - int i, j, i1=0, nitems=7; - - m[0].type = NM_TYPE_RADIO; m[0].text = "KEYBOARD"; m[0].value = 0; m[0].group = 0; - m[1].type = NM_TYPE_RADIO; m[1].text = "JOYSTICK"; m[1].value = 0; m[1].group = 0; - m[2].type = NM_TYPE_RADIO; m[2].text = "MOUSE"; m[2].value = 0; m[2].group = 0; - m[3].type = NM_TYPE_TEXT; m[3].text=""; - m[4].type = NM_TYPE_MENU; m[4].text="CUSTOMIZE ABOVE"; - m[5].type = NM_TYPE_MENU; m[5].text="CUSTOMIZE KEYBOARD"; - m[6].type = NM_TYPE_MENU; m[6].text="CUSTOMIZE D1X KEYS"; - - do { - i = Config_control_type; - if(i==CONTROL_MOUSE) i = 2; - m[i].value=1; - i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 ); - -//added 6-15-99 Owen Evans - for (j = 0; j <= 2; j++) - if (m[j].value) - Config_control_type = j; - i = Config_control_type; - if (Config_control_type == 2) - Config_control_type = CONTROL_MOUSE; -//end added - OE - - switch(i1) { - case 4: - kconfig (i, m[i].text); - break; - case 5: - kconfig(0, "KEYBOARD"); - break; - case 6: - kconfig(3, "D1X KEYS"); - break; - } - } while(i1>-1); -} diff --git a/input/win32_joyhh.c b/input/win32_joyhh.c deleted file mode 100644 index 0bf9c97b..00000000 --- a/input/win32_joyhh.c +++ /dev/null @@ -1,667 +0,0 @@ -//JOYC.C for D1_3Dfx and D1OpenGL -//D1_3Dfx is a Win32 executable using Glide and DirectX 3 -//D1OpenGL is a Win32 executable using OpenGL and DirectX 3 -//This joystick code should run on DirectInput 2 and higher -//We are not using DirectX 5 for now, since we want to stay compatible to the HH-loved Windows NT :). -//So ForceFeedback is not supported - -//Notes: -// 1) Windows DirectX supports up to 7 axes, D1/DOS only 4, so we needed to increase the number to 7 at several points -// Also JOY_ALL_AXIS must be (1+2+4+8+16+32+64) in JOY.H file -// 2) Windows DirectX supports up to 32 buttons. So far we however only support 4. Adding support for more should be however easily possible. -// 3) _enable and _disable are not needed -// 4) joy_bogus_reading is not needed, so all calls are just removed -// 5) The joystick query goes over the DirectInputs function -// MMRESULT joyGetPosEx(UINT uJoyID, LPJOYINFOEX pji); -// All functions reading over BIOS, including the ASM code are removed - - - -/* -THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ - -/* -Modifications by Heiko Herrmann -Later modified by Owen Evans to work with D1X (3/7/99) -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#define _WIN32_OS //HH - - -#include //HH -#include //HH -#include -#include - -#undef min /* kludge */ -#undef max /* kludge */ -#include "pstypes.h" -#include "joy.h" -#include "timer.h" - -#define my_hwnd g_hWnd // D1X compatibility -extern HWND g_hWnd; - -char joy_installed = 0; -char joy_present = 0; - -typedef struct Button_info { - ubyte ignore; - ubyte state; - ubyte last_state; - int timedown; - ubyte downcount; - ubyte upcount; -} Button_info; - -typedef struct Joy_info { - int joyid; - ubyte present_mask; - ubyte slow_read; - int max_timer; - int read_count; - ubyte last_value; - Button_info buttons[MAX_BUTTONS]; - int axis_min[JOY_NUM_AXES]; //changed - int axis_center[JOY_NUM_AXES]; //changed --orulz - int axis_max[JOY_NUM_AXES]; //changed -} Joy_info; - -Joy_info joystick; - - -int joy_deadzone = 0; - -void joy_get_cal_vals(int *axis_min, int *axis_center, int *axis_max) -{ - int i; - - for (i=0; iignore) { - if ( i < (MAX_BUTTONS-4) ) - state = (value >> i) & 1; - else - state = 0; - - if ( button->last_state == state ) { - if (state) { - button->timedown += time_diff; //ticks_this_time; - } - } else { - if (state) { - button->downcount += state; - button->state = 1; - } else { - button->upcount += button->state; - button->state = 0; - } - button->last_state = state; - } - } - } - - time_last = time_now; -#endif - return 0; -} - - -//Begin section modified 3/7/99 - Owen Evans - -ubyte joy_read_raw_buttons() -{ -#if 0 - JOYINFOEX joy; - int i; - - if (!joy_present) - return 0; - - memset(&joy, 0, sizeof(joy)); - joy.dwSize = sizeof(joy); - joy.dwFlags = JOY_RETURNBUTTONS | JOY_RETURNPOVCTS | JOY_USEDEADZONE; - - if (joyGetPosEx(joystick.joyid, &joy)!=JOYERR_NOERROR) - return 0; - - for (i = 0; i < MAX_BUTTONS; i++) { - joystick.buttons[i].last_state = joystick.buttons[i].state; - joystick.buttons[i].state = (joy.dwButtons >> i) & 0x1; - if (!joystick.buttons[i].last_state && joystick.buttons[i].state) { - joystick.buttons[i].timedown = timer_get_fixed_seconds(); - joystick.buttons[i].downcount++; - } - } - - /* Hat stuff */ - - if (joy.dwPOV != JOY_POVCENTERED) - { - joystick.buttons[19].state = (joy.dwPOV < JOY_POVRIGHT || joy.dwPOV > JOY_POVLEFT); - joystick.buttons[15].state = (joy.dwPOV < JOY_POVBACKWARD && joy.dwPOV > JOY_POVFORWARD); - joystick.buttons[11].state = (joy.dwPOV < JOY_POVLEFT && joy.dwPOV > JOY_POVRIGHT); - joystick.buttons[7].state = (joy.dwPOV > JOY_POVBACKWARD); - } - - return (ubyte)joy.dwButtons; -#else - return 0; -#endif -} - -//end changed section - OE - - -ubyte joystick_read_raw_axis( ubyte mask, int * axis ) -{ -#if 0 - JOYINFOEX joy; - ubyte read_masks = 0; - - axis[0] = 0; axis[1] = 0; //orulz: 1=x 2=y 3=r 4=z 5=u 6=v - axis[2] = 0; axis[3] = 0; - axis[4] = 0; axis[5] = 0; //HH: Added support for axes R and U - - if (!joy_installed) { - return 0; - } - - memset(&joy, 0, sizeof(joy)); - joy.dwSize = sizeof(joy); - joy.dwFlags = JOY_RETURNALL | JOY_USEDEADZONE; - if (joyGetPosEx(joystick.joyid, &joy)!=JOYERR_NOERROR) { - return 0; - } - - mask &= joystick.present_mask; // Don't read non-present channels - if ( mask==0 ) { - return 0; // Don't read if no stick connected. - } - - if (mask & JOY_1_X_AXIS) { axis[0] = joy.dwXpos; read_masks |= JOY_1_X_AXIS; } - if (mask & JOY_1_Y_AXIS) { axis[1] = joy.dwYpos; read_masks |= JOY_1_Y_AXIS; } -//orulz: -// if (mask & JOY_1_Z_AXIS) { axis[2] = joy.dwZpos; read_masks |= JOY_1_Z_AXIS; } -// if (mask & JOY_1_POV) { axis[3] = joy.dwPOV; read_masks |= JOY_1_POV; } -// if (mask & JOY_1_R_AXIS) { axis[4] = joy.dwRpos; read_masks |= JOY_1_R_AXIS; } -// if (mask & JOY_1_U_AXIS) { axis[5] = joy.dwUpos; read_masks |= JOY_1_U_AXIS; } -// if (mask & JOY_1_V_AXIS) { axis[6] = joy.dwVpos; read_masks |= JOY_1_V_AXIS; } - if (mask & JOY_1_R_AXIS) { axis[2] = joy.dwRpos; read_masks |= JOY_1_R_AXIS; } - if (mask & JOY_1_Z_AXIS) { axis[3] = joy.dwZpos; read_masks |= JOY_1_Z_AXIS; } - if (mask & JOY_1_U_AXIS) { axis[4] = joy.dwZpos; read_masks |= JOY_1_U_AXIS; } - if (mask & JOY_1_V_AXIS) { axis[5] = joy.dwUpos; read_masks |= JOY_1_V_AXIS; } - - return read_masks; -} - -int hh_average(int val1, int val2) -{ - return abs(val1-val2)/2; -} - -int joy_init(int joyid) //HH: added joyid parameter -{ - int i; - int temp_axis[JOY_NUM_AXES]; //changed - orulz - JOYCAPS pjc; - - atexit(joy_close); //HH: we are a bit lazy :). Errors are ignored, so we are even double-lazy :) - - joy_flush(); - memset(&joystick, 0, sizeof(joystick)); - - for (i=0; i 127 ) x = 127; - -//added on 4/13/99 by Victor Rachels to add deadzone control - d = (joy_deadzone) * 6; - if ((x > (-1*d)) && (x < d)) - x = 0; -//end this section addition -VR - - return x; -} - -void joy_get_pos( int *x, int *y ) -{ - ubyte flags; - int axis[JOY_NUM_AXES]; - - if ((!joy_installed)||(!joy_present)) { *x=*y=0; return; } - - flags=joystick_read_raw_axis( JOY_1_X_AXIS+JOY_1_Y_AXIS, axis ); - - if ( flags & JOY_1_X_AXIS ) - *x = joy_get_scaled_reading( axis[0], 0 ); - else - *x = 0; - - if ( flags & JOY_1_Y_AXIS ) - *y = joy_get_scaled_reading( axis[1], 1 ); - else - *y = 0; -} - -ubyte joy_read_stick( ubyte masks, int *axis ) -{ - ubyte flags; - int raw_axis[JOY_NUM_AXES]; - - if ((!joy_installed)||(!joy_present)) { - axis[0] = 0; axis[1] = 0; - axis[2] = 0; axis[3] = 0; - axis[4] = 0; axis[5] = 0; - return 0; - } - - flags=joystick_read_raw_axis( masks, raw_axis ); - - if ( flags & JOY_1_X_AXIS ) - axis[0] = joy_get_scaled_reading( raw_axis[0], 0 ); - else - axis[0] = 0; - - if ( flags & JOY_1_Y_AXIS ) - axis[1] = joy_get_scaled_reading( raw_axis[1], 1 ); - else - axis[1] = 0; - - if ( flags & JOY_1_R_AXIS ) - axis[2] = joy_get_scaled_reading( raw_axis[2], 2 ); - else - axis[2] = 0; - - if ( flags & JOY_1_Z_AXIS ) - axis[3] = joy_get_scaled_reading( raw_axis[3], 3 ); - else - axis[3] = 0; - - if ( flags & JOY_1_U_AXIS ) - axis[4] = joy_get_scaled_reading( raw_axis[4], 4); - else - axis[4] = 0; - - if ( flags & JOY_1_V_AXIS ) - axis[5] = joy_get_scaled_reading( raw_axis[5], 5 ); - else - axis[5] = 0; - - - return flags; -} - -int joy_get_btns() -{ - if ((!joy_installed)||(!joy_present)) return 0; - - return joy_read_raw_buttons(); -} - - -//Begin section modified 3/7/99 - Owen Evans - -void joy_get_btn_down_cnt( int *btn0, int *btn1 ) -{ - if ((!joy_installed)||(!joy_present)) { *btn0=*btn1=0; return; } - - joy_get_btns(); - - *btn0 = joystick.buttons[0].downcount; - joystick.buttons[0].downcount = 0; - *btn1 = joystick.buttons[1].downcount; - joystick.buttons[1].downcount = 0; -} - -int joy_get_button_state( int btn ) -{ - if ((!joy_installed)||(!joy_present)) return 0; - if ( btn >= MAX_BUTTONS ) return 0; - - joy_get_btns(); - - return joystick.buttons[btn].state; -} - -int joy_get_button_up_cnt( int btn ) -{ - int count; - - if ((!joy_installed)||(!joy_present)) return 0; - - if ( btn >= MAX_BUTTONS ) return 0; - - count = joystick.buttons[btn].upcount; - joystick.buttons[btn].upcount = 0; - - return count; -} - -int joy_get_button_down_cnt( int btn ) -{ - int count; - - if ((!joy_installed)||(!joy_present)) return 0; - if ( btn >= MAX_BUTTONS ) return 0; - - joy_get_btns(); - - count = joystick.buttons[btn].downcount; - joystick.buttons[btn].downcount = 0; - - return count; -} - -fix joy_get_button_down_time( int btn ) -{ - fix count; - - if ((!joy_installed)||(!joy_present)) return 0; - if ( btn >= MAX_BUTTONS ) return 0; - - joy_get_btns(); - - if (joystick.buttons[btn].state) { - count = timer_get_fixed_seconds() - joystick.buttons[btn].timedown; - joystick.buttons[btn].timedown = 0; - } else count = 0; - - return count; -} - -//end changed section - OE - - -void joy_get_btn_up_cnt( int *btn0, int *btn1 ) -{ - if ((!joy_installed)||(!joy_present)) { *btn0=*btn1=0; return; } - - *btn0 = joystick.buttons[0].upcount; - joystick.buttons[0].upcount = 0; - *btn1 = joystick.buttons[1].upcount; - joystick.buttons[1].upcount = 0; -} - -#if 0 -void joy_set_btn_values( int btn, int state, fix timedown, int downcount, int upcount ) -{ - joystick.buttons[btn].ignore = 1; - joystick.buttons[btn].state = state; - joystick.buttons[btn].timedown = fixmuldiv( timedown, 1193180, 65536 ); - joystick.buttons[btn].downcount = downcount; - joystick.buttons[btn].upcount = upcount; -} -#endif - -void joy_poll() -{ -} - -void joy_set_slow_reading(int flag) { -} - -int joy_init(void) -{ - return 0; -} -- 2.39.2