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