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