home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / joydefs.c < prev    next >
Text File  |  1998-06-08  |  19KB  |  626 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/joydefs.c $
  15.  * $Revision: 2.2 $
  16.  * $Author: john $
  17.  * $Date: 1995/06/30 12:30:22 $
  18.  * 
  19.  * .
  20.  * 
  21.  * $Log: joydefs.c $
  22.  * Revision 2.2  1995/06/30  12:30:22  john
  23.  * Added -Xname command line.
  24.  * 
  25.  * Revision 2.1  1995/04/06  12:13:20  john
  26.  * Made so you can calibrate Gravis Gamepad.
  27.  * 
  28.  * Revision 2.0  1995/02/27  11:30:27  john
  29.  * New version 2.0, which has no anonymous unions, builds with
  30.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  31.  * 
  32.  * Revision 1.71  1995/02/12  02:06:10  john
  33.  * Fixed bug with joystick incorrectly asking for
  34.  * calibration.
  35.  * 
  36.  * Revision 1.70  1995/01/28  15:58:07  john
  37.  * Made joystick calibration be only when wrong detected in
  38.  * menu or joystick axis changed.
  39.  * 
  40.  * Revision 1.69  1995/01/25  14:37:55  john
  41.  * Made joystick only prompt for calibration once...
  42.  * 
  43.  * Revision 1.68  1995/01/24  16:34:29  john
  44.  * Made so that if you reconfigure joystick and
  45.  * add or subtract an axis, it asks for a recalibration
  46.  * upon leaving.
  47.  * 
  48.  * Revision 1.67  1994/12/29  11:08:51  john
  49.  * Fixed Thrustmaster and Logitech Wingman extreme
  50.  * Hat by reading the y2 axis during the center stage
  51.  * of the calibration, and using 75, 50, 27, and 3 %
  52.  * as values for the 4 positions.
  53.  * 
  54.  * Revision 1.66  1994/12/15  18:17:39  john
  55.  * Fixed warning with previous.
  56.  * 
  57.  * Revision 1.65  1994/12/15  18:15:48  john
  58.  * Made the joy cal only write the .cfg file, not
  59.  * the player file.
  60.  * 
  61.  * Revision 1.64  1994/12/13  14:43:35  john
  62.  * Took out the code in kconfig to build direction array.
  63.  * Called kc_set_controls after selecting a new control type.
  64.  * 
  65.  * Revision 1.63  1994/12/10  12:08:47  john
  66.  * Changed some delays to use TICKER instead of timer_get_fixed_seconds.
  67.  * 
  68.  * Revision 1.62  1994/12/09  11:01:07  mike
  69.  * force calibration of joystick on joystick selection from Controls... menu.
  70.  * 
  71.  * Revision 1.61  1994/12/07  21:50:27  john
  72.  * Put stop/start time around joystick delay.
  73.  * 
  74.  * Revision 1.60  1994/12/07  19:34:39  john
  75.  * Added delay.
  76.  * 
  77.  * Revision 1.59  1994/12/07  18:12:14  john
  78.  * NEatened up joy cal.,
  79.  * 
  80.  * Revision 1.58  1994/12/07  17:07:51  john
  81.  * Fixed up joy cal.
  82.  * 
  83.  * Revision 1.57  1994/12/07  16:48:53  yuan
  84.  * localization
  85.  * 
  86.  * Revision 1.56  1994/12/07  16:05:55  john
  87.  * Changed the way joystick calibration works.
  88.  * 
  89.  * Revision 1.55  1994/12/06  20:15:22  john
  90.  * Took out code that unpauses songs that were never paused.
  91.  * 
  92.  * Revision 1.54  1994/12/06  15:14:09  yuan
  93.  * Localization
  94.  * 
  95.  * Revision 1.53  1994/12/05  16:29:16  john
  96.  * Took out music pause around the cheat menu.
  97.  * 
  98.  * Revision 1.52  1994/12/04  12:39:10  john
  99.  * MAde so that FCS calibration doesn't ask for axis #2.
  100.  * 
  101.  * Revision 1.51  1994/12/03  15:14:59  john
  102.  * Took out the delay mentioned previosuly cause it would
  103.  * cause bigger problems than it helps, especially with netgames.
  104.  * 
  105.  * Revision 1.50  1994/12/03  14:16:14  john
  106.  * Put a delay between screens in joy cal to keep Yuan from
  107.  * double hitting.
  108.  * 
  109.  * Revision 1.49  1994/12/03  11:04:06  john
  110.  * Changed newmenu code a bit to fix bug with bogus
  111.  * backgrounds occcasionally.
  112.  * 
  113.  * Revision 1.48  1994/12/02  11:03:44  yuan
  114.  * Localization.
  115.  * 
  116.  * Revision 1.47  1994/12/02  10:50:33  yuan
  117.  * Localization
  118.  * 
  119.  * Revision 1.46  1994/12/01  12:21:59  john
  120.  * Added code to calibrate 2 joysticks separately.
  121.  * 
  122.  * Revision 1.45  1994/12/01  11:52:31  john
  123.  * Added message when you select FCS to say that if
  124.  * you have WCS, see manuel.
  125.  * 
  126.  * Revision 1.44  1994/11/29  02:26:28  john
  127.  * Made the prompts for upper-left, lower right for joy
  128.  * calibration more obvious.
  129.  * 
  130.  * Revision 1.43  1994/11/26  13:13:59  matt
  131.  * Changed "none" option to "keyboard only"
  132.  * 
  133.  * Revision 1.42  1994/11/21  19:35:13  john
  134.  * Replaced calls to joy_init with if (joy_present)
  135.  * 
  136.  * Revision 1.41  1994/11/21  19:28:34  john
  137.  * Changed warning for no joystick to use nm_messagebox..
  138.  * 
  139.  * Revision 1.40  1994/11/21  19:06:25  john
  140.  * Made it so that it only stops sound when your in game mode. 
  141.  * 
  142.  * Revision 1.39  1994/11/21  11:47:18  john
  143.  * Made sound pause during joystick calibration.
  144.  * 
  145.  * Revision 1.38  1994/11/10  20:34:18  rob
  146.  * Removed menu-specific network mode support in favor in new stuff
  147.  * in newmenu.c
  148.  * 
  149.  * Revision 1.37  1994/11/08  21:21:38  john
  150.  * Made Esc exit joystick calibration.
  151.  * 
  152.  * Revision 1.36  1994/11/08  15:14:42  john
  153.  * Added more calls so net doesn't die in net game.
  154.  * 
  155.  * Revision 1.35  1994/11/08  14:59:12  john
  156.  * Added code to respond to network while in menus.
  157.  * 
  158.  * Revision 1.34  1994/10/24  19:56:32  john
  159.  * Made the new user setup prompt for config options.
  160.  * 
  161.  * Revision 1.33  1994/10/22  14:11:52  mike
  162.  * Suppress compiler warning message.
  163.  * 
  164.  * Revision 1.32  1994/10/19  12:44:24  john
  165.  * Added hours field to player structure.
  166.  * 
  167.  * Revision 1.31  1994/10/17  13:07:13  john
  168.  * Moved the descent.cfg info into the player config file.
  169.  * 
  170.  * Revision 1.30  1994/10/13  21:41:12  john
  171.  * MAde Esc exit out of joystick calibration.
  172.  * 
  173.  * Revision 1.29  1994/10/13  19:22:27  john
  174.  * Added separate config saves for different devices.
  175.  * Made all the devices work together better, such as mice won't
  176.  * get read when you're playing with the joystick.
  177.  * 
  178.  * Revision 1.28  1994/10/13  11:40:18  john
  179.  * Took out warnings.
  180.  * 
  181.  * Revision 1.27  1994/10/13  11:35:23  john
  182.  * Made Thrustmaster FCS Hat work.  Put a background behind the
  183.  * keyboard configure.  Took out turn_sensitivity.  Changed sound/config
  184.  * menu to new menu. Made F6 be calibrate joystick.
  185.  * 
  186.  * Revision 1.26  1994/10/11  21:29:03  matt
  187.  * Made a bunch of menus have good initial selected values
  188.  * 
  189.  * Revision 1.25  1994/10/11  17:08:39  john
  190.  * Added sliders for volume controls.
  191.  * 
  192.  * Revision 1.24  1994/10/10  17:59:21  john
  193.  * Neatend previous.
  194.  * 
  195.  * Revision 1.23  1994/10/10  17:57:59  john
  196.  * Neatend previous.
  197.  * 
  198.  * Revision 1.22  1994/10/10  17:56:11  john
  199.  * Added messagebox that tells that config has been saved.
  200.  * 
  201.  * Revision 1.21  1994/09/30  12:37:26  john
  202.  * Added midi,digi volume to configuration.
  203.  * 
  204.  * Revision 1.20  1994/09/22  16:14:14  john
  205.  * Redid intro sequecing.
  206.  * 
  207.  * Revision 1.19  1994/09/19  18:50:15  john
  208.  * Added switch to disable joystick.
  209.  * 
  210.  * Revision 1.18  1994/09/12  11:47:36  john
  211.  * Made stupid cruise work better.  Make kconfig values get
  212.  * read/written to disk.
  213.  * 
  214.  * Revision 1.17  1994/09/10  15:46:47  john
  215.  * First version of new keyboard configuration.
  216.  * 
  217.  * Revision 1.16  1994/09/06  19:35:44  john
  218.  * Fixed bug that didn';t load new size .cal file.
  219.  * 
  220.  * Revision 1.15  1994/09/06  14:51:58  john
  221.  * Added sensitivity adjustment, fixed bug with joystick button not
  222.  * staying down.
  223.  * 
  224.  * Revision 1.14  1994/09/02  16:13:47  john
  225.  * Made keys fill in position.
  226.  * 
  227.  * Revision 1.13  1994/08/31  17:58:50  john
  228.  * Made a bit simpler.
  229.  * 
  230.  * Revision 1.12  1994/08/31  14:17:54  john
  231.  * *** empty log message ***
  232.  * 
  233.  * Revision 1.11  1994/08/31  14:10:56  john
  234.  * Made keys not work when KEY_DELETE pressed.
  235.  * 
  236.  * Revision 1.10  1994/08/31  13:40:47  mike
  237.  * Change constant
  238.  * 
  239.  * Revision 1.9  1994/08/31  12:56:27  john
  240.  * *** empty log message ***
  241.  * 
  242.  * Revision 1.8  1994/08/30  20:38:29  john
  243.  * Add more config stuff..
  244.  * 
  245.  * Revision 1.7  1994/08/30  16:37:25  john
  246.  * Added menu options to set controls.
  247.  * 
  248.  * Revision 1.6  1994/08/30  09:27:18  john
  249.  * *** empty log message ***
  250.  * 
  251.  * Revision 1.5  1994/08/30  09:12:01  john
  252.  * *** empty log message ***
  253.  * 
  254.  * Revision 1.4  1994/08/29  21:18:32  john
  255.  * First version of new keyboard/oystick remapping stuff.
  256.  * 
  257.  * Revision 1.3  1994/08/24  19:00:29  john
  258.  * Changed key_down_time to return fixed seconds instead of
  259.  * milliseconds.
  260.  * 
  261.  * Revision 1.2  1994/08/17  16:50:37  john
  262.  * Added damaging fireballs, missiles.
  263.  * 
  264.  * Revision 1.1  1994/08/17  10:07:12  john
  265.  * Initial revision
  266.  * 
  267.  * 
  268.  */
  269.  
  270.  
  271. #pragma off (unreferenced)
  272. static char rcsid[] = "$Id: joydefs.c 2.2 1995/06/30 12:30:22 john Exp $";
  273. #pragma on (unreferenced)
  274.  
  275. #include <conio.h>
  276. #include <stdlib.h>
  277. #include <stdio.h>
  278. #include <io.h>
  279. #include <string.h>
  280. #include <dos.h>
  281.  
  282. #include "mono.h"
  283. #include "key.h"
  284. #include "joy.h"
  285. #include "timer.h"
  286. #include "error.h"
  287.  
  288. #include "inferno.h"
  289. #include "game.h"
  290. #include "object.h"
  291. #include "player.h"
  292.  
  293. #include "controls.h"
  294. #include "joydefs.h"
  295. #include "victor.h"
  296. #include "render.h"
  297. #include "palette.h"
  298. #include "newmenu.h"
  299. #include "args.h"
  300. #include "text.h"
  301. #include "kconfig.h"
  302. #include "digi.h"
  303. #include "playsave.h"
  304.  
  305. int joydefs_calibrate_flag = 0;
  306.  
  307. void joy_delay()
  308. {
  309.     int t1 = TICKER + 19/4;            // Wait 1/4 second...
  310.     stop_time();
  311.     while( TICKER < t1 );
  312.     joy_flush();
  313.     start_time();
  314. }
  315.  
  316.  
  317. int joycal_message( char * title, char * text )
  318. {
  319.     int i;
  320.     newmenu_item    m[2];
  321.     m[0].type = NM_TYPE_TEXT; m[0].text = text;
  322.     m[1].type = NM_TYPE_MENU; m[1].text = TXT_OK;
  323.     i = newmenu_do( title, NULL, 2, m, NULL );
  324.     if ( i < 0 ) 
  325.         return 1;
  326.     return 0;
  327. }
  328.  
  329. extern int WriteConfigFile();    
  330.  
  331. void joydefs_calibrate()
  332. {
  333.     ubyte masks;
  334.     int org_axis_min[4];
  335.     int org_axis_center[4];
  336.     int org_axis_max[4];
  337.  
  338.     int axis_min[4] = { 0, 0, 0, 0 };
  339.     int axis_cen[4] = { 0, 0, 0, 0 };
  340.     int axis_max[4] = { 0, 0, 0, 0 };
  341.  
  342.     int temp_values[4];
  343.     char title[50];
  344.     char text[50];
  345.     int nsticks = 0;
  346.  
  347.     joydefs_calibrate_flag = 0;
  348.  
  349.     if ( (Config_control_type!=CONTROL_JOYSTICK) && (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) && (Config_control_type!=CONTROL_THRUSTMASTER_FCS) && (Config_control_type!=CONTROL_GRAVIS_GAMEPAD) )    
  350.         return;
  351.  
  352.     joy_get_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  353.  
  354.     joy_set_cen();
  355.     joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  356.  
  357.     if (!joy_present)    {
  358.         nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK );
  359.         return;
  360.     }
  361.     
  362.     masks = joy_get_present_mask();
  363.     if ( masks == JOY_ALL_AXIS )
  364.         nsticks = 2;
  365.     else
  366.         nsticks = 1;
  367.  
  368.     if ( nsticks == 2 )    {
  369.         sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
  370.         sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
  371.     } else {
  372.         sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
  373.         sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
  374.     }
  375.     if (joycal_message( title, text )) {
  376.         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  377.         return;
  378.     }
  379.     joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  380.     axis_min[0] = temp_values[0];
  381.     axis_min[1] = temp_values[1];
  382.     joy_delay();
  383.  
  384.     if ( nsticks == 2 )    {
  385.         sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
  386.         sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
  387.     } else {
  388.         sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
  389.         sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
  390.     }
  391.     if (joycal_message( title, text)) {
  392.         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  393.         return;
  394.     }
  395.     joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  396.     axis_max[0] = temp_values[0];
  397.     axis_max[1] = temp_values[1];
  398.     joy_delay();
  399.  
  400.     if ( nsticks == 2 )    {
  401.         sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_CENTER);
  402.         sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
  403.     } else {
  404.         sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_CENTER);
  405.         sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
  406.     }
  407.     if (joycal_message( title, text)) {
  408.         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  409.         return;
  410.     }
  411.     joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  412.     axis_cen[0] = temp_values[0];
  413.     axis_cen[1] = temp_values[1];
  414.     joy_delay();
  415.  
  416.     // The fcs uses axes 3 for hat, so don't calibrate it.
  417.     if ( Config_control_type == CONTROL_THRUSTMASTER_FCS )    {
  418.         axis_min[3] = 0;
  419.         axis_cen[3] = temp_values[3]/2;
  420.         axis_max[3] = temp_values[3];
  421.         joy_delay();
  422.     } else {
  423.         masks = joy_get_present_mask();
  424.  
  425.         if ( nsticks == 2 )    {
  426.             if ( kconfig_is_axes_used(2) || kconfig_is_axes_used(3) )    {
  427.                 sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
  428.                 sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
  429.                 if (joycal_message( title, text )) {
  430.                     joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  431.                     return;
  432.                 }
  433.                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  434.                 axis_min[2] = temp_values[2];
  435.                 axis_min[3] = temp_values[3];
  436.                 joy_delay();
  437.  
  438.                 sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
  439.                 sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
  440.                 if (joycal_message( title, text ))    {
  441.                     joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); 
  442.                     return;
  443.                 }
  444.                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  445.                 axis_max[2] = temp_values[2];
  446.                 axis_max[3] = temp_values[3];
  447.                 joy_delay();
  448.         
  449.                 sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_CENTER);
  450.                 sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
  451.                 if (joycal_message( title, text ))    {
  452.                     joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  453.                     return;
  454.                 }
  455.                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  456.                 axis_cen[2] = temp_values[2];
  457.                 axis_cen[3] = temp_values[3];    
  458.                 joy_delay();
  459.             }
  460.         } else if ( (!(masks & JOY_2_X_AXIS)) && (masks & JOY_2_Y_AXIS) )    {
  461.             if ( kconfig_is_axes_used(3) )    {
  462.                 // A throttle axis!!!!!
  463.                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_FORWARD);
  464.                 if (joycal_message( title, TXT_MOVE_THROTTLE_F))    {
  465.                     joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  466.                     return;
  467.                 }
  468.                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  469.                 axis_min[3] = temp_values[3];
  470.                 joy_delay();
  471.         
  472.                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_REVERSE);
  473.                 if (joycal_message( title, TXT_MOVE_THROTTLE_R)) {
  474.                     joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  475.                     return;
  476.                 }
  477.                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  478.                 axis_max[3] = temp_values[3];
  479.                 joy_delay();
  480.         
  481.                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_CENTER);
  482.                 if (joycal_message( title, TXT_MOVE_THROTTLE_C)) {
  483.                     joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  484.                     return;
  485.                 }
  486.                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  487.                 axis_cen[3] = temp_values[3];
  488.                 joy_delay();
  489.             }
  490.         }
  491.     }
  492.     joy_set_cal_vals(axis_min, axis_cen, axis_max);
  493.  
  494.     WriteConfigFile();    
  495. }
  496.  
  497.  
  498. //char *control_text[CONTROL_MAX_TYPES] = { "Keyboard only", "Joystick", "Flightstick Pro", "Thrustmaster FCS", "Gravis Gamepad", "Mouse", "Cyberman" };
  499.  
  500. void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
  501. {
  502.     int i;
  503.     int oc_type = Config_control_type;
  504.  
  505.     nitems = nitems;
  506.     last_key = last_key;
  507.     citem = citem;        
  508.  
  509.     for (i=0; i<CONTROL_MAX_TYPES; i++ )
  510.         if (items[i].value) Config_control_type = i;
  511.  
  512.     if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) )    {
  513.         nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS );
  514.     }
  515.  
  516.     if (oc_type != Config_control_type) {
  517.         switch (Config_control_type) {
  518.     //        case    CONTROL_NONE:
  519.             case    CONTROL_JOYSTICK:
  520.             case    CONTROL_FLIGHTSTICK_PRO:
  521.             case    CONTROL_THRUSTMASTER_FCS:
  522.             case    CONTROL_GRAVIS_GAMEPAD:
  523.     //        case    CONTROL_MOUSE:
  524.     //        case    CONTROL_CYBERMAN:
  525.                 joydefs_calibrate_flag = 1;
  526.         }
  527.         kc_set_controls();
  528.     }
  529.  
  530. }
  531.  
  532. extern ubyte kc_use_external_control;
  533. extern ubyte kc_enable_external_control;
  534. extern ubyte *kc_external_name;
  535.  
  536. void joydefs_config()
  537. {
  538.     char xtext[128];
  539.     int i, old_masks, masks;
  540.     newmenu_item m[13];
  541.     int i1=9;
  542.     int nitems;
  543.  
  544.     do {
  545.         nitems = 10;
  546.         m[0].type = NM_TYPE_RADIO; m[0].text = CONTROL_TEXT(0); m[0].value = 0; m[0].group = 0;
  547.         m[1].type = NM_TYPE_RADIO; m[1].text = CONTROL_TEXT(1); m[1].value = 0; m[1].group = 0;
  548.         m[2].type = NM_TYPE_RADIO; m[2].text = CONTROL_TEXT(2); m[2].value = 0; m[2].group = 0;
  549.         m[3].type = NM_TYPE_RADIO; m[3].text = CONTROL_TEXT(3); m[3].value = 0; m[3].group = 0;
  550.         m[4].type = NM_TYPE_RADIO; m[4].text = CONTROL_TEXT(4); m[4].value = 0; m[4].group = 0;
  551.         m[5].type = NM_TYPE_RADIO; m[5].text = CONTROL_TEXT(5); m[5].value = 0; m[5].group = 0;
  552.         m[6].type = NM_TYPE_RADIO; m[6].text = CONTROL_TEXT(6); m[6].value = 0; m[6].group = 0;
  553.         m[7].type = NM_TYPE_MENU; m[7].text=TXT_CUST_ABOVE;
  554.         m[8].type = NM_TYPE_TEXT; m[8].text="";
  555.         m[9].type = NM_TYPE_MENU; m[9].text=TXT_CUST_KEYBOARD;
  556.     
  557.         if ( kc_use_external_control )    {
  558.             sprintf( xtext, "Enable %s", kc_external_name );
  559.             m[10].type = NM_TYPE_CHECK; m[10].text = xtext; m[10].value = kc_enable_external_control;
  560.             nitems = nitems + 1;
  561.         }
  562.         
  563.         m[Config_control_type].value = 1;
  564.      
  565.         i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 );
  566.  
  567.         switch(i1)    {
  568.         case 7: {
  569.                 old_masks = 0;
  570.                 for (i=0; i<4; i++ )        {
  571.                     if (kconfig_is_axes_used(i))
  572.                         old_masks |= (1<<i);
  573.                 }
  574.                 if ( Config_control_type==0 )
  575.                     // nothing...
  576.                     Config_control_type=0;
  577.                 else if ( Config_control_type<5 ) 
  578.                     kconfig(1, CONTROL_TEXT(Config_control_type) ); 
  579.                 else 
  580.                     kconfig(2, CONTROL_TEXT(Config_control_type) ); 
  581.  
  582.                 masks = 0;
  583.                 for (i=0; i<4; i++ )        {
  584.                     if (kconfig_is_axes_used(i))
  585.                         masks |= (1<<i);
  586.                 }
  587.  
  588.                 switch (Config_control_type) {
  589.                 case    CONTROL_JOYSTICK:
  590.                 case    CONTROL_FLIGHTSTICK_PRO:
  591.                 case    CONTROL_THRUSTMASTER_FCS:    
  592.                     {
  593.                         for (i=0; i<4; i++ )    {
  594.                             if ( (masks&(1<<i)) && (!(old_masks&(1<<i))))
  595.                                 joydefs_calibrate_flag = 1;
  596.                         }
  597.                     }
  598.                     break;
  599.                 }
  600.             }
  601.             break;
  602.         case 9: 
  603.             kconfig(0, TXT_KEYBOARD); 
  604.             break;
  605.         } 
  606.  
  607.         if ( kc_use_external_control )    {
  608.             kc_enable_external_control = m[10].value;
  609.         }
  610.  
  611.     } while(i1>-1);
  612.  
  613.     switch (Config_control_type) {
  614.     case    CONTROL_JOYSTICK:
  615.     case    CONTROL_FLIGHTSTICK_PRO:
  616.     case    CONTROL_THRUSTMASTER_FCS:
  617.     case    CONTROL_GRAVIS_GAMEPAD:
  618.         if ( joydefs_calibrate_flag )
  619.             joydefs_calibrate();
  620.         break;
  621.     }
  622.  
  623. }
  624.  
  625. 
  626.