]> icculus.org git repositories - btb/d2x.git/blob - main/old/joydefs.c
This commit was manufactured by cvs2svn to create tag 'd2x-0_1_3'.
[btb/d2x.git] / main / old / joydefs.c
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-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14
15 #pragma off (unreferenced)
16 static char rcsid[] = "$Id: joydefs.c,v 1.1.1.1 2001-01-19 03:30:14 bradleyb Exp $";
17 #pragma on (unreferenced)
18
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
22
23 #include "mono.h"
24 #include "key.h"
25 #include "joy.h"
26 #include "timer.h"
27 #include "error.h"
28
29 #include "inferno.h"
30 #include "game.h"
31 #include "object.h"
32 #include "player.h"
33
34 #include "controls.h"
35 #include "joydefs.h"
36 #include "render.h"
37 #include "palette.h"
38 #include "newmenu.h"
39 #include "args.h"
40 #include "text.h"
41 #include "kconfig.h"
42 #include "digi.h"
43 #include "playsave.h"
44
45 int joydefs_calibrate_flag = 0;
46
47 #ifdef MACINTOSH
48 ubyte joydefs_calibrating = 0;          // stupid hack all because of silly mouse cursor emulation
49 #endif
50
51 void joy_delay()
52 {
53         stop_time();
54 //      timer_delay(.25);
55         delay(250);                             // changed by allender because  1) more portable
56                                                         //                                                              2) was totally broken on PC
57         joy_flush();
58         start_time();
59 }
60
61
62 int joycal_message( char * title, char * text )
63 {
64         int i;
65         newmenu_item    m[2];
66         MAC(joydefs_calibrating = 1;)
67         m[0].type = NM_TYPE_TEXT; m[0].text = text;
68         m[1].type = NM_TYPE_MENU; m[1].text = TXT_OK;
69         i = newmenu_do( title, NULL, 2, m, NULL );
70         MAC(joydefs_calibrating = 0;)
71         if ( i < 0 ) 
72                 return 1;
73         return 0;
74 }
75
76 extern int WriteConfigFile();   
77
78 void joydefs_calibrate(void)
79 {
80         #ifndef MACINTOSH
81         if ( (Config_control_type!=CONTROL_JOYSTICK) && (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) && (Config_control_type!=CONTROL_THRUSTMASTER_FCS) )     
82                 return;
83         #else
84         if ( (Config_control_type == CONTROL_NONE) || (Config_control_type == CONTROL_MOUSE) )
85                 return;
86         #endif
87
88         palette_save();
89         apply_modified_palette();
90         reset_palette_add();
91
92         gr_palette_load(gr_palette);
93         joydefs_calibrate2();
94
95         reset_cockpit();
96
97         palette_restore();
98
99 }
100
101 #ifndef MACINTOSH
102 void joydefs_calibrate2()
103 {
104         ubyte masks;
105         int org_axis_min[4];
106         int org_axis_center[4];
107         int org_axis_max[4];
108
109         int axis_min[4] = { 0, 0, 0, 0 };
110         int axis_cen[4] = { 0, 0, 0, 0 };
111         int axis_max[4] = { 0, 0, 0, 0 };
112
113         int temp_values[4];
114         char title[50];
115         char text[50];
116         int nsticks = 0;
117
118         joydefs_calibrate_flag = 0;
119
120         joy_get_cal_vals(org_axis_min, org_axis_center, org_axis_max);
121
122         joy_set_cen();
123         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
124
125         if (!joy_present)       {
126                 nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK );
127                 return;
128         }
129         
130         masks = joy_get_present_mask();
131
132 #ifndef WINDOWS
133         if ( masks == JOY_ALL_AXIS )
134                 nsticks = 2;
135         else
136                 nsticks = 1;
137 #else
138         nsticks = 1;
139 #endif
140
141         if (Config_control_type == CONTROL_THRUSTMASTER_FCS)
142                 nsticks = 1;            //ignore for now the Sidewinder Pro X2 axis
143
144         if ( nsticks == 2 )     {
145                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
146                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
147         } else {
148                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
149                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
150         }
151         
152         if (joycal_message( title, text )) {
153                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
154                 return;
155         }
156         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
157         axis_min[0] = temp_values[0];
158         axis_min[1] = temp_values[1];
159         joy_delay();
160
161         if ( nsticks == 2 )     {
162                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
163                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
164         } else {
165                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
166                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
167         }
168         if (joycal_message( title, text)) {
169                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
170                 return;
171         }
172         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
173         axis_max[0] = temp_values[0];
174         axis_max[1] = temp_values[1];
175         joy_delay();
176
177         if ( nsticks == 2 )     {
178                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_CENTER);
179                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
180         } else {
181                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_CENTER);
182                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
183         }
184         if (joycal_message( title, text)) {
185                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
186                 return;
187         }
188         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
189         axis_cen[0] = temp_values[0];
190         axis_cen[1] = temp_values[1];
191         axis_cen[2] = temp_values[2];
192         joy_delay();
193
194         // The fcs uses axes 3 for hat, so don't calibrate it.
195         if ( Config_control_type == CONTROL_THRUSTMASTER_FCS )  {
196         #ifndef WINDOWS
197                 //set Y2 axis, which is hat
198                 axis_min[3] = 0;
199                 axis_cen[3] = temp_values[3]/2;
200                 axis_max[3] = temp_values[3];
201                 joy_delay();
202
203                 //if X2 exists, calibrate it (for Sidewinder Pro)
204                 if ( kconfig_is_axes_used(2) && (masks & JOY_2_X_AXIS) )        {
205                         sprintf( title, "Joystick X2 axis\nLEFT");
206                         sprintf( text, "Move joystick X2 axis\nall the way left");
207                         if (joycal_message( title, text )) {
208                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
209                                 return;
210                         }
211                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
212                         axis_min[2] = temp_values[2];
213                         axis_min[3] = temp_values[3];
214                         joy_delay();
215
216                         sprintf( title, "Joystick X2 axis\nRIGHT");
217                         sprintf( text, "Move joystick X2 axis\nall the way right");
218                         if (joycal_message( title, text ))      {
219                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); 
220                                 return;
221                         }
222                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
223                         axis_max[2] = temp_values[2];
224                         axis_max[3] = temp_values[3];
225                         joy_delay();
226                 }
227         #endif
228         } else {
229                 masks = joy_get_present_mask();
230
231                 if ( nsticks == 2 )     {
232                         if ( kconfig_is_axes_used(2) || kconfig_is_axes_used(3) )       {
233                                 sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
234                                 sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
235                                 if (joycal_message( title, text )) {
236                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
237                                         return;
238                                 }
239                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
240                                 axis_min[2] = temp_values[2];
241                                 axis_min[3] = temp_values[3];
242                                 joy_delay();
243
244                                 sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
245                                 sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
246                                 if (joycal_message( title, text ))      {
247                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); 
248                                         return;
249                                 }
250                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
251                                 axis_max[2] = temp_values[2];
252                                 axis_max[3] = temp_values[3];
253                                 joy_delay();
254                 
255                                 sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_CENTER);
256                                 sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
257                                 if (joycal_message( title, text ))      {
258                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
259                                         return;
260                                 }
261                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
262                                 axis_cen[2] = temp_values[2];
263                                 axis_cen[3] = temp_values[3];   
264                                 joy_delay();
265                         }
266                 }
267         #ifndef WINDOWS 
268                 else if ( (!(masks & JOY_2_X_AXIS)) && (masks & JOY_2_Y_AXIS) ) {
269                         if ( kconfig_is_axes_used(3) )  {
270                                 // A throttle axis!!!!!
271                                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_FORWARD);
272                                 if (joycal_message( title, TXT_MOVE_THROTTLE_F))        {
273                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
274                                         return;
275                                 }
276                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
277                                 axis_min[3] = temp_values[3];
278                                 joy_delay();
279                 
280                                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_REVERSE);
281                                 if (joycal_message( title, TXT_MOVE_THROTTLE_R)) {
282                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
283                                         return;
284                                 }
285                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
286                                 axis_max[3] = temp_values[3];
287                                 joy_delay();
288                 
289                                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_CENTER);
290                                 if (joycal_message( title, TXT_MOVE_THROTTLE_C)) {
291                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
292                                         return;
293                                 }
294                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
295                                 axis_cen[3] = temp_values[3];
296                                 joy_delay();
297                         }
298                 }
299         #endif
300         }
301         joy_set_cal_vals(axis_min, axis_cen, axis_max);
302
303         WriteConfigFile();      
304 }
305 #else
306 void joydefs_calibrate2()
307 {
308         ubyte masks;
309         int org_axis_min[4];
310         int org_axis_center[4];
311         int org_axis_max[4];
312
313         int axis_min[4] = { 0, 0, 0, 0 };
314         int axis_cen[4] = { 0, 0, 0, 0 };
315         int axis_max[4] = { 0, 0, 0, 0 };
316
317         int temp_values[4];
318         char title[50];
319         char text[50];
320         int i, nsticks = 0;
321
322         joydefs_calibrate_flag = 0;
323
324         if ( Config_control_type == CONTROL_THRUSTMASTER_FCS ) {
325                 axis_cen[0] = axis_cen[1] = axis_cen[2] = 0;
326                 axis_min[0] = axis_min[1] = axis_min[2] = -127;
327                 axis_max[0] = axis_max[1] = axis_max[2] = 127;
328                 axis_min[3] = 0;
329                 axis_max[3] = 255;
330                 axis_cen[3] = 128;
331                 joy_set_cal_vals(axis_min, axis_cen, axis_max);
332                 return;
333         }
334         
335         if ( Config_control_type == CONTROL_FLIGHTSTICK_PRO )           // no calibration needed
336                 return;
337                 
338         joy_get_cal_vals(org_axis_min, org_axis_center, org_axis_max);
339
340         joy_set_cen();
341         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
342
343         if (!joy_present)       {
344                 nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK );
345                 return;
346         }
347         
348         masks = joy_get_present_mask();
349
350         if ( masks == JOY_ALL_AXIS )
351                 nsticks = 2;
352         else
353                 nsticks = 1;
354
355         if ( (Config_control_type == CONTROL_THRUSTMASTER_FCS) || (Config_control_type == CONTROL_FLIGHTSTICK_PRO) )
356                 nsticks = 1;            //ignore for now the Sidewinder Pro X2 axis
357
358         if ( nsticks == 2 )     {
359                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
360                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
361         } else {
362                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
363                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
364         }
365         
366         if (joycal_message( title, text )) {
367                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
368                 return;
369         }
370         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
371         axis_min[0] = temp_values[0];
372         axis_min[1] = temp_values[1];
373         joy_delay();
374
375         if ( nsticks == 2 )     {
376                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
377                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
378         } else {
379                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
380                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
381         }
382         if (joycal_message( title, text)) {
383                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
384                 return;
385         }
386         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
387         axis_max[0] = temp_values[0];
388         axis_max[1] = temp_values[1];
389         joy_delay();
390
391         if ( nsticks == 2 )     {
392                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_CENTER);
393                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
394         } else {
395                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_CENTER);
396                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
397         }
398         if (joycal_message( title, text)) {
399                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
400                 return;
401         }
402         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
403         axis_cen[0] = temp_values[0];
404         axis_cen[1] = temp_values[1];
405         axis_cen[2] = temp_values[2];
406         joy_delay();
407
408         masks = joy_get_present_mask();
409
410         if ( nsticks == 2 )     {
411                 if ( kconfig_is_axes_used(2) || kconfig_is_axes_used(3) )       {
412                         sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
413                         sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
414                         if (joycal_message( title, text )) {
415                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
416                                 return;
417                         }
418                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
419                         axis_min[2] = temp_values[2];
420                         axis_min[3] = temp_values[3];
421                         joy_delay();
422
423                         sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
424                         sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
425                         if (joycal_message( title, text ))      {
426                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); 
427                                 return;
428                         }
429                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
430                         axis_max[2] = temp_values[2];
431                         axis_max[3] = temp_values[3];
432                         joy_delay();
433         
434                         sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_CENTER);
435                         sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
436                         if (joycal_message( title, text ))      {
437                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
438                                 return;
439                         }
440                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
441                         axis_cen[2] = temp_values[2];
442                         axis_cen[3] = temp_values[3];   
443                         joy_delay();
444                 }
445         } else {
446                 if ( kconfig_is_axes_used(3) )  {
447                         // A throttle axis!!!!!
448                         sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_FORWARD);
449                         if (joycal_message( title, TXT_MOVE_THROTTLE_F))        {
450                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
451                                 return;
452                         }
453                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
454                         axis_min[3] = temp_values[3];
455                         joy_delay();
456         
457                         sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_REVERSE);
458                         if (joycal_message( title, TXT_MOVE_THROTTLE_R)) {
459                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
460                                 return;
461                         }
462                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
463                         axis_max[3] = temp_values[3];
464                         joy_delay();
465         
466                         sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_CENTER);
467                         if (joycal_message( title, TXT_MOVE_THROTTLE_C)) {
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_cen[3] = temp_values[3];
473                         joy_delay();
474                 }
475         }
476         joy_set_cal_vals(axis_min, axis_cen, axis_max);
477
478         WriteConfigFile();      
479 }
480 #endif
481
482
483 //char *control_text[CONTROL_MAX_TYPES] = { "Keyboard only", "Joystick", "Flightstick Pro", "Thrustmaster FCS", "Gravis Gamepad", "Mouse", "Cyberman" };
484
485 #ifndef MACINTOSH               // mac will have own verion of this function
486
487 #define CONTROL_MAX_TYPES_DOS   (CONTROL_MAX_TYPES-1)   //last item is windows only
488
489 void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
490 {
491         int i;
492         int oc_type = Config_control_type;
493
494         nitems = nitems;
495         last_key = last_key;
496         citem = citem;          
497
498         for (i=0; i<CONTROL_MAX_TYPES_DOS; i++ )
499                 if (items[i].value) Config_control_type = i;
500
501         if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) )   {
502                 nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS );
503         }
504
505         if (oc_type != Config_control_type) {
506                 switch (Config_control_type) {
507         //              case    CONTROL_NONE:
508                         case    CONTROL_JOYSTICK:
509                         case    CONTROL_FLIGHTSTICK_PRO:
510                         case    CONTROL_THRUSTMASTER_FCS:
511         //              case    CONTROL_GRAVIS_GAMEPAD:
512         //              case    CONTROL_MOUSE:
513         //              case    CONTROL_CYBERMAN:
514                                 joydefs_calibrate_flag = 1;
515                 }
516                 kc_set_controls();
517         }
518
519 }
520
521 #else           // ifndef MACINTOSH
522
523 #define MAX_MAC_CONTROL_TYPES   6
524
525 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.";
526 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.";
527 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.";
528 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.";
529
530 void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
531 {
532         int i;
533         int oc_type = Config_control_type;
534         char *warning_text = NULL;
535
536         nitems = nitems;
537         last_key = last_key;
538         citem = citem;          
539
540         for (i=0; i<MAX_MAC_CONTROL_TYPES; i++ )
541                 if (items[i].value) Config_control_type = i;
542                 
543         if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_FLIGHTSTICK_PRO ) )    {
544                 warning_text = ch_warning;
545         }
546
547         if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) )   {
548                 warning_text = tm_warning;
549         }
550
551         if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_GRAVIS_GAMEPAD ) )     {
552                 warning_text = ms_warning;
553         }
554         
555         if (warning_text) {
556                 hide_cursor();
557                 nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, warning_text );
558                 show_cursor();
559         }
560
561         if (oc_type != Config_control_type) {
562                 switch (Config_control_type) {
563                         case    CONTROL_JOYSTICK:
564                         case    CONTROL_FLIGHTSTICK_PRO:
565                         case    CONTROL_THRUSTMASTER_FCS:
566                         case    CONTROL_GRAVIS_GAMEPAD:         // this really means a firebird or mousestick
567                                 joydefs_calibrate_flag = 1;
568                 }
569                 kc_set_controls();
570                 joydefs_set_type( Config_control_type );
571         }
572
573 }
574
575 #endif
576
577 extern ubyte kc_use_external_control;
578 extern ubyte kc_enable_external_control;
579 extern ubyte *kc_external_name;
580
581 #ifndef WINDOWS
582
583 #ifdef MACINTOSH
584
585 //NOTE: MAC VERSION
586 void joydefs_config()
587 {
588         int i, old_masks, masks,nitems;
589         newmenu_item m[14];
590         int i1=11;
591         char xtext[128];
592
593         do {
594                 m[0].type = NM_TYPE_RADIO; m[0].text = CONTROL_TEXT(0); m[0].value = 0; m[0].group = 0;
595                 m[1].type = NM_TYPE_RADIO; m[1].text = CONTROL_TEXT(1); m[1].value = 0; m[1].group = 0;
596                 m[2].type = NM_TYPE_RADIO; m[2].text = CONTROL_TEXT(2); m[2].value = 0; m[2].group = 0;
597                 m[3].type = NM_TYPE_RADIO; m[3].text = CONTROL_TEXT(3); m[3].value = 0; m[3].group = 0;
598 // change the text for the thrustmaster
599                 m[3].text = "Thrustmaster";
600                 m[4].type = NM_TYPE_RADIO; m[4].text = CONTROL_TEXT(4); m[4].value = 0; m[4].group = 0;
601 // change the text of the gravis gamepad to be the mac gravis sticks
602                 m[4].text = "Gravis Firebird/MouseStick II";
603                 m[5].type = NM_TYPE_RADIO; m[5].text = CONTROL_TEXT(5); m[5].value = 0; m[5].group = 0;
604
605                 
606                 m[6].type = NM_TYPE_MENU;   m[6].text=TXT_CUST_ABOVE;
607                 m[7].type = NM_TYPE_TEXT;   m[7].text="";
608                 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;
609                 m[9].type = NM_TYPE_TEXT;   m[9].text="";
610                 m[10].type = NM_TYPE_MENU;  m[10].text=TXT_CUST_KEYBOARD;
611                 nitems=11;
612
613                 m[Config_control_type].value = 1;
614
615                 i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 );
616                 Config_joystick_sensitivity = m[8].value;
617
618                 switch(i1)      {
619                 case 6: {
620                                 old_masks = 0;
621                                 for (i=0; i<4; i++ )            {
622                                         if (kconfig_is_axes_used(i))
623                                                 old_masks |= (1<<i);
624                                 }
625                                 if ( Config_control_type==0 )
626                                         // nothing...
627                                         Config_control_type=0;
628                                 else if ( Config_control_type == 1)  // this is just a joystick
629                                         nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, joy_warning );
630                                 else if ( Config_control_type<5 ) {
631                                         char title[64];
632                                         
633
634                                         if (Config_control_type == 3)
635                                                 strcpy(title, "Thrustmaster");
636                                         else if (Config_control_type == 4)
637                                                 strcpy(title, "Gravis Firebird/Mousestick II");
638                                         else
639                                                 strcpy(title, CONTROL_TEXT(Config_control_type) );
640                                                 
641
642                                         kconfig(1, title ); 
643                                 } else
644                                         kconfig(2, CONTROL_TEXT(Config_control_type) ); 
645                                 
646                                 masks = 0;
647                                 for (i=0; i<4; i++ )            {
648                                         if (kconfig_is_axes_used(i))
649                                                 masks |= (1<<i);
650                                 }
651
652                                 switch (Config_control_type) {
653                                 case    CONTROL_JOYSTICK:
654                                 case    CONTROL_FLIGHTSTICK_PRO:
655                                 case    CONTROL_THRUSTMASTER_FCS:       
656                                 case    CONTROL_GRAVIS_GAMEPAD:
657                                         {
658                                                 for (i=0; i<4; i++ )    {
659                                                         if ( (masks&(1<<i)) && (!(old_masks&(1<<i))))
660                                                                 joydefs_calibrate_flag = 1;
661                                                 }
662                                         }
663                                         break;
664                                 }
665                         }
666                         break;
667                 case 10: 
668                         kconfig(0, TXT_KEYBOARD); 
669                         break;
670                 } 
671
672         } while(i1>-1);
673
674         switch (Config_control_type) {
675         case    CONTROL_JOYSTICK:
676 //      case    CONTROL_FLIGHTSTICK_PRO:
677         case    CONTROL_THRUSTMASTER_FCS:
678         case    CONTROL_GRAVIS_GAMEPAD:
679                 if ( joydefs_calibrate_flag )
680                         joydefs_calibrate();
681                 break;
682         }
683
684 }
685
686 // silly routine to tell the joystick handler which type of control
687 // we are using
688 void joydefs_set_type(ubyte type)
689 {
690         ubyte joy_type;
691         
692         switch (type)
693         {
694                 case    CONTROL_NONE:                           joy_type = JOY_AS_NONE;                                 break;
695                 case    CONTROL_JOYSTICK:                       joy_type = JOY_AS_MOUSE;                                break;
696                 case    CONTROL_FLIGHTSTICK_PRO:        joy_type = JOY_AS_JOYMANAGER;                   break;
697                 case    CONTROL_THRUSTMASTER_FCS:       joy_type = JOY_AS_THRUSTMASTER;                 break;
698                 case    CONTROL_GRAVIS_GAMEPAD:         joy_type = JOY_AS_MOUSESTICK;                   break;
699                 case    CONTROL_MOUSE:                          joy_type = JOY_AS_MOUSE;                                break;
700         }
701         joy_set_type(joy_type);
702 }
703
704 #else           // #ifdef MACINTOSH
705
706 //NOTE: DOS VERSION
707 void joydefs_config()
708 {
709         int i, old_masks, masks,nitems;
710         newmenu_item m[14];
711         int i1=11;
712         char xtext[128];
713
714         do {
715                 nitems=12;
716                 m[0].type = NM_TYPE_RADIO; m[0].text = CONTROL_TEXT(0); m[0].value = 0; m[0].group = 0;
717                 m[1].type = NM_TYPE_RADIO; m[1].text = CONTROL_TEXT(1); m[1].value = 0; m[1].group = 0;
718                 m[2].type = NM_TYPE_RADIO; m[2].text = CONTROL_TEXT(2); m[2].value = 0; m[2].group = 0;
719                 m[3].type = NM_TYPE_RADIO; m[3].text = CONTROL_TEXT(3); m[3].value = 0; m[3].group = 0;
720                 m[4].type = NM_TYPE_RADIO; m[4].text = CONTROL_TEXT(4); m[4].value = 0; m[4].group = 0;
721                 m[5].type = NM_TYPE_RADIO; m[5].text = CONTROL_TEXT(5); m[5].value = 0; m[5].group = 0;
722                 m[6].type = NM_TYPE_RADIO; m[6].text = CONTROL_TEXT(6); m[6].value = 0; m[6].group = 0;
723
724                 m[ 7].type = NM_TYPE_MENU;              m[ 7].text=TXT_CUST_ABOVE;
725                 m[ 8].type = NM_TYPE_TEXT;              m[ 8].text="";
726                 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;
727                 m[10].type = NM_TYPE_TEXT;              m[10].text="";
728                 m[11].type = NM_TYPE_MENU;              m[11].text=TXT_CUST_KEYBOARD;
729
730                 m[Config_control_type].value = 1;
731
732                 if ( kc_use_external_control )  {
733                         sprintf( xtext, "Enable %s", kc_external_name );
734                         m[12].type = NM_TYPE_CHECK; m[12].text = xtext; m[12].value = kc_enable_external_control;
735                         nitems++;
736                 }
737       
738                 i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 );
739                 Config_joystick_sensitivity = m[9].value;
740
741                 switch(i1)      {
742                 case 7: {
743                                 old_masks = 0;
744                                 for (i=0; i<4; i++ )            {
745                                         if (kconfig_is_axes_used(i))
746                                                 old_masks |= (1<<i);
747                                 }
748                                 if ( Config_control_type==0 )
749                                         kconfig(0, TXT_KEYBOARD); 
750                                 else if ( Config_control_type<5 ) 
751                                         kconfig(1, CONTROL_TEXT(Config_control_type) ); 
752                                 else 
753                                         kconfig(2, CONTROL_TEXT(Config_control_type) ); 
754
755                                 masks = 0;
756                                 for (i=0; i<4; i++ )            {
757                                         if (kconfig_is_axes_used(i))
758                                                 masks |= (1<<i);
759                                 }
760
761                                 switch (Config_control_type) {
762                                 case    CONTROL_JOYSTICK:
763                                 case    CONTROL_FLIGHTSTICK_PRO:
764                                 case    CONTROL_THRUSTMASTER_FCS:       
765                                         {
766                                                 for (i=0; i<4; i++ )    {
767                                                         if ( (masks&(1<<i)) && (!(old_masks&(1<<i))))
768                                                                 joydefs_calibrate_flag = 1;
769                                                 }
770                                         }
771                                         break;
772                                 }
773                         }
774                         break;
775                 case 11: 
776                         kconfig(0, TXT_KEYBOARD); 
777                         break;
778                 } 
779
780                 if ( kc_use_external_control )  {
781                         kc_enable_external_control = m[12].value;
782                 }
783
784         } while(i1>-1);
785
786         switch (Config_control_type) {
787         case    CONTROL_JOYSTICK:
788         case    CONTROL_FLIGHTSTICK_PRO:
789         case    CONTROL_THRUSTMASTER_FCS:
790                 if ( joydefs_calibrate_flag )
791                         joydefs_calibrate();
792                 break;
793         }
794
795 }
796
797 #endif  // ifdef MACINTOSH
798
799 #else   //ifndef WINDOWS
800
801 void joydef_menuset_win(int nitems, newmenu_item * items, int *last_key, int citem )
802 {
803         int i;
804         int oc_type = Config_control_type;
805
806         Int3(); //need to make this code work for windows
807
808         nitems = nitems;
809         last_key = last_key;
810         citem = citem;          
811
812         for (i=0; i<CONTROL_MAX_TYPES; i++ )
813                 if (items[i].value) Config_control_type = i;
814
815         if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) )   {
816                 nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS );
817         }
818
819         if (oc_type != Config_control_type) {
820                 switch (Config_control_type) {
821         //              case    CONTROL_NONE:
822                         case    CONTROL_JOYSTICK:
823                         case    CONTROL_FLIGHTSTICK_PRO:
824                         case    CONTROL_THRUSTMASTER_FCS:
825         //              case    CONTROL_GRAVIS_GAMEPAD:
826         //              case    CONTROL_MOUSE:
827         //              case    CONTROL_CYBERMAN:
828                                 joydefs_calibrate_flag = 1;
829                 }
830                 kc_set_controls();
831         }
832
833 }
834
835 //NOTE: WINDOWS VERSION
836 void joydefs_config()
837 {
838         int i, old_masks, masks,nitems;
839         newmenu_item m[14];
840         int i1=11;
841         char xtext[128];
842
843         Int3();         //this routine really needs to be cleaned up
844  
845         do {
846                 nitems=13;
847                 m[0].type = NM_TYPE_RADIO; m[0].text = CONTROL_TEXT(0); m[0].value = 0; m[0].group = 0;
848                 m[1].type = NM_TYPE_RADIO; m[1].text = CONTROL_TEXT(1); m[1].value = 0; m[1].group = 0;
849                 m[2].type = NM_TYPE_RADIO; m[2].text = CONTROL_TEXT(2); m[2].value = 0; m[2].group = 0;
850                 m[3].type = NM_TYPE_RADIO; m[3].text = CONTROL_TEXT(3); m[3].value = 0; m[3].group = 0;
851                 m[4].type = NM_TYPE_RADIO; m[4].text = CONTROL_TEXT(4); m[4].value = 0; m[4].group = 0;
852                 m[5].type = NM_TYPE_RADIO; m[5].text = CONTROL_TEXT(5); m[5].value = 0; m[5].group = 0;
853                 m[6].type = NM_TYPE_RADIO; m[6].text = CONTROL_TEXT(6); m[6].value = 0; m[6].group = 0;
854                 m[7].type = NM_TYPE_RADIO; m[7].text = CONTROL_TEXT(7); m[7].value = 0; m[7].group = 0;
855
856                 m[8].type = NM_TYPE_MENU; m[8].text=TXT_CUST_ABOVE;
857                 m[9].type = NM_TYPE_TEXT;   m[9].text="";
858                 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;
859                 m[11].type = NM_TYPE_TEXT;   m[11].text="";
860                 m[12].type = NM_TYPE_MENU; m[12].text=TXT_CUST_KEYBOARD;
861
862                 m[Config_control_type].value = 1;
863
864                 if ( kc_use_external_control )  {
865                         sprintf( xtext, "Enable %s", kc_external_name );
866                         m[13].type = NM_TYPE_CHECK; m[13].text = xtext; m[13].value = kc_enable_external_control;
867                         nitems++;
868                 }
869       
870                 i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_win, i1 );
871                 Config_joystick_sensitivity = m[10].value;
872
873                 switch(i1)      {
874                 case 8: {
875                                 old_masks = 0;
876                                 for (i=0; i<4; i++ )            {
877                                         if (kconfig_is_axes_used(i))
878                                                 old_masks |= (1<<i);
879                                 }
880                                 if ( Config_control_type==0 )
881                                         // nothing...
882                                         Config_control_type=0;
883                                 else if ( Config_control_type<5 ) 
884                                         kconfig(1, CONTROL_TEXT(Config_control_type) ); 
885                                 else 
886                                         kconfig(2, CONTROL_TEXT(Config_control_type) ); 
887
888                                 masks = 0;
889                                 for (i=0; i<4; i++ )            {
890                                         if (kconfig_is_axes_used(i))
891                                                 masks |= (1<<i);
892                                 }
893
894                                 switch (Config_control_type) {
895                                 case    CONTROL_JOYSTICK:
896                                 case    CONTROL_FLIGHTSTICK_PRO:
897                                 case    CONTROL_THRUSTMASTER_FCS:       
898                                         {
899                                                 for (i=0; i<4; i++ )    {
900                                                         if ( (masks&(1<<i)) && (!(old_masks&(1<<i))))
901                                                                 joydefs_calibrate_flag = 1;
902                                                 }
903                                         }
904                                         break;
905                                 }
906                         }
907                         break;
908                 case 12: 
909                         kconfig(0, TXT_KEYBOARD); 
910                         break;
911                 } 
912
913                 if ( kc_use_external_control )  {
914                         kc_enable_external_control = m[13].value;
915                 }
916
917         } while(i1>-1);
918
919         switch (Config_control_type) {
920         case    CONTROL_JOYSTICK:
921         case    CONTROL_FLIGHTSTICK_PRO:
922         case    CONTROL_THRUSTMASTER_FCS:
923                 if ( joydefs_calibrate_flag )
924                         joydefs_calibrate();
925                 break;
926         }
927
928 }
929
930 #endif  //ifndef WINDOWS