]> icculus.org git repositories - btb/d2x.git/blob - arch/linux/joydefs.c
move remaining playsave variables to config cvars.
[btb/d2x.git] / arch / linux / 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  * Linux joystick support
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 "victor.h"
43 #include "render.h"
44 #include "palette.h"
45 #include "newmenu.h"
46 #include "args.h"
47 #include "text.h"
48 #include "kconfig.h"
49 #include "digi.h"
50 #include "joystick.h"
51
52 int joydefs_calibrate_flag = 0;
53
54 //added 9/6/98 Matt Mueller - not needed at all in linux code but bunches 
55 int Joy_is_Sidewinder=0;//    of main/* stuff uses it
56 //end addition
57
58 void joy_delay()
59 {
60         //int t1 = TICKER + 19/4;                       // Wait 1/4 second...
61         //stop_time();
62         //while( TICKER < t1 );
63         //joy_flush();
64         //start_time();
65 }
66
67
68 int joycal_message( char * title, char * text )
69 {
70         int i;
71         newmenu_item    m[2];
72         m[0].type = NM_TYPE_TEXT; m[0].text = text;
73         m[1].type = NM_TYPE_MENU; m[1].text = TXT_OK;
74         i = newmenu_do( title, NULL, 2, m, NULL );
75         if ( i < 0 ) 
76                 return 1;
77         return 0;
78 }
79
80 extern int WriteConfigFile();   
81
82 extern joystick_device j_joystick[MAX_JOY_DEVS];
83 extern joystick_axis j_axis[JOY_MAX_AXES];
84 extern joystick_button j_button[JOY_MAX_BUTTONS];
85
86 void joydefs_calibrate()
87 {
88
89         int i;
90         int temp_values[JOY_MAX_AXES];
91         char title[50];
92         char text[256];
93 //added/killed on 10/17/98 by Hans de Goede for joystick/mouse # fix
94 //-killed-        int nsticks = 0;
95 //end this section kill - Hans
96
97         joydefs_calibrate_flag = 0;
98
99         if (!joy_present)       {
100                 nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK );
101                 return;
102         }
103
104         if (j_joystick[0].version) {
105                 joycal_message ("No Calibration", "calibration not required for\njoystick v1.x");
106                 return;
107         }
108
109         for (i = 0; i < joy_num_axes; i += 2)
110         {
111                 sprintf (title, "js%d Calibration", j_axis[i].joydev);
112
113                 sprintf (text, "center joystick %d", j_axis[i].joydev);
114                 joycal_message (title, text);
115                 joystick_read_raw_axis (JOY_ALL_AXIS, temp_values);
116                 j_axis[i].center_val = temp_values[i];
117                 j_axis[i + 1].center_val = temp_values[i + 1];
118
119                 sprintf (text, "move joystick %d to the upper left", j_axis[i].joydev);
120                 joycal_message (title, text);
121                 joystick_read_raw_axis (JOY_ALL_AXIS, temp_values);
122                 j_axis[i].min_val = temp_values[i];
123                 j_axis[i + 1].min_val = temp_values[i + 1];
124
125                 sprintf (text, "move joystick %d to the lower right", j_axis[i].joydev);
126                 joycal_message (title, text);
127                 joystick_read_raw_axis (JOY_ALL_AXIS, temp_values);
128                 j_axis[i].max_val = temp_values[i];
129                 j_axis[i + 1].max_val = temp_values[i + 1];
130
131         }
132         
133         WriteConfigFile ();
134 }
135
136
137 //char *control_text[CONTROL_MAX_TYPES] = { "Keyboard only", "Joystick", "Flightstick Pro", "Thrustmaster FCS", "Gravis Gamepad", "Mouse", "Cyberman" };
138
139 void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
140 {
141         int i;
142         int oc_type = Config_control_type.intval;
143
144         nitems = nitems;
145         last_key = last_key;
146         citem = citem;          
147
148         for (i=0; i<3; i++ )
149                 if (items[i].value)
150                         cvar_setint(&Config_control_type, i);
151
152 //added on 10/17/98 by Hans de Goede for joystick/mouse # fix
153        // remap mouse, since "Flightstick Pro", "Thrustmaster FCS"
154        //   and "Gravis Gamepad" where removed from the options
155         if (Config_control_type.intval == 2)
156                         cvar_setint(&Config_control_type, CONTROL_MOUSE);
157 //end this section addition - Hans
158
159         if ( (oc_type != Config_control_type.intval) && (Config_control_type.intval == CONTROL_THRUSTMASTER_FCS ) )     {
160                 nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS );
161         }
162
163         if (oc_type != Config_control_type.intval) {
164                 switch (Config_control_type.intval) {
165         //              case    CONTROL_NONE:
166                         case    CONTROL_JOYSTICK:
167                         case    CONTROL_FLIGHTSTICK_PRO:
168                         case    CONTROL_THRUSTMASTER_FCS:
169                         case    CONTROL_GRAVIS_GAMEPAD:
170         //              case    CONTROL_MOUSE:
171         //              case    CONTROL_CYBERMAN:
172                                 joydefs_calibrate_flag = 1;
173                 }
174                 kc_set_controls();
175         }
176
177 }
178
179 extern ubyte kc_use_external_control;
180 extern ubyte kc_enable_external_control;
181 extern ubyte *kc_external_name;
182
183 void joydefs_config()
184 {
185 //added/changed/killed on 10/17/98 by Hans de Goede for joystick/mouse # fix
186 //-killed-        char xtext[128];
187 //-killed-        int i, old_masks, masks;
188         newmenu_item m[13];
189 //-killed-        int i1=5;
190 //-killed-        int nitems;
191 //-killed-
192 //-killed-        do {
193 //-killed-                nitems = 6;
194         int i, i1=5, j, nitems=7;
195 //end this section kill/change - Hans
196
197             m[0].type = NM_TYPE_RADIO; m[0].text = "KEYBOARD"; m[0].value = 0; m[0].group = 0;
198             m[1].type = NM_TYPE_RADIO; m[1].text = "JOYSTICK"; m[1].value = 0; m[1].group = 0;
199             m[2].type = NM_TYPE_RADIO; m[2].text = "MOUSE"; m[2].value = 0; m[2].group = 0;
200             m[3].type = NM_TYPE_TEXT; m[3].text="";
201             m[4].type = NM_TYPE_MENU; m[4].text="CUSTOMIZE ABOVE";
202             m[5].type = NM_TYPE_MENU; m[5].text="CUSTOMIZE KEYBOARD";
203 //added on 2/5/99 by Victor Rachels for D1X keys menu
204             m[6].type = NM_TYPE_MENU; m[6].text="CUSTOMIZE D1X KEYS";
205 //end this section addition - VR
206
207 //added/changed/killed on 10/17/98 by Hans de Goede for joystick/mouse # fix
208 //-killed-                m[Config_control_type.intval].value = 1;
209
210             do {
211
212
213               i = Config_control_type.intval;
214               if(i==CONTROL_MOUSE) i = 2;
215               m[i].value=1;
216 //end section - OE
217 //end this section change/addition - Hans
218
219                 i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 );
220
221 //added 6-15-99 Owen Evans
222                 for (j = 0; j <= 2; j++)
223                         if (m[j].value)
224                                 cvar_setint(&Config_control_type, j);
225                 i = Config_control_type.intval;
226                 if (Config_control_type.intval == 2)
227                         cvar_setint(&Config_control_type, CONTROL_MOUSE);
228 //end added - OE
229
230                 switch(i1)      {
231                         case 4: 
232 //added/changed on 10/17/98 by Hans de Goede for joystick/mouse # fix
233 //-killed-                                kconfig(Config_control_type.intval, m[Config_control_type.intval].text);
234                                 kconfig (i, m[i].text);
235 //end this section change - Hans
236                                 break;
237                         case 5: 
238                                 kconfig(0, "KEYBOARD"); 
239                                 break;
240 //added on 2/5/99 by Victor Rachels for D1X keys menu
241                         case 6:
242                                 kconfig(3, "D1X KEYS");
243                                 break;
244 //end this section addition - VR
245                 } 
246
247         } while(i1>-1);
248
249 }