]> icculus.org git repositories - btb/d2x.git/blob - arch/linux/joydefs.c
gcc fixes
[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 void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
138 {
139         int i;
140         int oc_type = Config_control_type.intval;
141
142         nitems = nitems;
143         last_key = last_key;
144         citem = citem;          
145
146         for (i=0; i<3; i++ )
147                 if (items[i].value)
148                         cvar_setint(&Config_control_type, i);
149
150 //added on 10/17/98 by Hans de Goede for joystick/mouse # fix
151        // remap mouse, since "Flightstick Pro", "Thrustmaster FCS"
152        //   and "Gravis Gamepad" where removed from the options
153         if (Config_control_type.intval == 2)
154                         cvar_setint(&Config_control_type, CONTROL_MOUSE);
155 //end this section addition - Hans
156
157         if ( (oc_type != Config_control_type.intval) && (Config_control_type.intval == CONTROL_THRUSTMASTER_FCS ) )     {
158                 nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS );
159         }
160
161         if (oc_type != Config_control_type.intval) {
162                 switch (Config_control_type.intval) {
163         //              case    CONTROL_NONE:
164                         case    CONTROL_JOYSTICK:
165                         case    CONTROL_FLIGHTSTICK_PRO:
166                         case    CONTROL_THRUSTMASTER_FCS:
167                         case    CONTROL_GRAVIS_GAMEPAD:
168         //              case    CONTROL_MOUSE:
169         //              case    CONTROL_CYBERMAN:
170                                 joydefs_calibrate_flag = 1;
171                 }
172                 kc_set_controls();
173         }
174
175 }
176
177 extern ubyte kc_use_external_control;
178 extern ubyte kc_enable_external_control;
179 extern ubyte *kc_external_name;
180
181 void joydefs_config()
182 {
183 //added/changed/killed on 10/17/98 by Hans de Goede for joystick/mouse # fix
184 //-killed-        char xtext[128];
185 //-killed-        int i, old_masks, masks;
186         newmenu_item m[13];
187 //-killed-        int i1=5;
188 //-killed-        int nitems;
189 //-killed-
190 //-killed-        do {
191 //-killed-                nitems = 6;
192         int i, i1=5, j, nitems=7;
193 //end this section kill/change - Hans
194
195             m[0].type = NM_TYPE_RADIO; m[0].text = "KEYBOARD"; m[0].value = 0; m[0].group = 0;
196             m[1].type = NM_TYPE_RADIO; m[1].text = "JOYSTICK"; m[1].value = 0; m[1].group = 0;
197             m[2].type = NM_TYPE_RADIO; m[2].text = "MOUSE"; m[2].value = 0; m[2].group = 0;
198             m[3].type = NM_TYPE_TEXT; m[3].text="";
199             m[4].type = NM_TYPE_MENU; m[4].text="CUSTOMIZE ABOVE";
200             m[5].type = NM_TYPE_MENU; m[5].text="CUSTOMIZE KEYBOARD";
201 //added on 2/5/99 by Victor Rachels for D1X keys menu
202             m[6].type = NM_TYPE_MENU; m[6].text="CUSTOMIZE D1X KEYS";
203 //end this section addition - VR
204
205 //added/changed/killed on 10/17/98 by Hans de Goede for joystick/mouse # fix
206 //-killed-                m[Config_control_type.intval].value = 1;
207
208             do {
209
210
211               i = Config_control_type.intval;
212               if(i==CONTROL_MOUSE) i = 2;
213               m[i].value=1;
214 //end section - OE
215 //end this section change/addition - Hans
216
217                 i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 );
218
219 //added 6-15-99 Owen Evans
220                 for (j = 0; j <= 2; j++)
221                         if (m[j].value)
222                                 cvar_setint(&Config_control_type, j);
223                 i = Config_control_type.intval;
224                 if (Config_control_type.intval == 2)
225                         cvar_setint(&Config_control_type, CONTROL_MOUSE);
226 //end added - OE
227
228                 switch(i1)      {
229                         case 4: 
230 //added/changed on 10/17/98 by Hans de Goede for joystick/mouse # fix
231 //-killed-                                kconfig(Config_control_type.intval, m[Config_control_type.intval].text);
232                                 kconfig (i, m[i].text);
233 //end this section change - Hans
234                                 break;
235                         case 5: 
236                                 kconfig(0, "KEYBOARD"); 
237                                 break;
238 //added on 2/5/99 by Victor Rachels for D1X keys menu
239                         case 6:
240                                 kconfig(3, "D1X KEYS");
241                                 break;
242 //end this section addition - VR
243                 } 
244
245         } while(i1>-1);
246
247 }