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