1 /* $Id: joydefs.c,v 1.1 2003/03/14 05:01:11 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14 
15 /*
16  *
17  * FIXME: add description
18  *
19  * Old Log:
20  * Revision 1.10  1995/10/18  22:21:21  allender
21  * fixed bug with gravis mousestick and call key_flush when
22  * calibrating joystick since it used keystrokes for the trigger
23  * (at least most of them do)
24  *
25  * Revision 1.9  1995/10/17  13:12:32  allender
26  * fixed up controller support for mac world
27  *
28  * Revision 1.8  1995/10/15  19:27:04  allender
29  * new Dave Denhart controller code
30  *
31  * Revision 1.7  1995/10/15  16:14:59  allender
32  * fixed axis value for Thrustmaster rudders
33  *
34  * Revision 1.6  1995/09/13  11:39:39  allender
35  * made joystick cal menu all text so buttons will work properly
36  *
37  * Revision 1.5  1995/09/01  13:13:13  allender
38  * added close box on controls menu
39  *
40  * Revision 1.4  1995/08/18  10:22:47  allender
41  * if thrustmaster choosen, set joystick at thrustmaster type
42  * for proper reading in joyc.c
43  *
44  * Revision 1.3  1995/07/26  17:00:34  allender
45  * put back in code to make joysticks work
46  *
47  * Revision 1.2  1995/07/17  08:52:21  allender
48  * put back in code that was taken out previously
49  *
50  * Revision 1.1  1995/05/16  15:26:48  allender
51  * Initial revision
52  *
53  * Revision 2.2  1995/06/30  12:30:22  john
54  * Added -Xname command line.
55  *
56  * Revision 2.1  1995/04/06  12:13:20  john
57  * Made so you can calibrate Gravis Gamepad.
58  *
59  * Revision 2.0  1995/02/27  11:30:27  john
60  * New version 2.0, which has no anonymous unions, builds with
61  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
62  *
63  * Revision 1.71  1995/02/12  02:06:10  john
64  * Fixed bug with joystick incorrectly asking for
65  * calibration.
66  *
67  * Revision 1.70  1995/01/28  15:58:07  john
68  * Made joystick calibration be only when wrong detected in
69  * menu or joystick axis changed.
70  *
71  * Revision 1.69  1995/01/25  14:37:55  john
72  * Made joystick only prompt for calibration once...
73  *
74  * Revision 1.68  1995/01/24  16:34:29  john
75  * Made so that if you reconfigure joystick and
76  * add or subtract an axis, it asks for a recalibration
77  * upon leaving.
78  *
79  * Revision 1.67  1994/12/29  11:08:51  john
80  * Fixed Thrustmaster and Logitech Wingman extreme
81  * Hat by reading the y2 axis during the center stage
82  * of the calibration, and using 75, 50, 27, and 3 %
83  * as values for the 4 positions.
84  *
85  * Revision 1.66  1994/12/15  18:17:39  john
86  * Fixed warning with previous.
87  *
88  * Revision 1.65  1994/12/15  18:15:48  john
89  * Made the joy cal only write the .cfg file, not
90  * the player file.
91  *
92  * Revision 1.64  1994/12/13  14:43:35  john
93  * Took out the code in kconfig to build direction array.
94  * Called kc_set_controls after selecting a new control type.
95  *
96  * Revision 1.63  1994/12/10  12:08:47  john
97  * Changed some delays to use TICKER instead of timer_get_fixed_seconds.
98  *
99  * Revision 1.62  1994/12/09  11:01:07  mike
100  * force calibration of joystick on joystick selection from Controls... menu.
101  *
102  * Revision 1.61  1994/12/07  21:50:27  john
103  * Put stop/start time around joystick delay.
104  *
105  * Revision 1.60  1994/12/07  19:34:39  john
106  * Added delay.
107  *
108  * Revision 1.59  1994/12/07  18:12:14  john
109  * NEatened up joy cal.,
110  *
111  * Revision 1.58  1994/12/07  17:07:51  john
112  * Fixed up joy cal.
113  *
114  * Revision 1.57  1994/12/07  16:48:53  yuan
115  * localization
116  *
117  * Revision 1.56  1994/12/07  16:05:55  john
118  * Changed the way joystick calibration works.
119  *
120  * Revision 1.55  1994/12/06  20:15:22  john
121  * Took out code that unpauses songs that were never paused.
122  *
123  * Revision 1.54  1994/12/06  15:14:09  yuan
124  * Localization
125  *
126  * Revision 1.53  1994/12/05  16:29:16  john
127  * Took out music pause around the cheat menu.
128  *
129  * Revision 1.52  1994/12/04  12:39:10  john
130  * MAde so that FCS calibration doesn't ask for axis #2.
131  *
132  * Revision 1.51  1994/12/03  15:14:59  john
133  * Took out the delay mentioned previosuly cause it would
134  * cause bigger problems than it helps, especially with netgames.
135  *
136  * Revision 1.50  1994/12/03  14:16:14  john
137  * Put a delay between screens in joy cal to keep Yuan from
138  * double hitting.
139  *
140  * Revision 1.49  1994/12/03  11:04:06  john
141  * Changed newmenu code a bit to fix bug with bogus
142  * backgrounds occcasionally.
143  *
144  * Revision 1.48  1994/12/02  11:03:44  yuan
145  * Localization.
146  *
147  * Revision 1.47  1994/12/02  10:50:33  yuan
148  * Localization
149  *
150  * Revision 1.46  1994/12/01  12:21:59  john
151  * Added code to calibrate 2 joysticks separately.
152  *
153  * Revision 1.45  1994/12/01  11:52:31  john
154  * Added message when you select FCS to say that if
155  * you have WCS, see manuel.
156  *
157  * Revision 1.44  1994/11/29  02:26:28  john
158  * Made the prompts for upper-left, lower right for joy
159  * calibration more obvious.
160  *
161  * Revision 1.43  1994/11/26  13:13:59  matt
162  * Changed "none" option to "keyboard only"
163  *
164  * Revision 1.42  1994/11/21  19:35:13  john
165  * Replaced calls to joy_init with if (joy_present)
166  *
167  * Revision 1.41  1994/11/21  19:28:34  john
168  * Changed warning for no joystick to use nm_messagebox..
169  *
170  * Revision 1.40  1994/11/21  19:06:25  john
171  * Made it so that it only stops sound when your in game mode.
172  *
173  * Revision 1.39  1994/11/21  11:47:18  john
174  * Made sound pause during joystick calibration.
175  *
176  * Revision 1.38  1994/11/10  20:34:18  rob
177  * Removed menu-specific network mode support in favor in new stuff
178  * in newmenu.c
179  *
180  * Revision 1.37  1994/11/08  21:21:38  john
181  * Made Esc exit joystick calibration.
182  *
183  * Revision 1.36  1994/11/08  15:14:42  john
184  * Added more calls so net doesn't die in net game.
185  *
186  * Revision 1.35  1994/11/08  14:59:12  john
187  * Added code to respond to network while in menus.
188  *
189  * Revision 1.34  1994/10/24  19:56:32  john
190  * Made the new user setup prompt for config options.
191  *
192  * Revision 1.33  1994/10/22  14:11:52  mike
193  * Suppress compiler warning message.
194  *
195  * Revision 1.32  1994/10/19  12:44:24  john
196  * Added hours field to player structure.
197  *
198  * Revision 1.31  1994/10/17  13:07:13  john
199  * Moved the descent.cfg info into the player config file.
200  *
201  * Revision 1.30  1994/10/13  21:41:12  john
202  * MAde Esc exit out of joystick calibration.
203  *
204  * Revision 1.29  1994/10/13  19:22:27  john
205  * Added separate config saves for different devices.
206  * Made all the devices work together better, such as mice won't
207  * get read when you're playing with the joystick.
208  *
209  * Revision 1.28  1994/10/13  11:40:18  john
210  * Took out warnings.
211  *
212  * Revision 1.27  1994/10/13  11:35:23  john
213  * Made Thrustmaster FCS Hat work.  Put a background behind the
214  * keyboard configure.  Took out turn_sensitivity.  Changed sound/config
215  * menu to new menu. Made F6 be calibrate joystick.
216  *
217  * Revision 1.26  1994/10/11  21:29:03  matt
218  * Made a bunch of menus have good initial selected values
219  *
220  * Revision 1.25  1994/10/11  17:08:39  john
221  * Added sliders for volume controls.
222  *
223  * Revision 1.24  1994/10/10  17:59:21  john
224  * Neatend previous.
225  *
226  * Revision 1.23  1994/10/10  17:57:59  john
227  * Neatend previous.
228  *
229  * Revision 1.22  1994/10/10  17:56:11  john
230  * Added messagebox that tells that config has been saved.
231  *
232  * Revision 1.21  1994/09/30  12:37:26  john
233  * Added midi,digi volume to configuration.
234  *
235  * Revision 1.20  1994/09/22  16:14:14  john
236  * Redid intro sequecing.
237  *
238  * Revision 1.19  1994/09/19  18:50:15  john
239  * Added switch to disable joystick.
240  *
241  * Revision 1.18  1994/09/12  11:47:36  john
242  * Made stupid cruise work better.  Make kconfig values get
243  * read/written to disk.
244  *
245  * Revision 1.17  1994/09/10  15:46:47  john
246  * First version of new keyboard configuration.
247  *
248  * Revision 1.16  1994/09/06  19:35:44  john
249  * Fixed bug that didn';t load new size .cal file.
250  *
251  * Revision 1.15  1994/09/06  14:51:58  john
252  * Added sensitivity adjustment, fixed bug with joystick button not
253  * staying down.
254  *
255  * Revision 1.14  1994/09/02  16:13:47  john
256  * Made keys fill in position.
257  *
258  * Revision 1.13  1994/08/31  17:58:50  john
259  * Made a bit simpler.
260  *
261  * Revision 1.12  1994/08/31  14:17:54  john
262  * *** empty log message ***
263  *
264  * Revision 1.11  1994/08/31  14:10:56  john
265  * Made keys not work when KEY_DELETE pressed.
266  *
267  * Revision 1.10  1994/08/31  13:40:47  mike
268  * Change constant
269  *
270  * Revision 1.9  1994/08/31  12:56:27  john
271  * *** empty log message ***
272  *
273  * Revision 1.8  1994/08/30  20:38:29  john
274  * Add more config stuff..
275  *
276  * Revision 1.7  1994/08/30  16:37:25  john
277  * Added menu options to set controls.
278  *
279  * Revision 1.6  1994/08/30  09:27:18  john
280  * *** empty log message ***
281  *
282  * Revision 1.5  1994/08/30  09:12:01  john
283  * *** empty log message ***
284  *
285  * Revision 1.4  1994/08/29  21:18:32  john
286  * First version of new keyboard/oystick remapping stuff.
287  *
288  * Revision 1.3  1994/08/24  19:00:29  john
289  * Changed key_down_time to return fixed seconds instead of
290  * milliseconds.
291  *
292  * Revision 1.2  1994/08/17  16:50:37  john
293  * Added damaging fireballs, missiles.
294  *
295  * Revision 1.1  1994/08/17  10:07:12  john
296  * Initial revision
297  *
298  *
299  */
300 
301 #ifdef RCS
302 static char rcsid[] = "$Id: joydefs.c,v 1.1 2003/03/14 05:01:11 btb Exp $";
303 #endif
304 
305 #ifdef HAVE_CONFIG_H
306 #include <conf.h>
307 #endif
308 
309 #include <stdlib.h>
310 #include <stdio.h>
311 #include <string.h>
312 #if 0
313 #include <dos.h>
314 #endif
315 
316 #include "mono.h"
317 #include "key.h"
318 #include "joy.h"
319 #include "timer.h"
320 #include "error.h"
321 
322 #include "inferno.h"
323 #include "game.h"
324 #include "object.h"
325 #include "player.h"
326 
327 #include "controls.h"
328 #include "joydefs.h"
329 #if 0
330 #include "victor.h"
331 #endif
332 #include "render.h"
333 #include "palette.h"
334 #include "newmenu.h"
335 #include "args.h"
336 #include "text.h"
337 #include "kconfig.h"
338 #include "digi.h"
339 #include "playsave.h"
340 
341 int joydefs_calibrate_flag = 0;
342 
343 #ifdef MACINTOSH
344 ubyte joydefs_calibrating = 0;		// stupid hack all because of silly mouse cursor emulation
345 #endif
346 
joy_delay()347 void joy_delay()
348 {
349 	stop_time();
350 	timer_delay(.25);
351 	//delay(250);				// changed by allender because	1) more portable
352 							//								2) was totally broken on PC
353 	joy_flush();
354 	start_time();
355 }
356 
357 
joycal_message(char * title,char * text)358 int joycal_message( char * title, char * text )
359 {
360 	int i;
361 	newmenu_item	m[2];
362 	MAC(joydefs_calibrating = 1;)
363 	m[0].type = NM_TYPE_TEXT; m[0].text = text;
364 	m[1].type = NM_TYPE_MENU; m[1].text = TXT_OK;
365 	i = newmenu_do( title, NULL, 2, m, NULL );
366 	MAC(joydefs_calibrating = 0;)
367 	if ( i < 0 )
368 		return 1;
369 	return 0;
370 }
371 
372 extern int WriteConfigFile();
373 
joydefs_calibrate(void)374 void joydefs_calibrate(void)
375 {
376 	#ifndef MACINTOSH
377 	if ( (Config_control_type!=CONTROL_JOYSTICK) && (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) && (Config_control_type!=CONTROL_THRUSTMASTER_FCS) )
378 		return;
379 	#else
380 	if ( (Config_control_type == CONTROL_NONE) || (Config_control_type == CONTROL_MOUSE) )
381 		return;
382 	#endif
383 
384 	palette_save();
385 	apply_modified_palette();
386 	reset_palette_add();
387 
388 	gr_palette_load(gr_palette);
389 #if 0
390 	joydefs_calibrate2();
391 #endif
392 
393 	reset_cockpit();
394 
395 	palette_restore();
396 
397 }
398 
399 #if 0
400 #ifndef MACINTOSH
401 void joydefs_calibrate2()
402 {
403 	ubyte masks;
404 	int org_axis_min[4];
405 	int org_axis_center[4];
406 	int org_axis_max[4];
407 
408 	int axis_min[4] = { 0, 0, 0, 0 };
409 	int axis_cen[4] = { 0, 0, 0, 0 };
410 	int axis_max[4] = { 0, 0, 0, 0 };
411 
412 	int temp_values[4];
413 	char title[50];
414 	char text[50];
415 	int nsticks = 0;
416 
417 	joydefs_calibrate_flag = 0;
418 
419 	joy_get_cal_vals(org_axis_min, org_axis_center, org_axis_max);
420 
421 	joy_set_cen();
422 	joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
423 
424 	if (!joy_present)	{
425 		nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK );
426 		return;
427 	}
428 
429 	masks = joy_get_present_mask();
430 
431 #ifndef WINDOWS
432 	if ( masks == JOY_ALL_AXIS )
433 		nsticks = 2;
434 	else
435 		nsticks = 1;
436 #else
437 	nsticks = 1;
438 #endif
439 
440 	if (Config_control_type == CONTROL_THRUSTMASTER_FCS)
441 		nsticks = 1;		//ignore for now the Sidewinder Pro X2 axis
442 
443 	if ( nsticks == 2 )	{
444 		sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
445 		sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
446 	} else {
447 		sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
448 		sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
449 	}
450 
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_min[0] = temp_values[0];
457 	axis_min[1] = temp_values[1];
458 	joy_delay();
459 
460 	if ( nsticks == 2 )	{
461 		sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
462 		sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
463 	} else {
464 		sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
465 		sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
466 	}
467 	if (joycal_message( title, text)) {
468 		joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
469 		return;
470 	}
471 	joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
472 	axis_max[0] = temp_values[0];
473 	axis_max[1] = temp_values[1];
474 	joy_delay();
475 
476 	if ( nsticks == 2 )	{
477 		sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_CENTER);
478 		sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
479 	} else {
480 		sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_CENTER);
481 		sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
482 	}
483 	if (joycal_message( title, text)) {
484 		joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
485 		return;
486 	}
487 	joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
488 	axis_cen[0] = temp_values[0];
489 	axis_cen[1] = temp_values[1];
490 	axis_cen[2] = temp_values[2];
491 	joy_delay();
492 
493 	// The fcs uses axes 3 for hat, so don't calibrate it.
494 	if ( Config_control_type == CONTROL_THRUSTMASTER_FCS )	{
495 	#ifndef WINDOWS
496 		//set Y2 axis, which is hat
497 		axis_min[3] = 0;
498 		axis_cen[3] = temp_values[3]/2;
499 		axis_max[3] = temp_values[3];
500 		joy_delay();
501 
502 		//if X2 exists, calibrate it (for Sidewinder Pro)
503 		if ( kconfig_is_axes_used(2) && (masks & JOY_2_X_AXIS) )	{
504 			sprintf( title, "Joystick X2 axis\nLEFT");
505 			sprintf( text, "Move joystick X2 axis\nall the way left");
506 			if (joycal_message( title, text )) {
507 				joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
508 				return;
509 			}
510 			joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
511 			axis_min[2] = temp_values[2];
512 			axis_min[3] = temp_values[3];
513 			joy_delay();
514 
515 			sprintf( title, "Joystick X2 axis\nRIGHT");
516 			sprintf( text, "Move joystick X2 axis\nall the way right");
517 			if (joycal_message( title, text ))	{
518 				joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
519 				return;
520 			}
521 			joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
522 			axis_max[2] = temp_values[2];
523 			axis_max[3] = temp_values[3];
524 			joy_delay();
525 		}
526 	#endif
527 	} else {
528 		masks = joy_get_present_mask();
529 
530 		if ( nsticks == 2 )	{
531 			if ( kconfig_is_axes_used(2) || kconfig_is_axes_used(3) )	{
532 				sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
533 				sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
534 				if (joycal_message( title, text )) {
535 					joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
536 					return;
537 				}
538 				joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
539 				axis_min[2] = temp_values[2];
540 				axis_min[3] = temp_values[3];
541 				joy_delay();
542 
543 				sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
544 				sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
545 				if (joycal_message( title, text ))	{
546 					joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
547 					return;
548 				}
549 				joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
550 				axis_max[2] = temp_values[2];
551 				axis_max[3] = temp_values[3];
552 				joy_delay();
553 
554 				sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_CENTER);
555 				sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
556 				if (joycal_message( title, text ))	{
557 					joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
558 					return;
559 				}
560 				joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
561 				axis_cen[2] = temp_values[2];
562 				axis_cen[3] = temp_values[3];
563 				joy_delay();
564 			}
565 		}
566 	#ifndef WINDOWS
567 		else if ( (!(masks & JOY_2_X_AXIS)) && (masks & JOY_2_Y_AXIS) )	{
568 			if ( kconfig_is_axes_used(3) )	{
569 				// A throttle axis!!!!!
570 				sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_FORWARD);
571 				if (joycal_message( title, TXT_MOVE_THROTTLE_F))	{
572 					joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
573 					return;
574 				}
575 				joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
576 				axis_min[3] = temp_values[3];
577 				joy_delay();
578 
579 				sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_REVERSE);
580 				if (joycal_message( title, TXT_MOVE_THROTTLE_R)) {
581 					joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
582 					return;
583 				}
584 				joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
585 				axis_max[3] = temp_values[3];
586 				joy_delay();
587 
588 				sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_CENTER);
589 				if (joycal_message( title, TXT_MOVE_THROTTLE_C)) {
590 					joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
591 					return;
592 				}
593 				joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
594 				axis_cen[3] = temp_values[3];
595 				joy_delay();
596 			}
597 		}
598 	#endif
599 	}
600 	joy_set_cal_vals(axis_min, axis_cen, axis_max);
601 
602 	WriteConfigFile();
603 }
604 #else
605 void joydefs_calibrate2()
606 {
607 	ubyte masks;
608 	int org_axis_min[4];
609 	int org_axis_center[4];
610 	int org_axis_max[4];
611 
612 	int axis_min[4] = { 0, 0, 0, 0 };
613 	int axis_cen[4] = { 0, 0, 0, 0 };
614 	int axis_max[4] = { 0, 0, 0, 0 };
615 
616 	int temp_values[4];
617 	char title[50];
618 	char text[50];
619 	int i, nsticks = 0;
620 
621 	joydefs_calibrate_flag = 0;
622 
623 	if ( Config_control_type == CONTROL_THRUSTMASTER_FCS ) {
624 		axis_cen[0] = axis_cen[1] = axis_cen[2] = 0;
625 		axis_min[0] = axis_min[1] = axis_min[2] = -127;
626 		axis_max[0] = axis_max[1] = axis_max[2] = 127;
627 		axis_min[3] = 0;
628 		axis_max[3] = 255;
629 		axis_cen[3] = 128;
630 		joy_set_cal_vals(axis_min, axis_cen, axis_max);
631 		return;
632 	}
633 
634 	if ( Config_control_type == CONTROL_FLIGHTSTICK_PRO ) 		// no calibration needed
635 		return;
636 
637 	joy_get_cal_vals(org_axis_min, org_axis_center, org_axis_max);
638 
639 	joy_set_cen();
640 	joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
641 
642 	if (!joy_present)	{
643 		nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK );
644 		return;
645 	}
646 
647 	masks = joy_get_present_mask();
648 
649 	if ( masks == JOY_ALL_AXIS )
650 		nsticks = 2;
651 	else
652 		nsticks = 1;
653 
654 	if ( (Config_control_type == CONTROL_THRUSTMASTER_FCS) || (Config_control_type == CONTROL_FLIGHTSTICK_PRO) )
655 		nsticks = 1;		//ignore for now the Sidewinder Pro X2 axis
656 
657 	if ( nsticks == 2 )	{
658 		sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
659 		sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
660 	} else {
661 		sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
662 		sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
663 	}
664 
665 	if (joycal_message( title, text )) {
666 		joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
667 		return;
668 	}
669 	joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
670 	axis_min[0] = temp_values[0];
671 	axis_min[1] = temp_values[1];
672 	joy_delay();
673 
674 	if ( nsticks == 2 )	{
675 		sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
676 		sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
677 	} else {
678 		sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
679 		sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
680 	}
681 	if (joycal_message( title, text)) {
682 		joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
683 		return;
684 	}
685 	joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
686 	axis_max[0] = temp_values[0];
687 	axis_max[1] = temp_values[1];
688 	joy_delay();
689 
690 	if ( nsticks == 2 )	{
691 		sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_CENTER);
692 		sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
693 	} else {
694 		sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_CENTER);
695 		sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
696 	}
697 	if (joycal_message( title, text)) {
698 		joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
699 		return;
700 	}
701 	joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
702 	axis_cen[0] = temp_values[0];
703 	axis_cen[1] = temp_values[1];
704 	axis_cen[2] = temp_values[2];
705 	joy_delay();
706 
707 	masks = joy_get_present_mask();
708 
709 	if ( nsticks == 2 )	{
710 		if ( kconfig_is_axes_used(2) || kconfig_is_axes_used(3) )	{
711 			sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
712 			sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
713 			if (joycal_message( title, text )) {
714 				joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
715 				return;
716 			}
717 			joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
718 			axis_min[2] = temp_values[2];
719 			axis_min[3] = temp_values[3];
720 			joy_delay();
721 
722 			sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
723 			sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
724 			if (joycal_message( title, text ))	{
725 				joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
726 				return;
727 			}
728 			joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
729 			axis_max[2] = temp_values[2];
730 			axis_max[3] = temp_values[3];
731 			joy_delay();
732 
733 			sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_CENTER);
734 			sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
735 			if (joycal_message( title, text ))	{
736 				joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
737 				return;
738 			}
739 			joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
740 			axis_cen[2] = temp_values[2];
741 			axis_cen[3] = temp_values[3];
742 			joy_delay();
743 		}
744 	} else {
745 		if ( kconfig_is_axes_used(3) )	{
746 			// A throttle axis!!!!!
747 			sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_FORWARD);
748 			if (joycal_message( title, TXT_MOVE_THROTTLE_F))	{
749 				joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
750 				return;
751 			}
752 			joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
753 			axis_min[3] = temp_values[3];
754 			joy_delay();
755 
756 			sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_REVERSE);
757 			if (joycal_message( title, TXT_MOVE_THROTTLE_R)) {
758 				joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
759 				return;
760 			}
761 			joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
762 			axis_max[3] = temp_values[3];
763 			joy_delay();
764 
765 			sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_CENTER);
766 			if (joycal_message( title, TXT_MOVE_THROTTLE_C)) {
767 				joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
768 				return;
769 			}
770 			joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
771 			axis_cen[3] = temp_values[3];
772 			joy_delay();
773 		}
774 	}
775 	joy_set_cal_vals(axis_min, axis_cen, axis_max);
776 
777 	WriteConfigFile();
778 }
779 #endif
780 #endif // 0
781 
782 //char *control_text[CONTROL_MAX_TYPES] = { "Keyboard only", "Joystick", "Flightstick Pro", "Thrustmaster FCS", "Gravis Gamepad", "Mouse", "Cyberman" };
783 
784 #ifndef MACINTOSH		// mac will have own verion of this function
785 
786 #define CONTROL_MAX_TYPES_DOS	(CONTROL_MAX_TYPES-1)	//last item is windows only
787 
joydef_menuset_1(int nitems,newmenu_item * items,int * last_key,int citem)788 void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
789 {
790 	int i;
791 	int oc_type = Config_control_type;
792 
793 	nitems = nitems;
794 	last_key = last_key;
795 	citem = citem;
796 
797 	for (i=0; i<CONTROL_MAX_TYPES_DOS; i++ )
798 		if (items[i].value) Config_control_type = i;
799 
800 	if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) )	{
801 		nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS );
802 	}
803 
804 	if (oc_type != Config_control_type) {
805 		switch (Config_control_type) {
806 	//		case	CONTROL_NONE:
807 			case	CONTROL_JOYSTICK:
808 			case	CONTROL_FLIGHTSTICK_PRO:
809 			case	CONTROL_THRUSTMASTER_FCS:
810 	//		case	CONTROL_GRAVIS_GAMEPAD:
811 	//		case	CONTROL_MOUSE:
812 	//		case	CONTROL_CYBERMAN:
813 				joydefs_calibrate_flag = 1;
814 		}
815 		kc_set_controls();
816 	}
817 
818 }
819 
820 #else		// ifndef MACINTOSH
821 
822 #define MAX_MAC_CONTROL_TYPES	6
823 
824 char *ch_warning = "Choosing this option will\noverride any settings for Descent II\nin the CH control panels.  This\noption provides direct programming\nonly.  See the readme for details.";
825 char *tm_warning = "Choosing this option might\ncause settings in the Thrustmaster\ncontrol panels to be overridden\ndepending on the direct inhibition\nsetting in that panel.\nSee the readme for details.";
826 char *ms_warning = "When using a Mousestick II,\nbe sure that there is not a stick\nset active for Descent II.\nHaving a stick set active might cause\nundesirable joystick and\nkeyboard behavior.  See\nthe readme for detals.";
827 char *joy_warning = "Please use your joystick's\ncontrol panel to customize the\nbuttons and axis for Descent II.\nSee the joystick's manual for\ninstructions.";
828 
joydef_menuset_1(int nitems,newmenu_item * items,int * last_key,int citem)829 void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
830 {
831 	int i;
832 	int oc_type = Config_control_type;
833 	char *warning_text = NULL;
834 
835 	nitems = nitems;
836 	last_key = last_key;
837 	citem = citem;
838 
839 	for (i=0; i<MAX_MAC_CONTROL_TYPES; i++ )
840 		if (items[i].value) Config_control_type = i;
841 
842 	if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_FLIGHTSTICK_PRO ) )	{
843 		warning_text = ch_warning;
844 	}
845 
846 	if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) )	{
847 		warning_text = tm_warning;
848 	}
849 
850 	if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_GRAVIS_GAMEPAD ) )	{
851 		warning_text = ms_warning;
852 	}
853 
854 	if (warning_text) {
855 		hide_cursor();
856 		nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, warning_text );
857 		show_cursor();
858 	}
859 
860 	if (oc_type != Config_control_type) {
861 		switch (Config_control_type) {
862 			case	CONTROL_JOYSTICK:
863 			case	CONTROL_FLIGHTSTICK_PRO:
864 			case	CONTROL_THRUSTMASTER_FCS:
865 			case	CONTROL_GRAVIS_GAMEPAD:		// this really means a firebird or mousestick
866 				joydefs_calibrate_flag = 1;
867 		}
868 		kc_set_controls();
869 		joydefs_set_type( Config_control_type );
870 	}
871 
872 }
873 
874 #endif
875 
876 extern ubyte kc_use_external_control;
877 extern ubyte kc_enable_external_control;
878 extern ubyte *kc_external_name;
879 
880 #ifndef WINDOWS
881 
882 #ifdef MACINTOSH
883 
884 //NOTE: MAC VERSION
joydefs_config()885 void joydefs_config()
886 {
887 	int i, old_masks, masks,nitems;
888 	newmenu_item m[14];
889 	int i1=11;
890 	char xtext[128];
891 
892 	do {
893 		m[0].type = NM_TYPE_RADIO; m[0].text = CONTROL_TEXT(0); m[0].value = 0; m[0].group = 0;
894 		m[1].type = NM_TYPE_RADIO; m[1].text = CONTROL_TEXT(1); m[1].value = 0; m[1].group = 0;
895 		m[2].type = NM_TYPE_RADIO; m[2].text = CONTROL_TEXT(2); m[2].value = 0; m[2].group = 0;
896 		m[3].type = NM_TYPE_RADIO; m[3].text = CONTROL_TEXT(3); m[3].value = 0; m[3].group = 0;
897 // change the text for the thrustmaster
898 		m[3].text = "Thrustmaster";
899 		m[4].type = NM_TYPE_RADIO; m[4].text = CONTROL_TEXT(4); m[4].value = 0; m[4].group = 0;
900 // change the text of the gravis gamepad to be the mac gravis sticks
901 		m[4].text = "Gravis Firebird/MouseStick II";
902 		m[5].type = NM_TYPE_RADIO; m[5].text = CONTROL_TEXT(5); m[5].value = 0; m[5].group = 0;
903 
904 		m[6].type = NM_TYPE_MENU;   m[6].text=TXT_CUST_ABOVE;
905 		m[7].type = NM_TYPE_TEXT;   m[7].text="";
906 		m[8].type = NM_TYPE_SLIDER; m[8].text=TXT_JOYS_SENSITIVITY; m[8].value=Config_joystick_sensitivity; m[8].min_value =0; m[8].max_value = 8;
907 		m[9].type = NM_TYPE_TEXT;   m[9].text="";
908 		m[10].type = NM_TYPE_MENU;  m[10].text=TXT_CUST_KEYBOARD;
909 		nitems=11;
910 
911 		m[Config_control_type].value = 1;
912 
913 		i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 );
914 		Config_joystick_sensitivity = m[8].value;
915 
916 		switch(i1)	{
917 		case 6: {
918 				old_masks = 0;
919 				for (i=0; i<4; i++ )		{
920 					if (kconfig_is_axes_used(i))
921 						old_masks |= (1<<i);
922 				}
923 				if ( Config_control_type==0 )
924 					// nothing...
925 					Config_control_type=0;
926 				else if ( Config_control_type == 1)  // this is just a joystick
927 					nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, joy_warning );
928 				else if ( Config_control_type<5 ) {
929 					char title[64];
930 
931 					if (Config_control_type == 3)
932 						strcpy(title, "Thrustmaster");
933 					else if (Config_control_type == 4)
934 						strcpy(title, "Gravis Firebird/Mousestick II");
935 					else
936 						strcpy(title, CONTROL_TEXT(Config_control_type) );
937 
938 
939 					kconfig(1, title );
940 				} else
941 					kconfig(2, CONTROL_TEXT(Config_control_type) );
942 
943 				masks = 0;
944 				for (i=0; i<4; i++ )		{
945 					if (kconfig_is_axes_used(i))
946 						masks |= (1<<i);
947 				}
948 
949 				switch (Config_control_type) {
950 				case	CONTROL_JOYSTICK:
951 				case	CONTROL_FLIGHTSTICK_PRO:
952 				case	CONTROL_THRUSTMASTER_FCS:
953 				case	CONTROL_GRAVIS_GAMEPAD:
954 					{
955 						for (i=0; i<4; i++ )	{
956 							if ( (masks&(1<<i)) && (!(old_masks&(1<<i))))
957 								joydefs_calibrate_flag = 1;
958 						}
959 					}
960 					break;
961 				}
962 			}
963 			break;
964 		case 10:
965 			kconfig(0, TXT_KEYBOARD);
966 			break;
967 		}
968 
969 	} while(i1>-1);
970 
971 	switch (Config_control_type) {
972 	case	CONTROL_JOYSTICK:
973 //	case	CONTROL_FLIGHTSTICK_PRO:
974 	case	CONTROL_THRUSTMASTER_FCS:
975 	case	CONTROL_GRAVIS_GAMEPAD:
976 		if ( joydefs_calibrate_flag )
977 			joydefs_calibrate();
978 		break;
979 	}
980 
981 }
982 
983 // silly routine to tell the joystick handler which type of control
984 // we are using
joydefs_set_type(ubyte type)985 void joydefs_set_type(ubyte type)
986 {
987 	ubyte joy_type;
988 
989 	switch (type)
990 	{
991 		case	CONTROL_NONE:				joy_type = JOY_AS_NONE;					break;
992 		case	CONTROL_JOYSTICK:			joy_type = JOY_AS_MOUSE;				break;
993 		case	CONTROL_FLIGHTSTICK_PRO:	joy_type = JOY_AS_JOYMANAGER;			break;
994 		case	CONTROL_THRUSTMASTER_FCS:	joy_type = JOY_AS_THRUSTMASTER;			break;
995 		case	CONTROL_GRAVIS_GAMEPAD:		joy_type = JOY_AS_MOUSESTICK;			break;
996 		case	CONTROL_MOUSE:				joy_type = JOY_AS_MOUSE;				break;
997 	}
998 	joy_set_type(joy_type);
999 }
1000 
1001 #else		// #ifdef MACINTOSH
1002 
1003 //NOTE: UNIX/DOS VERSION
joydefs_config()1004 void joydefs_config()
1005 {
1006 	int i, old_masks, masks,nitems;
1007 	newmenu_item m[14];
1008 	int i1=11;
1009 	char xtext[128];
1010 
1011 	do {
1012 		nitems=12;
1013 		m[0].type = NM_TYPE_RADIO; m[0].text = CONTROL_TEXT(0); m[0].value = 0; m[0].group = 0;
1014 		m[1].type = NM_TYPE_RADIO; m[1].text = CONTROL_TEXT(1); m[1].value = 0; m[1].group = 0;
1015 		m[2].type = NM_TYPE_RADIO; m[2].text = CONTROL_TEXT(2); m[2].value = 0; m[2].group = 0;
1016 		m[3].type = NM_TYPE_RADIO; m[3].text = CONTROL_TEXT(3); m[3].value = 0; m[3].group = 0;
1017 		m[4].type = NM_TYPE_RADIO; m[4].text = CONTROL_TEXT(4); m[4].value = 0; m[4].group = 0;
1018 		m[5].type = NM_TYPE_RADIO; m[5].text = CONTROL_TEXT(5); m[5].value = 0; m[5].group = 0;
1019 		m[6].type = NM_TYPE_RADIO; m[6].text = CONTROL_TEXT(6); m[6].value = 0; m[6].group = 0;
1020 
1021 		m[ 7].type = NM_TYPE_MENU;		m[ 7].text=TXT_CUST_ABOVE;
1022 		m[ 8].type = NM_TYPE_TEXT;		m[ 8].text="";
1023 		m[ 9].type = NM_TYPE_SLIDER;	m[ 9].text=TXT_JOYS_SENSITIVITY; m[9].value=Config_joystick_sensitivity; m[9].min_value =0; m[9].max_value = 8;
1024 		m[10].type = NM_TYPE_TEXT;		m[10].text="";
1025 		m[11].type = NM_TYPE_MENU;		m[11].text=TXT_CUST_KEYBOARD;
1026 
1027 		m[Config_control_type].value = 1;
1028 
1029 		if ( kc_use_external_control )	{
1030 			sprintf( xtext, "Enable %s", kc_external_name );
1031 			m[12].type = NM_TYPE_CHECK; m[12].text = xtext; m[12].value = kc_enable_external_control;
1032 			nitems++;
1033 		}
1034 
1035 		m[nitems].type = NM_TYPE_MENU; m[nitems].text="CUSTOMIZE D2X KEYS"; nitems++;
1036 
1037 		i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 );
1038 		Config_joystick_sensitivity = m[9].value;
1039 
1040 		switch(i1)	{
1041 		case 7: {
1042 				old_masks = 0;
1043 				for (i=0; i<4; i++ )		{
1044 					if (kconfig_is_axes_used(i))
1045 						old_masks |= (1<<i);
1046 				}
1047 				if ( Config_control_type==0 )
1048 					kconfig(0, TXT_KEYBOARD);
1049 				else if ( Config_control_type<5 )
1050 					kconfig(1, CONTROL_TEXT(Config_control_type) );
1051 				else
1052 					kconfig(2, CONTROL_TEXT(Config_control_type) );
1053 
1054 				masks = 0;
1055 				for (i=0; i<4; i++ )		{
1056 					if (kconfig_is_axes_used(i))
1057 						masks |= (1<<i);
1058 				}
1059 
1060 				switch (Config_control_type) {
1061 				case	CONTROL_JOYSTICK:
1062 				case	CONTROL_FLIGHTSTICK_PRO:
1063 				case	CONTROL_THRUSTMASTER_FCS:
1064 					{
1065 						for (i=0; i<4; i++ )	{
1066 							if ( (masks&(1<<i)) && (!(old_masks&(1<<i))))
1067 								joydefs_calibrate_flag = 1;
1068 						}
1069 					}
1070 					break;
1071 				}
1072 			}
1073 			break;
1074 		case 11:
1075 			kconfig(0, TXT_KEYBOARD);
1076 			break;
1077 		case 12:
1078 			kconfig(4, "D2X KEYS");
1079 			break;
1080 		}
1081 
1082 		if ( kc_use_external_control )	{
1083 			kc_enable_external_control = m[12].value;
1084 		}
1085 
1086 	} while(i1>-1);
1087 
1088 	switch (Config_control_type) {
1089 	case	CONTROL_JOYSTICK:
1090 	case	CONTROL_FLIGHTSTICK_PRO:
1091 	case	CONTROL_THRUSTMASTER_FCS:
1092 		if ( joydefs_calibrate_flag )
1093 			joydefs_calibrate();
1094 		break;
1095 	}
1096 
1097 }
1098 
1099 #endif	// ifdef MACINTOSH
1100 
1101 #else 	//ifndef WINDOWS
1102 
joydef_menuset_win(int nitems,newmenu_item * items,int * last_key,int citem)1103 void joydef_menuset_win(int nitems, newmenu_item * items, int *last_key, int citem )
1104 {
1105 	int i;
1106 	int oc_type = Config_control_type;
1107 
1108 	Int3();	//need to make this code work for windows
1109 
1110 	nitems = nitems;
1111 	last_key = last_key;
1112 	citem = citem;
1113 
1114 	for (i=0; i<CONTROL_MAX_TYPES; i++ )
1115 		if (items[i].value) Config_control_type = i;
1116 
1117 	if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) )	{
1118 		nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS );
1119 	}
1120 
1121 	if (oc_type != Config_control_type) {
1122 		switch (Config_control_type) {
1123 	//		case	CONTROL_NONE:
1124 			case	CONTROL_JOYSTICK:
1125 			case	CONTROL_FLIGHTSTICK_PRO:
1126 			case	CONTROL_THRUSTMASTER_FCS:
1127 	//		case	CONTROL_GRAVIS_GAMEPAD:
1128 	//		case	CONTROL_MOUSE:
1129 	//		case	CONTROL_CYBERMAN:
1130 				joydefs_calibrate_flag = 1;
1131 		}
1132 		kc_set_controls();
1133 	}
1134 
1135 }
1136 
1137 //NOTE: WINDOWS VERSION
joydefs_config()1138 void joydefs_config()
1139 {
1140 	int i, old_masks, masks,nitems;
1141 	newmenu_item m[14];
1142 	int i1=11;
1143 	char xtext[128];
1144 
1145 	Int3();		//this routine really needs to be cleaned up
1146 
1147 	do {
1148 		nitems=13;
1149 		m[0].type = NM_TYPE_RADIO; m[0].text = CONTROL_TEXT(0); m[0].value = 0; m[0].group = 0;
1150 		m[1].type = NM_TYPE_RADIO; m[1].text = CONTROL_TEXT(1); m[1].value = 0; m[1].group = 0;
1151 		m[2].type = NM_TYPE_RADIO; m[2].text = CONTROL_TEXT(2); m[2].value = 0; m[2].group = 0;
1152 		m[3].type = NM_TYPE_RADIO; m[3].text = CONTROL_TEXT(3); m[3].value = 0; m[3].group = 0;
1153 		m[4].type = NM_TYPE_RADIO; m[4].text = CONTROL_TEXT(4); m[4].value = 0; m[4].group = 0;
1154 		m[5].type = NM_TYPE_RADIO; m[5].text = CONTROL_TEXT(5); m[5].value = 0; m[5].group = 0;
1155 		m[6].type = NM_TYPE_RADIO; m[6].text = CONTROL_TEXT(6); m[6].value = 0; m[6].group = 0;
1156 		m[7].type = NM_TYPE_RADIO; m[7].text = CONTROL_TEXT(7); m[7].value = 0; m[7].group = 0;
1157 
1158 		m[8].type = NM_TYPE_MENU; m[8].text=TXT_CUST_ABOVE;
1159 		m[9].type = NM_TYPE_TEXT;   m[9].text="";
1160 		m[10].type = NM_TYPE_SLIDER; m[10].text=TXT_JOYS_SENSITIVITY; m[10].value=Config_joystick_sensitivity; m[10].min_value =0; m[10].max_value = 8;
1161 		m[11].type = NM_TYPE_TEXT;   m[11].text="";
1162 		m[12].type = NM_TYPE_MENU; m[12].text=TXT_CUST_KEYBOARD;
1163 
1164 		m[Config_control_type].value = 1;
1165 
1166 		if ( kc_use_external_control )	{
1167 			sprintf( xtext, "Enable %s", kc_external_name );
1168 			m[13].type = NM_TYPE_CHECK; m[13].text = xtext; m[13].value = kc_enable_external_control;
1169 			nitems++;
1170 		}
1171 
1172 		i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_win, i1 );
1173 		Config_joystick_sensitivity = m[10].value;
1174 
1175 		switch(i1)	{
1176 		case 8: {
1177 				old_masks = 0;
1178 				for (i=0; i<4; i++ )		{
1179 					if (kconfig_is_axes_used(i))
1180 						old_masks |= (1<<i);
1181 				}
1182 				if ( Config_control_type==0 )
1183 					// nothing...
1184 					Config_control_type=0;
1185 				else if ( Config_control_type<5 )
1186 					kconfig(1, CONTROL_TEXT(Config_control_type) );
1187 				else
1188 					kconfig(2, CONTROL_TEXT(Config_control_type) );
1189 
1190 				masks = 0;
1191 				for (i=0; i<4; i++ )		{
1192 					if (kconfig_is_axes_used(i))
1193 						masks |= (1<<i);
1194 				}
1195 
1196 				switch (Config_control_type) {
1197 				case	CONTROL_JOYSTICK:
1198 				case	CONTROL_FLIGHTSTICK_PRO:
1199 				case	CONTROL_THRUSTMASTER_FCS:
1200 					{
1201 						for (i=0; i<4; i++ )	{
1202 							if ( (masks&(1<<i)) && (!(old_masks&(1<<i))))
1203 								joydefs_calibrate_flag = 1;
1204 						}
1205 					}
1206 					break;
1207 				}
1208 			}
1209 			break;
1210 		case 12:
1211 			kconfig(0, TXT_KEYBOARD);
1212 			break;
1213 		}
1214 
1215 		if ( kc_use_external_control )	{
1216 			kc_enable_external_control = m[13].value;
1217 		}
1218 
1219 	} while(i1>-1);
1220 
1221 	switch (Config_control_type) {
1222 	case	CONTROL_JOYSTICK:
1223 	case	CONTROL_FLIGHTSTICK_PRO:
1224 	case	CONTROL_THRUSTMASTER_FCS:
1225 		if ( joydefs_calibrate_flag )
1226 			joydefs_calibrate();
1227 		break;
1228 	}
1229 
1230 }
1231 
1232 #endif 	//ifndef WINDOWS
1233