/* 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. */ /* * $Source: /cvsroot/dxx-rebirth/d2x-rebirth/arch/dos/joydefs.c,v $ * $Revision: 1.1.1.1 $ * $Author: zicodxx $ * $Date: 2006/03/17 19:52:48 $ * * . * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include "pstypes.h" #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; void joy_delay() { #ifdef __MSDOS__ int t1 = TICKER + 19/4; // Wait 1/4 second... stop_time(); while( TICKER < t1 ); joy_flush(); start_time(); #endif } 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; } extern int WriteConfigFile(); void joydefs_calibrate() { ubyte masks; int org_axis_min[4]; int org_axis_center[4]; int org_axis_max[4]; int axis_min[4] = { 0, 0, 0, 0 }; int axis_cen[4] = { 0, 0, 0, 0 }; int axis_max[4] = { 0, 0, 0, 0 }; int temp_values[4]; char title[50]; char text[50]; int nsticks = 0; joydefs_calibrate_flag = 0; if ( (Config_control_type!=CONTROL_JOYSTICK) && (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) && (Config_control_type!=CONTROL_THRUSTMASTER_FCS) && (Config_control_type!=CONTROL_GRAVIS_GAMEPAD) ) return; joy_get_cal_vals(org_axis_min, org_axis_center, org_axis_max); joy_set_cen(); joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); if (!joy_present) { nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK ); return; } masks = joy_get_present_mask(); if ( masks == JOY_ALL_AXIS ) nsticks = 2; else nsticks = 1; if ( nsticks == 2 && !Joy_is_Sidewinder) { sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT); sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL); } else { sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT); sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_UL); } if (joycal_message( title, text )) { joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); return; } joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); axis_min[0] = temp_values[0]; axis_min[1] = temp_values[1]; joy_delay(); if ( nsticks == 2 && !Joy_is_Sidewinder) { sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT); sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR); } else { sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT); sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_LR); } if (joycal_message( title, text)) { joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); return; } joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); axis_max[0] = temp_values[0]; axis_max[1] = temp_values[1]; joy_delay(); if ( nsticks == 2 && !Joy_is_Sidewinder) { sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_CENTER); sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_C); } else { sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_CENTER); sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_C); } if (joycal_message( title, text)) { joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); return; } joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); axis_cen[0] = temp_values[0]; axis_cen[1] = temp_values[1]; joy_delay(); // The fcs uses axes 3 for hat, so don't calibrate it. if (Config_control_type == CONTROL_THRUSTMASTER_FCS) { axis_min[3] = 0; axis_cen[3] = temp_values[3]/2; axis_max[3] = temp_values[3]; joy_delay(); } if (Joy_is_Sidewinder || Config_control_type != CONTROL_THRUSTMASTER_FCS) { // masks = joy_get_present_mask(); if ( nsticks == 2 ) { if ( kconfig_is_axes_used(2) || kconfig_is_axes_used(3) ) { if(Joy_is_Sidewinder) { sprintf( title, "%s\nTWIST-LEFT", TXT_JOYSTICK); sprintf( text, "Twist Joystick to \nthe left side"); } else { sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT); sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL); } if (joycal_message( title, text )) { joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); return; } joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); axis_min[2] = temp_values[2]; axis_min[3] = temp_values[3]; joy_delay(); if(Joy_is_Sidewinder) { sprintf( title, "%s\nTWIST-RIGHT", TXT_JOYSTICK); sprintf( text, "Twist Joystick to \nthe right side"); } else { sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT); sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR); } if (joycal_message( title, text )) { joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); return; } joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); axis_max[2] = temp_values[2]; axis_max[3] = temp_values[3]; joy_delay(); if(Joy_is_Sidewinder) { sprintf( title, "%s\nCENTER", TXT_JOYSTICK); sprintf( text, "%s %s",TXT_MOVE_JOYSTICK, TXT_TO_C); } else { sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_CENTER); sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_C); } if (joycal_message( title, text )) { joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); return; } joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); axis_cen[2] = temp_values[2]; axis_cen[3] = temp_values[3]; joy_delay(); } } else if ( (!(masks & JOY_2_X_AXIS)) && (masks & JOY_2_Y_AXIS) ) { if ( kconfig_is_axes_used(3) ) { // A throttle axis!!!!! sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_FORWARD); if (joycal_message( title, TXT_MOVE_THROTTLE_F)) { joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); return; } joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); axis_min[3] = temp_values[3]; joy_delay(); sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_REVERSE); if (joycal_message( title, TXT_MOVE_THROTTLE_R)) { joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); return; } joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); axis_max[3] = temp_values[3]; joy_delay(); sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_CENTER); if (joycal_message( title, TXT_MOVE_THROTTLE_C)) { joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); return; } joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); axis_cen[3] = temp_values[3]; joy_delay(); } } } joy_set_cal_vals(axis_min, axis_cen, axis_max); //added 9/1/98 by Victor Rachels to make sidewinder calibratable /* if(Joy_is_Sidewinder) Config_control_type=tempstick; */ //end this section addition - Victor Rachels WriteConfigFile(); } //char *control_text[CONTROL_MAX_TYPES] = { "Keyboard only", "Joystick", "Flightstick Pro", "Thrustmaster FCS", "Gravis Gamepad", "Mouse", "Cyberman" }; 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-1); switch (Config_control_type) { case CONTROL_JOYSTICK: case CONTROL_FLIGHTSTICK_PRO: case CONTROL_THRUSTMASTER_FCS: case CONTROL_GRAVIS_GAMEPAD: if ( joydefs_calibrate_flag ) joydefs_calibrate(); break; } }