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