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