]> icculus.org git repositories - btb/d2x.git/blob - main/kconfig.c
console.h pulls in cmd.h
[btb/d2x.git] / main / kconfig.c
1 /* $Id: kconfig.c,v 1.40 2005-08-02 06:13:56 chris Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Routines to configure keyboard, joystick, etc..
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #ifdef RCS
26 static char rcsid[] = "$Id: kconfig.c,v 1.40 2005-08-02 06:13:56 chris Exp $";
27 #endif
28
29 #ifdef WINDOWS
30 #include "desw.h"
31 #endif
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdarg.h>
37 #include <ctype.h>
38
39 #include "error.h"
40 #include "pstypes.h"
41 #include "gr.h"
42 #include "mono.h"
43 #include "key.h"
44 #include "palette.h"
45 #include "game.h"
46 #include "gamefont.h"
47 #include "iff.h"
48 #include "u_mem.h"
49 #include "joy.h"
50 #include "mouse.h"
51 #include "kconfig.h"
52 #include "gauges.h"
53 #include "joydefs.h"
54 #include "songs.h"
55 #include "render.h"
56 #include "digi.h"
57 #include "newmenu.h"
58 #include "endlevel.h"
59 #include "multi.h"
60 #include "timer.h"
61 #include "text.h"
62 #include "player.h"
63 #include "menu.h"
64 #include "automap.h"
65 #include "args.h"
66 #include "lighting.h"
67 #include "ai.h"
68 #include "cntrlcen.h"
69 #if defined (TACTILE)
70  #include "tactile.h"
71 #endif
72
73 #include "collide.h"
74
75 #ifdef USE_LINUX_JOY
76 #include "joystick.h"
77 #endif
78 #include "console.h"
79
80 ubyte ExtGameStatus=1;
81
82 vms_vector ExtForceVec;
83 vms_matrix ExtApplyForceMatrix;
84
85 int ExtJoltInfo[3]={0,0,0};
86 int ExtXVibrateInfo[2]={0,0};
87 int ExtYVibrateInfo[2]={0,0};
88 ubyte ExtXVibrateClear=0;
89 ubyte ExtYVibrateClear=0;
90
91 #define TABLE_CREATION 1
92
93 // Array used to 'blink' the cursor while waiting for a keypress.
94 sbyte fades[64] = { 1,1,1,2,2,3,4,4,5,6,8,9,10,12,13,15,16,17,19,20,22,23,24,26,27,28,28,29,30,30,31,31,31,31,31,30,30,29,28,28,27,26,24,23,22,20,19,17,16,15,13,12,10,9,8,6,5,4,4,3,2,2,1,1 };
95
96 //char * invert_text[2] = { "N", "Y" };
97 //char * joybutton_text[28] = { "BTN 1", "BTN 2", "BTN 3", "BTN 4", "", "TRIG", "LEFT", "HAT \x81", "RIGHT", "", "", "HAT \x80", "MID", "", "", "HAT \x7f", "", "", "", "HAT \x82", "TRIG", "LEFT", "RIGHT", "", "UP","DOWN","LEFT", "RIGHT" };
98 //char * joyaxis_text[4] = { "X1", "Y1", "X2", "Y2" };
99 //char * mouseaxis_text[2] = { "L/R", "F/B" };
100 //char * mousebutton_text[3] = { "Left", "Right", "Mid" };
101
102 int invert_text[2] = { TNUM_N, TNUM_Y };
103
104 #ifndef USE_LINUX_JOY
105 #ifdef WINDOWS
106         int joybutton_text[28] = 
107         { TNUM_BTN_1, TNUM_BTN_2, TNUM_BTN_3, TNUM_BTN_4,
108           -1, -1, -1, -1,
109           -1, -1, -1, -1,
110           -1, -1, -1, -1,
111           TNUM_HAT_L, TNUM_HAT_R, TNUM_HAT_U, TNUM_HAT_D,
112           -1, -1, -1, -1,
113           -1, -1, -1, -1
114         };
115         int joyaxis_text[7] = { TNUM_X1, TNUM_Y1, TNUM_Z1, TNUM_UN, TNUM_P1,TNUM_R1,TNUM_YA1 };
116 #elif defined(SDL_INPUT)
117 char *joybutton_text[JOY_MAX_BUTTONS];
118 char *joyaxis_text[JOY_MAX_AXES];
119 #else
120         int joybutton_text[28] = 
121         { TNUM_BTN_1, TNUM_BTN_2, TNUM_BTN_3, TNUM_BTN_4,
122           -1, TNUM_TRIG, TNUM_LEFT, TNUM_HAT_L,
123          TNUM_RIGHT, -1, TNUM_HAT2_D, TNUM_HAT_R,
124          TNUM_MID, -1, TNUM_HAT2_R, TNUM_HAT_U,
125          TNUM_HAT2_L, -1, TNUM_HAT2_U, TNUM_HAT_D,
126          TNUM_TRIG, TNUM_LEFT, TNUM_RIGHT, -1, 
127          TNUM_UP, TNUM_DOWN, TNUM_LEFT, TNUM_RIGHT };
128
129         int joyaxis_text[7] = { TNUM_X1, TNUM_Y1, TNUM_Z1, TNUM_UN, TNUM_P1,TNUM_R1,TNUM_YA1 };
130 //      int joyaxis_text[4] = { TNUM_X1, TNUM_Y1, TNUM_X2, TNUM_Y2 };
131 #endif
132 #endif
133
134 int mouseaxis_text[3] = { TNUM_L_R, TNUM_F_B, TNUM_Z1 };
135 #ifndef MACINTOSH
136 int mousebutton_text[3] = { TNUM_LEFT, TNUM_RIGHT, TNUM_MID };
137 char * mousebutton_textra[13] = { "M4", "M5", "M6", "M7", "M8", "M9", "M10","M11","M12","M13","M14","M15","M16" };//text for buttons above 3. -MPM
138 #else
139 char *mousebutton_text[3] = { "Btn", "", "" };          // only one silly mouse button on the mac
140 #endif
141
142 #ifdef MACINTOSH
143 char * key_text[256] = {         
144 "","S","D","F","H","G","Z","X","C","V","","B","Q", "W", "E", "R",
145 "Y","T","1","2","3","4","6","5","=","9","7","-", "8", "0", "]", "O",
146 "U","[","I","P","RET","L","J","'","K", ";", "\\", ",", "/", "N", "M", ".",
147 "TAB","SPC","`","DEL","","ESC","","APL","SHIFT","CAPSL","OPTN","CTRL","","","","A",
148 "","PAD.","","PAD*","","PAD+","","NMLCK","","","","PAD/","ENTER","","PAD-","",
149 "","PAD=","PAD0","PAD1","PAD2","PAD3","PAD4","PAD5","PAD6","PAD7","","PAD8","PAD9","","","",
150 "F5","F6","F7","","F8","F9","","F11","","F13","","F14","","F10","","F12",
151 "","PAUSE","HELP","HOME","PGUP","DEL","","END","F2","","F1","LARW","RARW","DARW","UARW","",
152 "","","","","","","","","","","","","","","","",
153 "","","","","","","","","","","","","","","","",
154 "","","","","","","","","","","","","","","","",
155 "","","","","","","","","","","","","","","","",
156 "","","","","","","","","","","","","","","","",
157 "","","","","","","","","","","","","","","","",
158 "","","","","","","","","","","","","","","","",
159 "","","","","","","","","","","","","","","",""};
160 #else
161 #if !defined OGL && !defined SDL_INPUT
162 char * key_text[256] = {         \
163 "","ESC","1","2","3","4","5","6","7","8","9","0","-",                   \
164 "=","BSPC","TAB","Q","W","E","R","T","Y","U","I","O",                           \
165 "P","[","]","\x83","LCTRL","A","S","D","F",        \
166 "G","H","J","K","L",";","'","`",        \
167 "LSHFT","\\","Z","X","C","V","B","N","M",",",      \
168 ".","/","RSHFT","PAD*","LALT","SPC",      \
169 "CPSLK","F1","F2","F3","F4","F5","F6","F7","F8","F9",        \
170 "F10","NMLCK","SCLK","PAD7","PAD8","PAD9","PAD-",   \
171 "PAD4","PAD5","PAD6","PAD+","PAD1","PAD2","PAD3","PAD0", \
172 "PAD.","","","","F11","F12","","","","","","","","","",         \
173 "","","","","","","","","","","","","","","","","","","","",     \
174 "","","","","","","","","","","","","","","","","","","","",     \
175 "","","","","","","","","","","","","","","","","","",           \
176 "PAD\x83","RCTRL","","","","","","","","","","","","","", \
177 "","","","","","","","","","","PAD/","","","RALT","",      \
178 "","","","","","","","","","","","","","HOME","\x82","PGUP",     \
179 "","\x81","","\x7f","","END","\x80","PGDN","INS",       \
180 "DEL","","","","","","","","","","","","","","","","","",     \
181 "","","","","","","","","","","","","","","","","","","","",     \
182 "","","","","","","" };
183 #endif /* OGL */
184 #endif
185
186 #ifdef D2X_KEYS
187 //added/removed by Victor Rachels for adding rebindable keys for these
188 // KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0
189 ubyte system_keys[] = { KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, KEY_MINUS, KEY_EQUAL, KEY_PRINT_SCREEN };
190 #else
191 ubyte system_keys[] = { KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0, KEY_MINUS, KEY_EQUAL, KEY_PRINT_SCREEN };
192 #endif
193
194 //extern void GameLoop(int, int );
195
196 extern void transfer_energy_to_shield(fix);
197 extern void CyclePrimary(),CycleSecondary(),InitMarkerInput();
198 extern ubyte DefiningMarkerMessage;
199 extern char CybermouseActive;
200
201 #ifdef WINDOWS
202 extern int joydefsw_do_button();
203 extern int joydefsw_do_winjoybutton(int *axis);
204 extern joydefsw_win_joyselect(char *title);
205 #endif
206
207 control_info Controls;
208
209 fix Cruise_speed=0;
210
211 // macros for drawing lo/hi res kconfig screens (see scores.c as well)
212
213 #define LHX(x)          ((x)*(MenuHires?2:1))
214 #define LHY(y)          ((y)*(MenuHires?2.4:1))
215
216
217 #define BT_KEY                          0
218 #define BT_MOUSE_BUTTON         1
219 #define BT_MOUSE_AXIS           2
220 #define BT_JOY_BUTTON           3
221 #define BT_JOY_AXIS                     4
222 #define BT_INVERT                               5
223
224 char *btype_text[] = { "BT_KEY", "BT_MOUSE_BUTTON", "BT_MOUSE_AXIS", "BT_JOY_BUTTON", "BT_JOY_AXIS", "BT_INVERT" };
225
226 #define INFO_Y 28
227
228 typedef struct kc_item {
229         short id;                               // The id of this item
230         short x, y;                             
231         short w1;
232         short w2;
233         short u,d,l,r;
234         //short text_num1;
235         char *text;
236         ubyte type;
237         ubyte value;            // what key,button,etc
238 } kc_item;
239
240 int Num_items=28;
241 kc_item *All_items;
242
243 ubyte kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS];
244
245 //added on 2/4/99 by Victor Rachels to add d1x new keys
246 ubyte kconfig_d2x_settings[MAX_D2X_CONTROLS];
247 //end this section addition - VR
248
249 //----------- WARNING!!!!!!! -------------------------------------------
250 // THESE NEXT FOUR BLOCKS OF DATA ARE GENERATED BY PRESSING DEL+F12 WHEN
251 // IN THE KEYBOARD CONFIG SCREEN.  BASICALLY, THAT PROCEDURE MODIFIES THE
252 // U,D,L,R FIELDS OF THE ARRAYS AND DUMPS THE NEW ARRAYS INTO KCONFIG.COD
253 //-------------------------------------------------------------------------
254 /*ubyte default_kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS] = {
255 {0xc8,0x48,0xd0,0x50,0xcb,0x4b,0xcd,0x4d,0x38,0xff,0xff,0x4f,0xff,0x51,0xff,0x4a,0xff,0x4e,0xff,0xff,0x10,0x47,0x12,0x49,0x1d,0x9d,0x39,0xff,0x21,0xff,0x1e,0xff,0x2c,0xff,0x30,0xff,0x13,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf,0xff,0x1f,0xff,0x33,0xff,0x34,0xff,0x23,0xff,0x14,0xff,0xff,0xff,0x0,0x0},
256 {0x0,0x1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
257 {0x5,0xc,0xff,0xff,0xff,0xff,0x7,0xf,0x13,0xb,0xff,0x6,0x8,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
258 {0x0,0x1,0xff,0xff,0x2,0xff,0x7,0xf,0x13,0xb,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0x3,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
259 {0x3,0x0,0x1,0x2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
260 {0x0,0x1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
261 {0x0,0x1,0xff,0xff,0x2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
262 };*/                                                                              
263
264 #ifndef MACINTOSH
265 ubyte default_kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS] = {
266 {0xc8,0x48,0xd0,0x50,0xcb,0x4b,0xcd,0x4d,0x38,0xff,0xff,0x4f,0xff,0x51,0xff,0x4a,0xff,0x4e,0xff,0xff,0x10,0x47,0x12,0x49,0x1d,0x9d,0x39,0xff,0x21,0xff,0x1e,0xff,0x2c,0xff,0x30,0xff,0x13,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf,0xff,0x1f,0xff,0x33,0xff,0x34,0xff,0x23,0xff,0x14,0xff,0xff,0xff,0x0,0x0},
267 {0x0,0x1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0},
268 {0x5,0xc,0xff,0xff,0xff,0xff,0x7,0xf,0x13,0xb,0xff,0x6,0x8,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0},
269 {0x0,0x1,0xff,0xff,0x2,0xff,0x7,0xf,0x13,0xb,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x3,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0},
270 {0x3,0x0,0x1,0x2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0},
271 {0x0,0x1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0},
272 {0x0,0x1,0xff,0xff,0x2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0},
273 #ifdef WINDOWS
274 {0x0,0x1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0},
275 #endif
276 };
277
278
279
280 kc_item kc_keyboard[NUM_KEY_CONTROLS] = {
281         {  0, 15, 49, 71, 26, 55,  2, 55,  1,"Pitch forward", BT_KEY, 255 },
282         {  1, 15, 49,100, 26, 50,  3,  0, 24,"Pitch forward", BT_KEY, 255 },
283         {  2, 15, 57, 71, 26,  0,  4, 25,  3,"Pitch backward", BT_KEY, 255 },
284         {  3, 15, 57,100, 26,  1,  5,  2, 26,"Pitch backward", BT_KEY, 255 },
285         {  4, 15, 65, 71, 26,  2,  6, 27,  5,"Turn left", BT_KEY, 255 },
286         {  5, 15, 65,100, 26,  3,  7,  4, 28,"Turn left", BT_KEY, 255 },
287         {  6, 15, 73, 71, 26,  4,  8, 29,  7,"Turn right", BT_KEY, 255 },
288         {  7, 15, 73,100, 26,  5,  9,  6, 34,"Turn right", BT_KEY, 255 },
289         {  8, 15, 85, 71, 26,  6, 10, 35,  9,"Slide on", BT_KEY, 255 },
290         {  9, 15, 85,100, 26,  7, 11,  8, 36,"Slide on", BT_KEY, 255 },
291         { 10, 15, 93, 71, 26,  8, 12, 37, 11,"Slide left", BT_KEY, 255 },
292         { 11, 15, 93,100, 26,  9, 13, 10, 44,"Slide left", BT_KEY, 255 },
293         { 12, 15,101, 71, 26, 10, 14, 45, 13,"Slide right", BT_KEY, 255 },
294         { 13, 15,101,100, 26, 11, 15, 12, 30,"Slide right", BT_KEY, 255 },
295         { 14, 15,109, 71, 26, 12, 16, 31, 15,"Slide up", BT_KEY, 255 },
296         { 15, 15,109,100, 26, 13, 17, 14, 32,"Slide up", BT_KEY, 255 },
297         { 16, 15,117, 71, 26, 14, 18, 33, 17,"Slide down", BT_KEY, 255 },
298         { 17, 15,117,100, 26, 15, 19, 16, 46,"Slide down", BT_KEY, 255 },
299         { 18, 15,129, 71, 26, 16, 20, 47, 19,"Bank on", BT_KEY, 255 },
300         { 19, 15,129,100, 26, 17, 21, 18, 38,"Bank on", BT_KEY, 255 },
301         { 20, 15,137, 71, 26, 18, 22, 39, 21,"Bank left", BT_KEY, 255 },
302         { 21, 15,137,100, 26, 19, 23, 20, 40,"Bank left", BT_KEY, 255 },
303         { 22, 15,145, 71, 26, 20, 48, 41, 23,"Bank right", BT_KEY, 255 },
304         { 23, 15,145,100, 26, 21, 49, 22, 42,"Bank right", BT_KEY, 255 },
305         { 24,158, 49, 83, 26, 51, 26,  1, 25,"Fire primary", BT_KEY, 255 },
306         { 25,158, 49,112, 26, 54, 27, 24,  2,"Fire primary", BT_KEY, 255 },
307         { 26,158, 57, 83, 26, 24, 28,  3, 27,"Fire secondary", BT_KEY, 255 },
308         { 27,158, 57,112, 26, 25, 29, 26,  4,"Fire secondary", BT_KEY, 255 },
309         { 28,158, 65, 83, 26, 26, 34,  5, 29,"Fire flare", BT_KEY, 255 },
310         { 29,158, 65,112, 26, 27, 35, 28,  6,"Fire flare", BT_KEY, 255 },
311         { 30,158,105, 83, 26, 44, 32, 13, 31,"Accelerate", BT_KEY, 255 },
312         { 31,158,105,112, 26, 45, 33, 30, 14,"Accelerate", BT_KEY, 255 },
313         { 32,158,113, 83, 26, 30, 46, 15, 33,"reverse", BT_KEY, 255 },
314         { 33,158,113,112, 26, 31, 47, 32, 16,"reverse", BT_KEY, 255 },
315         { 34,158, 73, 83, 26, 28, 36,  7, 35,"Drop Bomb", BT_KEY, 255 },
316         { 35,158, 73,112, 26, 29, 37, 34,  8,"Drop Bomb", BT_KEY, 255 },
317         { 36,158, 85, 83, 26, 34, 44,  9, 37,"REAR VIEW", BT_KEY, 255 },
318         { 37,158, 85,112, 26, 35, 45, 36, 10,"REAR VIEW", BT_KEY, 255 },
319         { 38,158,133, 83, 26, 46, 40, 19, 39,"Cruise Faster", BT_KEY, 255 },
320         { 39,158,133,112, 26, 47, 41, 38, 20,"Cruise Faster", BT_KEY, 255 },
321         { 40,158,141, 83, 26, 38, 42, 21, 41,"Cruise Slower", BT_KEY, 255 },
322         { 41,158,141,112, 26, 39, 43, 40, 22,"Cruise Slower", BT_KEY, 255 },
323         { 42,158,149, 83, 26, 40, 52, 23, 43,"Cruise Off", BT_KEY, 255 },
324         { 43,158,149,112, 26, 41, 53, 42, 48,"Cruise Off", BT_KEY, 255 },
325         { 44,158, 93, 83, 26, 36, 30, 11, 45,"Automap", BT_KEY, 255 },
326         { 45,158, 93,112, 26, 37, 31, 44, 12,"Automap", BT_KEY, 255 },
327         { 46,158,121, 83, 26, 32, 38, 17, 47,"Afterburner", BT_KEY, 255 },
328         { 47,158,121,112, 26, 33, 39, 46, 18,"Afterburner", BT_KEY, 255 },
329         { 48, 15,161, 71, 26, 22, 50, 43, 49,"Cycle Primary", BT_KEY, 255 },
330         { 49, 15,161,100, 26, 23, 51, 48, 52,"Cycle Primary", BT_KEY, 255 },
331         { 50, 15,169, 71, 26, 48,  1, 53, 51,"Cycle Second", BT_KEY, 255 },
332         { 51, 15,169,100, 26, 49, 24, 50, 54,"Cycle Second", BT_KEY, 255 },
333         { 52,158,163, 83, 26, 42, 54, 49, 53,"Headlight", BT_KEY, 255 },
334         { 53,158,163,112, 26, 43, 55, 52, 50,"Headlight", BT_KEY, 255 },
335         { 54,158,171, 83, 26, 52, 56, 51, 55,"Energy->Shield", BT_KEY, 255 },
336         { 55,158,171,112, 26, 53,  0, 54,  0,"Energy->Shield", BT_KEY, 255 },
337    { 56,158,179,83,  26, 54,  0, 0,  0, "Toggle Bomb",  BT_KEY,255},
338 };
339 kc_item kc_joystick[NUM_OTHER_CONTROLS] = {
340         {  0, 25, 46, 85, 40, 15,  1, 24,  5,"Fire primary", BT_JOY_BUTTON, 255 },
341         {  1, 25, 54, 85, 40,  0,  4,  5,  6,"Fire secondary", BT_JOY_BUTTON, 255 },
342         {  2, 25, 85, 85, 40, 26,  3,  9, 10,"Accelerate", BT_JOY_BUTTON, 255 },
343         {  3, 25, 93, 85, 40,  2, 25, 10, 11,"reverse", BT_JOY_BUTTON, 255 },
344         {  4, 25, 62, 85, 40,  1, 26,  6,  7,"Fire flare", BT_JOY_BUTTON, 255 },
345         {  5,180, 46, 79, 40, 23,  6,  0,  1,"Slide on", BT_JOY_BUTTON, 255 },
346         {  6,180, 54, 79, 40,  5,  7,  1,  4,"Slide left", BT_JOY_BUTTON, 255 },
347         {  7,180, 62, 79, 40,  6,  8,  4, 26,"Slide right", BT_JOY_BUTTON, 255 },
348         {  8,180, 70, 79, 40,  7,  9, 26,  9,"Slide up", BT_JOY_BUTTON, 255 },
349         {  9,180, 78, 79, 40,  8, 10,  8,  2,"Slide down", BT_JOY_BUTTON, 255 },
350         { 10,180, 90, 79, 40,  9, 11,  2,  3,"Bank on", BT_JOY_BUTTON, 255 },
351         { 11,180, 98, 79, 40, 10, 12,  3, 12,"Bank left", BT_JOY_BUTTON, 255 },
352         { 12,180,106, 79, 40, 11, 28, 11, 25,"Bank right", BT_JOY_BUTTON, 255 },
353         { 13, 22,154, 51, 40, 24, 15, 30, 14,"Pitch U/D", BT_JOY_AXIS, 255 },
354         { 14, 22,154, 99,  8, 30, 16, 13, 17,"Pitch U/D", BT_INVERT, 255 },
355         { 15, 22,162, 51, 40, 13,  0, 18, 16,"Turn L/R", BT_JOY_AXIS, 255 },
356         { 16, 22,162, 99,  8, 14, 17, 15, 19,"Turn L/R", BT_INVERT, 255 },
357         { 17,164,154, 58, 40, 16, 19, 14, 18,"Slide L/R", BT_JOY_AXIS, 255 },
358         { 18,164,154,106,  8, 29, 20, 17, 15,"Slide L/R", BT_INVERT, 255 },
359         { 19,164,162, 58, 40, 17, 21, 16, 20,"Slide U/D", BT_JOY_AXIS, 255 },
360         { 20,164,162,106,  8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 },
361         { 21,164,172, 58, 40, 19, 23, 20, 22,"Bank L/R", BT_JOY_AXIS, 255 },
362         { 22,164,172,106,  8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 },
363         { 23,164,180, 58, 40, 21,  5, 22, 24,"throttle", BT_JOY_AXIS, 255 },
364         { 24,164,180,106,  8, 22, 13, 23,  0,"throttle", BT_INVERT, 255 },
365         { 25, 25,109, 85, 40,  3, 27, 12, 28,"REAR VIEW", BT_JOY_BUTTON, 255 },
366         { 26, 25, 70, 85, 40,  4,  2,  7,  8,"Drop Bomb", BT_JOY_BUTTON, 255 },
367         { 27, 25,117, 85, 40, 25, 30, 28, 29,"Afterburner", BT_JOY_BUTTON, 255 },
368         { 28,180,114, 79, 40, 12, 29, 25, 27,"Cycle Primary", BT_JOY_BUTTON, 255 },
369         { 29,180,122, 79, 40, 28, 18, 27, 30,"Cycle Secondary", BT_JOY_BUTTON, 255 },
370         { 30, 25,125, 85, 40, 27, 14, 29, 13,"Headlight", BT_JOY_BUTTON, 255 },
371 };
372 kc_item kc_superjoy[NUM_OTHER_CONTROLS] = {
373         {  0, 25, 46, 85, 26, 15,  1, 24,  5,"Fire primary", BT_JOY_BUTTON, 255 },
374         {  1, 25, 54, 85, 26,  0,  4,  5,  6,"Fire secondary", BT_JOY_BUTTON, 255 },
375         {  2, 25, 85, 85, 26, 26,  3,  9, 10,"Accelerate", BT_JOY_BUTTON, 255 },
376         {  3, 25, 93, 85, 26,  2, 25, 10, 11,"reverse", BT_JOY_BUTTON, 255 },
377         {  4, 25, 62, 85, 26,  1, 26,  6,  7,"Fire flare", BT_JOY_BUTTON, 255 },
378         {  5,180, 46, 79, 26, 23,  6,  0,  1,"Slide on", BT_JOY_BUTTON, 255 },
379         {  6,180, 54, 79, 26,  5,  7,  1,  4,"Slide left", BT_JOY_BUTTON, 255 },
380         {  7,180, 62, 79, 26,  6,  8,  4, 26,"Slide right", BT_JOY_BUTTON, 255 },
381         {  8,180, 70, 79, 26,  7,  9, 26,  9,"Slide up", BT_JOY_BUTTON, 255 },
382         {  9,180, 78, 79, 26,  8, 10,  8,  2,"Slide down", BT_JOY_BUTTON, 255 },
383         { 10,180, 90, 79, 26,  9, 11,  2,  3,"Bank on", BT_JOY_BUTTON, 255 },
384         { 11,180, 98, 79, 26, 10, 12,  3, 12,"Bank left", BT_JOY_BUTTON, 255 },
385         { 12,180,106, 79, 26, 11, 28, 11, 25,"Bank right", BT_JOY_BUTTON, 255 },
386         { 13, 22,154, 51, 26, 24, 15, 30, 14,"Pitch U/D", BT_JOY_AXIS, 255 },
387         { 14, 22,154, 99,  8, 30, 16, 13, 17,"Pitch U/D", BT_INVERT, 255 },
388         { 15, 22,162, 51, 26, 13,  0, 18, 16,"Turn L/R", BT_JOY_AXIS, 255 },
389         { 16, 22,162, 99,  8, 14, 17, 15, 19,"Turn L/R", BT_INVERT, 255 },
390         { 17,164,154, 58, 26, 16, 19, 14, 18,"Slide L/R", BT_JOY_AXIS, 255 },
391         { 18,164,154,106,  8, 29, 20, 17, 15,"Slide L/R", BT_INVERT, 255 },
392         { 19,164,162, 58, 26, 17, 21, 16, 20,"Slide U/D", BT_JOY_AXIS, 255 },
393         { 20,164,162,106,  8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 },
394         { 21,164,172, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_JOY_AXIS, 255 },
395         { 22,164,172,106,  8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 },
396         { 23,164,180, 58, 26, 21,  5, 22, 24,"throttle", BT_JOY_AXIS, 255 },
397         { 24,164,180,106,  8, 22, 13, 23,  0,"throttle", BT_INVERT, 255 },
398         { 25, 25,109, 85, 26,  3, 27, 12, 28,"REAR VIEW", BT_JOY_BUTTON, 255 },
399         { 26, 25, 70, 85, 26,  4,  2,  7,  8,"Drop Bomb", BT_JOY_BUTTON, 255 },
400         { 27, 25,117, 85, 26, 25, 30, 28, 29,"Afterburner", BT_JOY_BUTTON, 255 },
401         { 28,180,114, 79, 26, 12, 29, 25, 27,"Cycle Primary", BT_JOY_BUTTON, 255 },
402         { 29,180,122, 79, 26, 28, 18, 27, 30,"Cycle Secondary", BT_JOY_BUTTON, 255 },
403         { 30, 25,125, 85, 26, 27, 14, 29, 13,"Headlight", BT_JOY_BUTTON, 255 },
404 };
405
406 kc_item kc_mouse[NUM_OTHER_CONTROLS] = {
407         {  0, 25, 46, 85, 26, 12,  1, 24,  5,"Fire primary", BT_MOUSE_BUTTON, 255 },
408         {  1, 25, 54, 85, 26,  0,  4,  5,  6,"Fire secondary", BT_MOUSE_BUTTON, 255 },
409         {  2, 25, 85, 85, 26, 26,  3,  9, 10,"Accelerate", BT_MOUSE_BUTTON, 255 },
410         {  3, 25, 93, 85, 26,  2, 25, 10, 11,"reverse", BT_MOUSE_BUTTON, 255 },
411         {  4, 25, 62, 85, 26,  1, 26,  6,  7,"Fire flare", BT_MOUSE_BUTTON, 255 },
412         {  5,180, 46, 59, 26, 24,  6,  0,  1,"Slide on", BT_MOUSE_BUTTON, 255 },
413         {  6,180, 54, 59, 26,  5,  7,  1,  4,"Slide left", BT_MOUSE_BUTTON, 255 },
414         {  7,180, 62, 59, 26,  6,  8,  4, 26,"Slide right", BT_MOUSE_BUTTON, 255 },
415         {  8,180, 70, 59, 26,  7,  9, 26,  9,"Slide up", BT_MOUSE_BUTTON, 255 },
416         {  9,180, 78, 59, 26,  8, 10,  8,  2,"Slide down", BT_MOUSE_BUTTON, 255 },
417         { 10,180, 90, 59, 26,  9, 11,  2,  3,"Bank on", BT_MOUSE_BUTTON, 255 },
418         { 11,180, 98, 59, 26, 10, 12,  3, 12,"Bank left", BT_MOUSE_BUTTON, 255 },
419         { 12,180,106, 59, 26, 11,  0, 11, 25,"Bank right", BT_MOUSE_BUTTON, 255 },
420         { 13,103,138, 58, 26, 27, 15, 25, 14,"Pitch U/D", BT_MOUSE_AXIS, 255 },
421         { 14,103,138,106,  8, 23, 16, 13, 15,"Pitch U/D", BT_INVERT, 255 },
422         { 15,103,146, 58, 26, 13, 17, 14, 16,"Turn L/R", BT_MOUSE_AXIS, 255 },
423         { 16,103,146,106,  8, 14, 18, 15, 17,"Turn L/R", BT_INVERT, 255 },
424         { 17,103,154, 58, 26, 15, 19, 16, 18,"Slide L/R", BT_MOUSE_AXIS, 255 },
425         { 18,103,154,106,  8, 16, 20, 17, 19,"Slide L/R", BT_INVERT, 255 },
426         { 19,103,162, 58, 26, 17, 21, 18, 20,"Slide U/D", BT_MOUSE_AXIS, 255 },
427         { 20,103,162,106,  8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 },
428         { 21,103,170, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_MOUSE_AXIS, 255 },
429         { 22,103,170,106,  8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 },
430         { 23,103,182, 58, 26, 21, 14, 22, 24,"throttle", BT_MOUSE_AXIS, 255 },
431         { 24,103,182,106,  8, 22,  5, 23,  0,"throttle", BT_INVERT, 255 },
432         { 25, 25,109, 85, 26,  3, 27, 12, 13,"REAR VIEW", BT_MOUSE_BUTTON, 255 },
433         { 26, 25, 70, 85, 26,  4,  2,  7,  8,"Drop Bomb", BT_MOUSE_BUTTON, 255 },
434         { 27, 25,117, 85, 26, 25, 13, 25, 13,"Afterburner", BT_MOUSE_BUTTON, 255 },
435 };
436
437 #ifdef D2X_KEYS
438 //added on 2/4/99 by Victor Rachels to add d1x new keys
439 kc_item kc_d2x[NUM_D2X_CONTROLS] = {
440 //        id,x,y,w1,w2,u,d,l,r,text_num1,type,value
441         {  0, 15, 49, 71, 26, 27,  2, 27,  1, "WEAPON 1", BT_KEY, 255},
442         {  1, 15, 49,100, 26, 26,  3,  0,  2, "WEAPON 1", BT_JOY_BUTTON, 255},
443         {  2, 15, 57, 71, 26,  0,  4,  1,  3, "WEAPON 2", BT_KEY, 255},
444         {  3, 15, 57,100, 26,  1,  5,  2,  4, "WEAPON 2", BT_JOY_BUTTON, 255},
445         {  4, 15, 65, 71, 26,  2,  6,  3,  5, "WEAPON 3", BT_KEY, 255},
446         {  5, 15, 65,100, 26,  3,  7,  4,  6, "WEAPON 3", BT_JOY_BUTTON, 255},
447         {  6, 15, 73, 71, 26,  4,  8,  5,  7, "WEAPON 4", BT_KEY, 255},
448         {  7, 15, 73,100, 26,  5,  9,  6,  8, "WEAPON 4", BT_JOY_BUTTON, 255},
449         {  8, 15, 81, 71, 26,  6, 10,  7,  9, "WEAPON 5", BT_KEY, 255},
450         {  9, 15, 81,100, 26,  7, 11,  8, 10, "WEAPON 5", BT_JOY_BUTTON, 255},
451
452         { 10, 15, 89, 71, 26,  8, 12,  9, 11, "WEAPON 6", BT_KEY, 255},
453         { 11, 15, 89,100, 26,  9, 13, 10, 12, "WEAPON 6", BT_JOY_BUTTON, 255},
454         { 12, 15, 97, 71, 26, 10, 14, 11, 13, "WEAPON 7", BT_KEY, 255},
455         { 13, 15, 97,100, 26, 11, 15, 12, 14, "WEAPON 7", BT_JOY_BUTTON, 255},
456         { 14, 15,105, 71, 26, 12, 16, 13, 15, "WEAPON 8", BT_KEY, 255},
457         { 15, 15,105,100, 26, 13, 17, 14, 16, "WEAPON 8", BT_JOY_BUTTON, 255},
458         { 16, 15,113, 71, 26, 14, 18, 15, 17, "WEAPON 9", BT_KEY, 255},
459         { 17, 15,113,100, 26, 15, 19, 16, 18, "WEAPON 9", BT_JOY_BUTTON, 255},
460         { 18, 15,121, 71, 26, 16, 20, 17, 19, "WEAPON 0", BT_KEY, 255},
461         { 19, 15,121,100, 26, 17, 21, 18, 20, "WEAPON 0", BT_JOY_BUTTON, 255},
462
463         //{ 20, 15,131, 71, 26, 18, 22, 19, 21, "CYC PRIMARY", BT_KEY, 255},
464         //{ 21, 15,131,100, 26, 19, 23, 20, 22, "CYC PRIMARY", BT_JOY_BUTTON, 255},
465         //{ 22, 15,139, 71, 26, 20, 24, 21, 23, "CYC SECONDARY", BT_KEY, 255},
466         //{ 23, 15,139,100, 26, 21, 25, 22, 24, "CYC SECONDARY", BT_JOY_BUTTON, 255},
467         //{ 24,  8,147, 78, 26, 22, 26, 23, 25, "TOGGLE_PRIM AUTO", BT_KEY, 255},
468         //{ 25,  8,147,107, 26, 23, 27, 24, 26, "TOGGLE_PRIM_AUTO", BT_JOY_BUTTON, 255},
469         //{ 26,  8,155, 78, 26, 24,  1, 25, 27, "TOGGLE SEC AUTO", BT_KEY, 255},
470         //{ 27,  8,155,107, 26, 25,  0, 26,  0, "TOGGLE SEC AUTO", BT_JOY_BUTTON, 255},
471 };
472 //end this section addition - VR
473 #endif
474
475 #else           // ifndef MACINTOSH (following are macintosh controls)
476
477 ubyte default_kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS] = {
478 {0x5b,0x7e,0x54,0x7d,0x56,0x7b,0x58,0x7c,0x3a,0xff,0xff,0x53,0xff,0x55,0xff,0x4e,0xff,0x45,0xff,0xff,0xc,0x59,0xe,0x5c,0x3b,0x24,0x31,0xff,0x3,0xff,0x3f,0xff,0x6,0xff,0xb,0xff,0xf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x30,0xff,0x1,0xff,0x2b,0xff,0x2f,0xff,0x4,0xff,0x11,0xff,0xff,0xff,0x0,0x0},
479 {0x0,0x1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0},
480 {0x0,0x3,0xff,0xff,0xff,0xff,0xb,0xc,0x9,0xa,0xff,0x1,0x2,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0},
481 {0x5,0x4,0xff,0xff,0x6,0xff,0x3,0x2,0x0,0x1,0xff,0x8,0xa,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x3,0x1,0xb,0x7,0xd,0xe,0xf,0xc,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0},
482 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0},
483 {0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0},
484 {0x0,0x1,0xff,0xff,0x2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0},
485 };
486
487 ubyte default_firebird_settings[MAX_CONTROLS] =
488 {0x0,0x1,0xff,0xff,0x2,0xff,0x4,0x6,0x5,0x7,0xff,0xb,0xc,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x03,0x0,0xff,0x3,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0};
489
490 ubyte default_mousestick_settings[MAX_CONTROLS] =
491 {0x2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3,0x4,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0};
492
493 kc_item kc_keyboard[NUM_KEY_CONTROLS] = {
494         {  0, 15, 49, 71, 26, 55,  2, 55,  1,"Pitch forward", BT_KEY, 255 },
495         {  1, 15, 49,100, 26, 50,  3,  0, 24,"Pitch forward", BT_KEY, 255 },
496         {  2, 15, 57, 71, 26,  0,  4, 25,  3,"Pitch backward", BT_KEY, 255 },
497         {  3, 15, 57,100, 26,  1,  5,  2, 26,"Pitch backward", BT_KEY, 255 },
498         {  4, 15, 65, 71, 26,  2,  6, 27,  5,"Turn left", BT_KEY, 255 },
499         {  5, 15, 65,100, 26,  3,  7,  4, 28,"Turn left", BT_KEY, 255 },
500         {  6, 15, 73, 71, 26,  4,  8, 29,  7,"Turn right", BT_KEY, 255 },
501         {  7, 15, 73,100, 26,  5,  9,  6, 34,"Turn right", BT_KEY, 255 },
502         {  8, 15, 85, 71, 26,  6, 10, 35,  9,"Slide on", BT_KEY, 255 },
503         {  9, 15, 85,100, 26,  7, 11,  8, 36,"Slide on", BT_KEY, 255 },
504         { 10, 15, 93, 71, 26,  8, 12, 37, 11,"Slide left", BT_KEY, 255 },
505         { 11, 15, 93,100, 26,  9, 13, 10, 44,"Slide left", BT_KEY, 255 },
506         { 12, 15,101, 71, 26, 10, 14, 45, 13,"Slide right", BT_KEY, 255 },
507         { 13, 15,101,100, 26, 11, 15, 12, 30,"Slide right", BT_KEY, 255 },
508         { 14, 15,109, 71, 26, 12, 16, 31, 15,"Slide up", BT_KEY, 255 },
509         { 15, 15,109,100, 26, 13, 17, 14, 32,"Slide up", BT_KEY, 255 },
510         { 16, 15,117, 71, 26, 14, 18, 33, 17,"Slide down", BT_KEY, 255 },
511         { 17, 15,117,100, 26, 15, 19, 16, 46,"Slide down", BT_KEY, 255 },
512         { 18, 15,129, 71, 26, 16, 20, 47, 19,"Bank on", BT_KEY, 255 },
513         { 19, 15,129,100, 26, 17, 21, 18, 38,"Bank on", BT_KEY, 255 },
514         { 20, 15,137, 71, 26, 18, 22, 39, 21,"Bank left", BT_KEY, 255 },
515         { 21, 15,137,100, 26, 19, 23, 20, 40,"Bank left", BT_KEY, 255 },
516         { 22, 15,145, 71, 26, 20, 48, 41, 23,"Bank right", BT_KEY, 255 },
517         { 23, 15,145,100, 26, 21, 49, 22, 42,"Bank right", BT_KEY, 255 },
518         { 24,158, 49, 83, 26, 51, 26,  1, 25,"Fire primary", BT_KEY, 255 },
519         { 25,158, 49,112, 26, 54, 27, 24,  2,"Fire primary", BT_KEY, 255 },
520         { 26,158, 57, 83, 26, 24, 28,  3, 27,"Fire secondary", BT_KEY, 255 },
521         { 27,158, 57,112, 26, 25, 29, 26,  4,"Fire secondary", BT_KEY, 255 },
522         { 28,158, 65, 83, 26, 26, 34,  5, 29,"Fire flare", BT_KEY, 255 },
523         { 29,158, 65,112, 26, 27, 35, 28,  6,"Fire flare", BT_KEY, 255 },
524         { 30,158,105, 83, 26, 44, 32, 13, 31,"Accelerate", BT_KEY, 255 },
525         { 31,158,105,112, 26, 45, 33, 30, 14,"Accelerate", BT_KEY, 255 },
526         { 32,158,113, 83, 26, 30, 46, 15, 33,"reverse", BT_KEY, 255 },
527         { 33,158,113,112, 26, 31, 47, 32, 16,"reverse", BT_KEY, 255 },
528         { 34,158, 73, 83, 26, 28, 36,  7, 35,"Drop Bomb", BT_KEY, 255 },
529         { 35,158, 73,112, 26, 29, 37, 34,  8,"Drop Bomb", BT_KEY, 255 },
530         { 36,158, 85, 83, 26, 34, 44,  9, 37,"REAR VIEW", BT_KEY, 255 },
531         { 37,158, 85,112, 26, 35, 45, 36, 10,"REAR VIEW", BT_KEY, 255 },
532         { 38,158,133, 83, 26, 46, 40, 19, 39,"Cruise Faster", BT_KEY, 255 },
533         { 39,158,133,112, 26, 47, 41, 38, 20,"Cruise Faster", BT_KEY, 255 },
534         { 40,158,141, 83, 26, 38, 42, 21, 41,"Cruise Slower", BT_KEY, 255 },
535         { 41,158,141,112, 26, 39, 43, 40, 22,"Cruise Slower", BT_KEY, 255 },
536         { 42,158,149, 83, 26, 40, 52, 23, 43,"Cruise Off", BT_KEY, 255 },
537         { 43,158,149,112, 26, 41, 53, 42, 48,"Cruise Off", BT_KEY, 255 },
538         { 44,158, 93, 83, 26, 36, 30, 11, 45,"Automap", BT_KEY, 255 },
539         { 45,158, 93,112, 26, 37, 31, 44, 12,"Automap", BT_KEY, 255 },
540         { 46,158,121, 83, 26, 32, 38, 17, 47,"Afterburner", BT_KEY, 255 },
541         { 47,158,121,112, 26, 33, 39, 46, 18,"Afterburner", BT_KEY, 255 },
542         { 48, 15,161, 71, 26, 22, 50, 43, 49,"Cycle Primary", BT_KEY, 255 },
543         { 49, 15,161,100, 26, 23, 51, 48, 52,"Cycle Primary", BT_KEY, 255 },
544         { 50, 15,169, 71, 26, 48,  1, 53, 51,"Cycle Second", BT_KEY, 255 },
545         { 51, 15,169,100, 26, 49, 24, 50, 54,"Cycle Second", BT_KEY, 255 },
546         { 52,158,163, 83, 26, 42, 54, 49, 53,"Headlight", BT_KEY, 255 },
547         { 53,158,163,112, 26, 43, 55, 52, 50,"Headlight", BT_KEY, 255 },
548         { 54,158,171, 83, 26, 52, 25, 51, 55,"Energy->Shield", BT_KEY, 255 },
549         { 55,158,171,112, 26, 53,  0, 54,  0,"Energy->Shield", BT_KEY, 255 },
550 };
551 kc_item kc_joystick[NUM_OTHER_CONTROLS] = {
552         {  0, 25, 46, 85, 28, 15,  1, 24,  5,"Fire primary", BT_JOY_BUTTON, 255 },
553         {  1, 25, 54, 85, 28,  0,  4,  5,  6,"Fire secondary", BT_JOY_BUTTON, 255 },
554         {  2, 25, 85, 85, 28, 26,  3,  9, 10,"Accelerate", BT_JOY_BUTTON, 255 },
555         {  3, 25, 93, 85, 28,  2, 25, 10, 11,"reverse", BT_JOY_BUTTON, 255 },
556         {  4, 25, 62, 85, 28,  1, 26,  6,  7,"Fire flare", BT_JOY_BUTTON, 255 },
557         {  5,180, 46, 79, 28, 23,  6,  0,  1,"Slide on", BT_JOY_BUTTON, 255 },
558         {  6,180, 54, 79, 28,  5,  7,  1,  4,"Slide left", BT_JOY_BUTTON, 255 },
559         {  7,180, 62, 79, 28,  6,  8,  4, 26,"Slide right", BT_JOY_BUTTON, 255 },
560         {  8,180, 70, 79, 28,  7,  9, 26,  9,"Slide up", BT_JOY_BUTTON, 255 },
561         {  9,180, 78, 79, 28,  8, 10,  8,  2,"Slide down", BT_JOY_BUTTON, 255 },
562         { 10,180, 90, 79, 28,  9, 11,  2,  3,"Bank on", BT_JOY_BUTTON, 255 },
563         { 11,180, 98, 79, 28, 10, 12,  3, 12,"Bank left", BT_JOY_BUTTON, 255 },
564         { 12,180,106, 79, 28, 11, 28, 11, 25,"Bank right", BT_JOY_BUTTON, 255 },
565         { 13, 22,154, 51, 26, 24, 15, 30, 14,"Pitch U/D", BT_JOY_AXIS, 255 },
566         { 14, 22,154, 99,  8, 30, 16, 13, 17,"Pitch U/D", BT_INVERT, 255 },
567         { 15, 22,162, 51, 26, 13,  0, 18, 16,"Turn L/R", BT_JOY_AXIS, 255 },
568         { 16, 22,162, 99,  8, 14, 17, 15, 19,"Turn L/R", BT_INVERT, 255 },
569         { 17,164,154, 58, 26, 16, 19, 14, 18,"Slide L/R", BT_JOY_AXIS, 255 },
570         { 18,164,154,106,  8, 29, 20, 17, 15,"Slide L/R", BT_INVERT, 255 },
571         { 19,164,162, 58, 26, 17, 21, 16, 20,"Slide U/D", BT_JOY_AXIS, 255 },
572         { 20,164,162,106,  8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 },
573         { 21,164,172, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_JOY_AXIS, 255 },
574         { 22,164,172,106,  8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 },
575         { 23,164,180, 58, 26, 21,  5, 22, 24,"throttle", BT_JOY_AXIS, 255 },
576         { 24,164,180,106,  8, 22, 13, 23,  0,"throttle", BT_INVERT, 255 },
577         { 25, 25,109, 85, 28,  3, 27, 12, 28,"REAR VIEW", BT_JOY_BUTTON, 255 },
578         { 26, 25, 70, 85, 28,  4,  2,  7,  8,"Drop Bomb", BT_JOY_BUTTON, 255 },
579         { 27, 25,117, 85, 28, 25, 30, 28, 29,"Afterburner", BT_JOY_BUTTON, 255 },
580         { 28,180,114, 79, 28, 12, 29, 25, 27,"Cycle Primary", BT_JOY_BUTTON, 255 },
581         { 29,180,122, 79, 28, 28, 18, 27, 30,"Cycle Secondary", BT_JOY_BUTTON, 255 },
582         { 30, 25,125, 85, 28, 27, 14, 29, 13,"Headlight", BT_JOY_BUTTON, 255 },
583 };
584 kc_item kc_superjoy[NUM_OTHER_CONTROLS] = {
585         {  0, 25, 46, 85, 26, 15,  1, 24,  5,"Fire primary", BT_JOY_BUTTON, 255 },
586         {  1, 25, 54, 85, 26,  0,  4,  5,  6,"Fire secondary", BT_JOY_BUTTON, 255 },
587         {  2, 25, 85, 85, 26, 26,  3,  9, 10,"Accelerate", BT_JOY_BUTTON, 255 },
588         {  3, 25, 93, 85, 26,  2, 25, 10, 11,"reverse", BT_JOY_BUTTON, 255 },
589         {  4, 25, 62, 85, 26,  1, 26,  6,  7,"Fire flare", BT_JOY_BUTTON, 255 },
590         {  5,180, 46, 79, 26, 23,  6,  0,  1,"Slide on", BT_JOY_BUTTON, 255 },
591         {  6,180, 54, 79, 26,  5,  7,  1,  4,"Slide left", BT_JOY_BUTTON, 255 },
592         {  7,180, 62, 79, 26,  6,  8,  4, 26,"Slide right", BT_JOY_BUTTON, 255 },
593         {  8,180, 70, 79, 26,  7,  9, 26,  9,"Slide up", BT_JOY_BUTTON, 255 },
594         {  9,180, 78, 79, 26,  8, 10,  8,  2,"Slide down", BT_JOY_BUTTON, 255 },
595         { 10,180, 90, 79, 26,  9, 11,  2,  3,"Bank on", BT_JOY_BUTTON, 255 },
596         { 11,180, 98, 79, 26, 10, 12,  3, 12,"Bank left", BT_JOY_BUTTON, 255 },
597         { 12,180,106, 79, 26, 11, 28, 11, 25,"Bank right", BT_JOY_BUTTON, 255 },
598         { 13, 22,154, 51, 26, 24, 15, 30, 14,"Pitch U/D", BT_JOY_AXIS, 255 },
599         { 14, 22,154, 99,  8, 30, 16, 13, 17,"Pitch U/D", BT_INVERT, 255 },
600         { 15, 22,162, 51, 26, 13,  0, 18, 16,"Turn L/R", BT_JOY_AXIS, 255 },
601         { 16, 22,162, 99,  8, 14, 17, 15, 19,"Turn L/R", BT_INVERT, 255 },
602         { 17,164,154, 58, 26, 16, 19, 14, 18,"Slide L/R", BT_JOY_AXIS, 255 },
603         { 18,164,154,106,  8, 29, 20, 17, 15,"Slide L/R", BT_INVERT, 255 },
604         { 19,164,162, 58, 26, 17, 21, 16, 20,"Slide U/D", BT_JOY_AXIS, 255 },
605         { 20,164,162,106,  8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 },
606         { 21,164,172, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_JOY_AXIS, 255 },
607         { 22,164,172,106,  8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 },
608         { 23,164,180, 58, 26, 21,  5, 22, 24,"throttle", BT_JOY_AXIS, 255 },
609         { 24,164,180,106,  8, 22, 13, 23,  0,"throttle", BT_INVERT, 255 },
610         { 25, 25,109, 85, 26,  3, 27, 12, 28,"REAR VIEW", BT_JOY_BUTTON, 255 },
611         { 26, 25, 70, 85, 26,  4,  2,  7,  8,"Drop Bomb", BT_JOY_BUTTON, 255 },
612         { 27, 25,117, 85, 26, 25, 30, 28, 29,"Afterburner", BT_JOY_BUTTON, 255 },
613         { 28,180,114, 79, 26, 12, 29, 25, 27,"Cycle Primary", BT_JOY_BUTTON, 255 },
614         { 29,180,122, 79, 26, 28, 18, 27, 30,"Cycle Secondary", BT_JOY_BUTTON, 255 },
615         { 30, 25,125, 85, 26, 27, 14, 29, 13,"Headlight", BT_JOY_BUTTON, 255 },
616 };
617
618 kc_item kc_mouse[NUM_OTHER_CONTROLS] = {
619         {  0, 25, 46, 85, 26, 28,  1, 28,  5,"Fire primary", BT_MOUSE_BUTTON, 255 },
620         {  1, 25, 54, 85, 26,  0,  4,  5,  6,"Fire secondary", BT_MOUSE_BUTTON, 255 },
621         {  2, 25, 85, 85, 26, 26,  3,  9, 10,"Accelerate", BT_MOUSE_BUTTON, 255 },
622         {  3, 25, 93, 85, 26,  2, 25, 10, 11,"reverse", BT_MOUSE_BUTTON, 255 },
623         {  4, 25, 62, 85, 26,  1, 26,  6,  7,"Fire flare", BT_MOUSE_BUTTON, 255 },
624         {  5,180, 46, 59, 26, 24,  6,  0,  1,"Slide on", BT_MOUSE_BUTTON, 255 },
625         {  6,180, 54, 59, 26,  5,  7,  1,  4,"Slide left", BT_MOUSE_BUTTON, 255 },
626         {  7,180, 62, 59, 26,  6,  8,  4, 26,"Slide right", BT_MOUSE_BUTTON, 255 },
627         {  8,180, 70, 59, 26,  7,  9, 26,  9,"Slide up", BT_MOUSE_BUTTON, 255 },
628         {  9,180, 78, 59, 26,  8, 10,  8,  2,"Slide down", BT_MOUSE_BUTTON, 255 },
629         { 10,180, 90, 59, 26,  9, 11,  2,  3,"Bank on", BT_MOUSE_BUTTON, 255 },
630         { 11,180, 98, 59, 26, 10, 12,  3, 12,"Bank left", BT_MOUSE_BUTTON, 255 },
631         { 12,180,106, 59, 26, 11, 28, 11, 25,"Bank right", BT_MOUSE_BUTTON, 255 },
632         { 13,103,138, 58, 26, 27, 15, 27, 14,"Pitch U/D", BT_MOUSE_AXIS, 255 },
633         { 14,103,138,106,  8, 23, 16, 13, 15,"Pitch U/D", BT_INVERT, 255 },
634         { 15,103,146, 58, 26, 13, 17, 14, 16,"Turn L/R", BT_MOUSE_AXIS, 255 },
635         { 16,103,146,106,  8, 14, 18, 15, 17,"Turn L/R", BT_INVERT, 255 },
636         { 17,103,154, 58, 26, 15, 19, 16, 18,"Slide L/R", BT_MOUSE_AXIS, 255 },
637         { 18,103,154,106,  8, 16, 20, 17, 19,"Slide L/R", BT_INVERT, 255 },
638         { 19,103,162, 58, 26, 17, 21, 18, 20,"Slide U/D", BT_MOUSE_AXIS, 255 },
639         { 20,103,162,106,  8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 },
640         { 21,103,170, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_MOUSE_AXIS, 255 },
641         { 22,103,170,106,  8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 },
642         { 23,103,182, 58, 26, 21, 14, 22, 24,"throttle", BT_MOUSE_AXIS, 255 },
643         { 24,103,182,106,  8, 22,  5, 23, 28,"throttle", BT_INVERT, 255 },
644         { 25, 25,109, 85, 26,  3, 27, 12, 27,"REAR VIEW", BT_MOUSE_BUTTON, 255 },
645         { 26, 25, 70, 85, 26,  4,  2,  7,  8,"Drop Bomb", BT_MOUSE_BUTTON, 255 },
646         { 27, 25,117, 85, 26, 25, 13, 25, 13,"Afterburner", BT_MOUSE_BUTTON, 255 },
647 };
648
649 #endif
650
651 //added on 2/4/99 by Victor Rachels to add new keys system
652 ubyte default_kconfig_d2x_settings[MAX_D2X_CONTROLS] = {
653  0x2 ,0xff,0x3 ,0xff,0x4 ,0xff,0x5 ,0xff,0x6 ,0xff,0x7 ,0xff,0x8 ,0xff,0x9 ,
654  0xff,0xa ,0xff,0xb ,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
655  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
656 //end this section addition - VR
657
658 void kc_drawitem( kc_item *item, int is_current );
659 void kc_change_key( kc_item * item );
660 void kc_change_joybutton( kc_item * item );
661 void kc_change_mousebutton( kc_item * item );
662 void kc_next_joyaxis(kc_item *item);  //added by WraithX on 11/22/00
663 void kc_change_joyaxis( kc_item * item );
664 void kc_change_mouseaxis( kc_item * item );
665 void kc_change_invert( kc_item * item );
666 void kconfig_read_fcs( int raw_axis );
667 void kconfig_set_fcs_button( int btn, int button );
668 void kconfig_read_external_controls( void );
669
670 // the following methods added by WraithX, 4/17/00
671 int isJoyRotationKey(int test_key)
672 {
673         if (test_key == kc_joystick[11].value ||
674             test_key == kc_joystick[12].value)
675         {
676                 return 1;
677         }// end if
678
679         // else...
680         return 0;
681 }// method isJoyRotationKey
682
683 int isMouseRotationKey(int test_key)
684 {
685         if (test_key == kc_mouse[11].value ||
686             test_key == kc_mouse[12].value)
687         {
688                 return 1;
689         }// end if
690
691         // else...
692         return 0;
693 }// method isMouseRotationKey
694
695 int isKeyboardRotationKey(int test_key)
696 {
697         if (test_key == kc_keyboard[0].value ||
698             test_key == kc_keyboard[1].value ||
699             test_key == kc_keyboard[2].value ||
700             test_key == kc_keyboard[3].value ||
701             test_key == kc_keyboard[4].value ||
702             test_key == kc_keyboard[5].value ||
703             test_key == kc_keyboard[6].value ||
704             test_key == kc_keyboard[7].value ||
705             test_key == kc_keyboard[20].value ||
706             test_key == kc_keyboard[21].value ||
707             test_key == kc_keyboard[22].value ||
708             test_key == kc_keyboard[23].value)
709         {
710                 return 1;
711         }// end if
712
713         // else...
714         return 0;
715 }// method isKeyboardRotationKey
716 // end addition - WraithX
717
718 int kconfig_is_axes_used(int axis)
719 {
720         int i;
721         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
722                 if (( kc_joystick[i].type == BT_JOY_AXIS ) && (kc_joystick[i].value == axis ))
723                         return 1;
724         }
725         return 0;
726 }
727
728 #ifdef TABLE_CREATION
729 int find_item_at( kc_item * items, int nitems, int x, int y )
730 {
731         int i;
732         
733         for (i=0; i<nitems; i++ )       {
734                 if ( ((items[i].x+items[i].w1)==x) && (items[i].y==y))
735                         return i;
736         }
737         return -1;
738 }
739
740 int find_next_item_up( kc_item * items, int nitems, int citem )
741 {
742         int x, y, i;
743
744         y = items[citem].y;
745         x = items[citem].x+items[citem].w1;
746         
747         do {    
748                 y--;
749                 if ( y < 0 ) {
750                         y = grd_curcanv->cv_bitmap.bm_h-1;
751                         x--;
752                         if ( x < 0 ) {
753                                 x = grd_curcanv->cv_bitmap.bm_w-1;
754                         }
755                 }
756                 i = find_item_at( items, nitems, x, y );
757         } while ( i < 0 );
758         
759         return i;
760 }
761
762 int find_next_item_down( kc_item * items, int nitems, int citem )
763 {
764         int x, y, i;
765
766         y = items[citem].y;
767         x = items[citem].x+items[citem].w1;
768         
769         do {    
770                 y++;
771                 if ( y > grd_curcanv->cv_bitmap.bm_h-1 ) {
772                         y = 0;
773                         x++;
774                         if ( x > grd_curcanv->cv_bitmap.bm_w-1 ) {
775                                 x = 0;
776                         }
777                 }
778                 i = find_item_at( items, nitems, x, y );
779         } while ( i < 0 );
780         
781         return i;
782 }
783
784 int find_next_item_right( kc_item * items, int nitems, int citem )
785 {
786         int x, y, i;
787
788         y = items[citem].y;
789         x = items[citem].x+items[citem].w1;
790         
791         do {    
792                 x++;
793                 if ( x > grd_curcanv->cv_bitmap.bm_w-1 ) {
794                         x = 0;
795                         y++;
796                         if ( y > grd_curcanv->cv_bitmap.bm_h-1 ) {
797                                 y = 0;
798                         }
799                 }
800                 i = find_item_at( items, nitems, x, y );
801         } while ( i < 0 );
802         
803         return i;
804 }
805
806 int find_next_item_left( kc_item * items, int nitems, int citem )
807 {
808         int x, y, i;
809
810         y = items[citem].y;
811         x = items[citem].x+items[citem].w1;
812         
813         do {    
814                 x--;
815                 if ( x < 0 ) {
816                         x = grd_curcanv->cv_bitmap.bm_w-1;
817                         y--;
818                         if ( y < 0 ) {
819                                 y = grd_curcanv->cv_bitmap.bm_h-1;
820                         }
821                 }
822                 i = find_item_at( items, nitems, x, y );
823         } while ( i < 0 );
824         
825         return i;
826 }
827 #endif
828
829 #ifdef NEWMENU_MOUSE
830 int get_item_height(kc_item *item)
831 {
832         int w, h, aw;
833         char btext[10];
834
835         if (item->value==255) {
836                 strcpy(btext, "");
837         } else {
838                 switch( item->type )    {
839                         case BT_KEY:
840                                 strncpy( btext, key_text[item->value], 10 ); break;
841                         case BT_MOUSE_BUTTON:
842 #ifndef MACINTOSH
843                                 strncpy( btext, Text_string[mousebutton_text[item->value]], 10); break;
844 #else
845                                 strncpy( btext, mousebutton_text[item->value], 10 ); break;
846 #endif
847                         case BT_MOUSE_AXIS:
848                                 strncpy( btext, Text_string[mouseaxis_text[item->value]], 10 ); break;
849                         case BT_JOY_BUTTON:
850 #ifdef USE_LINUX_JOY
851                                 sprintf(btext, "J%d B%d", j_button[item->value].joydev, j_Get_joydev_button_number(item->value));
852 #elif defined(SDL_INPUT)
853                                 if (joybutton_text[item->value])
854                                         strncpy(btext, joybutton_text[item->value], 10);
855                                 else
856                                         sprintf(btext, "BTN%2d", item->value + 1);
857 #else
858                                 if ( joybutton_text[item->value] !=-1 )
859                                         strncpy( btext, Text_string[ joybutton_text[item->value]  ], 10 );
860                                 else
861                                         sprintf( btext, "BTN%d", item->value );
862 #endif
863                                 break;
864                         case BT_JOY_AXIS:
865 #ifdef USE_LINUX_JOY
866                                 sprintf( btext, "J%d A%d", j_axis[item->value].joydev, j_Get_joydev_axis_number (item->value) );
867 #elif defined(SDL_INPUT)
868                                 if (joyaxis_text[item->value])
869                                         strncpy(btext, joyaxis_text[item->value], 10);
870                                 else
871                                         sprintf(btext, "AXIS%2d", item->value + 1);
872 #else
873                                 strncpy(btext, Text_string[joyaxis_text[item->value]], 10);
874 #endif
875                                 break;
876                         case BT_INVERT:
877                                 strncpy( btext, Text_string[invert_text[item->value]], 10 ); break;
878                 }
879         }
880         gr_get_string_size(btext, &w, &h, &aw  );
881
882         return h;
883 }
884 #endif
885
886 void kconfig_sub(kc_item * items,int nitems, char * title)
887 {
888         grs_canvas * save_canvas;
889         grs_font * save_font;
890         int old_keyd_repeat;
891 #ifdef NEWMENU_MOUSE
892         int mouse_state, omouse_state, mx, my, x1, x2, y1, y2;
893         int close_x, close_y, close_size;
894 #endif
895
896         int i,k,ocitem,citem;
897         int time_stopped = 0;
898
899         All_items = items;
900         Num_items = nitems;
901
902         if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
903         {
904                 time_stopped = 1;
905                 stop_time();
906         }
907
908 //      if (Config_control_type == CONTROL_WINJOYSTICK) {
909 //              WINDOS(
910 //                      joydefsw_win_joyselect(title2); title = title2,
911 //                      Int3()
912 //              );                                                                                              // Get Samir...
913 //      }
914
915         save_canvas = grd_curcanv;
916
917
918         gr_set_current_canvas(NULL);
919         save_font = grd_curcanv->cv_font;
920
921 #ifdef WINDOWS
922 KConfigPaint:
923 #endif
924         game_flush_inputs();
925         old_keyd_repeat = keyd_repeat;
926         keyd_repeat = 1;
927
928         //gr_clear_canvas( BM_XRGB(0,0,0) );
929
930         nm_draw_background(0, 0, grd_curcanv->cv_bitmap.bm_w - 1, grd_curcanv->cv_bitmap.bm_h - 1);
931    gr_palette_load (gr_palette);
932
933         grd_curcanv->cv_font = MEDIUM3_FONT;
934
935         {
936                 char * p;
937                 p = strchr( title, '\n' );
938                 if ( p ) *p = 32;
939                 gr_string( 0x8000, LHY(8), title );
940                 if ( p ) *p = '\n';
941         }
942
943
944 //      if ( items == kc_keyboard )     {
945 //              gr_string( 0x8000, 8, "Keyboard" );
946 //      } else if ( items == kc_joystick )      {
947 //              gr_string( 0x8000, 8, "Joysticks" );
948 //      } else if ( items == kc_mouse ) {
949 //              gr_string( 0x8000, 8, "Mouse" );
950 //      }
951
952 #ifdef NEWMENU_MOUSE
953         close_x = close_y = MenuHires?15:7;
954         close_size = MenuHires?10:5;
955         gr_setcolor( BM_XRGB(0, 0, 0) );
956         gr_rect(close_x, close_y, close_x + close_size, close_y + close_size);
957         gr_setcolor( BM_XRGB(21, 21, 21) );
958         gr_rect(close_x + LHX(1), close_y + LHX(1), close_x + close_size - LHX(1), close_y + close_size - LHX(1));
959 #endif
960
961         grd_curcanv->cv_font = GAME_FONT;
962         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
963
964         #ifndef MACINTOSH
965         gr_string( 0x8000, LHY(20), TXT_KCONFIG_STRING_1 );
966         #else
967         gr_string( 0x8000, LHY(20), "Enter changes, ctrl-d deletes, ctrl-r resets defaults, ESC exits");
968         #endif
969         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
970         if ( items == kc_keyboard )     {
971                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
972                 gr_setcolor( BM_XRGB(31,27,6) );
973                 
974                 gr_scanline( LHX(98), LHX(106), LHY(42) );
975                 gr_scanline( LHX(120), LHX(128), LHY(42) );
976                 gr_pixel( LHX(98), LHY(43) );                                           
977                 gr_pixel( LHX(98), LHY(44) );                                           
978                 gr_pixel( LHX(128), LHY(43) );                                          
979                 gr_pixel( LHX(128), LHY(44) );                                          
980                 
981                 gr_string( LHX(109), LHY(40), "OR" );
982
983                 gr_scanline( LHX(253), LHX(261), LHY(42) );
984                 gr_scanline( LHX(274), LHX(283), LHY(42) );
985                 gr_pixel( LHX(253), LHY(43) );                                          
986                 gr_pixel( LHX(253), LHY(44) );                                          
987                 gr_pixel( LHX(283), LHY(43) );                                          
988                 gr_pixel( LHX(283), LHY(44) );                                          
989
990                 gr_string( LHX(264), LHY(40), "OR" );
991
992         } if ( items == kc_joystick )   {
993                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
994                 gr_setcolor( BM_XRGB(31,27,6) );
995                 gr_scanline( LHX(18), LHX(135), LHY(37) );
996                 gr_scanline( LHX(181), LHX(294), LHY(37) );
997                 gr_scanline( LHX(18), LHX(144), LHY(119+18) );
998                 gr_scanline( LHX(174), LHX(294), LHY(119+18) );
999                 gr_string( 0x8000, LHY(35), TXT_BUTTONS );
1000                 gr_string( 0x8000,LHY(117+18), TXT_AXES );
1001                 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1002                 gr_string( LHX(81), LHY(137+8), TXT_AXIS );
1003                 gr_string( LHX(111), LHY(137+8), TXT_INVERT );
1004                 gr_string( LHX(230), LHY(137+8), TXT_AXIS );
1005                 gr_string( LHX(260), LHY(137+8), TXT_INVERT );
1006         } else if ( items == kc_mouse ) {
1007                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
1008                 gr_setcolor( BM_XRGB(31,27,6) );
1009                 gr_scanline( LHX(18), LHX(135), LHY(37) );
1010                 gr_scanline( LHX(181), LHX(294), LHY(37) );
1011                 gr_scanline( LHX(18), LHX(144), LHY(119+5) );
1012                 gr_scanline( LHX(174), LHX(294), LHY(119+5) );
1013                 gr_string( 0x8000, LHY(35), TXT_BUTTONS );
1014                 gr_string( 0x8000,LHY(117+5), TXT_AXES );
1015                 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1016                 gr_string( LHX(169), LHY(129), TXT_AXIS );
1017                 gr_string( LHX(199), LHY(129), TXT_INVERT );
1018         }
1019 #ifdef D2X_KEYS
1020         else if ( items == kc_d2x )
1021         {
1022                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
1023                 gr_setcolor( BM_XRGB(31,27,6) );
1024
1025                 gr_string(LHX( 94), LHY(40), "KB");
1026                 gr_string(LHX(121), LHY(40), "JOY");
1027         }
1028 #endif
1029
1030         for (i=0; i<nitems; i++ )       {
1031                 kc_drawitem( &items[i], 0 );
1032         }
1033
1034         citem = 0;
1035         kc_drawitem( &items[citem], 1 );
1036
1037         newmenu_show_cursor();
1038
1039 #ifdef NEWMENU_MOUSE
1040         mouse_state = omouse_state = 0;
1041 #endif
1042
1043         while(1)                {
1044         //      Windows addendum to allow for kconfig input.
1045                 gr_update();
1046
1047                 //see if redbook song needs to be restarted
1048                 songs_check_redbook_repeat();
1049
1050                 k = key_inkey();
1051
1052 #ifdef NEWMENU_MOUSE
1053                 omouse_state = mouse_state;
1054                 mouse_state = mouse_button_state(0);
1055 #endif
1056
1057                 if ( !time_stopped ) {
1058                         #ifdef NETWORK
1059                         if (multi_menu_poll() == -1)
1060                                 k = -2;
1061                         #endif
1062                 }
1063                 ocitem = citem;
1064                 switch( k )     {
1065                 case KEY_BACKSP:
1066                         Int3();
1067                         break;
1068                 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
1069                 case KEY_PRINT_SCREEN:
1070                         save_screen_shot(0);
1071                         break;                                                  
1072                 case KEY_CTRLED+KEY_D:
1073                         items[citem].value = 255;
1074                         kc_drawitem( &items[citem], 1 );
1075                         break;
1076                 case KEY_CTRLED+KEY_R:  
1077                         if ( items==kc_keyboard )       {
1078                                 for (i=0; i<NUM_KEY_CONTROLS; i++ )             {
1079                                         items[i].value=default_kconfig_settings[0][i];
1080                                         kc_drawitem( &items[i], 0 );
1081                                 }
1082 #ifdef D2X_KEYS
1083                         } else if ( items==kc_d2x ) {
1084                                 for(i=0;i<NUM_D2X_CONTROLS;i++)
1085                                 {
1086                                         items[i].value=default_kconfig_d2x_settings[i];
1087                                         kc_drawitem( &items[i], 0 );
1088                                 }
1089 #endif
1090                         } else {
1091                                 #ifdef MACINTOSH
1092                           // hack for firebire and mousestick default controls since I made
1093                           // them the same control type -- dumb dumb dumb
1094                                 if (joy_have_firebird())
1095                                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1096                                                 items[i].value = default_firebird_settings[i];
1097                                                 kc_drawitem( &items[i], 0 );
1098                                         }
1099                                 else if (joy_have_mousestick())
1100                                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1101                                                 items[i].value = default_mousestick_settings[i];
1102                                                 kc_drawitem( &items[i], 0 );
1103                                         }
1104                                 else
1105                                 #endif  // note link to above else
1106                                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1107                                                 items[i].value = default_kconfig_settings[Config_control_type][i];
1108                                                 kc_drawitem( &items[i], 0 );
1109                                         }
1110                         }
1111                         kc_drawitem( &items[citem], 1 );
1112                         break;
1113                 case KEY_DELETE:
1114                         items[citem].value=255;
1115                         kc_drawitem( &items[citem], 1 );
1116                         break;
1117                 case KEY_UP:            
1118                 case KEY_PAD8:
1119 #ifdef TABLE_CREATION
1120                         if (items[citem].u==-1) items[citem].u=find_next_item_up( items,nitems, citem);
1121 #endif
1122                         citem = items[citem].u; 
1123                         break;
1124                 
1125                 case KEY_DOWN:  
1126                 case KEY_PAD2:
1127 #ifdef TABLE_CREATION
1128                         if (items[citem].d==-1) items[citem].d=find_next_item_down( items,nitems, citem);
1129 #endif
1130                         citem = items[citem].d; 
1131                         break;
1132                 case KEY_LEFT:  
1133                 case KEY_PAD4:
1134 #ifdef TABLE_CREATION
1135                         if (items[citem].l==-1) items[citem].l=find_next_item_left( items,nitems, citem);
1136 #endif
1137                         citem = items[citem].l; 
1138                         break;
1139                 case KEY_RIGHT:         
1140                 case KEY_PAD6:
1141 #ifdef TABLE_CREATION
1142                         if (items[citem].r==-1) items[citem].r=find_next_item_right( items,nitems, citem);
1143 #endif
1144                         citem = items[citem].r; 
1145                         break;
1146                 case KEY_ENTER: 
1147                 case KEY_PADENTER:      
1148                         switch( items[citem].type )     {
1149                         case BT_KEY:            kc_change_key( &items[citem] ); break;
1150                         case BT_MOUSE_BUTTON:   kc_change_mousebutton( &items[citem] ); break;
1151                         case BT_MOUSE_AXIS:     kc_change_mouseaxis( &items[citem] ); break;
1152                         case BT_JOY_BUTTON:     kc_change_joybutton( &items[citem] ); break;
1153                         case BT_JOY_AXIS:       kc_change_joyaxis( &items[citem] ); break;
1154                         case BT_INVERT:         kc_change_invert( &items[citem] ); break;
1155                         }
1156                         break;
1157                 //the following case added by WraithX on 11/22/00 to work around the weird joystick bug...
1158                 case KEY_SPACEBAR:
1159                         switch(items[citem].type)
1160                         {
1161                         case BT_JOY_AXIS:
1162                                 kc_next_joyaxis(&items[citem]);
1163                                 break;
1164                         }
1165                         break;
1166                 //end addition by WraithX
1167                 case -2:        
1168                 case KEY_ESC:
1169                         grd_curcanv->cv_font    = save_font;
1170
1171                         gr_set_current_canvas( save_canvas );
1172                         keyd_repeat = old_keyd_repeat;
1173                         game_flush_inputs();
1174                         newmenu_hide_cursor();
1175                         if (time_stopped)
1176                                 start_time();
1177                         return;
1178 #ifdef TABLE_CREATION
1179                 case KEY_DEBUGGED+KEY_F12:      {
1180                         FILE * fp;
1181                         for (i=0; i<NUM_KEY_CONTROLS; i++ )     {
1182                                 kc_keyboard[i].u = find_next_item_up( kc_keyboard,NUM_KEY_CONTROLS, i);
1183                                 kc_keyboard[i].d = find_next_item_down( kc_keyboard,NUM_KEY_CONTROLS, i);
1184                                 kc_keyboard[i].l = find_next_item_left( kc_keyboard,NUM_KEY_CONTROLS, i);
1185                                 kc_keyboard[i].r = find_next_item_right( kc_keyboard,NUM_KEY_CONTROLS, i);
1186                         }
1187                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1188                                 kc_joystick[i].u = find_next_item_up( kc_joystick,NUM_OTHER_CONTROLS, i);
1189                                 kc_joystick[i].d = find_next_item_down( kc_joystick,NUM_OTHER_CONTROLS, i);
1190                                 kc_joystick[i].l = find_next_item_left( kc_joystick,NUM_OTHER_CONTROLS, i);
1191                                 kc_joystick[i].r = find_next_item_right( kc_joystick,NUM_OTHER_CONTROLS, i);
1192                         }
1193                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1194                                 kc_mouse[i].u = find_next_item_up( kc_mouse,NUM_OTHER_CONTROLS, i);
1195                                 kc_mouse[i].d = find_next_item_down( kc_mouse,NUM_OTHER_CONTROLS, i);
1196                                 kc_mouse[i].l = find_next_item_left( kc_mouse,NUM_OTHER_CONTROLS, i);
1197                                 kc_mouse[i].r = find_next_item_right( kc_mouse,NUM_OTHER_CONTROLS, i);
1198                         }
1199                         fp = fopen( "kconfig.cod", "wt" );
1200
1201                         fprintf( fp, "ubyte default_kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS] = {\n" );
1202                         for (i=0; i<CONTROL_MAX_TYPES; i++ )    {
1203                                 int j;
1204                                 fprintf( fp, "{0x%x", kconfig_settings[i][0] );
1205                                 for (j=1; j<MAX_CONTROLS; j++ )
1206                                         fprintf( fp, ",0x%x", kconfig_settings[i][j] );
1207                                 fprintf( fp, "},\n" );
1208                         }
1209                         fprintf( fp, "};\n" );
1210                 
1211                         fprintf( fp, "\nkc_item kc_keyboard[NUM_KEY_CONTROLS] = {\n" );
1212                         for (i=0; i<NUM_KEY_CONTROLS; i++ )     {
1213                                 fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
1214                                         kc_keyboard[i].id, kc_keyboard[i].x, kc_keyboard[i].y, kc_keyboard[i].w1, kc_keyboard[i].w2,
1215                                         kc_keyboard[i].u, kc_keyboard[i].d, kc_keyboard[i].l, kc_keyboard[i].r,
1216                                         34, kc_keyboard[i].text, 34, btype_text[kc_keyboard[i].type] );
1217                         }
1218                         fprintf( fp, "};" );
1219
1220                         fprintf( fp, "\nkc_item kc_joystick[NUM_OTHER_CONTROLS] = {\n" );
1221                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1222                                 if (kc_joystick[i].type == BT_JOY_BUTTON)
1223                                         fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
1224                                                 kc_joystick[i].id, kc_joystick[i].x, kc_joystick[i].y, kc_joystick[i].w1, kc_joystick[i].w2,
1225                                                 kc_joystick[i].u, kc_joystick[i].d, kc_joystick[i].l, kc_joystick[i].r,
1226                                                 34, kc_joystick[i].text, 34, btype_text[kc_joystick[i].type] );
1227                 else
1228                                         fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
1229                                                 kc_joystick[i].id, kc_joystick[i].x, kc_joystick[i].y, kc_joystick[i].w1, kc_joystick[i].w2,
1230                                                 kc_joystick[i].u, kc_joystick[i].d, kc_joystick[i].l, kc_joystick[i].r,
1231                                                 34, kc_joystick[i].text, 34, btype_text[kc_joystick[i].type] );
1232                         }
1233                         fprintf( fp, "};" );
1234
1235                         fprintf( fp, "\nkc_item kc_mouse[NUM_OTHER_CONTROLS] = {\n" );
1236                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1237                                 fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
1238                                         kc_mouse[i].id, kc_mouse[i].x, kc_mouse[i].y, kc_mouse[i].w1, kc_mouse[i].w2,
1239                                         kc_mouse[i].u, kc_mouse[i].d, kc_mouse[i].l, kc_mouse[i].r,
1240                                         34, kc_mouse[i].text, 34, btype_text[kc_mouse[i].type] );
1241                         }
1242                         fprintf( fp, "};" );
1243
1244                         fclose(fp);
1245
1246                         }
1247                         break;
1248 #endif
1249                 }
1250
1251 #ifdef NEWMENU_MOUSE
1252                 if ( (mouse_state && !omouse_state) || (mouse_state && omouse_state) ) {
1253                         int item_height;
1254                         
1255                         mouse_get_pos(&mx, &my);
1256                         for (i=0; i<nitems; i++ )       {
1257                                 item_height = get_item_height( &items[i] );
1258                                 x1 = grd_curcanv->cv_bitmap.bm_x + LHX(items[i].x) + LHX(items[i].w1);
1259                                 x2 = x1 + LHX(items[i].w2);
1260                                 y1 = grd_curcanv->cv_bitmap.bm_y + LHY(items[i].y);
1261                                 y2 = y1 + LHX(item_height);
1262                                 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1263                                         citem = i;
1264                                         break;
1265                                 }
1266                         }
1267                 }
1268                 else if ( !mouse_state && omouse_state ) {
1269                         int item_height;
1270                         
1271                         mouse_get_pos(&mx, &my);
1272                         item_height = get_item_height( &items[citem] );
1273                         x1 = grd_curcanv->cv_bitmap.bm_x + LHX(items[citem].x) + LHX(items[citem].w1);
1274                         x2 = x1 + LHX(items[citem].w2);
1275                         y1 = grd_curcanv->cv_bitmap.bm_y + LHY(items[citem].y);
1276                         y2 = y1 + LHY(item_height);
1277                         if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1278                                 newmenu_hide_cursor();
1279                                 switch( items[citem].type )     {
1280                                 case BT_KEY:                            kc_change_key( &items[citem] ); break;
1281                                 case BT_MOUSE_BUTTON:   kc_change_mousebutton( &items[citem] ); break;
1282                                 case BT_MOUSE_AXIS:             kc_change_mouseaxis( &items[citem] ); break;
1283                                 case BT_JOY_BUTTON:             kc_change_joybutton( &items[citem] ); break;
1284                                 case BT_JOY_AXIS:               kc_change_joyaxis( &items[citem] ); break;
1285                                 case BT_INVERT:                         kc_change_invert( &items[citem] ); break;
1286                                 }
1287                                 newmenu_show_cursor();
1288                         } else {
1289                                 x1 = grd_curcanv->cv_bitmap.bm_x + close_x + LHX(1);
1290                                 x2 = x1 + close_size - LHX(1);
1291                                 y1 = grd_curcanv->cv_bitmap.bm_y + close_y + LHX(1);
1292                                 y2 = y1 + close_size - LHX(1);
1293                                 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1294                                         grd_curcanv->cv_font    = save_font;
1295                                         gr_set_current_canvas( save_canvas );
1296                                         keyd_repeat = old_keyd_repeat;
1297                                         game_flush_inputs();
1298                                         newmenu_hide_cursor();
1299                                         if (time_stopped)
1300                                                 start_time();
1301                                         return;
1302                                 }
1303                         }
1304
1305                 }
1306 #endif // NEWMENU_MOUSE
1307
1308                 if (ocitem!=citem)      {
1309                         newmenu_hide_cursor();
1310                         kc_drawitem( &items[ocitem], 0 );
1311                         kc_drawitem( &items[citem], 1 );
1312                         newmenu_show_cursor();
1313                 }
1314         }
1315 }
1316
1317
1318 void kc_drawitem( kc_item *item, int is_current )
1319 {
1320         int x, w, h, aw;
1321         char btext[16];
1322
1323         if (is_current)
1324                 gr_set_fontcolor( BM_XRGB(20,20,29), -1 );
1325         else
1326                 gr_set_fontcolor( BM_XRGB(15,15,24), -1 );
1327    gr_string( LHX(item->x), LHY(item->y), item->text );
1328
1329         if (item->value==255) {
1330                 strcpy( btext, "" );
1331         } else {
1332                 switch( item->type )    {
1333                         case BT_KEY:
1334                                 strncpy( btext, key_text[item->value], 10 ); break;
1335                         case BT_MOUSE_BUTTON:
1336                                 #ifndef MACINTOSH
1337                                 //strncpy( btext, Text_string[mousebutton_text[item->value]], 10 ); break;
1338                                 strncpy( btext, (item->value <= 3)?Text_string[mousebutton_text[item->value]]:mousebutton_textra[item->value-3], 10 ); break;
1339                                 #else
1340                                 strncpy( btext, mousebutton_text[item->value], 10 ); break;
1341                                 #endif
1342                         case BT_MOUSE_AXIS:
1343                                 strncpy( btext, Text_string[mouseaxis_text[item->value]], 10 ); break;
1344                         case BT_JOY_BUTTON:
1345 #ifdef USE_LINUX_JOY
1346                                 sprintf(btext, "J%d B%d", j_button[item->value].joydev, j_Get_joydev_button_number(item->value));
1347 #elif defined(SDL_INPUT)
1348                                 if (joybutton_text[item->value])
1349                                         strncpy(btext, joybutton_text[item->value], 10);
1350                                 else
1351                                         sprintf(btext, "BTN%2d", item->value + 1);
1352 #else
1353 # ifndef MACINTOSH
1354 #  ifdef WINDOWS
1355                                 if (joybutton_text[item->value] != -1) 
1356                                         strncpy( btext, Text_string[ joybutton_text[item->value]  ], 10 );
1357                                 else 
1358                                         sprintf( btext, "BTN%2d", item->value+1 );
1359 #  else
1360                                 if ( joybutton_text[item->value] !=-1 )
1361                                         strncpy( btext, Text_string[ joybutton_text[item->value]  ], 10 );
1362                                 else
1363                                         sprintf( btext, "BTN%d", item->value );
1364 #  endif
1365 # else
1366                                 strncpy( btext, joy_btn_name( item->value ), 10);
1367                                 if (btext == NULL)
1368                                         sprintf( btext, "BTN%d", item->value );
1369 # endif
1370 #endif
1371                                 break;
1372                         case BT_JOY_AXIS:
1373 #ifdef USE_LINUX_JOY
1374                                 sprintf(btext, "J%d A%d", j_axis[item->value].joydev, j_Get_joydev_axis_number(item->value));
1375 #elif defined(SDL_INPUT)
1376                                 if (joyaxis_text[item->value])
1377                                         strncpy(btext, joyaxis_text[item->value], 10);
1378                                 else
1379                                         sprintf(btext, "AXIS%2d", item->value + 1);
1380 #else
1381                                 strncpy(btext, Text_string[joyaxis_text[item->value]], 10);
1382 #endif
1383                                 break;
1384                         case BT_INVERT:
1385                                 strncpy( btext, Text_string[invert_text[item->value]], 10 ); break;
1386                 }
1387         }
1388         if (item->w1) {
1389                 gr_get_string_size(btext, &w, &h, &aw  );
1390
1391                 if (is_current)
1392                         gr_setcolor( BM_XRGB(21,0,24) );
1393                 else
1394                         gr_setcolor( BM_XRGB(16,0,19) );
1395                 gr_urect( LHX(item->w1+item->x), LHY(item->y-1), LHX(item->w1+item->x+item->w2), LHY(item->y)+h );
1396                 
1397                 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1398
1399                 x = LHX(item->w1+item->x)+((LHX(item->w2)-w)/2);
1400         
1401                 gr_string( x, LHY(item->y), btext );
1402         }
1403 }
1404
1405
1406 static int looper=0;
1407
1408 void kc_drawquestion( kc_item *item )
1409 {
1410         int c, x, w, h, aw;
1411
1412         gr_get_string_size("?", &w, &h, &aw  );
1413
1414         c = BM_XRGB(21,0,24);
1415
1416         //@@gr_setcolor( gr_fade_table[fades[looper]*256+c] );
1417         gr_setcolor(BM_XRGB(21*fades[looper]/31,0,24*fades[looper]/31));
1418         looper++;
1419         if (looper>63) looper=0;
1420
1421         gr_urect( LHX(item->w1+item->x), LHY(item->y-1), LHX(item->w1+item->x+item->w2), LHY(item->y)+h );
1422         
1423         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1424
1425         x = LHX(item->w1+item->x)+((LHX(item->w2)-w)/2);
1426    
1427         gr_string( x, LHY(item->y), "?" );
1428 gr_update();
1429 }
1430
1431 void kc_change_key( kc_item * item )
1432 {
1433         int i,n,f,k;
1434         ubyte keycode;
1435
1436         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1437         
1438         gr_string( 0x8000, LHY(INFO_Y), TXT_PRESS_NEW_KEY );
1439
1440         game_flush_inputs();
1441         keycode=255;
1442         k=255;
1443         
1444         while( (k!=KEY_ESC) && (keycode==255) ) 
1445         {                               
1446                 #ifdef NETWORK
1447                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1448                         multi_menu_poll();
1449                 #endif
1450 //              if ( Game_mode & GM_MULTI )
1451 //                      GameLoop( 0, 0 );                               // Continue
1452                 k = key_inkey();
1453                 timer_delay(f0_1/10);
1454                 kc_drawquestion( item );
1455         
1456                 for (i=0; i<256; i++ )  {
1457                         if (keyd_pressed[i] && (strlen(key_text[i])>0)) {
1458                                 f = 0;
1459                                 for (n=0; n<sizeof(system_keys); n++ )
1460                                         if ( system_keys[n] == i )
1461                                                 f=1;
1462                                 if (!f) 
1463                                         keycode=i;
1464                         }
1465                 }
1466         }
1467
1468         if (k!=KEY_ESC) {
1469                 for (i=0; i<Num_items; i++ )    {
1470                         n = item - All_items;
1471                         if ( (i!=n) && (All_items[i].type==BT_KEY) && (All_items[i].value==keycode) )           {
1472                                 All_items[i].value = 255;
1473                                 kc_drawitem( &All_items[i], 0 );
1474                         }
1475                 }
1476                 item->value = keycode;
1477         }
1478         kc_drawitem( item, 1 );
1479
1480         gr_set_fontcolor( BM_XRGB(28,28,28), BM_XRGB(0,0,0) );
1481
1482         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1483
1484         game_flush_inputs();
1485
1486 }
1487
1488 void kc_change_joybutton( kc_item * item )
1489 {
1490         int n,i,k;
1491         ubyte code;
1492
1493         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1494         
1495         gr_string( 0x8000, LHY(INFO_Y), TXT_PRESS_NEW_JBUTTON );
1496
1497         game_flush_inputs();
1498         code=255;
1499         k=255;
1500         
1501         while( (k!=KEY_ESC) && (code==255))     
1502         {                               
1503                 #ifdef NETWORK
1504                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1505                         multi_menu_poll();
1506                 #endif
1507 //              if ( Game_mode & GM_MULTI )
1508 //                      GameLoop( 0, 0 );                               // Continue
1509                 k = key_inkey();
1510                 timer_delay(f0_1/10);
1511
1512                 if (k == KEY_PRINT_SCREEN)
1513                         save_screen_shot(0);
1514
1515                 kc_drawquestion( item );
1516
1517                 WIN(code = joydefsw_do_button());
1518                 
1519 #ifdef MACINTOSH
1520                 code = joy_do_buttons();
1521 #endif
1522                 
1523 #if !defined(WINDOWS) && !defined(MACINTOSH)
1524                 if (Config_control_type==CONTROL_THRUSTMASTER_FCS)      {
1525                         int axis[4];
1526                         joystick_read_raw_axis( JOY_ALL_AXIS, axis );
1527                         kconfig_read_fcs( axis[3] );
1528                         if ( joy_get_button_state(7) ) code = 7;
1529                         if ( joy_get_button_state(11) ) code = 11;
1530                         if ( joy_get_button_state(15) ) code = 15;
1531                         if ( joy_get_button_state(19) ) code = 19;
1532                         for (i=0; i<4; i++ )    {
1533                                 if ( joy_get_button_state(i) )
1534                                         code = i;
1535                         }
1536                 } else if (Config_control_type==CONTROL_FLIGHTSTICK_PRO) {
1537                         for (i=4; i<20; i++ )   {
1538                                 if ( joy_get_button_state(i)  ) {
1539                                         code = i;
1540                                         mprintf(( 0, "JB: %d\n", code ));
1541                                 }
1542                         }
1543                 } else {
1544                         for (i = 0; i < JOY_MAX_BUTTONS; i++)
1545                         {
1546                                 if ( joy_get_button_state(i) )
1547                                         code = i;
1548                         }
1549                 }
1550 #endif
1551         }
1552         if (code!=255)  {
1553                 for (i=0; i<Num_items; i++ )    {
1554                         n = item - All_items;
1555                         if ( (i!=n) && (All_items[i].type==BT_JOY_BUTTON) && (All_items[i].value==code) ) {
1556                                 All_items[i].value = 255;
1557                                 kc_drawitem( &All_items[i], 0 );
1558                         }
1559                 }
1560                 item->value = code;
1561         }
1562         kc_drawitem( item, 1 );
1563         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1564         game_flush_inputs();
1565 }
1566
1567 void kc_change_mousebutton( kc_item * item )
1568 {
1569         int n,i,b,k;
1570         ubyte code;
1571
1572         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1573         
1574         gr_string( 0x8000, LHY(INFO_Y), TXT_PRESS_NEW_MBUTTON );
1575
1576         game_flush_inputs();
1577         code=255;
1578         k=255;
1579         
1580         while( (k!=KEY_ESC) && (code==255))     
1581         {                               
1582                 #ifdef NETWORK
1583                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1584                         multi_menu_poll();
1585                 #endif
1586 //              if ( Game_mode & GM_MULTI )
1587 //                      GameLoop( 0, 0 );                               // Continue
1588                 k = key_inkey();
1589                 timer_delay(f0_1/10);
1590
1591                 if (k == KEY_PRINT_SCREEN)
1592                         save_screen_shot(0);
1593
1594                 kc_drawquestion( item );
1595
1596                 b = mouse_get_btns();
1597                 for (i = 0; i < 16; i++ ) {
1598                         if ( b & (1<<i) )       
1599                                 code = i;
1600                 }
1601         }
1602         if (code!=255)  {
1603                 for (i=0; i<Num_items; i++ )    {
1604                         n = item - All_items;
1605                         if ( (i!=n) && (All_items[i].type==BT_MOUSE_BUTTON) && (All_items[i].value==code) )             {
1606                                 All_items[i].value = 255;
1607                                 kc_drawitem( &All_items[i], 0 );
1608                         }
1609                 }
1610                 item->value = code;
1611         }
1612         kc_drawitem( item, 1 );
1613         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1614         game_flush_inputs();
1615
1616 }
1617
1618
1619 // the following function added by WraithX on 11/22/00 to work around the weird joystick bug... - modified my Matt Mueller to skip already allocated axes
1620 void kc_next_joyaxis(kc_item *item)
1621 {
1622         int n, i, k, max, tries;
1623         ubyte code = 0;
1624
1625         k = 255;
1626         n = 0;
1627         i = 0;
1628
1629         // I modelled this ifdef after the code in the kc_change_joyaxis method.
1630         // So, if somethin's not workin here, it might not be workin there either.
1631         max = JOY_MAX_AXES;
1632         tries = 1;
1633         code = (item->value + 1) % max;
1634
1635         if (code != 255)
1636         {
1637                 for (i = 0; i < Num_items; i++)
1638                 {
1639                         n = item - All_items;
1640                         if ((i != n) && (All_items[i].type == BT_JOY_AXIS) && (All_items[i].value == code))
1641                         {
1642                                 if (tries > max)
1643                                         return; // all axes allocated already
1644                                 i = -1; // -1 so the i++ will push back to 0
1645                                 code = (item->value + ++tries) % max; // try next axis
1646                         }//end if
1647                 }//end for
1648
1649                 item->value = code;
1650         }//end if
1651
1652         kc_drawitem(item, 1);
1653         nm_restore_background(0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h);
1654         game_flush_inputs();
1655
1656 }//method kc_next_joyaxis
1657 //end addition by WraithX
1658
1659
1660 void kc_change_joyaxis( kc_item * item )
1661 {
1662         int axis[JOY_MAX_AXES];
1663         int old_axis[JOY_MAX_AXES];
1664         int numaxis = joy_num_axes;
1665         int n,i,k;
1666         ubyte code;
1667
1668         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1669         
1670         gr_string( 0x8000, LHY(INFO_Y), TXT_MOVE_NEW_JOY_AXIS );
1671
1672         game_flush_inputs();
1673         code=255;
1674         k=255;
1675
1676         WINDOS(
1677                 joystick_read_raw_axis( JOY_ALL_AXIS+JOY_EXT_AXIS, old_axis ),
1678                 joystick_read_raw_axis( JOY_ALL_AXIS, old_axis )
1679         );
1680
1681         while( (k!=KEY_ESC) && (code==255))     
1682         {                               
1683                 #ifdef NETWORK
1684                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1685                         multi_menu_poll();
1686                 #endif
1687 //              if ( Game_mode & GM_MULTI )
1688 //                      GameLoop( 0, 0 );                               // Continue
1689                 k = key_inkey();
1690                 timer_delay(f0_1/10);
1691
1692                 if (k == KEY_PRINT_SCREEN)
1693                         save_screen_shot(0);
1694
1695                 kc_drawquestion( item );
1696
1697                 WINDOS(
1698                         joystick_read_raw_axis( JOY_ALL_AXIS+JOY_EXT_AXIS, axis ),
1699                         joystick_read_raw_axis( JOY_ALL_AXIS, axis )
1700                 );
1701                 
1702                 for (i=0; i<numaxis; i++ )      {
1703 #if defined (MACINTOSH)
1704                         if ( abs(axis[i]-old_axis[i])>100 )
1705 #elif defined(WINDOWS)
1706                         if ( abs(axis[i]-old_axis[i])>1024 )
1707 #else
1708                         if ( abs(axis[i]-old_axis[i])>200 )
1709 #endif
1710                         {
1711                                 code = i;
1712                                 con_printf(CON_DEBUG, "Axis Movement detected: Axis %i\n", i);
1713                         }
1714                         //old_axis[i] = axis[i];
1715                 }
1716                 for (i=0; i<Num_items; i++ )    
1717                  {
1718                         n = item - All_items;
1719                         if ( (i!=n) && (All_items[i].type==BT_JOY_AXIS) && (All_items[i].value==code) ) 
1720                                 code = 255;
1721                  }
1722         
1723         }
1724         if (code!=255)  {
1725                 for (i=0; i<Num_items; i++ )    {
1726                         n = item - All_items;
1727                         if ( (i!=n) && (All_items[i].type==BT_JOY_AXIS) && (All_items[i].value==code) ) {
1728                                 All_items[i].value = 255;
1729                                 kc_drawitem( &All_items[i], 0 );
1730                         }
1731                 }
1732
1733                 item->value = code;                                      
1734         }
1735         kc_drawitem( item, 1 );
1736         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1737         game_flush_inputs();
1738
1739 }
1740
1741 void kc_change_mouseaxis( kc_item * item )
1742 {
1743         int i,n,k;
1744         ubyte code;
1745         int dx,dy;
1746 #ifdef SDL_INPUT
1747         int dz;
1748 #endif
1749
1750         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1751         
1752         gr_string( 0x8000, LHY(INFO_Y), TXT_MOVE_NEW_MSE_AXIS );
1753
1754         game_flush_inputs();
1755         code=255;
1756         k=255;
1757
1758         mouse_get_delta( &dx, &dy );
1759
1760         while( (k!=KEY_ESC) && (code==255))     
1761         {                               
1762                 #ifdef NETWORK
1763                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1764                         multi_menu_poll();
1765                 #endif
1766 //              if ( Game_mode & GM_MULTI )
1767 //                      GameLoop( 0, 0 );                               // Continue
1768                 k = key_inkey();
1769                 timer_delay(f0_1/10);
1770
1771                 if (k == KEY_PRINT_SCREEN)
1772                         save_screen_shot(0);
1773
1774                 kc_drawquestion( item );
1775
1776 #ifdef SDL_INPUT
1777                 mouse_get_delta_z( &dx, &dy, &dz );
1778 #else
1779                 mouse_get_delta( &dx, &dy );
1780 #endif
1781                 if ( abs(dx)>20 ) code = 0;
1782                 if ( abs(dy)>20 ) code = 1;
1783 #ifdef SDL_INPUT
1784                 if ( abs(dz)>20 ) code = 2;
1785 #endif
1786         }
1787         if (code!=255)  {
1788                 for (i=0; i<Num_items; i++ )    {
1789                         n = item - All_items;
1790                         if ( (i!=n) && (All_items[i].type==BT_MOUSE_AXIS) && (All_items[i].value==code) )               {
1791                                 All_items[i].value = 255;
1792                                 kc_drawitem( &All_items[i], 0 );
1793                         }
1794                 }
1795                 item->value = code;
1796         }
1797         kc_drawitem( item, 1 );
1798         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1799         game_flush_inputs();
1800
1801 }
1802
1803
1804 void kc_change_invert( kc_item * item )
1805 {
1806         game_flush_inputs();
1807
1808         if (item->value)
1809                 item->value = 0;
1810         else 
1811                 item->value = 1;
1812
1813         kc_drawitem( item, 1 );
1814
1815 }
1816
1817 #include "screens.h"
1818
1819 void kconfig(int n, char * title)
1820 {
1821         int i;
1822         grs_bitmap *save_bm;
1823
1824         set_screen_mode( SCREEN_MENU );
1825
1826         kc_set_controls();
1827
1828         //save screen
1829         save_bm = gr_create_bitmap( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h );
1830         Assert( save_bm != NULL );
1831         
1832         gr_bm_bitblt(grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_w, 
1833                                         0, 0, 0, 0, &grd_curcanv->cv_bitmap, save_bm );
1834
1835         switch(n)       {
1836         case 0:kconfig_sub( kc_keyboard, NUM_KEY_CONTROLS, title );break;
1837         case 1:kconfig_sub( kc_joystick, NUM_OTHER_CONTROLS, title );break;
1838         case 2:kconfig_sub( kc_mouse, NUM_OTHER_CONTROLS, title ); break;
1839         case 3:kconfig_sub( kc_superjoy, NUM_OTHER_CONTROLS, title); break;
1840 #ifdef D2X_KEYS
1841         //added on 2/4/99 by Victor Rachels for new keys menu
1842         case 4:kconfig_sub( kc_d2x, NUM_D2X_CONTROLS, title ); break;
1843         //end this section addition - VR
1844 #endif
1845         default:
1846                 Int3();
1847                 return;
1848         }
1849
1850         //restore screen
1851         gr_bitmap(0, 0, save_bm);
1852         gr_free_bitmap(save_bm);
1853
1854 #if 0 // set_screen_mode always calls this later... right?
1855         reset_cockpit();                //force cockpit redraw next time
1856 #endif
1857
1858         // Update save values...
1859         
1860         for (i=0; i<NUM_KEY_CONTROLS; i++ )     
1861                 kconfig_settings[0][i] = kc_keyboard[i].value;
1862
1863         if ( (Config_control_type>0) && (Config_control_type<5)) { 
1864                 for (i=0; i<NUM_OTHER_CONTROLS; i++ )   
1865                         kconfig_settings[Config_control_type][i] = kc_joystick[i].value;
1866         } else if (Config_control_type>4 && Config_control_type<CONTROL_WINJOYSTICK) {
1867                 for (i=0; i<NUM_OTHER_CONTROLS; i++ )   
1868                         kconfig_settings[Config_control_type][i] = kc_mouse[i].value;
1869         }
1870         else if (Config_control_type == CONTROL_WINJOYSTICK) {
1871                 for (i=0; i<NUM_OTHER_CONTROLS; i++ )   
1872                         kconfig_settings[Config_control_type][i] = kc_superjoy[i].value;
1873         }
1874
1875 #ifdef D2X_KEYS
1876         for (i=0; i<NUM_D2X_CONTROLS; i++)
1877                 kconfig_d2x_settings[i] = kc_d2x[i].value;
1878 #endif
1879 }
1880
1881
1882 void kconfig_read_fcs( int raw_axis )
1883 {
1884         int raw_button, button, axis_min[4], axis_center[4], axis_max[4];
1885
1886         if (Config_control_type!=CONTROL_THRUSTMASTER_FCS) return;
1887
1888         joy_get_cal_vals(axis_min, axis_center, axis_max);
1889
1890         if ( axis_max[3] > 1 )
1891                 raw_button = (raw_axis*100)/axis_max[3];
1892         else
1893                 raw_button = 0;
1894
1895         if ( raw_button > 88 )
1896                 button = 0;
1897         else if ( raw_button > 63 )
1898                 button = 7;
1899         else if ( raw_button > 39 )
1900                 button = 11;
1901         else if ( raw_button > 15 )
1902                 button = 15;
1903         else    
1904                 button = 19;
1905
1906         kconfig_set_fcs_button( 19, button );
1907         kconfig_set_fcs_button( 15, button );
1908         kconfig_set_fcs_button( 11, button );
1909         kconfig_set_fcs_button( 7, button );
1910 }
1911                 
1912
1913 void kconfig_set_fcs_button( int btn, int button )
1914 {
1915         int state,time_down,upcount,downcount;
1916         state = time_down = upcount = downcount = 0;
1917
1918         if ( joy_get_button_state(btn) ) {
1919                 if ( btn==button )      {
1920                         state = 1;
1921                         time_down = FrameTime;
1922                 } else {
1923                         upcount=1;
1924                 }
1925         } else {
1926                 if ( btn==button )      {
1927                         state = 1;
1928                         time_down = FrameTime;
1929                         downcount=1;
1930                 } else {
1931                         upcount=1;
1932                 }
1933         }                               
1934                         
1935         joy_set_btn_values( btn, state, time_down, downcount, upcount );
1936                                         
1937 }
1938
1939
1940
1941 fix Last_angles_p = 0;
1942 fix Last_angles_b = 0;
1943 fix Last_angles_h = 0;
1944 ubyte Last_angles_read = 0;
1945
1946 extern int                      VR_sensitivity;
1947                                                 
1948 int VR_sense_range[3] = { 25, 50, 75 };
1949
1950 #if 0 //ndef MACINTOSH
1951 read_head_tracker()
1952 {
1953 #ifndef WINDOWS
1954
1955         fix yaw, pitch, roll;
1956         int buttons;
1957
1958 //------ read vfx1 helmet --------
1959         if (vfx1_installed) {
1960                 vfx_get_data(&yaw,&pitch,&roll,&buttons);
1961         } else if (iglasses_headset_installed)  {
1962                 iglasses_read_headset( &yaw, &pitch, &roll );
1963         } else if (Victor_headset_installed)   {
1964                 victor_read_headset_filtered( &yaw, &pitch, &roll );
1965         } else {
1966                 return;
1967         }
1968
1969         Use_player_head_angles = 0;
1970         if ( Last_angles_read ) {
1971                 fix yaw1 = yaw;
1972                 
1973                 yaw1 = yaw;
1974                 if ( (Last_angles_h < (F1_0/4) ) && (yaw > ((F1_0*3)/4) ) )     
1975                         yaw1 -= F1_0;
1976                 else if ( (yaw < (F1_0/4) ) && (Last_angles_h > ((F1_0*3)/4) ) )        
1977                         yaw1 += F1_0;
1978         
1979                 Controls.pitch_time     += fixmul((pitch- Last_angles_p)*VR_sense_range[VR_sensitivity],FrameTime);
1980                 Controls.heading_time+= fixmul((yaw1 -  Last_angles_h)*VR_sense_range[VR_sensitivity],FrameTime);
1981                 Controls.bank_time      += fixmul((roll - Last_angles_b)*VR_sense_range[VR_sensitivity],FrameTime);
1982         }
1983         Last_angles_read = 1;
1984         Last_angles_p = pitch;
1985         Last_angles_h = yaw;
1986         Last_angles_b = roll;
1987 #endif
1988 }
1989 #endif
1990
1991 #define PH_SCALE        8
1992
1993 #ifndef __MSDOS__ // WINDOWS
1994 #define JOYSTICK_READ_TIME      (F1_0/40)               //      Read joystick at 40 Hz.
1995 #else
1996 #define JOYSTICK_READ_TIME      (F1_0/10)               //      Read joystick at 10 Hz.
1997 #endif
1998
1999 fix     LastReadTime = 0;
2000
2001 fix     joy_axis[JOY_MAX_AXES];
2002
2003 ubyte                   kc_use_external_control = 0;
2004 ubyte                   kc_enable_external_control = 0;
2005 ubyte                   kc_external_intno = 0;
2006 ext_control_info        *kc_external_control = NULL;
2007 char                    *kc_external_name = NULL;
2008 ubyte                   kc_external_version = 0;
2009 extern int Automap_active;
2010
2011 void kconfig_init_external_controls(int intno, int address)
2012 {
2013         int i;
2014         kc_external_intno = intno;
2015         kc_external_control     = (ext_control_info *)address;
2016         kc_use_external_control = 1;
2017         kc_enable_external_control  = 1;
2018
2019         i = FindArg ( "-xname" );
2020         if ( i )        
2021                 kc_external_name = Args[i+1];
2022         else
2023                 kc_external_name = "External Controller";
2024
2025    for (i=0;i<strlen (kc_external_name);i++)
2026     if (kc_external_name[i]=='_')
2027           kc_external_name[i]=' '; 
2028
2029         i = FindArg ( "-xver" );
2030         if ( i )
2031                 kc_external_version = atoi(Args[i+1]);
2032         
2033         printf( "%s int: 0x%x, data: 0x%p, ver:%d\n", kc_external_name, kc_external_intno, kc_external_control, kc_external_version );
2034
2035 }
2036
2037 #if !defined(MACINTOSH)
2038 /*void kconfig_read_external_controls()
2039 {
2040         union REGS r;
2041
2042         if ( !kc_enable_external_control && !CybermouseActive) 
2043                 return;
2044
2045         if ( kc_external_version == 0 ) 
2046                 memset( kc_external_control, 0, sizeof(control_info) );
2047         else if ( kc_external_version > 0 )     {
2048                 memset( kc_external_control, 0, sizeof(control_info)+sizeof(vms_angvec) + 64 );
2049                 if ( kc_external_version > 1 ) {
2050                         // Write ship pos and angles to external controls...
2051                         ubyte *temp_ptr = (ubyte *)kc_external_control;
2052                         vms_vector *ship_pos;
2053                         vms_matrix *ship_orient;
2054                         memset( kc_external_control, 0, sizeof(control_info)+sizeof(vms_angvec) + 64 + sizeof(vms_vector)+sizeof(vms_matrix) );
2055                         temp_ptr += sizeof(control_info)+sizeof(vms_angvec) + 64;
2056                         ship_pos = (vms_vector *)temp_ptr;
2057                         temp_ptr += sizeof(vms_vector);
2058                         ship_orient = (vms_matrix *)temp_ptr;
2059                         // Fill in ship postion...
2060                         *ship_pos = Objects[Players[Player_num].objnum].pos;
2061                         // Fill in ship orientation...
2062                         *ship_orient = Objects[Players[Player_num].objnum].orient;
2063                 }
2064         }
2065
2066         if ( Automap_active )                    // (If in automap...)
2067                 kc_external_control->automap_state = 1;
2068         memset(&r,0,sizeof(r));
2069
2070 #ifndef WINDOWS
2071   
2072    if (!CybermouseActive)
2073         int386 ( kc_external_intno, &r, &r);            // Read external info...
2074 //      else
2075   //            ReadOWL (kc_external_control);
2076
2077 #endif
2078
2079         if ( Player_num > -1 )  {
2080                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_TURNROLL);    // Turn off roll when turning
2081                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_LEVELLING);   // Turn off leveling to nearest side.
2082                 Auto_leveling_on = 0;
2083
2084                 if ( kc_external_version > 0 ) {                
2085                         vms_matrix tempm, ViewMatrix;
2086                         vms_angvec * Kconfig_abs_movement;
2087                         char * oem_message;
2088         
2089                         Kconfig_abs_movement = (vms_angvec *)((uint)kc_external_control + sizeof(control_info));
2090         
2091                         if ( Kconfig_abs_movement->p || Kconfig_abs_movement->b || Kconfig_abs_movement->h )    {
2092                                 vm_angles_2_matrix(&tempm,Kconfig_abs_movement);
2093                                 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
2094                                 Objects[Players[Player_num].objnum].orient = ViewMatrix;                
2095                         }
2096                         oem_message = (char *)((uint)Kconfig_abs_movement + sizeof(vms_angvec));
2097                         if (oem_message[0] != '\0' )
2098                                 HUD_init_message( oem_message );
2099                 }
2100         }
2101
2102         Controls.pitch_time += fixmul(kc_external_control->pitch_time,FrameTime);                                               
2103         Controls.vertical_thrust_time += fixmul(kc_external_control->vertical_thrust_time,FrameTime);
2104         Controls.heading_time += fixmul(kc_external_control->heading_time,FrameTime);
2105         Controls.sideways_thrust_time += fixmul(kc_external_control->sideways_thrust_time ,FrameTime);
2106         Controls.bank_time += fixmul(kc_external_control->bank_time ,FrameTime);
2107         Controls.forward_thrust_time += fixmul(kc_external_control->forward_thrust_time ,FrameTime);
2108         Controls.rear_view_down_count += kc_external_control->rear_view_down_count;     
2109         Controls.rear_view_down_state |= kc_external_control->rear_view_down_state;     
2110         Controls.fire_primary_down_count += kc_external_control->fire_primary_down_count;
2111         Controls.fire_primary_state |= kc_external_control->fire_primary_state;
2112         Controls.fire_secondary_state |= kc_external_control->fire_secondary_state;
2113         Controls.fire_secondary_down_count += kc_external_control->fire_secondary_down_count;
2114         Controls.fire_flare_down_count += kc_external_control->fire_flare_down_count;
2115         Controls.drop_bomb_down_count += kc_external_control->drop_bomb_down_count;     
2116         Controls.automap_down_count += kc_external_control->automap_down_count;
2117         Controls.automap_state |= kc_external_control->automap_state;
2118 } */
2119 #endif
2120
2121 #ifdef WINDOWS
2122 void controls_read_all_win()
2123 {
2124         int i;
2125         int slide_on, bank_on;
2126         int dx, dy;
2127         fix ctime;
2128         fix mouse_axis[2];
2129         int raw_joy_axis[7];
2130         int mouse_buttons;
2131         fix k0, k1, k2, k3, kp;
2132         fix k4, k5, k6, k7, kh;
2133         ubyte channel_masks;
2134         int use_mouse, use_joystick;
2135         int speed_factor=1;
2136
2137         if (Game_turbo_mode)
2138                 speed_factor = 2;
2139         
2140         {
2141                 fix temp = Controls.heading_time;
2142                 fix temp1 = Controls.pitch_time;
2143                 memset( &Controls, 0, sizeof(control_info) );
2144                 Controls.heading_time = temp;
2145                 Controls.pitch_time = temp1;
2146         }
2147         slide_on = 0;
2148         bank_on = 0;
2149
2150         ctime = timer_get_fixed_seconds();
2151
2152 //      DO JOYSTICK (X,Y,Z  R,U,V)
2153 //      ----------------------------------------------------------------------------
2154         if ( (LastReadTime + JOYSTICK_READ_TIME) > ctime ) {
2155                 if ((ctime < 0) && (LastReadTime > 0))
2156                         LastReadTime = ctime;
2157                 use_joystick=1;
2158         } else if ((Config_control_type==CONTROL_WINJOYSTICK)) {
2159                 LastReadTime = ctime;
2160                 channel_masks = joystick_read_raw_axis( JOY_ALL_AXIS+JOY_EXT_AXIS, raw_joy_axis );
2161
2162                 for (i=0; i<7; i++ )    {
2163                         if (channel_masks&(1<<i))       {
2164                                 int joy_null_value = 28;
2165
2166                         // DO POV if joystick has a hat.
2167                         //      --------------------------------------------------------------------
2168                                 if (i == 3) {
2169                                         joydefsw_do_winjoybutton(raw_joy_axis);
2170                                 }
2171                                 else {
2172                                 // DO AXIS
2173                                 //      --------------------------------------------------------------------    
2174                                 //      mprintf((0, "(%d)=%d,", i, raw_joy_axis[i]));
2175                                         raw_joy_axis[i] = joy_get_scaled_reading( raw_joy_axis[i], i );
2176                                 //      mprintf((0, "%d  ",raw_joy_axis[i]));
2177                                 //      if (i%2) mprintf((0,"\n"));
2178
2179         
2180                                         if (kc_superjoy[23].value==i)           // If this is the throttle
2181                                                 joy_null_value = 32;                            // Then use a larger dead-zone
2182         
2183                                         if (raw_joy_axis[i] > (joy_null_value-2)) 
2184                                                 raw_joy_axis[i] = ((raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value);
2185                                         else if (raw_joy_axis[i] < -(joy_null_value+2))
2186                                                 raw_joy_axis[i] = ((raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value);
2187                                         else
2188                                                 raw_joy_axis[i] = 0;
2189                                         joy_axis[i]     = (raw_joy_axis[i]*FrameTime)/128;      
2190                                 }
2191                         } else {
2192                                 joy_axis[i] = 0;
2193                         }
2194                 }       
2195                 use_joystick=1;
2196
2197         } else {
2198                 for (i=0; i<6; i++ )
2199                         joy_axis[i] = 0;
2200                 use_joystick=0;
2201         }
2202
2203 //      DO MOUSE 
2204 //      ----------------------------------------------------------------------------
2205         if (Config_control_type==5) {
2206                 mouse_get_delta( &dx, &dy );
2207                 mouse_axis[0] = (dx*FrameTime)/35;
2208                 mouse_axis[1] = (dy*FrameTime)/25;
2209                 mouse_buttons = mouse_get_btns();
2210                 //mprintf(( 0, "Mouse %d,%d b:%d, 0x%x\n", mouse_axis[0], mouse_axis[1], mouse_buttons, FrameTime ));
2211                 use_mouse=1;
2212    } else {
2213                 mouse_axis[0] = 0;
2214                 mouse_axis[1] = 0;
2215                 mouse_buttons = 0;
2216                 use_mouse=0;
2217         }
2218
2219 //------------- Read slide_on -------------
2220         
2221         // From keyboard...
2222         if ( kc_keyboard[8].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[8].value ];
2223         if ( kc_keyboard[9].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[9].value ];
2224         // From joystick...
2225         if ((use_joystick)&&(kc_superjoy[5].value<255)) slide_on |= joy_get_button_state( kc_superjoy[5].value );
2226         // From mouse...
2227         if ((use_mouse)&&(kc_mouse[5].value<255)) slide_on |= mouse_buttons & (1<<kc_mouse[5].value);
2228
2229 //------------- Read bank_on ---------------
2230
2231         // From keyboard...
2232         if ( kc_keyboard[18].value < 255 ) bank_on |= keyd_pressed[ kc_keyboard[18].value ];
2233         if ( kc_keyboard[19].value < 255 ) bank_on |= keyd_pressed[ kc_keyboard[19].value ];
2234         // From joystick...
2235         if ( (use_joystick)&&(kc_superjoy[10].value < 255 )) bank_on |= joy_get_button_state( kc_superjoy[10].value );
2236         // From mouse...
2237         if ( (use_mouse)&&(kc_mouse[10].value < 255 )) bank_on |= mouse_buttons & (1<<kc_mouse[10].value);
2238
2239 //------------ Read pitch_time -----------
2240         if ( !slide_on )        {
2241                 // mprintf((0, "pitch: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
2242                 kp = 0;
2243                 k0 = speed_factor*key_down_time( kc_keyboard[0].value )/2;      // Divide by two since we want pitch to go slower
2244                 k1 = speed_factor*key_down_time( kc_keyboard[1].value )/2;
2245                 k2 = speed_factor*key_down_time( kc_keyboard[2].value )/2;
2246                 k3 = speed_factor*key_down_time( kc_keyboard[3].value )/2;
2247
2248                 // From keyboard...
2249                 if ( kc_keyboard[0].value < 255 ) kp += k0/PH_SCALE;
2250                 if ( kc_keyboard[1].value < 255 ) kp += k1/PH_SCALE;
2251                 if ( kc_keyboard[2].value < 255 ) kp -= k2/PH_SCALE;
2252                 if ( kc_keyboard[3].value < 255 ) kp -= k3/PH_SCALE;
2253
2254                 // From Cyberman...
2255                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2256                         kp += mouse_button_down_time(MB_PITCH_FORWARD)/(PH_SCALE*2);
2257                         kp -= mouse_button_down_time(MB_PITCH_BACKWARD)/(PH_SCALE*2);
2258                 }
2259         
2260                 if (kp == 0)
2261                         Controls.pitch_time = 0;
2262                 else if (kp > 0) {
2263                         if (Controls.pitch_time < 0)
2264                                 Controls.pitch_time = 0;
2265                 } else // kp < 0
2266                         if (Controls.pitch_time > 0)
2267                                 Controls.pitch_time = 0;
2268                 Controls.pitch_time += kp;
2269         
2270                 // From joystick...
2271                 if ( (use_joystick)&&(kc_superjoy[13].value < 255 ))    {
2272                         if ( !kc_superjoy[14].value )           // If not inverted...
2273                                 Controls.pitch_time -= (joy_axis[kc_superjoy[13].value]*Config_joystick_sensitivity)/8;
2274                         else
2275                                 Controls.pitch_time += (joy_axis[kc_superjoy[13].value]*Config_joystick_sensitivity)/8;
2276                 }
2277         
2278                 // From mouse...
2279                 //mprintf(( 0, "UM: %d, PV: %d\n", use_mouse, kc_mouse[13].value ));
2280                 if ( (use_mouse)&&(kc_mouse[13].value < 255) )  {
2281                         if ( !kc_mouse[14].value )              // If not inverted...
2282                                 Controls.pitch_time -= (mouse_axis[kc_mouse[13].value]*Config_joystick_sensitivity)/8;
2283                         else
2284                                 Controls.pitch_time += (mouse_axis[kc_mouse[13].value]*Config_joystick_sensitivity)/8;
2285                 }
2286         } else {
2287                 Controls.pitch_time = 0;
2288         }
2289
2290
2291 //----------- Read vertical_thrust_time -----------------
2292
2293         if ( slide_on ) {
2294                 k0 = speed_factor*key_down_time( kc_keyboard[0].value );
2295                 k1 = speed_factor*key_down_time( kc_keyboard[1].value );
2296                 k2 = speed_factor*key_down_time( kc_keyboard[2].value );
2297                 k3 = speed_factor*key_down_time( kc_keyboard[3].value );
2298
2299                 // From keyboard...
2300                 if ( kc_keyboard[0].value < 255 ) Controls.vertical_thrust_time += k0;
2301                 if ( kc_keyboard[1].value < 255 ) Controls.vertical_thrust_time += k1;
2302                 if ( kc_keyboard[2].value < 255 ) Controls.vertical_thrust_time -= k2;
2303                 if ( kc_keyboard[3].value < 255 ) Controls.vertical_thrust_time -= k3;
2304
2305                 // From Cyberman...
2306                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2307                         Controls.vertical_thrust_time -= mouse_button_down_time(MB_PITCH_FORWARD);
2308                         Controls.vertical_thrust_time += mouse_button_down_time(MB_PITCH_BACKWARD);
2309                 }
2310         
2311                 // From joystick...
2312                 if ((use_joystick)&&( kc_superjoy[13].value < 255 ))    {
2313                         if ( !kc_superjoy[14].value )           // If not inverted...
2314                                 Controls.vertical_thrust_time += joy_axis[kc_superjoy[13].value];
2315                         else
2316                                 Controls.vertical_thrust_time -= joy_axis[kc_superjoy[13].value];
2317                 }
2318         
2319                 // From mouse...
2320                 if ( (use_mouse)&&(kc_mouse[13].value < 255 ))  {
2321                         if ( !kc_mouse[14].value )              // If not inverted...
2322                                 Controls.vertical_thrust_time -= mouse_axis[kc_mouse[13].value];
2323                         else
2324                                 Controls.vertical_thrust_time += mouse_axis[kc_mouse[13].value];
2325                 }
2326         }
2327
2328         // From keyboard...
2329         if ( kc_keyboard[14].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[14].value );
2330         if ( kc_keyboard[15].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[15].value );
2331         if ( kc_keyboard[16].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[16].value );
2332         if ( kc_keyboard[17].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[17].value );
2333         
2334         // From joystick...
2335         if ((use_joystick)&&( kc_superjoy[19].value < 255 ))    {
2336                 if ( !kc_superjoy[20].value )           // If not inverted...
2337                         Controls.vertical_thrust_time += joy_axis[kc_superjoy[19].value];
2338                 else
2339                         Controls.vertical_thrust_time -= joy_axis[kc_superjoy[19].value];
2340         }
2341
2342         // From joystick buttons
2343         if ( (use_joystick)&&(kc_superjoy[8].value < 255 )) Controls.vertical_thrust_time += joy_get_button_down_time( kc_superjoy[8].value );
2344         if ( (use_joystick)&&(kc_superjoy[9].value < 255 )) Controls.vertical_thrust_time -= joy_get_button_down_time( kc_superjoy[9].value );
2345
2346         // From mouse buttons
2347         if ( (use_mouse)&&(kc_mouse[8].value < 255 )) Controls.vertical_thrust_time += mouse_button_down_time( kc_mouse[8].value );
2348         if ( (use_mouse)&&(kc_mouse[9].value < 255 )) Controls.vertical_thrust_time -= mouse_button_down_time( kc_mouse[9].value );
2349
2350         // From mouse...
2351         if ( (use_mouse)&&(kc_mouse[19].value < 255 ))  {
2352                 if ( !kc_mouse[20].value )              // If not inverted...
2353                         Controls.vertical_thrust_time += mouse_axis[kc_mouse[19].value];
2354                 else
2355                         Controls.vertical_thrust_time -= mouse_axis[kc_mouse[19].value];
2356         }
2357
2358         // From Cyberman...
2359         if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2360                 Controls.vertical_thrust_time += mouse_button_down_time(MB_Z_UP)/2;
2361                 Controls.vertical_thrust_time -= mouse_button_down_time(MB_Z_DOWN)/2;
2362         }
2363
2364 //---------- Read heading_time -----------
2365
2366         if (!slide_on && !bank_on)      {
2367                 //mprintf((0, "heading: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
2368                 kh = 0;
2369                 k4 = speed_factor*key_down_time( kc_keyboard[4].value );
2370                 k5 = speed_factor*key_down_time( kc_keyboard[5].value );
2371                 k6 = speed_factor*key_down_time( kc_keyboard[6].value );
2372                 k7 = speed_factor*key_down_time( kc_keyboard[7].value );
2373
2374                 // From keyboard...
2375                 if ( kc_keyboard[4].value < 255 ) kh -= k4/PH_SCALE;
2376                 if ( kc_keyboard[5].value < 255 ) kh -= k5/PH_SCALE;
2377                 if ( kc_keyboard[6].value < 255 ) kh += k6/PH_SCALE;
2378                 if ( kc_keyboard[7].value < 255 ) kh += k7/PH_SCALE;
2379
2380                 // From Cyberman...
2381                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2382                         kh -= mouse_button_down_time(MB_HEAD_LEFT)/PH_SCALE;
2383                         kh += mouse_button_down_time(MB_HEAD_RIGHT)/PH_SCALE;
2384                 }
2385         
2386                 if (kh == 0)
2387                         Controls.heading_time = 0;
2388                 else if (kh > 0) {
2389                         if (Controls.heading_time < 0)
2390                                 Controls.heading_time = 0;
2391                 } else // kh < 0
2392                         if (Controls.heading_time > 0)
2393                                 Controls.heading_time = 0;
2394                 Controls.heading_time += kh;
2395
2396                 // From joystick...
2397                 if ( (use_joystick)&&(kc_superjoy[15].value < 255 ))    {
2398                         if ( !kc_superjoy[16].value )           // If not inverted...
2399                                 Controls.heading_time += (joy_axis[kc_superjoy[15].value]*Config_joystick_sensitivity)/8;
2400                         else
2401                                 Controls.heading_time -= (joy_axis[kc_superjoy[15].value]*Config_joystick_sensitivity)/8;
2402                 }
2403         
2404                 // From mouse...
2405                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
2406                         if ( !kc_mouse[16].value )              // If not inverted...
2407                                 Controls.heading_time += (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
2408                         else
2409                                 Controls.heading_time -= (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
2410                 }
2411         } else {
2412                 Controls.heading_time = 0;
2413         }
2414
2415 //----------- Read sideways_thrust_time -----------------
2416
2417         if ( slide_on ) {
2418                 k0 = speed_factor*key_down_time( kc_keyboard[4].value );
2419                 k1 = speed_factor*key_down_time( kc_keyboard[5].value );
2420                 k2 = speed_factor*key_down_time( kc_keyboard[6].value );
2421                 k3 = speed_factor*key_down_time( kc_keyboard[7].value );
2422
2423                 // From keyboard...
2424                 if ( kc_keyboard[4].value < 255 ) Controls.sideways_thrust_time -= k0;
2425                 if ( kc_keyboard[5].value < 255 ) Controls.sideways_thrust_time -= k1;
2426                 if ( kc_keyboard[6].value < 255 ) Controls.sideways_thrust_time += k2;
2427                 if ( kc_keyboard[7].value < 255 ) Controls.sideways_thrust_time += k3;
2428         
2429                 // From joystick...
2430                 if ( (use_joystick)&&(kc_superjoy[15].value < 255 ))    {
2431                         if ( !kc_superjoy[16].value )           // If not inverted...
2432                                 Controls.sideways_thrust_time += joy_axis[kc_superjoy[15].value];
2433                         else
2434                                 Controls.sideways_thrust_time -= joy_axis[kc_superjoy[15].value];
2435                 }
2436                 
2437                 // From cyberman
2438                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2439                         Controls.sideways_thrust_time -= mouse_button_down_time(MB_HEAD_LEFT);
2440                         Controls.sideways_thrust_time += mouse_button_down_time(MB_HEAD_RIGHT);
2441                 }
2442         
2443                 // From mouse...
2444                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
2445                         if ( !kc_mouse[16].value )              // If not inverted...
2446                                 Controls.sideways_thrust_time += mouse_axis[kc_mouse[15].value];
2447                         else
2448                                 Controls.sideways_thrust_time -= mouse_axis[kc_mouse[15].value];
2449                 }
2450         }
2451
2452         // From keyboard...
2453         if ( kc_keyboard[10].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[10].value );
2454         if ( kc_keyboard[11].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[11].value );
2455         if ( kc_keyboard[12].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[12].value );
2456         if ( kc_keyboard[13].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[13].value );
2457         
2458         // From joystick...
2459         if ( (use_joystick)&&(kc_superjoy[17].value < 255 ))    {
2460                 if ( !kc_superjoy[18].value )           // If not inverted...
2461                         Controls.sideways_thrust_time -= joy_axis[kc_superjoy[17].value];
2462                 else
2463                         Controls.sideways_thrust_time += joy_axis[kc_superjoy[17].value];
2464         }
2465
2466         // From joystick buttons
2467         if ( (use_joystick)&&(kc_superjoy[6].value < 255 )) Controls.sideways_thrust_time -= joy_get_button_down_time( kc_superjoy[6].value );
2468         if ( (use_joystick)&&(kc_superjoy[7].value < 255 )) Controls.sideways_thrust_time += joy_get_button_down_time( kc_superjoy[7].value );
2469
2470         // From mouse buttons
2471         if ( (use_mouse)&&(kc_mouse[6].value < 255 )) Controls.sideways_thrust_time -= mouse_button_down_time( kc_mouse[6].value );
2472         if ( (use_mouse)&&(kc_mouse[7].value < 255 )) Controls.sideways_thrust_time += mouse_button_down_time( kc_mouse[7].value );
2473
2474         // From mouse...
2475         if ( (use_mouse)&&(kc_mouse[17].value < 255 ))  {
2476                 if ( !kc_mouse[18].value )              // If not inverted...
2477                         Controls.sideways_thrust_time += mouse_axis[kc_mouse[17].value];
2478                 else
2479                         Controls.sideways_thrust_time -= mouse_axis[kc_mouse[17].value];
2480         }
2481
2482 //----------- Read bank_time -----------------
2483
2484         if ( bank_on )  {
2485                 k0 = speed_factor*key_down_time( kc_keyboard[4].value );
2486                 k1 = speed_factor*key_down_time( kc_keyboard[5].value );
2487                 k2 = speed_factor*key_down_time( kc_keyboard[6].value );
2488                 k3 = speed_factor*key_down_time( kc_keyboard[7].value );
2489
2490                 // From keyboard...
2491                 if ( kc_keyboard[4].value < 255 ) Controls.bank_time += k0;
2492                 if ( kc_keyboard[5].value < 255 ) Controls.bank_time += k1;
2493                 if ( kc_keyboard[6].value < 255 ) Controls.bank_time -= k2;
2494                 if ( kc_keyboard[7].value < 255 ) Controls.bank_time -= k3;
2495
2496                 // From Cyberman...
2497                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2498                         Controls.bank_time -= mouse_button_down_time(MB_HEAD_LEFT);
2499                         Controls.bank_time += mouse_button_down_time(MB_HEAD_RIGHT);
2500                 }
2501
2502                 // From joystick...
2503                 if ( (use_joystick)&&(kc_superjoy[15].value < 255) )    {
2504                         if ( !kc_superjoy[16].value )           // If not inverted...
2505                                 Controls.bank_time -= (joy_axis[kc_superjoy[15].value]*Config_joystick_sensitivity)/8;
2506                         else
2507                                 Controls.bank_time += (joy_axis[kc_superjoy[15].value]*Config_joystick_sensitivity)/8;
2508                 }
2509         
2510                 // From mouse...
2511                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
2512                         if ( !kc_mouse[16].value )              // If not inverted...
2513                                 Controls.bank_time += (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
2514                         else
2515                                 Controls.bank_time -= (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
2516                 }
2517         }
2518
2519         // From keyboard...
2520         if ( kc_keyboard[20].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[20].value );
2521         if ( kc_keyboard[21].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[21].value );
2522         if ( kc_keyboard[22].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[22].value );
2523         if ( kc_keyboard[23].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[23].value );
2524
2525         // From joystick...
2526         if ( (use_joystick)&&(kc_superjoy[21].value < 255) )    {
2527                 if ( !kc_superjoy[22].value )           // If not inverted...
2528                         Controls.bank_time -= joy_axis[kc_superjoy[21].value];
2529                 else
2530                         Controls.bank_time += joy_axis[kc_superjoy[21].value];
2531         }
2532
2533         // From joystick buttons
2534         if ( (use_joystick)&&(kc_superjoy[11].value < 255 )) Controls.bank_time += joy_get_button_down_time( kc_superjoy[11].value );
2535         if ( (use_joystick)&&(kc_superjoy[12].value < 255 )) Controls.bank_time -= joy_get_button_down_time( kc_superjoy[12].value );
2536
2537         // From mouse buttons
2538         if ( (use_mouse)&&(kc_mouse[11].value < 255 )) Controls.bank_time += mouse_button_down_time( kc_mouse[11].value );
2539         if ( (use_mouse)&&(kc_mouse[12].value < 255 )) Controls.bank_time -= mouse_button_down_time( kc_mouse[12].value );
2540
2541         // From mouse...
2542         if ( (use_mouse)&&(kc_mouse[21].value < 255 ))  {
2543                 if ( !kc_mouse[22].value )              // If not inverted...
2544                         Controls.bank_time += mouse_axis[kc_mouse[21].value];
2545                 else
2546                         Controls.bank_time -= mouse_axis[kc_mouse[21].value];
2547         }
2548
2549         // From Cyberman
2550         if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2551                 Controls.bank_time += mouse_button_down_time(MB_BANK_LEFT);
2552                 Controls.bank_time -= mouse_button_down_time(MB_BANK_RIGHT);
2553         }
2554
2555 //----------- Read forward_thrust_time -------------
2556
2557         // From keyboard...
2558         if ( kc_keyboard[30].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[30].value );
2559         if ( kc_keyboard[31].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[31].value );
2560         if ( kc_keyboard[32].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[32].value );
2561         if ( kc_keyboard[33].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[33].value );
2562
2563         // From joystick...
2564         if ( (use_joystick)&&(kc_superjoy[23].value < 255 ))    {
2565                 if ( !kc_superjoy[24].value )           // If not inverted...
2566                         Controls.forward_thrust_time -= joy_axis[kc_superjoy[23].value];
2567                 else
2568                         Controls.forward_thrust_time += joy_axis[kc_superjoy[23].value];
2569         }
2570
2571         // From joystick buttons
2572         if ( (use_joystick)&&(kc_superjoy[2].value < 255 )) Controls.forward_thrust_time += joy_get_button_down_time( kc_superjoy[2].value );
2573         if ( (use_joystick)&&(kc_superjoy[3].value < 255 )) Controls.forward_thrust_time -= joy_get_button_down_time( kc_superjoy[3].value );
2574
2575         // From mouse...
2576         if ( (use_mouse)&&(kc_mouse[23].value < 255 ))  {
2577                 if ( !kc_mouse[24].value )              // If not inverted...
2578                         Controls.forward_thrust_time -= mouse_axis[kc_mouse[23].value];
2579                 else
2580                         Controls.forward_thrust_time += mouse_axis[kc_mouse[23].value];
2581         }
2582
2583         // From mouse buttons
2584         if ( (use_mouse)&&(kc_mouse[2].value < 255 )) Controls.forward_thrust_time += mouse_button_down_time( kc_mouse[2].value );
2585         if ( (use_mouse)&&(kc_mouse[3].value < 255 )) Controls.forward_thrust_time -= mouse_button_down_time( kc_mouse[3].value );
2586
2587 //----------- Read afterburner_state -------------
2588
2589         // From keyboard...
2590         if ( kc_keyboard[46].value < 255 ) Controls.afterburner_state |= keyd_pressed[kc_keyboard[46].value];
2591         if ( kc_keyboard[47].value < 255 ) Controls.afterburner_state |= keyd_pressed[kc_keyboard[47].value];
2592
2593         if ( (use_mouse)&&(kc_mouse[27].value < 255 )) Controls.afterburner_state |= mouse_button_state(kc_mouse[27].value);
2594
2595         if ( (use_joystick)&&(kc_superjoy[27].value < 255 )) Controls.afterburner_state |= joy_get_button_state(kc_superjoy[27].value);
2596
2597 //-------Read headlight key--------------------------
2598         if (kc_keyboard[52].value < 255 )
2599                    Controls.headlight_count=key_down_count(kc_keyboard[52].value);
2600         if (kc_keyboard[53].value < 255 )
2601                    Controls.headlight_count=key_down_count(kc_keyboard[53].value);
2602                   if ((use_joystick)&&(kc_superjoy[30].value < 255 )) 
2603          Controls.headlight_count=joy_get_button_down_cnt(kc_superjoy[30].value);
2604                  
2605 //--------Read Cycle Primary Key------------------
2606
2607                   if (kc_keyboard[48].value<255)
2608                          Controls.cycle_primary_count=key_down_count(kc_keyboard[48].value);
2609                   if (kc_keyboard[49].value<255)
2610                         Controls.cycle_primary_count+=key_down_count(kc_keyboard[49].value);
2611              if ((use_joystick)&&(kc_superjoy[28].value < 255 )) 
2612          Controls.cycle_primary_count+=joy_get_button_down_cnt(kc_superjoy[28].value);
2613
2614 //--------Read Cycle Secondary Key------------------
2615
2616                   if (kc_keyboard[50].value<255)
2617                          Controls.cycle_secondary_count=key_down_count(kc_keyboard[50].value);
2618                   if (kc_keyboard[51].value<255)
2619                         Controls.cycle_secondary_count+=key_down_count(kc_keyboard[51].value);
2620              if ((use_joystick)&&(kc_superjoy[29].value < 255 )) 
2621                         Controls.cycle_secondary_count=joy_get_button_down_cnt(kc_superjoy[29].value);
2622
2623 //--------Read Toggle Bomb key----------------------
2624
2625                   if (kc_keyboard[56].value<255 && key_down_count(kc_keyboard[56].value))
2626          {
2627           int bomb = Secondary_last_was_super[PROXIMITY_INDEX]?PROXIMITY_INDEX:SMART_MINE_INDEX;
2628
2629                          if (!Players[Player_num].secondary_ammo[PROXIMITY_INDEX] &&
2630                                   !Players[Player_num].secondary_ammo[SMART_MINE_INDEX])
2631                            {
2632                                  digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
2633                                  HUD_init_message ("No bombs available!");
2634                                 }
2635                          else
2636                                 {       
2637                                  if (Players[Player_num].secondary_ammo[bomb]==0)
2638                                         {
2639                                          digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
2640                                          HUD_init_message ("No %s available!",(bomb==SMART_MINE_INDEX)?"Smart mines":"Proximity bombs");
2641                                         }
2642                                   else
2643                                         {
2644                                Secondary_last_was_super[PROXIMITY_INDEX]=!Secondary_last_was_super[PROXIMITY_INDEX];
2645                                          digi_play_sample_once( SOUND_GOOD_SELECTION_SECONDARY, F1_0 );
2646                                         }
2647                                 }
2648                         }
2649           
2650 //---------Read Energy->Shield key----------
2651
2652         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[kc_keyboard[54].value])
2653                 transfer_energy_to_shield(key_down_time(kc_keyboard[54].value));
2654         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[kc_keyboard[55].value])
2655                 transfer_energy_to_shield(key_down_time(kc_keyboard[55].value));
2656
2657 //----------- Read fire_primary_down_count
2658         if (kc_keyboard[24].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[24].value);
2659         if (kc_keyboard[25].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[25].value);
2660         if ((use_joystick)&&(kc_superjoy[0].value < 255 )) Controls.fire_primary_down_count += joy_get_button_down_cnt(kc_superjoy[0].value);
2661         if ((use_mouse)&&(kc_mouse[0].value < 255 )) Controls.fire_primary_down_count += mouse_button_down_count(kc_mouse[0].value);
2662
2663 //----------- Read fire_primary_state
2664         if (kc_keyboard[24].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[24].value];
2665         if (kc_keyboard[25].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[25].value];
2666         if ((use_joystick)&&(kc_superjoy[0].value < 255 )) Controls.fire_primary_state |= joy_get_button_state(kc_superjoy[0].value);
2667         if ((use_mouse)&&(kc_mouse[0].value < 255) ) Controls.fire_primary_state |= mouse_button_state(kc_mouse[0].value);
2668
2669 //----------- Read fire_secondary_down_count
2670         if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[26].value);
2671         if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[27].value);
2672         if ((use_joystick)&&(kc_superjoy[1].value < 255 )) Controls.fire_secondary_down_count += joy_get_button_down_cnt(kc_superjoy[1].value);
2673         if ((use_mouse)&&(kc_mouse[1].value < 255 )) Controls.fire_secondary_down_count += mouse_button_down_count(kc_mouse[1].value);
2674
2675 //----------- Read fire_secondary_state
2676         if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[26].value];
2677         if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[27].value];
2678         if ((use_joystick)&&(kc_superjoy[1].value < 255 )) Controls.fire_secondary_state |= joy_get_button_state(kc_superjoy[1].value);
2679         if ((use_mouse)&&(kc_mouse[1].value < 255) ) Controls.fire_secondary_state |= mouse_button_state(kc_mouse[1].value);
2680
2681 //----------- Read fire_flare_down_count
2682         if (kc_keyboard[28].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[28].value);
2683         if (kc_keyboard[29].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[29].value);
2684         if ((use_joystick)&&(kc_superjoy[4].value < 255 )) Controls.fire_flare_down_count += joy_get_button_down_cnt(kc_superjoy[4].value);
2685         if ((use_mouse)&&(kc_mouse[4].value < 255 )) Controls.fire_flare_down_count += mouse_button_down_count(kc_mouse[4].value);
2686
2687 //----------- Read drop_bomb_down_count
2688         if (kc_keyboard[34].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[34].value);
2689         if (kc_keyboard[35].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[35].value);
2690         if ((use_joystick)&&(kc_superjoy[26].value < 255 )) Controls.drop_bomb_down_count += joy_get_button_down_cnt(kc_superjoy[26].value);
2691         if ((use_mouse)&&(kc_mouse[26].value < 255 )) Controls.drop_bomb_down_count += mouse_button_down_count(kc_mouse[26].value);
2692
2693 //----------- Read rear_view_down_count
2694         if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[36].value);
2695         if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[37].value);
2696         if ((use_joystick)&&(kc_superjoy[25].value < 255 )) Controls.rear_view_down_count += joy_get_button_down_cnt(kc_superjoy[25].value);
2697         if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_count += mouse_button_down_count(kc_mouse[25].value);
2698
2699 //----------- Read rear_view_down_state
2700         if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[36].value];
2701         if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[37].value];
2702         if ((use_joystick)&&(kc_superjoy[25].value < 255 )) Controls.rear_view_down_state |= joy_get_button_state(kc_superjoy[25].value);
2703         if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_state |= mouse_button_state(kc_mouse[25].value);
2704
2705 //----------- Read automap_down_count
2706         if (kc_keyboard[44].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[44].value);
2707         if (kc_keyboard[45].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[45].value);
2708
2709 //----------- Read automap_state
2710         if (kc_keyboard[44].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[44].value];
2711         if (kc_keyboard[45].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[45].value];
2712
2713 //----------- Read stupid-cruise-control-type of throttle.
2714         {
2715                 if ( kc_keyboard[38].value < 255 ) Cruise_speed += fixdiv(speed_factor*key_down_time(kc_keyboard[38].value)*5,FrameTime);
2716                 if ( kc_keyboard[39].value < 255 ) Cruise_speed += fixdiv(speed_factor*key_down_time(kc_keyboard[39].value)*5,FrameTime);
2717                 if ( kc_keyboard[40].value < 255 ) Cruise_speed -= fixdiv(speed_factor*key_down_time(kc_keyboard[40].value)*5,FrameTime);
2718                 if ( kc_keyboard[41].value < 255 ) Cruise_speed -= fixdiv(speed_factor*key_down_time(kc_keyboard[41].value)*5,FrameTime);
2719                 if ( (kc_keyboard[42].value < 255) && (key_down_count(kc_keyboard[42].value)) )
2720                         Cruise_speed = 0;
2721                 if ( (kc_keyboard[43].value < 255) && (key_down_count(kc_keyboard[43].value)) )
2722                         Cruise_speed = 0;
2723         
2724                 if (Cruise_speed > i2f(100) ) Cruise_speed = i2f(100);
2725                 if (Cruise_speed < 0 ) Cruise_speed = 0;
2726         
2727                 if (Controls.forward_thrust_time==0)
2728                         Controls.forward_thrust_time = fixmul(Cruise_speed,FrameTime)/100;
2729         }
2730
2731         //read_head_tracker();
2732
2733         // Read external controls
2734         if (kc_use_external_control || CybermouseActive)
2735                 kconfig_read_external_controls();
2736
2737 //----------- Clamp values between -FrameTime and FrameTime
2738         if (FrameTime > F1_0 )
2739                 mprintf( (1, "Bogus frame time of %.2f seconds\n", f2fl(FrameTime) ));
2740
2741         if (Controls.pitch_time > FrameTime/2 ) Controls.pitch_time = FrameTime/2;
2742         if (Controls.vertical_thrust_time > FrameTime ) Controls.vertical_thrust_time = FrameTime;
2743         if (Controls.heading_time > FrameTime ) Controls.heading_time = FrameTime;
2744         if (Controls.sideways_thrust_time > FrameTime ) Controls.sideways_thrust_time = FrameTime;
2745         if (Controls.bank_time > FrameTime ) Controls.bank_time = FrameTime;
2746         if (Controls.forward_thrust_time > FrameTime ) Controls.forward_thrust_time = FrameTime;
2747 //      if (Controls.afterburner_time > FrameTime ) Controls.afterburner_time = FrameTime;
2748
2749         if (Controls.pitch_time < -FrameTime/2 ) Controls.pitch_time = -FrameTime/2;
2750         if (Controls.vertical_thrust_time < -FrameTime ) Controls.vertical_thrust_time = -FrameTime;
2751         if (Controls.heading_time < -FrameTime ) Controls.heading_time = -FrameTime;
2752         if (Controls.sideways_thrust_time < -FrameTime ) Controls.sideways_thrust_time = -FrameTime;
2753         if (Controls.bank_time < -FrameTime ) Controls.bank_time = -FrameTime;
2754         if (Controls.forward_thrust_time < -FrameTime ) Controls.forward_thrust_time = -FrameTime;
2755 //      if (Controls.afterburner_time < -FrameTime ) Controls.afterburner_time = -FrameTime;
2756
2757
2758 //--------- Don't do anything if in debug mode
2759         #ifndef RELEASE
2760         if ( keyd_pressed[KEY_DELETE] ) {
2761                 memset( &Controls, 0, sizeof(control_info) );
2762         }
2763         #endif
2764 }
2765 #else
2766
2767
2768 fix Next_toggle_time[3]={0,0,0};
2769
2770 int allowed_to_toggle(int i)
2771 {
2772   //used for keeping tabs of when its ok to toggle headlight,primary,and secondary
2773  
2774         if (Next_toggle_time[i] > GameTime)
2775                 if (Next_toggle_time[i] < GameTime + (F1_0/8))  //      In case time is bogus, never wait > 1 second.
2776                         return 0;
2777
2778         Next_toggle_time[i] = GameTime + (F1_0/8);
2779
2780         return 1;
2781 }
2782
2783
2784 #ifdef D2X_KEYS
2785 //added on 2/7/99 by Victor Rachels for jostick state setting
2786 int d2x_joystick_ostate[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
2787 //end this section adition - VR
2788 #endif
2789
2790
2791 void controls_read_all()
2792 {
2793         int i;
2794         int slide_on, bank_on;
2795         int dx, dy;
2796 #ifdef SDL_INPUT
2797         int dz;
2798 #endif
2799         int idx, idy;
2800         fix ctime;
2801         fix mouse_axis[3] = {0,0,0};
2802         int raw_joy_axis[JOY_MAX_AXES];
2803         int mouse_buttons;
2804         fix k0, k1, k2, k3, kp;
2805         fix k4, k5, k6, k7, kh;
2806         ubyte channel_masks;
2807         int use_mouse, use_joystick;
2808         int speed_factor=1;
2809
2810         mouse_buttons=0;
2811         use_mouse=0;
2812
2813         if (Game_turbo_mode)
2814                 speed_factor = 2;
2815         
2816         {
2817                 fix temp = Controls.heading_time;
2818                 fix temp1 = Controls.pitch_time;
2819                 memset( &Controls, 0, sizeof(control_info) );
2820                 Controls.heading_time = temp;
2821                 Controls.pitch_time = temp1;
2822         }
2823         slide_on = 0;
2824         bank_on = 0;
2825
2826         ctime = timer_get_fixed_seconds();
2827
2828         //---------  Read Joystick -----------
2829 #ifndef MACINTOSH
2830         if ( (LastReadTime + JOYSTICK_READ_TIME > ctime) && (Config_control_type!=CONTROL_THRUSTMASTER_FCS) ) {
2831 # ifndef __MSDOS__
2832                 if ((ctime < 0) && (LastReadTime >= 0))
2833 # else
2834                 if ((ctime < 0) && (LastReadTime > 0))
2835 # endif
2836                         LastReadTime = ctime;
2837                 use_joystick=1;
2838         } else if ((Config_control_type>0) && (Config_control_type<5) ) {
2839                 LastReadTime = ctime;
2840                 channel_masks = joystick_read_raw_axis( JOY_ALL_AXIS, raw_joy_axis );
2841
2842                 for (i = 0; i < joy_num_axes; i++)
2843                 {
2844 #ifndef SDL_INPUT
2845                         if (channel_masks&(1<<i))       {
2846 #endif
2847                                 int joy_null_value = 10;
2848
2849                                 if ( (i==3) && (Config_control_type==CONTROL_THRUSTMASTER_FCS) )        {
2850                                         kconfig_read_fcs( raw_joy_axis[i] );
2851                                 } else {
2852                                         raw_joy_axis[i] = joy_get_scaled_reading( raw_joy_axis[i], i );
2853         
2854                                         if (kc_joystick[23].value==i)           // If this is the throttle
2855                                                 joy_null_value = 20;            // Then use a larger dead-zone
2856         
2857                                         if (raw_joy_axis[i] > joy_null_value) 
2858                                           raw_joy_axis[i] = ((raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value);
2859                                         else if (raw_joy_axis[i] < -joy_null_value)
2860                                           raw_joy_axis[i] = ((raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value);
2861                                         else
2862                                           raw_joy_axis[i] = 0;
2863                                         joy_axis[i]     = (raw_joy_axis[i]*FrameTime)/128;      
2864                                 }
2865 #ifndef SDL_INPUT
2866                         } else {
2867                                 joy_axis[i] = 0;
2868                         }
2869 #endif
2870                 }       
2871                 use_joystick=1;
2872         } else {
2873                 for (i = 0; i < joy_num_axes; i++)
2874                         joy_axis[i] = 0;
2875                 use_joystick=0;
2876         }
2877 #else   // MACINTOSH
2878         //---------  Read Joystick -----------
2879         if ((Config_control_type>0) && (Config_control_type<5) ) {
2880                 channel_masks = joystick_read_raw_axis( JOY_ALL_AXIS, raw_joy_axis );
2881                 for (i=0; i<4; i++ )    {
2882                         if (channel_masks&(1<<i))       {
2883                                 int joy_null_value = 10;
2884
2885                                 raw_joy_axis[i] = joy_get_scaled_reading( raw_joy_axis[i], i );
2886
2887                                 if (kc_joystick[23].value==i)           // If this is the throttle
2888                                         joy_null_value = 20;                            // Then use a larger dead-zone
2889
2890                                 if (raw_joy_axis[i] > joy_null_value) 
2891                                         raw_joy_axis[i] = ((raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value);
2892                                 else if (raw_joy_axis[i] < -joy_null_value)
2893                                         raw_joy_axis[i] = ((raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value);
2894                                 else
2895                                         raw_joy_axis[i] = 0;
2896                                 joy_axis[i]     = (raw_joy_axis[i]*FrameTime)/128;      
2897                         } else {
2898                                 joy_axis[i] = 0;
2899                         }
2900                 }       
2901                 use_joystick=1;
2902         } else {
2903                 for (i=0; i<4; i++ )
2904                         joy_axis[i] = 0;
2905                 use_joystick=0;
2906         }
2907 #endif          // ifndef MACINTOSH
2908
2909         if (Config_control_type==5 && !CybermouseActive) {
2910                 //---------  Read Mouse -----------
2911 #ifdef SDL_INPUT
2912                 mouse_get_delta_z( &dx, &dy, &dz );
2913 #else
2914                 mouse_get_delta( &dx, &dy );
2915 #endif
2916                 mouse_axis[0] = (dx*FrameTime)/35;
2917                 mouse_axis[1] = (dy*FrameTime)/25;
2918 #ifdef SDL_INPUT
2919                 mouse_axis[2] = (dz*FrameTime);
2920 #endif
2921                 mouse_buttons = mouse_get_btns();
2922                 //mprintf(( 0, "Mouse %d,%d b:%d, 0x%x\n", mouse_axis[0], mouse_axis[1], mouse_buttons, FrameTime ));
2923                 use_mouse=1;
2924         } else if (Config_control_type==6 && !CybermouseActive) {
2925                 //---------  Read Cyberman -----------
2926                 mouse_get_cyberman_pos(&idx,&idy );
2927                 mouse_axis[0] = (idx*FrameTime)/128;
2928                 mouse_axis[1] = (idy*FrameTime)/128;
2929                 mouse_buttons = mouse_get_btns();
2930                 use_mouse=1;
2931         } else if (CybermouseActive) {
2932 //              ReadOWL (kc_external_control);
2933 //              CybermouseAdjust();
2934         } else {
2935                 mouse_axis[0] = 0;
2936                 mouse_axis[1] = 0;
2937                 mouse_buttons = 0;
2938                 use_mouse=0;
2939         }
2940
2941 #ifdef D2X_KEYS
2942         //added on 2/4/99 by Victor Rachels for d1x keys
2943         //--------- Read primary weapon select -------------
2944         //the following "if" added by WraithX to stop deadies from switchin weapons, 4/14/00
2945         if (!Player_is_dead)
2946         {
2947                 {
2948                         int d2x_joystick_state[10];
2949
2950                         for(i=0;i<10;i++)
2951                                 d2x_joystick_state[i] = joy_get_button_state(kc_d2x[i*2+1].value);
2952
2953
2954                         //----------------Weapon 1----------------
2955                         if(key_down_count(kc_d2x[0].value) ||
2956                            (joy_get_button_state(kc_d2x[1].value) &&
2957                                 (d2x_joystick_state[0]!=d2x_joystick_ostate[0]) ) )
2958                         {
2959                                 //int i, valu=0;
2960                                 do_weapon_select(0,0);
2961                                 /*
2962                                 for(i=MAX_PRIMARY_WEAPONS;i<MAX_PRIMARY_WEAPONS+NEWPRIMS;i++)
2963                                         if(primary_order[i]>primary_order[valu]&&player_has_weapon(i,0))
2964                                                 valu = i;
2965                                 LaserPowSelected = valu;
2966                                 */
2967                         }
2968                         //----------------Weapon 2----------------
2969                         if(key_down_count(kc_d2x[2].value) ||
2970                            (joy_get_button_state(kc_d2x[3].value) &&
2971                                 (d2x_joystick_state[1]!=d2x_joystick_ostate[1]) ) )
2972                                 do_weapon_select(1,0);
2973                         //----------------Weapon 3----------------
2974                         if(key_down_count(kc_d2x[4].value) ||
2975                            (joy_get_button_state(kc_d2x[5].value) &&
2976                                 (d2x_joystick_state[2]!=d2x_joystick_ostate[2]) ) )
2977                                 do_weapon_select(2,0);
2978                         //----------------Weapon 4----------------
2979                         if(key_down_count(kc_d2x[6].value) ||
2980                            (joy_get_button_state(kc_d2x[7].value) &&
2981                                 (d2x_joystick_state[3]!=d2x_joystick_ostate[3]) ) )
2982                                 do_weapon_select(3,0);
2983                         //----------------Weapon 5----------------
2984                         if(key_down_count(kc_d2x[8].value) ||
2985                            (joy_get_button_state(kc_d2x[9].value) &&
2986                                 (d2x_joystick_state[4]!=d2x_joystick_ostate[4]) ) )
2987                                 do_weapon_select(4,0);
2988  
2989                         //--------- Read secondary weapon select ----------
2990                         //----------------Weapon 6----------------
2991                         if(key_down_count(kc_d2x[10].value) ||
2992                            (joy_get_button_state(kc_d2x[11].value) &&
2993                                 (d2x_joystick_state[5]!=d2x_joystick_ostate[5]) ) )
2994                                 do_weapon_select(0,1);
2995                         //----------------Weapon 7----------------
2996                         if(key_down_count(kc_d2x[12].value) ||
2997                            (joy_get_button_state(kc_d2x[13].value) &&
2998                                 (d2x_joystick_state[6]!=d2x_joystick_ostate[6]) ) )
2999                                 do_weapon_select(1,1);
3000                         //----------------Weapon 8----------------
3001                         if(key_down_count(kc_d2x[14].value) ||
3002                            (joy_get_button_state(kc_d2x[15].value) &&
3003                                 (d2x_joystick_state[7]!=d2x_joystick_ostate[7]) ) )
3004                                 do_weapon_select(2,1);
3005                         //----------------Weapon 9----------------
3006                         if(key_down_count(kc_d2x[16].value) ||
3007                            (joy_get_button_state(kc_d2x[17].value) &&
3008                                 (d2x_joystick_state[8]!=d2x_joystick_ostate[8]) ) )
3009                                 do_weapon_select(3,1);
3010                         //----------------Weapon 0----------------
3011                         if(key_down_count(kc_d2x[18].value) ||
3012                            (joy_get_button_state(kc_d2x[19].value) &&
3013                                 (d2x_joystick_state[9]!=d2x_joystick_ostate[9]) ) )
3014                                 do_weapon_select(4,1);
3015                         memcpy(d2x_joystick_ostate,d2x_joystick_state,10*sizeof(int));
3016                 }
3017                 //end this section addition - VR
3018
3019
3020         }//end "if (!Player_is_dead)" - WraithX
3021 #endif
3022
3023
3024 //------------- Read slide_on -------------
3025         
3026         // From keyboard...
3027         if ( kc_keyboard[8].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[8].value ];
3028         if ( kc_keyboard[9].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[9].value ];
3029         // From joystick...
3030         if ((use_joystick)&&(kc_joystick[5].value<255)) slide_on |= joy_get_button_state( kc_joystick[5].value );
3031         // From mouse...
3032         if ((use_mouse)&&(kc_mouse[5].value<255)) slide_on |= mouse_buttons & (1<<kc_mouse[5].value);
3033
3034 //------------- Read bank_on ---------------
3035
3036         // From keyboard...
3037         if ( kc_keyboard[18].value < 255 ) bank_on |= keyd_pressed[ kc_keyboard[18].value ];
3038         if ( kc_keyboard[19].value < 255 ) bank_on |= keyd_pressed[ kc_keyboard[19].value ];
3039         // From joystick...
3040         if ( (use_joystick)&&(kc_joystick[10].value < 255 )) bank_on |= joy_get_button_state( kc_joystick[10].value );
3041         // From mouse...
3042         if ( (use_mouse)&&(kc_mouse[10].value < 255 )) bank_on |= mouse_buttons & (1<<kc_mouse[10].value);
3043
3044 //------------ Read pitch_time -----------
3045         if ( !slide_on )        {
3046                 // mprintf((0, "pitch: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
3047                 kp = 0;
3048                 k0 = speed_factor*key_down_time( kc_keyboard[0].value )/2;      // Divide by two since we want pitch to go slower
3049                 k1 = speed_factor*key_down_time( kc_keyboard[1].value )/2;
3050                 k2 = speed_factor*key_down_time( kc_keyboard[2].value )/2;
3051                 k3 = speed_factor*key_down_time( kc_keyboard[3].value )/2;
3052
3053                 // From keyboard...
3054                 if ( kc_keyboard[0].value < 255 ) kp += k0/PH_SCALE;
3055                 if ( kc_keyboard[1].value < 255 ) kp += k1/PH_SCALE;
3056                 if ( kc_keyboard[2].value < 255 ) kp -= k2/PH_SCALE;
3057                 if ( kc_keyboard[3].value < 255 ) kp -= k3/PH_SCALE;
3058
3059                 // From Cyberman...
3060                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3061                         kp += mouse_button_down_time(MB_PITCH_FORWARD)/(PH_SCALE*2);
3062                         kp -= mouse_button_down_time(MB_PITCH_BACKWARD)/(PH_SCALE*2);
3063                 }
3064         
3065                 if (kp == 0)
3066                         Controls.pitch_time = 0;
3067                 else if (kp > 0) {
3068                         if (Controls.pitch_time < 0)
3069                                 Controls.pitch_time = 0;
3070                 } else // kp < 0
3071                         if (Controls.pitch_time > 0)
3072                                 Controls.pitch_time = 0;
3073                 Controls.pitch_time += kp;
3074         
3075                 // From joystick...
3076                 if ( (use_joystick)&&(kc_joystick[13].value < 255 ))    {
3077                         if ( !kc_joystick[14].value )           // If not inverted...
3078                                 Controls.pitch_time -= (joy_axis[kc_joystick[13].value]*Config_joystick_sensitivity)/8;
3079                         else
3080                                 Controls.pitch_time += (joy_axis[kc_joystick[13].value]*Config_joystick_sensitivity)/8;
3081                 }
3082         
3083                 // From mouse...
3084                 //mprintf(( 0, "UM: %d, PV: %d\n", use_mouse, kc_mouse[13].value ));
3085                 if ( (use_mouse)&&(kc_mouse[13].value < 255) )  {
3086                         if ( !kc_mouse[14].value )              // If not inverted...
3087                                 Controls.pitch_time -= (mouse_axis[kc_mouse[13].value]*Config_joystick_sensitivity)/8;
3088                         else
3089                                 Controls.pitch_time += (mouse_axis[kc_mouse[13].value]*Config_joystick_sensitivity)/8;
3090                 }
3091         } else {
3092                 Controls.pitch_time = 0;
3093         }
3094
3095
3096 // the following "if" added by WraithX, 4/14/00
3097 // done so that dead players can't move
3098 if (!Player_is_dead)
3099 {
3100 //----------- Read vertical_thrust_time -----------------
3101
3102         if ( slide_on ) {
3103                 k0 = speed_factor*key_down_time( kc_keyboard[0].value );
3104                 k1 = speed_factor*key_down_time( kc_keyboard[1].value );
3105                 k2 = speed_factor*key_down_time( kc_keyboard[2].value );
3106                 k3 = speed_factor*key_down_time( kc_keyboard[3].value );
3107
3108                 // From keyboard...
3109                 if ( kc_keyboard[0].value < 255 ) Controls.vertical_thrust_time += k0;
3110                 if ( kc_keyboard[1].value < 255 ) Controls.vertical_thrust_time += k1;
3111                 if ( kc_keyboard[2].value < 255 ) Controls.vertical_thrust_time -= k2;
3112                 if ( kc_keyboard[3].value < 255 ) Controls.vertical_thrust_time -= k3;
3113
3114                 // From Cyberman...
3115                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3116                         Controls.vertical_thrust_time -= mouse_button_down_time(MB_PITCH_FORWARD);
3117                         Controls.vertical_thrust_time += mouse_button_down_time(MB_PITCH_BACKWARD);
3118                 }
3119         
3120                 // From joystick...
3121                 if ((use_joystick)&&( kc_joystick[13].value < 255 ))    {
3122                         if ( !kc_joystick[14].value )           // If not inverted...
3123                                 Controls.vertical_thrust_time += joy_axis[kc_joystick[13].value];
3124                         else
3125                                 Controls.vertical_thrust_time -= joy_axis[kc_joystick[13].value];
3126                 }
3127         
3128                 // From mouse...
3129                 if ( (use_mouse)&&(kc_mouse[13].value < 255 ))  {
3130                         if ( !kc_mouse[14].value )              // If not inverted...
3131                                 Controls.vertical_thrust_time -= mouse_axis[kc_mouse[13].value];
3132                         else
3133                                 Controls.vertical_thrust_time += mouse_axis[kc_mouse[13].value];
3134                 }
3135         }
3136
3137         // From keyboard...
3138         if ( kc_keyboard[14].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[14].value );
3139         if ( kc_keyboard[15].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[15].value );
3140         if ( kc_keyboard[16].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[16].value );
3141         if ( kc_keyboard[17].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[17].value );
3142         
3143         // From joystick...
3144         if ((use_joystick)&&( kc_joystick[19].value < 255 ))    {
3145                 if ( !kc_joystick[20].value )           // If not inverted...
3146                         Controls.vertical_thrust_time += joy_axis[kc_joystick[19].value];
3147                 else
3148                         Controls.vertical_thrust_time -= joy_axis[kc_joystick[19].value];
3149         }
3150
3151         // From joystick buttons
3152         if ( (use_joystick)&&(kc_joystick[8].value < 255 )) Controls.vertical_thrust_time += joy_get_button_down_time( kc_joystick[8].value );
3153         if ( (use_joystick)&&(kc_joystick[9].value < 255 )) Controls.vertical_thrust_time -= joy_get_button_down_time( kc_joystick[9].value );
3154
3155         // From mouse buttons
3156         if ( (use_mouse)&&(kc_mouse[8].value < 255 )) Controls.vertical_thrust_time += mouse_button_down_time( kc_mouse[8].value );
3157         if ( (use_mouse)&&(kc_mouse[9].value < 255 )) Controls.vertical_thrust_time -= mouse_button_down_time( kc_mouse[9].value );
3158
3159         // From mouse...
3160         if ( (use_mouse)&&(kc_mouse[19].value < 255 ))  {
3161                 if ( !kc_mouse[20].value )              // If not inverted...
3162                         Controls.vertical_thrust_time += mouse_axis[kc_mouse[19].value];
3163                 else
3164                         Controls.vertical_thrust_time -= mouse_axis[kc_mouse[19].value];
3165         }
3166
3167         // From Cyberman...
3168         if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3169                 Controls.vertical_thrust_time += mouse_button_down_time(MB_Z_UP)/2;
3170                 Controls.vertical_thrust_time -= mouse_button_down_time(MB_Z_DOWN)/2;
3171         }
3172 }// end "if" added by WraithX
3173
3174 //---------- Read heading_time -----------
3175
3176         if (!slide_on && !bank_on)      {
3177                 //mprintf((0, "heading: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
3178                 kh = 0;
3179                 k4 = speed_factor*key_down_time( kc_keyboard[4].value );
3180                 k5 = speed_factor*key_down_time( kc_keyboard[5].value );
3181                 k6 = speed_factor*key_down_time( kc_keyboard[6].value );
3182                 k7 = speed_factor*key_down_time( kc_keyboard[7].value );
3183
3184                 // From keyboard...
3185                 if ( kc_keyboard[4].value < 255 ) kh -= k4/PH_SCALE;
3186                 if ( kc_keyboard[5].value < 255 ) kh -= k5/PH_SCALE;
3187                 if ( kc_keyboard[6].value < 255 ) kh += k6/PH_SCALE;
3188                 if ( kc_keyboard[7].value < 255 ) kh += k7/PH_SCALE;
3189
3190                 // From Cyberman...
3191                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3192                         kh -= mouse_button_down_time(MB_HEAD_LEFT)/PH_SCALE;
3193                         kh += mouse_button_down_time(MB_HEAD_RIGHT)/PH_SCALE;
3194                 }
3195         
3196                 if (kh == 0)
3197                         Controls.heading_time = 0;
3198                 else if (kh > 0) {
3199                         if (Controls.heading_time < 0)
3200                                 Controls.heading_time = 0;
3201                 } else // kh < 0
3202                         if (Controls.heading_time > 0)
3203                                 Controls.heading_time = 0;
3204                 Controls.heading_time += kh;
3205
3206                 // From joystick...
3207                 if ( (use_joystick)&&(kc_joystick[15].value < 255 ))    {
3208                         if ( !kc_joystick[16].value )           // If not inverted...
3209                                 Controls.heading_time += (joy_axis[kc_joystick[15].value]*Config_joystick_sensitivity)/8;
3210                         else
3211                                 Controls.heading_time -= (joy_axis[kc_joystick[15].value]*Config_joystick_sensitivity)/8;
3212                 }
3213         
3214                 // From mouse...
3215                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
3216                         if ( !kc_mouse[16].value )              // If not inverted...
3217                                 Controls.heading_time += (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
3218                         else
3219                                 Controls.heading_time -= (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
3220                 }
3221         } else {
3222                 Controls.heading_time = 0;
3223         }
3224
3225 // the following "if" added by WraithX, 4/14/00
3226 // done so that dead players can't move
3227 if (!Player_is_dead)
3228 {
3229 //----------- Read sideways_thrust_time -----------------
3230
3231         if ( slide_on ) {
3232                 k0 = speed_factor*key_down_time( kc_keyboard[4].value );
3233                 k1 = speed_factor*key_down_time( kc_keyboard[5].value );
3234                 k2 = speed_factor*key_down_time( kc_keyboard[6].value );
3235                 k3 = speed_factor*key_down_time( kc_keyboard[7].value );
3236
3237                 // From keyboard...
3238                 if ( kc_keyboard[4].value < 255 ) Controls.sideways_thrust_time -= k0;
3239                 if ( kc_keyboard[5].value < 255 ) Controls.sideways_thrust_time -= k1;
3240                 if ( kc_keyboard[6].value < 255 ) Controls.sideways_thrust_time += k2;
3241                 if ( kc_keyboard[7].value < 255 ) Controls.sideways_thrust_time += k3;
3242         
3243                 // From joystick...
3244                 if ( (use_joystick)&&(kc_joystick[15].value < 255 ))    {
3245                         if ( !kc_joystick[16].value )           // If not inverted...
3246                                 Controls.sideways_thrust_time += joy_axis[kc_joystick[15].value];
3247                         else
3248                                 Controls.sideways_thrust_time -= joy_axis[kc_joystick[15].value];
3249                 }
3250                 
3251                 // From cyberman
3252                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3253                         Controls.sideways_thrust_time -= mouse_button_down_time(MB_HEAD_LEFT);
3254                         Controls.sideways_thrust_time += mouse_button_down_time(MB_HEAD_RIGHT);
3255                 }
3256         
3257                 // From mouse...
3258                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
3259                         if ( !kc_mouse[16].value )              // If not inverted...
3260                                 Controls.sideways_thrust_time += mouse_axis[kc_mouse[15].value];
3261                         else
3262                                 Controls.sideways_thrust_time -= mouse_axis[kc_mouse[15].value];
3263                 }
3264         }
3265
3266         // From keyboard...
3267         if ( kc_keyboard[10].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[10].value );
3268         if ( kc_keyboard[11].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[11].value );
3269         if ( kc_keyboard[12].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[12].value );
3270         if ( kc_keyboard[13].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[13].value );
3271         
3272         // From joystick...
3273         if ( (use_joystick)&&(kc_joystick[17].value < 255 ))    {
3274                 if ( !kc_joystick[18].value )           // If not inverted...
3275                         Controls.sideways_thrust_time -= joy_axis[kc_joystick[17].value];
3276                 else
3277                         Controls.sideways_thrust_time += joy_axis[kc_joystick[17].value];
3278         }
3279
3280         // From joystick buttons
3281         if ( (use_joystick)&&(kc_joystick[6].value < 255 )) Controls.sideways_thrust_time -= joy_get_button_down_time( kc_joystick[6].value );
3282         if ( (use_joystick)&&(kc_joystick[7].value < 255 )) Controls.sideways_thrust_time += joy_get_button_down_time( kc_joystick[7].value );
3283
3284         // From mouse buttons
3285         if ( (use_mouse)&&(kc_mouse[6].value < 255 )) Controls.sideways_thrust_time -= mouse_button_down_time( kc_mouse[6].value );
3286         if ( (use_mouse)&&(kc_mouse[7].value < 255 )) Controls.sideways_thrust_time += mouse_button_down_time( kc_mouse[7].value );
3287
3288         // From mouse...
3289         if ( (use_mouse)&&(kc_mouse[17].value < 255 ))  {
3290                 if ( !kc_mouse[18].value )              // If not inverted...
3291                         Controls.sideways_thrust_time += mouse_axis[kc_mouse[17].value];
3292                 else
3293                         Controls.sideways_thrust_time -= mouse_axis[kc_mouse[17].value];
3294         }
3295 }// end "if" added by WraithX
3296
3297 //----------- Read bank_time -----------------
3298
3299         if ( bank_on )  {
3300                 k0 = speed_factor*key_down_time( kc_keyboard[4].value );
3301                 k1 = speed_factor*key_down_time( kc_keyboard[5].value );
3302                 k2 = speed_factor*key_down_time( kc_keyboard[6].value );
3303                 k3 = speed_factor*key_down_time( kc_keyboard[7].value );
3304
3305                 // From keyboard...
3306                 if ( kc_keyboard[4].value < 255 ) Controls.bank_time += k0;
3307                 if ( kc_keyboard[5].value < 255 ) Controls.bank_time += k1;
3308                 if ( kc_keyboard[6].value < 255 ) Controls.bank_time -= k2;
3309                 if ( kc_keyboard[7].value < 255 ) Controls.bank_time -= k3;
3310
3311                 // From Cyberman...
3312                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3313                         Controls.bank_time -= mouse_button_down_time(MB_HEAD_LEFT);
3314                         Controls.bank_time += mouse_button_down_time(MB_HEAD_RIGHT);
3315                 }
3316
3317                 // From joystick...
3318                 if ( (use_joystick)&&(kc_joystick[15].value < 255) )    {
3319                         if ( !kc_joystick[16].value )           // If not inverted...
3320                                 Controls.bank_time -= (joy_axis[kc_joystick[15].value]*Config_joystick_sensitivity)/8;
3321                         else
3322                                 Controls.bank_time += (joy_axis[kc_joystick[15].value]*Config_joystick_sensitivity)/8;
3323                 }
3324         
3325                 // From mouse...
3326                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
3327                         if ( !kc_mouse[16].value )              // If not inverted...
3328                                 Controls.bank_time += (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
3329                         else
3330                                 Controls.bank_time -= (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
3331                 }
3332         }
3333
3334         // From keyboard...
3335         if ( kc_keyboard[20].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[20].value );
3336         if ( kc_keyboard[21].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[21].value );
3337         if ( kc_keyboard[22].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[22].value );
3338         if ( kc_keyboard[23].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[23].value );
3339
3340         // From joystick...
3341         if ( (use_joystick)&&(kc_joystick[21].value < 255) )    {
3342                 if ( !kc_joystick[22].value )           // If not inverted...
3343                         Controls.bank_time -= joy_axis[kc_joystick[21].value];
3344                 else
3345                         Controls.bank_time += joy_axis[kc_joystick[21].value];
3346         }
3347
3348         // From joystick buttons
3349         if ( (use_joystick)&&(kc_joystick[11].value < 255 )) Controls.bank_time += joy_get_button_down_time( kc_joystick[11].value );
3350         if ( (use_joystick)&&(kc_joystick[12].value < 255 )) Controls.bank_time -= joy_get_button_down_time( kc_joystick[12].value );
3351
3352         // From mouse buttons
3353         if ( (use_mouse)&&(kc_mouse[11].value < 255 )) Controls.bank_time += mouse_button_down_time( kc_mouse[11].value );
3354         if ( (use_mouse)&&(kc_mouse[12].value < 255 )) Controls.bank_time -= mouse_button_down_time( kc_mouse[12].value );
3355
3356         // From mouse...
3357         if ( (use_mouse)&&(kc_mouse[21].value < 255 ))  {
3358                 if ( !kc_mouse[22].value )              // If not inverted...
3359                         Controls.bank_time += mouse_axis[kc_mouse[21].value];
3360                 else
3361                         Controls.bank_time -= mouse_axis[kc_mouse[21].value];
3362         }
3363
3364         // From Cyberman
3365         if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3366                 Controls.bank_time += mouse_button_down_time(MB_BANK_LEFT);
3367                 Controls.bank_time -= mouse_button_down_time(MB_BANK_RIGHT);
3368         }
3369
3370 // the following "if" added by WraithX, 4/14/00
3371 // done so that dead players can't move
3372 if (!Player_is_dead)
3373 {
3374 //----------- Read forward_thrust_time -------------
3375
3376         // From keyboard...
3377         if ( kc_keyboard[30].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[30].value );
3378         if ( kc_keyboard[31].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[31].value );
3379         if ( kc_keyboard[32].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[32].value );
3380         if ( kc_keyboard[33].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[33].value );
3381
3382         // From joystick...
3383         if ( (use_joystick)&&(kc_joystick[23].value < 255 ))    {
3384                 if ( !kc_joystick[24].value )           // If not inverted...
3385                         Controls.forward_thrust_time -= joy_axis[kc_joystick[23].value];
3386                 else
3387                         Controls.forward_thrust_time += joy_axis[kc_joystick[23].value];
3388         }
3389
3390         // From joystick buttons
3391         if ( (use_joystick)&&(kc_joystick[2].value < 255 )) Controls.forward_thrust_time += joy_get_button_down_time( kc_joystick[2].value );
3392         if ( (use_joystick)&&(kc_joystick[3].value < 255 )) Controls.forward_thrust_time -= joy_get_button_down_time( kc_joystick[3].value );
3393
3394         // From mouse...
3395         if ( (use_mouse)&&(kc_mouse[23].value < 255 ))  {
3396                 if ( !kc_mouse[24].value )              // If not inverted...
3397                         Controls.forward_thrust_time -= mouse_axis[kc_mouse[23].value];
3398                 else
3399                         Controls.forward_thrust_time += mouse_axis[kc_mouse[23].value];
3400         }
3401
3402         // From mouse buttons
3403         if ( (use_mouse)&&(kc_mouse[2].value < 255 )) Controls.forward_thrust_time += mouse_button_down_time( kc_mouse[2].value );
3404         if ( (use_mouse)&&(kc_mouse[3].value < 255 )) Controls.forward_thrust_time -= mouse_button_down_time( kc_mouse[3].value );
3405
3406 //----------- Read afterburner_state -------------
3407
3408         // From keyboard...
3409         if ( kc_keyboard[46].value < 255 ) Controls.afterburner_state |= keyd_pressed[kc_keyboard[46].value];
3410         if ( kc_keyboard[47].value < 255 ) Controls.afterburner_state |= keyd_pressed[kc_keyboard[47].value];
3411
3412         if ( (use_mouse)&&(kc_mouse[27].value < 255 )) Controls.afterburner_state |= mouse_button_state(kc_mouse[27].value);
3413
3414         if ( (use_joystick)&&(kc_joystick[27].value < 255 )) Controls.afterburner_state |= joy_get_button_state(kc_joystick[27].value);
3415
3416 //-------Read headlight key--------------------------
3417
3418         if (kc_keyboard[52].value < 255 )
3419                    Controls.headlight_count=key_down_count(kc_keyboard[52].value);
3420         if (kc_keyboard[53].value < 255 )
3421                    Controls.headlight_count+=key_down_count(kc_keyboard[53].value);
3422                   if ((use_joystick)&&(kc_joystick[30].value < 255 )) 
3423                Controls.headlight_count+=joy_get_button_down_cnt(kc_joystick[30].value);
3424
3425 //--------Read Cycle Primary Key------------------
3426
3427                   if (kc_keyboard[48].value<255)
3428                          Controls.cycle_primary_count=key_down_count(kc_keyboard[48].value);
3429                   if (kc_keyboard[49].value<255)
3430                         Controls.cycle_primary_count+=key_down_count(kc_keyboard[49].value);
3431              if ((use_joystick)&&(kc_joystick[28].value < 255 )) 
3432          Controls.cycle_primary_count+=joy_get_button_down_cnt(kc_joystick[28].value);
3433
3434
3435 //--------Read Cycle Secondary Key------------------
3436
3437                   if (kc_keyboard[50].value<255)
3438                          Controls.cycle_secondary_count=key_down_count(kc_keyboard[50].value);
3439                   if (kc_keyboard[51].value<255)
3440                         Controls.cycle_secondary_count+=key_down_count(kc_keyboard[51].value);
3441              if ((use_joystick)&&(kc_joystick[29].value < 255 )) 
3442                         Controls.cycle_secondary_count=joy_get_button_down_cnt(kc_joystick[29].value);
3443
3444 //--------Read Toggle Bomb key----------------------
3445
3446                   if (kc_keyboard[56].value<255 && key_down_count(kc_keyboard[56].value))
3447          {
3448           int bomb = Secondary_last_was_super[PROXIMITY_INDEX]?PROXIMITY_INDEX:SMART_MINE_INDEX;
3449
3450                          if (!Players[Player_num].secondary_ammo[PROXIMITY_INDEX] &&
3451                                   !Players[Player_num].secondary_ammo[SMART_MINE_INDEX])
3452                            {
3453                                  digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
3454                                  HUD_init_message ("No bombs available!");
3455                                 }
3456                          else
3457                                 {       
3458                                  if (Players[Player_num].secondary_ammo[bomb]==0)
3459                                         {
3460                                          digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
3461                                          HUD_init_message ("No %s available!",(bomb==SMART_MINE_INDEX)?"Smart mines":"Proximity bombs");
3462                                         }
3463                                   else
3464                                         {
3465                                Secondary_last_was_super[PROXIMITY_INDEX]=!Secondary_last_was_super[PROXIMITY_INDEX];
3466                                          digi_play_sample_once( SOUND_GOOD_SELECTION_SECONDARY, F1_0 );
3467                                         }
3468                                 }
3469                         }
3470           
3471 //---------Read Energy->Shield key----------
3472
3473         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[kc_keyboard[54].value])
3474                 transfer_energy_to_shield(key_down_time(kc_keyboard[54].value));
3475         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[kc_keyboard[55].value])
3476                 transfer_energy_to_shield(key_down_time(kc_keyboard[55].value));
3477
3478 //----------- Read fire_primary_down_count
3479         if (kc_keyboard[24].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[24].value);
3480         if (kc_keyboard[25].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[25].value);
3481         if ((use_joystick)&&(kc_joystick[0].value < 255 )) Controls.fire_primary_down_count += joy_get_button_down_cnt(kc_joystick[0].value);
3482         if ((use_mouse)&&(kc_mouse[0].value < 255 )) Controls.fire_primary_down_count += mouse_button_down_count(kc_mouse[0].value);
3483
3484 //----------- Read fire_primary_state
3485         if (kc_keyboard[24].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[24].value];
3486         if (kc_keyboard[25].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[25].value];
3487         if ((use_joystick)&&(kc_joystick[0].value < 255 )) Controls.fire_primary_state |= joy_get_button_state(kc_joystick[0].value);
3488         if ((use_mouse)&&(kc_mouse[0].value < 255) ) Controls.fire_primary_state |= mouse_button_state(kc_mouse[0].value);
3489
3490 //----------- Read fire_secondary_down_count
3491         if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[26].value);
3492         if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[27].value);
3493         if ((use_joystick)&&(kc_joystick[1].value < 255 )) Controls.fire_secondary_down_count += joy_get_button_down_cnt(kc_joystick[1].value);
3494         if ((use_mouse)&&(kc_mouse[1].value < 255 )) Controls.fire_secondary_down_count += mouse_button_down_count(kc_mouse[1].value);
3495
3496 //----------- Read fire_secondary_state
3497         if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[26].value];
3498         if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[27].value];
3499         if ((use_joystick)&&(kc_joystick[1].value < 255 )) Controls.fire_secondary_state |= joy_get_button_state(kc_joystick[1].value);
3500         if ((use_mouse)&&(kc_mouse[1].value < 255) ) Controls.fire_secondary_state |= mouse_button_state(kc_mouse[1].value);
3501
3502 //----------- Read fire_flare_down_count
3503         if (kc_keyboard[28].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[28].value);
3504         if (kc_keyboard[29].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[29].value);
3505         if ((use_joystick)&&(kc_joystick[4].value < 255 )) Controls.fire_flare_down_count += joy_get_button_down_cnt(kc_joystick[4].value);
3506         if ((use_mouse)&&(kc_mouse[4].value < 255 )) Controls.fire_flare_down_count += mouse_button_down_count(kc_mouse[4].value);
3507
3508 //----------- Read drop_bomb_down_count
3509         if (kc_keyboard[34].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[34].value);
3510         if (kc_keyboard[35].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[35].value);
3511         if ((use_joystick)&&(kc_joystick[26].value < 255 )) Controls.drop_bomb_down_count += joy_get_button_down_cnt(kc_joystick[26].value);
3512         if ((use_mouse)&&(kc_mouse[26].value < 255 )) Controls.drop_bomb_down_count += mouse_button_down_count(kc_mouse[26].value);
3513
3514 //----------- Read rear_view_down_count
3515         if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[36].value);
3516         if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[37].value);
3517         if ((use_joystick)&&(kc_joystick[25].value < 255 )) Controls.rear_view_down_count += joy_get_button_down_cnt(kc_joystick[25].value);
3518         if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_count += mouse_button_down_count(kc_mouse[25].value);
3519
3520 //----------- Read rear_view_down_state
3521         if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[36].value];
3522         if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[37].value];
3523         if ((use_joystick)&&(kc_joystick[25].value < 255 )) Controls.rear_view_down_state |= joy_get_button_state(kc_joystick[25].value);
3524         if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_state |= mouse_button_state(kc_mouse[25].value);
3525
3526 }//end "if" added by WraithX
3527
3528 //----------- Read automap_down_count
3529         if (kc_keyboard[44].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[44].value);
3530         if (kc_keyboard[45].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[45].value);
3531
3532 //----------- Read automap_state
3533         if (kc_keyboard[44].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[44].value];
3534         if (kc_keyboard[45].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[45].value];
3535
3536 //----------- Read stupid-cruise-control-type of throttle.
3537         {
3538                 if ( kc_keyboard[38].value < 255 ) Cruise_speed += fixdiv(speed_factor*key_down_time(kc_keyboard[38].value)*5,FrameTime);
3539                 if ( kc_keyboard[39].value < 255 ) Cruise_speed += fixdiv(speed_factor*key_down_time(kc_keyboard[39].value)*5,FrameTime);
3540                 if ( kc_keyboard[40].value < 255 ) Cruise_speed -= fixdiv(speed_factor*key_down_time(kc_keyboard[40].value)*5,FrameTime);
3541                 if ( kc_keyboard[41].value < 255 ) Cruise_speed -= fixdiv(speed_factor*key_down_time(kc_keyboard[41].value)*5,FrameTime);
3542                 if ( (kc_keyboard[42].value < 255) && (key_down_count(kc_keyboard[42].value)) )
3543                         Cruise_speed = 0;
3544                 if ( (kc_keyboard[43].value < 255) && (key_down_count(kc_keyboard[43].value)) )
3545                         Cruise_speed = 0;
3546         
3547                 if (Cruise_speed > i2f(100) ) Cruise_speed = i2f(100);
3548                 if (Cruise_speed < 0 ) Cruise_speed = 0;
3549         
3550                 if (Controls.forward_thrust_time==0)
3551                         Controls.forward_thrust_time = fixmul(Cruise_speed,FrameTime)/100;
3552         }
3553
3554 #if !defined(MACINTOSH)
3555         //read_head_tracker();
3556
3557         // Read external controls
3558         // if (kc_use_external_control || CybermouseActive)
3559         //      kconfig_read_external_controls();
3560 #endif
3561
3562 //----------- Clamp values between -FrameTime and FrameTime
3563         if (FrameTime > F1_0 )
3564                 mprintf( (1, "Bogus frame time of %.2f seconds\n", f2fl(FrameTime) ));
3565
3566         if (Controls.pitch_time > FrameTime/2 ) Controls.pitch_time = FrameTime/2;
3567         if (Controls.vertical_thrust_time > FrameTime ) Controls.vertical_thrust_time = FrameTime;
3568         if (Controls.heading_time > FrameTime ) Controls.heading_time = FrameTime;
3569         if (Controls.sideways_thrust_time > FrameTime ) Controls.sideways_thrust_time = FrameTime;
3570         if (Controls.bank_time > FrameTime ) Controls.bank_time = FrameTime;
3571         if (Controls.forward_thrust_time > FrameTime ) Controls.forward_thrust_time = FrameTime;
3572 //      if (Controls.afterburner_time > FrameTime ) Controls.afterburner_time = FrameTime;
3573
3574         if (Controls.pitch_time < -FrameTime/2 ) Controls.pitch_time = -FrameTime/2;
3575         if (Controls.vertical_thrust_time < -FrameTime ) Controls.vertical_thrust_time = -FrameTime;
3576         if (Controls.heading_time < -FrameTime ) Controls.heading_time = -FrameTime;
3577         if (Controls.sideways_thrust_time < -FrameTime ) Controls.sideways_thrust_time = -FrameTime;
3578         if (Controls.bank_time < -FrameTime ) Controls.bank_time = -FrameTime;
3579         if (Controls.forward_thrust_time < -FrameTime ) Controls.forward_thrust_time = -FrameTime;
3580 //      if (Controls.afterburner_time < -FrameTime ) Controls.afterburner_time = -FrameTime;
3581
3582
3583 //--------- Don't do anything if in debug mode
3584         #ifndef RELEASE
3585         if ( keyd_pressed[KEY_DELETE] ) {
3586                 memset( &Controls, 0, sizeof(control_info) );
3587         }
3588         #endif
3589 }
3590 #endif
3591
3592
3593 void controls_read_console()
3594 {
3595         //      Controls.pitch_time += fixmul(kc_external_control->pitch_time,FrameTime);
3596         //      Controls.vertical_thrust_time += fixmul(kc_external_control->vertical_thrust_time,FrameTime);
3597         //      Controls.heading_time += fixmul(kc_external_control->heading_time,FrameTime);
3598         //      Controls.sideways_thrust_time += fixmul(kc_external_control->sideways_thrust_time ,FrameTime);
3599         //      Controls.bank_time += fixmul(kc_external_control->bank_time ,FrameTime);
3600         //      Controls.forward_thrust_time += fixmul(kc_external_control->forward_thrust_time ,FrameTime);
3601         //      Controls.rear_view_down_count += kc_external_control->rear_view_down_count;
3602         //      Controls.rear_view_down_state |= kc_external_control->rear_view_down_state;
3603         //      Controls.fire_primary_down_count += kc_external_control->fire_primary_down_count;
3604         Controls.fire_primary_state |= Console_button_states[CMD_ATTACK];
3605         Controls.fire_secondary_state |= Console_button_states[CMD_ATTACK2];
3606         //      Controls.fire_secondary_down_count += kc_external_control->fire_secondary_down_count;
3607         //      Controls.fire_flare_down_count += kc_external_control->fire_flare_down_count;
3608         //      Controls.drop_bomb_down_count += kc_external_control->drop_bomb_down_count;
3609         //      Controls.automap_down_count += kc_external_control->automap_down_count;
3610         //      Controls.automap_state |= kc_external_control->automap_state;
3611 }
3612
3613
3614 void reset_cruise(void)
3615 {
3616         Cruise_speed=0;
3617 }
3618
3619
3620 void kc_set_controls()
3621 {
3622         int i;
3623
3624         for (i=0; i<NUM_KEY_CONTROLS; i++ )     
3625                 kc_keyboard[i].value = kconfig_settings[0][i];
3626
3627         if ( (Config_control_type>0) && (Config_control_type<5)) {
3628                 for (i=0; i<NUM_OTHER_CONTROLS; i++ ) {
3629                         kc_joystick[i].value = kconfig_settings[Config_control_type][i];
3630                         if (kc_joystick[i].type == BT_INVERT )  {
3631                                 if (kc_joystick[i].value!=1)
3632                                         kc_joystick[i].value    = 0;
3633                                 kconfig_settings[Config_control_type][i] = kc_joystick[i].value;
3634                         }
3635                 }
3636         } else if (Config_control_type>4 && Config_control_type<CONTROL_WINJOYSTICK) {
3637                 for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
3638                         kc_mouse[i].value = kconfig_settings[Config_control_type][i];
3639                         if (kc_mouse[i].type == BT_INVERT )     {
3640                                 if (kc_mouse[i].value!=1)
3641                                         kc_mouse[i].value       = 0;
3642                                 kconfig_settings[Config_control_type][i] = kc_mouse[i].value;
3643                         }
3644                 }
3645         } else if (Config_control_type == CONTROL_WINJOYSTICK) {
3646                 for (i=0; i<NUM_OTHER_CONTROLS; i++ ) {
3647                         kc_superjoy[i].value = kconfig_settings[Config_control_type][i];
3648                         if (kc_superjoy[i].type == BT_INVERT )  {
3649                                 if (kc_superjoy[i].value!=1)
3650                                         kc_superjoy[i].value    = 0;
3651                                 kconfig_settings[Config_control_type][i] = kc_superjoy[i].value;
3652                         }
3653                 }
3654         }
3655
3656 #ifdef D2X_KEYS
3657         for (i=0; i<NUM_D2X_CONTROLS; i++ )
3658                 kc_d2x[i].value = kconfig_d2x_settings[i];
3659 #endif
3660 }
3661
3662 #if 0 //ndef MACINTOSH  // no mac support for vr headset
3663
3664 void kconfig_center_headset()
3665 {
3666 #ifndef WINDOWS
3667         if (vfx1_installed)
3668                 vfx_center_headset();
3669 #endif
3670 //      } else if (iglasses_headset_installed)  {
3671 //      } else if (Victor_headset_installed)   {
3672 //      } else {
3673 //      }
3674
3675 }
3676
3677 #endif  // end of #ifndef MACINTOSH for kconfig_center_headset
3678
3679 void CybermouseAdjust ()
3680  {
3681 /*      if ( Player_num > -1 )  {
3682                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_TURNROLL);    // Turn off roll when turning
3683                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_LEVELLING);   // Turn off leveling to nearest side.
3684                 Auto_leveling_on = 0;
3685
3686                 if ( kc_external_version > 0 ) {                
3687                         vms_matrix tempm, ViewMatrix;
3688                         vms_angvec * Kconfig_abs_movement;
3689                         char * oem_message;
3690         
3691                         Kconfig_abs_movement = (vms_angvec *)((uint)kc_external_control + sizeof(control_info));
3692         
3693                         if ( Kconfig_abs_movement->p || Kconfig_abs_movement->b || Kconfig_abs_movement->h )    {
3694                                 vm_angles_2_matrix(&tempm,Kconfig_abs_movement);
3695                                 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
3696                                 Objects[Players[Player_num].objnum].orient = ViewMatrix;                
3697                         }
3698                         oem_message = (char *)((uint)Kconfig_abs_movement + sizeof(vms_angvec));
3699                         if (oem_message[0] != '\0' )
3700                                 HUD_init_message( oem_message );
3701                 }
3702         }*/
3703
3704         Controls.pitch_time += fixmul(kc_external_control->pitch_time,FrameTime);                                               
3705         Controls.vertical_thrust_time += fixmul(kc_external_control->vertical_thrust_time,FrameTime);
3706         Controls.heading_time += fixmul(kc_external_control->heading_time,FrameTime);
3707         Controls.sideways_thrust_time += fixmul(kc_external_control->sideways_thrust_time ,FrameTime);
3708         Controls.bank_time += fixmul(kc_external_control->bank_time ,FrameTime);
3709         Controls.forward_thrust_time += fixmul(kc_external_control->forward_thrust_time ,FrameTime);
3710 //      Controls.rear_view_down_count += kc_external_control->rear_view_down_count;     
3711 //      Controls.rear_view_down_state |= kc_external_control->rear_view_down_state;     
3712         Controls.fire_primary_down_count += kc_external_control->fire_primary_down_count;
3713         Controls.fire_primary_state |= kc_external_control->fire_primary_state;
3714         Controls.fire_secondary_state |= kc_external_control->fire_secondary_state;
3715         Controls.fire_secondary_down_count += kc_external_control->fire_secondary_down_count;
3716         Controls.fire_flare_down_count += kc_external_control->fire_flare_down_count;
3717         Controls.drop_bomb_down_count += kc_external_control->drop_bomb_down_count;     
3718 //      Controls.automap_down_count += kc_external_control->automap_down_count;
3719 //      Controls.automap_state |= kc_external_control->automap_state;
3720   } 
3721
3722 char GetKeyValue (char key)
3723   {
3724         mprintf ((0,"Returning %c!\n",kc_keyboard[(int)key].value));
3725         return (kc_keyboard[(int)key].value);
3726   }
3727
3728 #if !defined(MACINTOSH)
3729
3730
3731 extern object *obj_find_first_of_type (int);
3732 void kconfig_read_external_controls()
3733 {
3734         //union REGS r;
3735    int i;
3736
3737         if ( !kc_enable_external_control ) return;
3738
3739         if ( kc_external_version == 0 ) 
3740                 memset( kc_external_control, 0, sizeof(ext_control_info));
3741         else if ( kc_external_version > 0 )     {
3742         
3743                 if (kc_external_version>=4)
3744                         memset( kc_external_control, 0, sizeof(advanced_ext_control_info));
3745       else if (kc_external_version>0)     
3746                         memset( kc_external_control, 0, sizeof(ext_control_info)+sizeof(vms_angvec) + 64 );
3747                 else if (kc_external_version>2)
3748                         memset( kc_external_control, 0, sizeof(ext_control_info)+sizeof(vms_angvec) + 64 + sizeof(vms_vector) + sizeof(vms_matrix) +4 );
3749
3750                 if ( kc_external_version > 1 ) {
3751                         // Write ship pos and angles to external controls...
3752                         ubyte *temp_ptr = (ubyte *)kc_external_control;
3753                         vms_vector *ship_pos;
3754                         vms_matrix *ship_orient;
3755                         memset( kc_external_control, 0, sizeof(ext_control_info)+sizeof(vms_angvec) + 64 + sizeof(vms_vector)+sizeof(vms_matrix) );
3756                         temp_ptr += sizeof(ext_control_info) + sizeof(vms_angvec) + 64;
3757                         ship_pos = (vms_vector *)temp_ptr;
3758                         temp_ptr += sizeof(vms_vector);
3759                         ship_orient = (vms_matrix *)temp_ptr;
3760                         // Fill in ship postion...
3761                         *ship_pos = Objects[Players[Player_num].objnum].pos;
3762                         // Fill in ship orientation...
3763                         *ship_orient = Objects[Players[Player_num].objnum].orient;
3764                 }
3765     if (kc_external_version>=4)
3766           {
3767            advanced_ext_control_info *temp_ptr=(advanced_ext_control_info *)kc_external_control;
3768  
3769       temp_ptr->headlight_state=(Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON);
3770                 temp_ptr->primary_weapon_flags=Players[Player_num].primary_weapon_flags;
3771                 temp_ptr->secondary_weapon_flags=Players[Player_num].secondary_weapon_flags;
3772       temp_ptr->current_primary_weapon=Primary_weapon;
3773       temp_ptr->current_secondary_weapon=Secondary_weapon;
3774
3775       temp_ptr->current_guidebot_command=Escort_goal_object;
3776
3777            temp_ptr->force_vector=ExtForceVec;
3778                 temp_ptr->force_matrix=ExtApplyForceMatrix;
3779            for (i=0;i<3;i++)
3780        temp_ptr->joltinfo[i]=ExtJoltInfo[i];  
3781       for (i=0;i<2;i++)
3782                    temp_ptr->x_vibrate_info[i]=ExtXVibrateInfo[i];
3783                 temp_ptr->x_vibrate_clear=ExtXVibrateClear;
3784            temp_ptr->game_status=ExtGameStatus;
3785    
3786       memset ((void *)&ExtForceVec,0,sizeof(vms_vector));
3787       memset ((void *)&ExtApplyForceMatrix,0,sizeof(vms_matrix));
3788       
3789       for (i=0;i<3;i++)
3790                  ExtJoltInfo[i]=0;
3791       for (i=0;i<2;i++)
3792                  ExtXVibrateInfo[i]=0;
3793       ExtXVibrateClear=0;
3794      }
3795         }
3796
3797         if ( Automap_active )                   // (If in automap...)
3798                 kc_external_control->automap_state = 1;
3799         //memset(&r,0,sizeof(r));
3800
3801   #if 0
3802  
3803         int386 ( kc_external_intno, &r, &r);            // Read external info...
3804
3805   #endif 
3806
3807         if ( Player_num > -1 )  {
3808                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_TURNROLL);    // Turn off roll when turning
3809                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_LEVELLING);   // Turn off leveling to nearest side.
3810                 Auto_leveling_on = 0;
3811
3812                 if ( kc_external_version > 0 ) {                
3813                         vms_matrix tempm, ViewMatrix;
3814                         vms_angvec * Kconfig_abs_movement;
3815                         char * oem_message;
3816         
3817                         Kconfig_abs_movement = (vms_angvec *)((uint)kc_external_control + sizeof(ext_control_info));
3818         
3819                         if ( Kconfig_abs_movement->p || Kconfig_abs_movement->b || Kconfig_abs_movement->h )    {
3820                                 vm_angles_2_matrix(&tempm,Kconfig_abs_movement);
3821                                 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
3822                                 Objects[Players[Player_num].objnum].orient = ViewMatrix;                
3823                         }
3824                         oem_message = (char *)((uint)Kconfig_abs_movement + sizeof(vms_angvec));
3825                         if (oem_message[0] != '\0' )
3826                                 HUD_init_message( oem_message );
3827                 }
3828         }
3829
3830         Controls.pitch_time += fixmul(kc_external_control->pitch_time,FrameTime);                                               
3831         Controls.vertical_thrust_time += fixmul(kc_external_control->vertical_thrust_time,FrameTime);
3832         Controls.heading_time += fixmul(kc_external_control->heading_time,FrameTime);
3833         Controls.sideways_thrust_time += fixmul(kc_external_control->sideways_thrust_time ,FrameTime);
3834         Controls.bank_time += fixmul(kc_external_control->bank_time ,FrameTime);
3835         Controls.forward_thrust_time += fixmul(kc_external_control->forward_thrust_time ,FrameTime);
3836         Controls.rear_view_down_count += kc_external_control->rear_view_down_count;     
3837         Controls.rear_view_down_state |= kc_external_control->rear_view_down_state;     
3838         Controls.fire_primary_down_count += kc_external_control->fire_primary_down_count;
3839         Controls.fire_primary_state |= kc_external_control->fire_primary_state;
3840         Controls.fire_secondary_state |= kc_external_control->fire_secondary_state;
3841         Controls.fire_secondary_down_count += kc_external_control->fire_secondary_down_count;
3842         Controls.fire_flare_down_count += kc_external_control->fire_flare_down_count;
3843         Controls.drop_bomb_down_count += kc_external_control->drop_bomb_down_count;     
3844         Controls.automap_down_count += kc_external_control->automap_down_count;
3845         Controls.automap_state |= kc_external_control->automap_state;
3846         
3847    if (kc_external_version>=3)
3848          {
3849                 ubyte *temp_ptr = (ubyte *)kc_external_control;
3850                 temp_ptr += (sizeof(ext_control_info) + sizeof(vms_angvec) + 64 + sizeof(vms_vector) + sizeof (vms_matrix));
3851   
3852            if (*(temp_ptr))
3853                  Controls.cycle_primary_count=(*(temp_ptr));
3854            if (*(temp_ptr+1))
3855                  Controls.cycle_secondary_count=(*(temp_ptr+1));
3856
3857                 if (*(temp_ptr+2))
3858                  Controls.afterburner_state=(*(temp_ptr+2));
3859                 if (*(temp_ptr+3))
3860                  Controls.headlight_count=(*(temp_ptr+3));
3861          }
3862    if (kc_external_version>=4)
3863          {
3864      int i;
3865           advanced_ext_control_info *temp_ptr=(advanced_ext_control_info *)kc_external_control;
3866      
3867      for (i=0;i<128;i++)
3868            if (temp_ptr->keyboard[i])
3869                         key_putkey (i);
3870
3871      if (temp_ptr->Reactor_blown)
3872       {
3873        if (Game_mode & GM_MULTI)
3874                     net_destroy_controlcen (obj_find_first_of_type (OBJ_CNTRLCEN));
3875                  else
3876                          do_controlcen_destroyed_stuff(obj_find_first_of_type (OBJ_CNTRLCEN));
3877            }
3878     }
3879   
3880 }
3881 #endif
3882