]> icculus.org git repositories - btb/d2x.git/blob - arch/dos/joydefs.c
unused
[btb/d2x.git] / arch / dos / 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-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  * 
16  * .
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
28 #include "pstypes.h"
29 #include "mono.h"
30 #include "key.h"
31 #include "joy.h"
32 #include "timer.h"
33 #include "error.h"
34
35 #include "inferno.h"
36 #include "game.h"
37 #include "object.h"
38 #include "player.h"
39
40 #include "controls.h"
41 #include "joydefs.h"
42 #include "render.h"
43 #include "palette.h"
44 #include "newmenu.h"
45 #include "args.h"
46 #include "text.h"
47 #include "kconfig.h"
48 #include "digi.h"
49
50 int joydefs_calibrate_flag = 0;
51
52 int Joy_is_Sidewinder = 0;
53
54 void joy_delay()
55 {
56 #ifdef __MSDOS__
57         int t1 = TICKER + 19/4;                 // Wait 1/4 second...
58         stop_time();
59         while( TICKER < t1 );
60         joy_flush();
61         start_time();
62 #endif
63 }
64
65
66 int joycal_message( char * title, char * text )
67 {
68         int i;
69         newmenu_item    m[2];
70         m[0].type = NM_TYPE_TEXT; m[0].text = text;
71         m[1].type = NM_TYPE_MENU; m[1].text = TXT_OK;
72         i = newmenu_do( title, NULL, 2, m, NULL );
73         if ( i < 0 ) 
74                 return 1;
75         return 0;
76 }
77
78 extern int WriteConfigFile();   
79
80 void joydefs_calibrate()
81 {
82         ubyte masks;
83         int org_axis_min[4];
84         int org_axis_center[4];
85         int org_axis_max[4];
86
87         int axis_min[4] = { 0, 0, 0, 0 };
88         int axis_cen[4] = { 0, 0, 0, 0 };
89         int axis_max[4] = { 0, 0, 0, 0 };
90
91         int temp_values[4];
92         char title[50];
93         char text[50];
94         int nsticks = 0;
95
96         joydefs_calibrate_flag = 0;
97
98         if ( (Config_control_type.intval != CONTROL_JOYSTICK) &&
99                  (Config_control_type.intval != CONTROL_FLIGHTSTICK_PRO) &&
100                  (Config_control_type.intval != CONTROL_THRUSTMASTER_FCS) &&
101                  (Config_control_type.intval != CONTROL_GRAVIS_GAMEPAD) )
102                 return;
103
104         joy_get_cal_vals(org_axis_min, org_axis_center, org_axis_max);
105
106         joy_set_cen();
107         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
108
109         if (!joy_present)       {
110                 nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK );
111                 return;
112         }
113         
114         masks = joy_get_present_mask();
115
116         if ( masks == JOY_ALL_AXIS )
117                 nsticks = 2;
118         else
119                 nsticks = 1;
120
121         if ( nsticks == 2 && !Joy_is_Sidewinder)     {
122                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
123                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
124         } else {
125                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
126                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
127         }
128         if (joycal_message( title, text )) {
129                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
130                 return;
131         }
132         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
133         axis_min[0] = temp_values[0];
134         axis_min[1] = temp_values[1];
135         joy_delay();
136
137         if ( nsticks == 2 && !Joy_is_Sidewinder)     {
138                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
139                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
140         } else {
141                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
142                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
143         }
144         if (joycal_message( title, text)) {
145                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
146                 return;
147         }
148         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
149         axis_max[0] = temp_values[0];
150         axis_max[1] = temp_values[1];
151         joy_delay();
152
153         if ( nsticks == 2 && !Joy_is_Sidewinder)     {
154                 sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_CENTER);
155                 sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
156         } else {
157                 sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_CENTER);
158                 sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
159         }
160         if (joycal_message( title, text)) {
161                 joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
162                 return;
163         }
164         joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
165         axis_cen[0] = temp_values[0];
166         axis_cen[1] = temp_values[1];
167         joy_delay();
168
169         // The fcs uses axes 3 for hat, so don't calibrate it.
170         if (Config_control_type.intval == CONTROL_THRUSTMASTER_FCS) {
171                 axis_min[3] = 0;
172                 axis_cen[3] = temp_values[3]/2;
173                 axis_max[3] = temp_values[3];
174                 joy_delay();
175         }
176
177         if (Joy_is_Sidewinder || Config_control_type.intval != CONTROL_THRUSTMASTER_FCS) {
178             //    masks = joy_get_present_mask();
179
180                 if ( nsticks == 2 )     {
181                         if ( kconfig_is_axes_used(2) || kconfig_is_axes_used(3) )       {
182                                 if(Joy_is_Sidewinder)
183                                  {
184                                   sprintf( title, "%s\nTWIST-LEFT", TXT_JOYSTICK);
185                                   sprintf( text, "Twist Joystick to \nthe left side");
186                                  }
187                                 else
188                                  {
189                                   sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
190                                   sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
191                                  }
192                                 if (joycal_message( title, text )) {
193                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
194                                         return;
195                                 }
196                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
197                                 axis_min[2] = temp_values[2];
198                                 axis_min[3] = temp_values[3];
199                                 joy_delay();
200
201                                 if(Joy_is_Sidewinder)
202                                  {
203                                   sprintf( title, "%s\nTWIST-RIGHT", TXT_JOYSTICK);
204                                   sprintf( text, "Twist Joystick to \nthe right side");
205                                  }
206                                 else
207                                  {
208                                   sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
209                                   sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
210                                  }
211                                 if (joycal_message( title, text ))      {
212                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); 
213                                         return;
214                                 }
215                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
216                                 axis_max[2] = temp_values[2];
217                                 axis_max[3] = temp_values[3];
218                                 joy_delay();
219
220                                 
221                                 if(Joy_is_Sidewinder)
222                                  {
223                                   sprintf( title, "%s\nCENTER", TXT_JOYSTICK);
224                                   sprintf( text, "%s %s",TXT_MOVE_JOYSTICK, TXT_TO_C);
225                                  }
226                                 else
227                                  {
228                                    sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_CENTER);
229                                    sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
230                                  }
231
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_cen[2] = temp_values[2];
238                                 axis_cen[3] = temp_values[3];   
239                                 joy_delay();
240                         }
241                 } else if ( (!(masks & JOY_2_X_AXIS)) && (masks & JOY_2_Y_AXIS) )       {
242                         if ( kconfig_is_axes_used(3) )  {
243                                 // A throttle axis!!!!!
244                                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_FORWARD);
245                                 if (joycal_message( title, TXT_MOVE_THROTTLE_F))        {
246                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
247                                         return;
248                                 }
249                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
250                                 axis_min[3] = temp_values[3];
251                                 joy_delay();
252                 
253                                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_REVERSE);
254                                 if (joycal_message( title, TXT_MOVE_THROTTLE_R)) {
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[3] = temp_values[3];
260                                 joy_delay();
261                 
262                                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_CENTER);
263                                 if (joycal_message( title, TXT_MOVE_THROTTLE_C)) {
264                                         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
265                                         return;
266                                 }
267                                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
268                                 axis_cen[3] = temp_values[3];
269                                 joy_delay();
270                         }
271                 }
272         }
273         joy_set_cal_vals(axis_min, axis_cen, axis_max);
274
275
276 //added 9/1/98 by Victor Rachels to make sidewinder calibratable
277 /*         if(Joy_is_Sidewinder)
278                 cvar_setint(&Config_control_type, tempstick); */
279 //end this section addition - Victor Rachels
280
281
282         WriteConfigFile();
283 }
284
285
286 void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
287 {
288         int i;
289         int oc_type = Config_control_type.intval;
290
291         nitems = nitems;
292         last_key = last_key;
293         citem = citem;          
294
295         for (i=0; i<CONTROL_MAX_TYPES; i++ )
296                 if (items[i].value)
297                         cvar_setint(&Config_control_type, i);
298
299         if ( (oc_type != Config_control_type.intval) && (Config_control_type.intval == CONTROL_THRUSTMASTER_FCS ) ) {
300                 nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS );
301         }
302
303         if (oc_type != Config_control_type.intval) {
304                 switch (Config_control_type.intval) {
305         //              case    CONTROL_NONE:
306                         case    CONTROL_JOYSTICK:
307                         case    CONTROL_FLIGHTSTICK_PRO:
308                         case    CONTROL_THRUSTMASTER_FCS:
309                         case    CONTROL_GRAVIS_GAMEPAD:
310         //              case    CONTROL_MOUSE:
311         //              case    CONTROL_CYBERMAN:
312                                 joydefs_calibrate_flag = 1;
313                 }
314                 kc_set_controls();
315         }
316
317 }
318
319 extern ubyte kc_use_external_control;
320 extern ubyte kc_enable_external_control;
321 extern ubyte *kc_external_name;
322
323 void joydefs_config()
324 {
325         char xtext[128];
326         int i, old_masks, masks;
327         newmenu_item m[13];
328         int i1=9;
329         int nitems;
330
331         do {
332                 nitems = 12;
333                 m[0].type = NM_TYPE_RADIO; m[0].text = CONTROL_TEXT(0); m[0].value = 0; m[0].group = 0;
334                 m[1].type = NM_TYPE_RADIO; m[1].text = CONTROL_TEXT(1); m[1].value = 0; m[1].group = 0;
335                 m[2].type = NM_TYPE_RADIO; m[2].text = CONTROL_TEXT(2); m[2].value = 0; m[2].group = 0;
336                 m[3].type = NM_TYPE_RADIO; m[3].text = CONTROL_TEXT(3); m[3].value = 0; m[3].group = 0;
337                 m[4].type = NM_TYPE_RADIO; m[4].text = CONTROL_TEXT(4); m[4].value = 0; m[4].group = 0;
338                 m[5].type = NM_TYPE_RADIO; m[5].text = CONTROL_TEXT(5); m[5].value = 0; m[5].group = 0;
339                 m[6].type = NM_TYPE_RADIO; m[6].text = CONTROL_TEXT(6); m[6].value = 0; m[6].group = 0;
340                 m[7].type = NM_TYPE_MENU; m[7].text=TXT_CUST_ABOVE;
341                 m[8].type = NM_TYPE_TEXT; m[8].text="";
342                 m[9].type = NM_TYPE_MENU; m[9].text=TXT_CUST_KEYBOARD;
343 //added on 2/5/99 by Victor Rachels to add d1x key menu
344                 m[10].type = NM_TYPE_MENU; m[10].text="CUSTOMIZE D1X KEYS";
345 //end this section addition - VR
346                 m[11].type = NM_TYPE_CHECK; m[11].text= "Joy is Sidewinder"; m[11].value=Joy_is_Sidewinder;
347         
348                 if ( kc_use_external_control )  {
349                         sprintf( xtext, "Enable %s", kc_external_name );
350                         m[12].type = NM_TYPE_CHECK; m[12].text = xtext; m[12].value = kc_enable_external_control;
351                         nitems = nitems + 1;
352                 }
353                 
354                 m[Config_control_type.intval].value = 1;
355          
356                 i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 );
357
358 //added on 9/1/98 by Victor Rachels to add Sidewinder calibration
359                 Joy_is_Sidewinder = m[11].value;
360 //end this section addition
361
362                 switch(i1)      {
363                 case 7: {
364                                 old_masks = 0;
365                                 for (i=0; i<4; i++ )            {
366                                         if (kconfig_is_axes_used(i))
367                                                 old_masks |= (1<<i);
368                                 }
369                                 if ( Config_control_type.intval == CONTROL_NONE )
370                                         // nothing...
371                                         cvar_setint(&Config_control_type, CONTROL_NONE);
372                                 else if ( Config_control_type.intval < CONTROL_MOUSE )
373                                         kconfig(1, CONTROL_TEXT(Config_control_type.intval) );
374                                 else 
375                                         kconfig(2, CONTROL_TEXT(Config_control_type.intval) );
376
377                                 masks = 0;
378                                 for (i=0; i<4; i++ )            {
379                                         if (kconfig_is_axes_used(i))
380                                                 masks |= (1<<i);
381                                 }
382
383                                 switch (Config_control_type.intval) {
384                                 case    CONTROL_JOYSTICK:
385                                 case    CONTROL_FLIGHTSTICK_PRO:
386                                 case    CONTROL_THRUSTMASTER_FCS:       
387                                         {
388                                                 for (i=0; i<4; i++ )    {
389                                                         if ( (masks&(1<<i)) && (!(old_masks&(1<<i))))
390                                                                 joydefs_calibrate_flag = 1;
391                                                 }
392                                         }
393                                         break;
394                                 }
395                         }
396                         break;
397                 case 9: 
398                         kconfig(0, TXT_KEYBOARD); 
399                         break;
400 //added on 2/5/99 by Victor Rachels to add d1x key menu
401                 case 10:
402                         kconfig(3,"D1X Keys");
403                         break;
404 //end this section addition - VR
405                 }
406
407                 if ( kc_use_external_control )  {
408                         kc_enable_external_control = m[12].value;
409                 }
410
411         } while(i1>-1);
412
413         switch (Config_control_type.intval) {
414         case    CONTROL_JOYSTICK:
415         case    CONTROL_FLIGHTSTICK_PRO:
416         case    CONTROL_THRUSTMASTER_FCS:
417         case    CONTROL_GRAVIS_GAMEPAD:
418                 if ( joydefs_calibrate_flag )
419                         joydefs_calibrate();
420                 break;
421         }
422
423 }