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