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