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