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