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