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