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