]> icculus.org git repositories - btb/d2x.git/blob - main/joydefs.c
Rename include/error.h to include/dxxerror.h
[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 "dxxerror.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         if ( masks == JOY_ALL_AXIS )
147                 nsticks = 2;
148         else
149                 nsticks = 1;
150
151         if (Config_control_type == CONTROL_THRUSTMASTER_FCS)
152                 nsticks = 1;            //ignore for now the Sidewinder Pro X2 axis
153
154         if ( nsticks == 2 )     {
155                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
156                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
157         } else {
158                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
159                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
160         }
161
162         if (joycal_message( title, text )) {
163                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
164                 return;
165         }
166         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
167         axis_min[0] = temp_values[0];
168         axis_min[1] = temp_values[1];
169         joy_delay();
170
171         if ( nsticks == 2 )     {
172                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
173                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
174         } else {
175                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
176                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
177         }
178         if (joycal_message( title, text)) {
179                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
180                 return;
181         }
182         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
183         axis_max[0] = temp_values[0];
184         axis_max[1] = temp_values[1];
185         joy_delay();
186
187         if ( nsticks == 2 )     {
188                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_CENTER);
189                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
190         } else {
191                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_CENTER);
192                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
193         }
194         if (joycal_message( title, text)) {
195                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
196                 return;
197         }
198         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
199         axis_cen[0] = temp_values[0];
200         axis_cen[1] = temp_values[1];
201         axis_cen[2] = temp_values[2];
202         joy_delay();
203
204         // The fcs uses axes 3 for hat, so don't calibrate it.
205         if ( Config_control_type == CONTROL_THRUSTMASTER_FCS )  {
206                 //set Y2 axis, which is hat
207                 axis_min[3] = 0;
208                 axis_cen[3] = temp_values[3]/2;
209                 axis_max[3] = temp_values[3];
210                 joy_delay();
211
212                 //if X2 exists, calibrate it (for Sidewinder Pro)
213                 if ( kconfig_is_axes_used(2) && (masks & JOY_2_X_AXIS) )        {
214                         sprintf( title, "Joystick X2 axis\nLEFT");
215                         sprintf( text, "Move joystick X2 axis\nall the way left");
216                         if (joycal_message( title, text )) {
217                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
218                                 return;
219                         }
220                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
221                         axis_min[2] = temp_values[2];
222                         axis_min[3] = temp_values[3];
223                         joy_delay();
224
225                         sprintf( title, "Joystick X2 axis\nRIGHT");
226                         sprintf( text, "Move joystick X2 axis\nall the way right");
227                         if (joycal_message( title, text ))      {
228                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
229                                 return;
230                         }
231                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
232                         axis_max[2] = temp_values[2];
233                         axis_max[3] = temp_values[3];
234                         joy_delay();
235                 }
236         } else {
237                 masks = joy_get_present_mask();
238
239                 if ( nsticks == 2 )     {
240                         if ( kconfig_is_axes_used(2) || kconfig_is_axes_used(3) )       {
241                                 sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
242                                 sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
243                                 if (joycal_message( title, text )) {
244                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
245                                         return;
246                                 }
247                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
248                                 axis_min[2] = temp_values[2];
249                                 axis_min[3] = temp_values[3];
250                                 joy_delay();
251
252                                 sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
253                                 sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
254                                 if (joycal_message( title, text ))      {
255                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
256                                         return;
257                                 }
258                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
259                                 axis_max[2] = temp_values[2];
260                                 axis_max[3] = temp_values[3];
261                                 joy_delay();
262
263                                 sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_CENTER);
264                                 sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
265                                 if (joycal_message( title, text ))      {
266                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
267                                         return;
268                                 }
269                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
270                                 axis_cen[2] = temp_values[2];
271                                 axis_cen[3] = temp_values[3];
272                                 joy_delay();
273                         }
274                 }
275                 else if ( (!(masks & JOY_2_X_AXIS)) && (masks & JOY_2_Y_AXIS) ) {
276                         if ( kconfig_is_axes_used(3) )  {
277                                 // A throttle axis!!!!!
278                                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_FORWARD);
279                                 if (joycal_message( title, TXT_MOVE_THROTTLE_F))        {
280                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
281                                         return;
282                                 }
283                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
284                                 axis_min[3] = temp_values[3];
285                                 joy_delay();
286
287                                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_REVERSE);
288                                 if (joycal_message( title, TXT_MOVE_THROTTLE_R)) {
289                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
290                                         return;
291                                 }
292                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
293                                 axis_max[3] = temp_values[3];
294                                 joy_delay();
295
296                                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_CENTER);
297                                 if (joycal_message( title, TXT_MOVE_THROTTLE_C)) {
298                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
299                                         return;
300                                 }
301                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
302                                 axis_cen[3] = temp_values[3];
303                                 joy_delay();
304                         }
305                 }
306         }
307         joy_set_cal_vals(axis_min, axis_cen, axis_max);
308
309         WriteConfigFile();
310 }
311 #else
312 void joydefs_calibrate2()
313 {
314         ubyte masks;
315         int org_axis_min[4];
316         int org_axis_center[4];
317         int org_axis_max[4];
318
319         int axis_min[4] = { 0, 0, 0, 0 };
320         int axis_cen[4] = { 0, 0, 0, 0 };
321         int axis_max[4] = { 0, 0, 0, 0 };
322
323         int temp_values[4];
324         char title[50];
325         char text[50];
326         int i, nsticks = 0;
327
328         joydefs_calibrate_flag = 0;
329
330         if ( Config_control_type == CONTROL_THRUSTMASTER_FCS ) {
331                 axis_cen[0] = axis_cen[1] = axis_cen[2] = 0;
332                 axis_min[0] = axis_min[1] = axis_min[2] = -127;
333                 axis_max[0] = axis_max[1] = axis_max[2] = 127;
334                 axis_min[3] = 0;
335                 axis_max[3] = 255;
336                 axis_cen[3] = 128;
337                 joy_set_cal_vals(axis_min, axis_cen, axis_max);
338                 return;
339         }
340
341         if ( Config_control_type == CONTROL_FLIGHTSTICK_PRO )           // no calibration needed
342                 return;
343
344         joy_get_cal_vals(org_axis_min, org_axis_center, org_axis_max);
345
346         joy_set_cen();
347         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
348
349         if (!joy_present)       {
350                 nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK );
351                 return;
352         }
353
354         masks = joy_get_present_mask();
355
356         if ( masks == JOY_ALL_AXIS )
357                 nsticks = 2;
358         else
359                 nsticks = 1;
360
361         if ( (Config_control_type == CONTROL_THRUSTMASTER_FCS) || (Config_control_type == CONTROL_FLIGHTSTICK_PRO) )
362                 nsticks = 1;            //ignore for now the Sidewinder Pro X2 axis
363
364         if ( nsticks == 2 )     {
365                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
366                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
367         } else {
368                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
369                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
370         }
371
372         if (joycal_message( title, text )) {
373                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
374                 return;
375         }
376         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
377         axis_min[0] = temp_values[0];
378         axis_min[1] = temp_values[1];
379         joy_delay();
380
381         if ( nsticks == 2 )     {
382                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
383                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
384         } else {
385                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
386                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
387         }
388         if (joycal_message( title, text)) {
389                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
390                 return;
391         }
392         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
393         axis_max[0] = temp_values[0];
394         axis_max[1] = temp_values[1];
395         joy_delay();
396
397         if ( nsticks == 2 )     {
398                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_CENTER);
399                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
400         } else {
401                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_CENTER);
402                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
403         }
404         if (joycal_message( title, text)) {
405                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
406                 return;
407         }
408         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
409         axis_cen[0] = temp_values[0];
410         axis_cen[1] = temp_values[1];
411         axis_cen[2] = temp_values[2];
412         joy_delay();
413
414         masks = joy_get_present_mask();
415
416         if ( nsticks == 2 )     {
417                 if ( kconfig_is_axes_used(2) || kconfig_is_axes_used(3) )       {
418                         sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
419                         sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
420                         if (joycal_message( title, text )) {
421                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
422                                 return;
423                         }
424                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
425                         axis_min[2] = temp_values[2];
426                         axis_min[3] = temp_values[3];
427                         joy_delay();
428
429                         sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
430                         sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
431                         if (joycal_message( title, text ))      {
432                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
433                                 return;
434                         }
435                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
436                         axis_max[2] = temp_values[2];
437                         axis_max[3] = temp_values[3];
438                         joy_delay();
439
440                         sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_CENTER);
441                         sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
442                         if (joycal_message( title, text ))      {
443                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
444                                 return;
445                         }
446                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
447                         axis_cen[2] = temp_values[2];
448                         axis_cen[3] = temp_values[3];
449                         joy_delay();
450                 }
451         } else {
452                 if ( kconfig_is_axes_used(3) )  {
453                         // A throttle axis!!!!!
454                         sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_FORWARD);
455                         if (joycal_message( title, TXT_MOVE_THROTTLE_F))        {
456                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
457                                 return;
458                         }
459                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
460                         axis_min[3] = temp_values[3];
461                         joy_delay();
462
463                         sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_REVERSE);
464                         if (joycal_message( title, TXT_MOVE_THROTTLE_R)) {
465                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
466                                 return;
467                         }
468                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
469                         axis_max[3] = temp_values[3];
470                         joy_delay();
471
472                         sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_CENTER);
473                         if (joycal_message( title, TXT_MOVE_THROTTLE_C)) {
474                                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
475                                 return;
476                         }
477                         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
478                         axis_cen[3] = temp_values[3];
479                         joy_delay();
480                 }
481         }
482         joy_set_cal_vals(axis_min, axis_cen, axis_max);
483
484         WriteConfigFile();
485 }
486 #endif
487 #endif // 0
488
489 //char *control_text[CONTROL_MAX_TYPES] = { "Keyboard only", "Joystick", "Flightstick Pro", "Thrustmaster FCS", "Gravis Gamepad", "Mouse", "Cyberman" };
490
491 #ifndef MACINTOSH               // mac will have own verion of this function
492
493 #define CONTROL_MAX_TYPES_DOS   (CONTROL_MAX_TYPES-1)   //last item is windows only
494
495 void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
496 {
497         int i;
498         int oc_type = Config_control_type;
499
500         nitems = nitems;
501         last_key = last_key;
502         citem = citem;
503
504         for (i=0; i<CONTROL_MAX_TYPES_DOS; i++ )
505                 if (items[i].value) Config_control_type = i;
506
507         if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) )   {
508                 nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS );
509         }
510
511         if (oc_type != Config_control_type) {
512                 switch (Config_control_type) {
513         //              case    CONTROL_NONE:
514                         case    CONTROL_JOYSTICK:
515                         case    CONTROL_FLIGHTSTICK_PRO:
516                         case    CONTROL_THRUSTMASTER_FCS:
517         //              case    CONTROL_GRAVIS_GAMEPAD:
518         //              case    CONTROL_MOUSE:
519         //              case    CONTROL_CYBERMAN:
520                                 joydefs_calibrate_flag = 1;
521                 }
522                 kc_set_controls();
523         }
524
525 }
526
527 #else           // ifndef MACINTOSH
528
529 #define MAX_MAC_CONTROL_TYPES   6
530
531 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.";
532 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.";
533 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.";
534 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.";
535
536 void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
537 {
538         int i;
539         int oc_type = Config_control_type;
540         char *warning_text = NULL;
541
542         nitems = nitems;
543         last_key = last_key;
544         citem = citem;
545
546         for (i=0; i<MAX_MAC_CONTROL_TYPES; i++ )
547                 if (items[i].value) Config_control_type = i;
548
549         if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_FLIGHTSTICK_PRO ) )    {
550                 warning_text = ch_warning;
551         }
552
553         if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) )   {
554                 warning_text = tm_warning;
555         }
556
557         if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_GRAVIS_GAMEPAD ) )     {
558                 warning_text = ms_warning;
559         }
560
561         if (warning_text) {
562                 hide_cursor();
563                 nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, warning_text );
564                 show_cursor();
565         }
566
567         if (oc_type != Config_control_type) {
568                 switch (Config_control_type) {
569                         case    CONTROL_JOYSTICK:
570                         case    CONTROL_FLIGHTSTICK_PRO:
571                         case    CONTROL_THRUSTMASTER_FCS:
572                         case    CONTROL_GRAVIS_GAMEPAD:         // this really means a firebird or mousestick
573                                 joydefs_calibrate_flag = 1;
574                 }
575                 kc_set_controls();
576                 joydefs_set_type( Config_control_type );
577         }
578
579 }
580
581 #endif
582
583 extern ubyte kc_use_external_control;
584 extern ubyte kc_enable_external_control;
585 extern ubyte *kc_external_name;
586
587
588 #ifdef MACINTOSH
589
590 //NOTE: MAC VERSION
591 void joydefs_config()
592 {
593         int i, old_masks, masks,nitems;
594         newmenu_item m[14];
595         int i1=11;
596         char xtext[128];
597
598         do {
599                 m[0].type = NM_TYPE_RADIO; m[0].text = CONTROL_TEXT(0); m[0].value = 0; m[0].group = 0;
600                 m[1].type = NM_TYPE_RADIO; m[1].text = CONTROL_TEXT(1); m[1].value = 0; m[1].group = 0;
601                 m[2].type = NM_TYPE_RADIO; m[2].text = CONTROL_TEXT(2); m[2].value = 0; m[2].group = 0;
602                 m[3].type = NM_TYPE_RADIO; m[3].text = CONTROL_TEXT(3); m[3].value = 0; m[3].group = 0;
603 // change the text for the thrustmaster
604                 m[3].text = "Thrustmaster";
605                 m[4].type = NM_TYPE_RADIO; m[4].text = CONTROL_TEXT(4); m[4].value = 0; m[4].group = 0;
606 // change the text of the gravis gamepad to be the mac gravis sticks
607                 m[4].text = "Gravis Firebird/MouseStick II";
608                 m[5].type = NM_TYPE_RADIO; m[5].text = CONTROL_TEXT(5); m[5].value = 0; m[5].group = 0;
609
610                 m[6].type = NM_TYPE_MENU;   m[6].text=TXT_CUST_ABOVE;
611                 m[7].type = NM_TYPE_TEXT;   m[7].text="";
612                 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;
613                 m[9].type = NM_TYPE_TEXT;   m[9].text="";
614                 m[10].type = NM_TYPE_MENU;  m[10].text=TXT_CUST_KEYBOARD;
615                 nitems=11;
616
617                 m[Config_control_type].value = 1;
618
619                 i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 );
620                 Config_joystick_sensitivity = m[8].value;
621
622                 switch(i1)      {
623                 case 6: {
624                                 old_masks = 0;
625                                 for (i=0; i<4; i++ )            {
626                                         if (kconfig_is_axes_used(i))
627                                                 old_masks |= (1<<i);
628                                 }
629                                 if ( Config_control_type==0 )
630                                         // nothing...
631                                         Config_control_type=0;
632                                 else if ( Config_control_type == 1)  // this is just a joystick
633                                         nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, joy_warning );
634                                 else if ( Config_control_type<5 ) {
635                                         char title[64];
636
637                                         if (Config_control_type == 3)
638                                                 strcpy(title, "Thrustmaster");
639                                         else if (Config_control_type == 4)
640                                                 strcpy(title, "Gravis Firebird/Mousestick II");
641                                         else
642                                                 strcpy(title, CONTROL_TEXT(Config_control_type) );
643
644
645                                         kconfig(1, title );
646                                 } else
647                                         kconfig(2, CONTROL_TEXT(Config_control_type) );
648
649                                 masks = 0;
650                                 for (i=0; i<4; i++ )            {
651                                         if (kconfig_is_axes_used(i))
652                                                 masks |= (1<<i);
653                                 }
654
655                                 switch (Config_control_type) {
656                                 case    CONTROL_JOYSTICK:
657                                 case    CONTROL_FLIGHTSTICK_PRO:
658                                 case    CONTROL_THRUSTMASTER_FCS:
659                                 case    CONTROL_GRAVIS_GAMEPAD:
660                                         {
661                                                 for (i=0; i<4; i++ )    {
662                                                         if ( (masks&(1<<i)) && (!(old_masks&(1<<i))))
663                                                                 joydefs_calibrate_flag = 1;
664                                                 }
665                                         }
666                                         break;
667                                 }
668                         }
669                         break;
670                 case 10:
671                         kconfig(0, TXT_KEYBOARD);
672                         break;
673                 }
674
675         } while(i1>-1);
676
677         switch (Config_control_type) {
678         case    CONTROL_JOYSTICK:
679 //      case    CONTROL_FLIGHTSTICK_PRO:
680         case    CONTROL_THRUSTMASTER_FCS:
681         case    CONTROL_GRAVIS_GAMEPAD:
682                 if ( joydefs_calibrate_flag )
683                         joydefs_calibrate();
684                 break;
685         }
686
687 }
688
689 // silly routine to tell the joystick handler which type of control
690 // we are using
691 void joydefs_set_type(ubyte type)
692 {
693         ubyte joy_type;
694
695         switch (type)
696         {
697                 case    CONTROL_NONE:                           joy_type = JOY_AS_NONE;                                 break;
698                 case    CONTROL_JOYSTICK:                       joy_type = JOY_AS_MOUSE;                                break;
699                 case    CONTROL_FLIGHTSTICK_PRO:        joy_type = JOY_AS_JOYMANAGER;                   break;
700                 case    CONTROL_THRUSTMASTER_FCS:       joy_type = JOY_AS_THRUSTMASTER;                 break;
701                 case    CONTROL_GRAVIS_GAMEPAD:         joy_type = JOY_AS_MOUSESTICK;                   break;
702                 case    CONTROL_MOUSE:                          joy_type = JOY_AS_MOUSE;                                break;
703         }
704         joy_set_type(joy_type);
705 }
706
707 #else           // #ifdef MACINTOSH
708
709 //NOTE: UNIX/DOS VERSION
710 void joydefs_config()
711 {
712         int i, old_masks, masks,nitems;
713         newmenu_item m[14];
714         int i1=11;
715         char xtext[128];
716
717         do {
718                 nitems=12;
719                 m[0].type = NM_TYPE_RADIO; m[0].text = CONTROL_TEXT(0); m[0].value = 0; m[0].group = 0;
720                 m[1].type = NM_TYPE_RADIO; m[1].text = CONTROL_TEXT(1); m[1].value = 0; m[1].group = 0;
721                 m[2].type = NM_TYPE_RADIO; m[2].text = CONTROL_TEXT(2); m[2].value = 0; m[2].group = 0;
722                 m[3].type = NM_TYPE_RADIO; m[3].text = CONTROL_TEXT(3); m[3].value = 0; m[3].group = 0;
723                 m[4].type = NM_TYPE_RADIO; m[4].text = CONTROL_TEXT(4); m[4].value = 0; m[4].group = 0;
724                 m[5].type = NM_TYPE_RADIO; m[5].text = CONTROL_TEXT(5); m[5].value = 0; m[5].group = 0;
725                 m[6].type = NM_TYPE_RADIO; m[6].text = CONTROL_TEXT(6); m[6].value = 0; m[6].group = 0;
726
727                 m[ 7].type = NM_TYPE_MENU;              m[ 7].text=TXT_CUST_ABOVE;
728                 m[ 8].type = NM_TYPE_TEXT;              m[ 8].text="";
729                 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;
730                 m[10].type = NM_TYPE_TEXT;              m[10].text="";
731                 m[11].type = NM_TYPE_MENU;              m[11].text=TXT_CUST_KEYBOARD;
732
733                 m[Config_control_type].value = 1;
734
735                 if ( kc_use_external_control )  {
736                         sprintf( xtext, "Enable %s", kc_external_name );
737                         m[12].type = NM_TYPE_CHECK; m[12].text = xtext; m[12].value = kc_enable_external_control;
738                         nitems++;
739                 }
740
741                 m[nitems].type = NM_TYPE_MENU; m[nitems].text="CUSTOMIZE D2X KEYS"; nitems++;
742
743                 i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 );
744                 Config_joystick_sensitivity = m[9].value;
745
746                 switch(i1)      {
747                 case 7: {
748                                 old_masks = 0;
749                                 for (i=0; i<4; i++ )            {
750                                         if (kconfig_is_axes_used(i))
751                                                 old_masks |= (1<<i);
752                                 }
753                                 if ( Config_control_type==0 )
754                                         kconfig(0, TXT_KEYBOARD);
755                                 else if ( Config_control_type<5 )
756                                         kconfig(1, CONTROL_TEXT(Config_control_type) );
757                                 else
758                                         kconfig(2, CONTROL_TEXT(Config_control_type) );
759
760                                 masks = 0;
761                                 for (i=0; i<4; i++ )            {
762                                         if (kconfig_is_axes_used(i))
763                                                 masks |= (1<<i);
764                                 }
765
766                                 switch (Config_control_type) {
767                                 case    CONTROL_JOYSTICK:
768                                 case    CONTROL_FLIGHTSTICK_PRO:
769                                 case    CONTROL_THRUSTMASTER_FCS:
770                                         {
771                                                 for (i=0; i<4; i++ )    {
772                                                         if ( (masks&(1<<i)) && (!(old_masks&(1<<i))))
773                                                                 joydefs_calibrate_flag = 1;
774                                                 }
775                                         }
776                                         break;
777                                 }
778                         }
779                         break;
780                 case 11:
781                         kconfig(0, TXT_KEYBOARD);
782                         break;
783                 case 12:
784                         kconfig(4, "D2X KEYS");
785                         break;
786                 }
787
788                 if ( kc_use_external_control )  {
789                         kc_enable_external_control = m[12].value;
790                 }
791
792         } while(i1>-1);
793
794         switch (Config_control_type) {
795         case    CONTROL_JOYSTICK:
796         case    CONTROL_FLIGHTSTICK_PRO:
797         case    CONTROL_THRUSTMASTER_FCS:
798                 if ( joydefs_calibrate_flag )
799                         joydefs_calibrate();
800                 break;
801         }
802
803 }
804
805 #endif  // ifdef MACINTOSH