]> icculus.org git repositories - btb/d2x.git/blob - main/kconfig.c
joy configuration next axis key from WraithX (d1x r1.10)
[btb/d2x.git] / main / kconfig.c
1 /* $Id: kconfig.c,v 1.29 2004-05-22 07:20:54 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.29 2004-05-22 07:20:54 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_next_joyaxis(kc_item *item);  //added by WraithX on 11/22/00
987 void kc_change_joyaxis( kc_item * item );
988 void kc_change_mouseaxis( kc_item * item );
989 void kc_change_invert( kc_item * item );
990 void kconfig_read_fcs( int raw_axis );
991 void kconfig_set_fcs_button( int btn, int button );
992 void kconfig_read_external_controls( void );
993
994 // the following methods added by WraithX, 4/17/00
995 int isJoyRotationKey(int test_key)
996 {
997         if (test_key == kc_joystick[11].value ||
998             test_key == kc_joystick[12].value)
999         {
1000                 return 1;
1001         }// end if
1002
1003         // else...
1004         return 0;
1005 }// method isJoyRotationKey
1006
1007 int isMouseRotationKey(int test_key)
1008 {
1009         if (test_key == kc_mouse[11].value ||
1010             test_key == kc_mouse[12].value)
1011         {
1012                 return 1;
1013         }// end if
1014
1015         // else...
1016         return 0;
1017 }// method isMouseRotationKey
1018
1019 int isKeyboardRotationKey(int test_key)
1020 {
1021         if (test_key == kc_keyboard[0].value ||
1022             test_key == kc_keyboard[1].value ||
1023             test_key == kc_keyboard[2].value ||
1024             test_key == kc_keyboard[3].value ||
1025             test_key == kc_keyboard[4].value ||
1026             test_key == kc_keyboard[5].value ||
1027             test_key == kc_keyboard[6].value ||
1028             test_key == kc_keyboard[7].value ||
1029             test_key == kc_keyboard[20].value ||
1030             test_key == kc_keyboard[21].value ||
1031             test_key == kc_keyboard[22].value ||
1032             test_key == kc_keyboard[23].value)
1033         {
1034                 return 1;
1035         }// end if
1036
1037         // else...
1038         return 0;
1039 }// method isKeyboardRotationKey
1040 // end addition - WraithX
1041
1042 int kconfig_is_axes_used(int axis)
1043 {
1044         int i;
1045         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1046                 if (( kc_joystick[i].type == BT_JOY_AXIS ) && (kc_joystick[i].value == axis ))
1047                         return 1;
1048         }
1049         return 0;
1050 }
1051
1052 #ifdef TABLE_CREATION
1053 int find_item_at( kc_item * items, int nitems, int x, int y )
1054 {
1055         int i;
1056         
1057         for (i=0; i<nitems; i++ )       {
1058                 if ( ((items[i].x+items[i].w1)==x) && (items[i].y==y))
1059                         return i;
1060         }
1061         return -1;
1062 }
1063
1064 int find_next_item_up( kc_item * items, int nitems, int citem )
1065 {
1066         int x, y, i;
1067
1068         y = items[citem].y;
1069         x = items[citem].x+items[citem].w1;
1070         
1071         do {    
1072                 y--;
1073                 if ( y < 0 ) {
1074                         y = grd_curcanv->cv_bitmap.bm_h-1;
1075                         x--;
1076                         if ( x < 0 ) {
1077                                 x = grd_curcanv->cv_bitmap.bm_w-1;
1078                         }
1079                 }
1080                 i = find_item_at( items, nitems, x, y );
1081         } while ( i < 0 );
1082         
1083         return i;
1084 }
1085
1086 int find_next_item_down( kc_item * items, int nitems, int citem )
1087 {
1088         int x, y, i;
1089
1090         y = items[citem].y;
1091         x = items[citem].x+items[citem].w1;
1092         
1093         do {    
1094                 y++;
1095                 if ( y > grd_curcanv->cv_bitmap.bm_h-1 ) {
1096                         y = 0;
1097                         x++;
1098                         if ( x > grd_curcanv->cv_bitmap.bm_w-1 ) {
1099                                 x = 0;
1100                         }
1101                 }
1102                 i = find_item_at( items, nitems, x, y );
1103         } while ( i < 0 );
1104         
1105         return i;
1106 }
1107
1108 int find_next_item_right( kc_item * items, int nitems, int citem )
1109 {
1110         int x, y, i;
1111
1112         y = items[citem].y;
1113         x = items[citem].x+items[citem].w1;
1114         
1115         do {    
1116                 x++;
1117                 if ( x > grd_curcanv->cv_bitmap.bm_w-1 ) {
1118                         x = 0;
1119                         y++;
1120                         if ( y > grd_curcanv->cv_bitmap.bm_h-1 ) {
1121                                 y = 0;
1122                         }
1123                 }
1124                 i = find_item_at( items, nitems, x, y );
1125         } while ( i < 0 );
1126         
1127         return i;
1128 }
1129
1130 int find_next_item_left( kc_item * items, int nitems, int citem )
1131 {
1132         int x, y, i;
1133
1134         y = items[citem].y;
1135         x = items[citem].x+items[citem].w1;
1136         
1137         do {    
1138                 x--;
1139                 if ( x < 0 ) {
1140                         x = grd_curcanv->cv_bitmap.bm_w-1;
1141                         y--;
1142                         if ( y < 0 ) {
1143                                 y = grd_curcanv->cv_bitmap.bm_h-1;
1144                         }
1145                 }
1146                 i = find_item_at( items, nitems, x, y );
1147         } while ( i < 0 );
1148         
1149         return i;
1150 }
1151 #endif
1152
1153 #ifdef NEWMENU_MOUSE
1154 int get_item_height(kc_item *item)
1155 {
1156         int w, h, aw;
1157         char btext[10];
1158
1159         if (item->value==255) {
1160                 strcpy(btext, "");
1161         } else {
1162                 switch( item->type )    {
1163                         case BT_KEY:
1164                                 strncpy( btext, key_text[item->value], 10 ); break;
1165                         case BT_MOUSE_BUTTON:
1166 #ifndef MACINTOSH
1167                                 strncpy( btext, Text_string[mousebutton_text[item->value]], 10); break;
1168 #else
1169                                 strncpy( btext, mousebutton_text[item->value], 10 ); break;
1170 #endif
1171                         case BT_MOUSE_AXIS:
1172                                 strncpy( btext, Text_string[mouseaxis_text[item->value]], 10 ); break;
1173                         case BT_JOY_BUTTON:
1174 #ifdef USE_LINUX_JOY
1175                                 sprintf(btext, "J%d B%d", j_button[item->value].joydev, j_Get_joydev_button_number(item->value));
1176 #else
1177                                 if ( joybutton_text[item->value] !=-1 )
1178                                         strncpy( btext, Text_string[ joybutton_text[item->value]  ], 10 );
1179                                 else
1180                                         sprintf( btext, "BTN%d", item->value );
1181 #endif
1182                                 break;
1183                         case BT_JOY_AXIS:
1184 #ifdef USE_LINUX_JOY
1185                                 sprintf( btext, "J%d A%d", j_axis[item->value].joydev, j_Get_joydev_axis_number (item->value) );
1186 #else
1187                                 strncpy(btext, Text_string[joyaxis_text[item->value]], 10);
1188 #endif
1189                                 break;
1190                         case BT_INVERT:
1191                                 strncpy( btext, Text_string[invert_text[item->value]], 10 ); break;
1192                 }
1193         }
1194         gr_get_string_size(btext, &w, &h, &aw  );
1195
1196         return h;
1197 }
1198 #endif
1199
1200 void kconfig_sub(kc_item * items,int nitems, char * title)
1201 {
1202 WINDOS(
1203         dd_grs_canvas * save_canvas,
1204         grs_canvas * save_canvas
1205 );
1206         grs_font * save_font;
1207         int old_keyd_repeat;
1208 #ifdef NEWMENU_MOUSE
1209         int mouse_state, omouse_state, mx, my, x1, x2, y1, y2;
1210         int close_x, close_y, close_size;
1211 #endif
1212
1213         int i,k,ocitem,citem;
1214         int time_stopped = 0;
1215 WIN(char *old_bg_pcx);
1216
1217 WIN(old_bg_pcx = _SCRContext.bkg_filename);
1218 WIN(DEFINE_SCREEN(NULL));
1219
1220         All_items = items;
1221         Num_items = nitems;
1222
1223         if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
1224         {
1225                 time_stopped = 1;
1226                 stop_time();
1227         }
1228
1229 //      if (Config_control_type == CONTROL_WINJOYSTICK) {
1230 //              WINDOS(
1231 //                      joydefsw_win_joyselect(title2); title = title2,
1232 //                      Int3()
1233 //              );                                                                                              // Get Samir...
1234 //      }
1235
1236 WINDOS(
1237         save_canvas = dd_grd_curcanv,
1238         save_canvas = grd_curcanv
1239 );
1240
1241
1242 WINDOS(
1243         dd_gr_set_current_canvas(NULL),
1244         gr_set_current_canvas(NULL)
1245 );              
1246         save_font = grd_curcanv->cv_font;
1247
1248 #ifdef WINDOWS
1249 KConfigPaint:
1250 #endif
1251         game_flush_inputs();
1252         old_keyd_repeat = keyd_repeat;
1253         keyd_repeat = 1;
1254
1255         //gr_clear_canvas( BM_XRGB(0,0,0) );
1256
1257         nm_draw_background(0, 0, grd_curcanv->cv_bitmap.bm_w - 1, grd_curcanv->cv_bitmap.bm_h - 1);
1258    gr_palette_load (gr_palette);
1259
1260         grd_curcanv->cv_font = MEDIUM3_FONT;
1261
1262 WIN(DDGRLOCK(dd_grd_curcanv));  
1263         {
1264                 char * p;
1265                 p = strchr( title, '\n' );
1266                 if ( p ) *p = 32;
1267                 gr_string( 0x8000, LHY(8), title );
1268                 if ( p ) *p = '\n';
1269         }
1270
1271
1272 //      if ( items == kc_keyboard )     {
1273 //              gr_string( 0x8000, 8, "Keyboard" );
1274 //      } else if ( items == kc_joystick )      {
1275 //              gr_string( 0x8000, 8, "Joysticks" );
1276 //      } else if ( items == kc_mouse ) {
1277 //              gr_string( 0x8000, 8, "Mouse" );
1278 //      }
1279
1280 #ifdef NEWMENU_MOUSE
1281         close_x = close_y = MenuHires?15:7;
1282         close_size = MenuHires?10:5;
1283         gr_setcolor( BM_XRGB(0, 0, 0) );
1284         gr_rect(close_x, close_y, close_x + close_size, close_y + close_size);
1285         gr_setcolor( BM_XRGB(21, 21, 21) );
1286         gr_rect(close_x + LHX(1), close_y + LHX(1), close_x + close_size - LHX(1), close_y + close_size - LHX(1));
1287 #endif
1288
1289         grd_curcanv->cv_font = GAME_FONT;
1290         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1291
1292         #ifndef MACINTOSH
1293         gr_string( 0x8000, LHY(20), TXT_KCONFIG_STRING_1 );
1294         #else
1295         gr_string( 0x8000, LHY(20), "Enter changes, ctrl-d deletes, ctrl-r resets defaults, ESC exits");
1296         #endif
1297         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1298         if ( items == kc_keyboard )     {
1299                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
1300                 gr_setcolor( BM_XRGB(31,27,6) );
1301                 
1302                 gr_scanline( LHX(98), LHX(106), LHY(42) );
1303                 gr_scanline( LHX(120), LHX(128), LHY(42) );
1304                 gr_pixel( LHX(98), LHY(43) );                                           
1305                 gr_pixel( LHX(98), LHY(44) );                                           
1306                 gr_pixel( LHX(128), LHY(43) );                                          
1307                 gr_pixel( LHX(128), LHY(44) );                                          
1308                 
1309                 gr_string( LHX(109), LHY(40), "OR" );
1310
1311                 gr_scanline( LHX(253), LHX(261), LHY(42) );
1312                 gr_scanline( LHX(274), LHX(283), LHY(42) );
1313                 gr_pixel( LHX(253), LHY(43) );                                          
1314                 gr_pixel( LHX(253), LHY(44) );                                          
1315                 gr_pixel( LHX(283), LHY(43) );                                          
1316                 gr_pixel( LHX(283), LHY(44) );                                          
1317
1318                 gr_string( LHX(264), LHY(40), "OR" );
1319
1320         } if ( items == kc_joystick )   {
1321                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
1322                 gr_setcolor( BM_XRGB(31,27,6) );
1323                 gr_scanline( LHX(18), LHX(135), LHY(37) );
1324                 gr_scanline( LHX(181), LHX(294), LHY(37) );
1325                 gr_scanline( LHX(18), LHX(144), LHY(119+18) );
1326                 gr_scanline( LHX(174), LHX(294), LHY(119+18) );
1327                 gr_string( 0x8000, LHY(35), TXT_BUTTONS );
1328                 gr_string( 0x8000,LHY(117+18), TXT_AXES );
1329                 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1330                 gr_string( LHX(81), LHY(137+8), TXT_AXIS );
1331                 gr_string( LHX(111), LHY(137+8), TXT_INVERT );
1332                 gr_string( LHX(222), LHY(137+8), TXT_AXIS );
1333                 gr_string( LHX(252), LHY(137+8), TXT_INVERT );
1334         } else if ( items == kc_mouse ) {
1335                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
1336                 gr_setcolor( BM_XRGB(31,27,6) );
1337                 gr_scanline( LHX(18), LHX(135), LHY(37) );
1338                 gr_scanline( LHX(181), LHX(294), LHY(37) );
1339                 gr_scanline( LHX(18), LHX(144), LHY(119+5) );
1340                 gr_scanline( LHX(174), LHX(294), LHY(119+5) );
1341                 gr_string( 0x8000, LHY(35), TXT_BUTTONS );
1342                 gr_string( 0x8000,LHY(117+5), TXT_AXES );
1343                 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1344                 gr_string( LHX(169), LHY(129), TXT_AXIS );
1345                 gr_string( LHX(199), LHY(129), TXT_INVERT );
1346         }
1347 #ifdef D2X_KEYS
1348         else if ( items == kc_d2x )
1349         {
1350                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
1351                 gr_setcolor( BM_XRGB(31,27,6) );
1352
1353                 gr_string(LHX( 94), LHY(40), "KB");
1354                 gr_string(LHX(121), LHY(40), "JOY");
1355         }
1356 #endif
1357
1358 WIN(DDGRUNLOCK(dd_grd_curcanv));        
1359
1360         for (i=0; i<nitems; i++ )       {
1361                 kc_drawitem( &items[i], 0 );
1362         }
1363
1364         citem = 0;
1365         kc_drawitem( &items[citem], 1 );
1366
1367         newmenu_show_cursor();
1368
1369 #ifdef NEWMENU_MOUSE
1370         mouse_state = omouse_state = 0;
1371 #endif
1372
1373         while(1)                {
1374         //      Windows addendum to allow for kconfig input.
1375         #ifdef WINDOWS
1376                 {
1377                         MSG msg;
1378
1379                         DoMessageStuff(&msg);
1380
1381                         if (_RedrawScreen) {
1382                                 _RedrawScreen = FALSE;
1383
1384                                 dd_gr_set_current_canvas(NULL); 
1385
1386                                 goto KConfigPaint;
1387                         }
1388
1389                         DDGRRESTORE;
1390                 }
1391         #endif
1392                 gr_update();
1393
1394                 //see if redbook song needs to be restarted
1395                 songs_check_redbook_repeat();
1396
1397                 k = key_inkey();
1398
1399 #ifdef NEWMENU_MOUSE
1400                 omouse_state = mouse_state;
1401                 mouse_state = mouse_button_state(0);
1402 #endif
1403
1404                 if ( !time_stopped ) {
1405                         #ifdef NETWORK
1406                         if (multi_menu_poll() == -1)
1407                                 k = -2;
1408                         #endif
1409                 }
1410                 ocitem = citem;
1411                 switch( k )     {
1412                 case KEY_BACKSP:
1413                         Int3();
1414                         break;
1415                 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1416                 case KEY_PRINT_SCREEN:
1417                         save_screen_shot(0);
1418                         break;                                                  
1419                 case KEY_CTRLED+KEY_D:
1420                         items[citem].value = 255;
1421                         kc_drawitem( &items[citem], 1 );
1422                         break;
1423                 case KEY_CTRLED+KEY_R:  
1424                         if ( items==kc_keyboard )       {
1425                                 for (i=0; i<NUM_KEY_CONTROLS; i++ )             {
1426                                         items[i].value=default_kconfig_settings[0][i];
1427                                         kc_drawitem( &items[i], 0 );
1428                                 }
1429 #ifdef D2X_KEYS
1430                         } else if ( items==kc_d2x ) {
1431                                 for(i=0;i<NUM_D2X_CONTROLS;i++)
1432                                 {
1433                                         items[i].value=default_kconfig_d2x_settings[i];
1434                                         kc_drawitem( &items[i], 0 );
1435                                 }
1436 #endif
1437                         } else {
1438                                 #ifdef MACINTOSH
1439                           // hack for firebire and mousestick default controls since I made
1440                           // them the same control type -- dumb dumb dumb
1441                                 if (joy_have_firebird())
1442                                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1443                                                 items[i].value = default_firebird_settings[i];
1444                                                 kc_drawitem( &items[i], 0 );
1445                                         }
1446                                 else if (joy_have_mousestick())
1447                                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1448                                                 items[i].value = default_mousestick_settings[i];
1449                                                 kc_drawitem( &items[i], 0 );
1450                                         }
1451                                 else
1452                                 #endif  // note link to above else
1453                                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1454                                                 items[i].value = default_kconfig_settings[Config_control_type][i];
1455                                                 kc_drawitem( &items[i], 0 );
1456                                         }
1457                         }
1458                         kc_drawitem( &items[citem], 1 );
1459                         break;
1460                 case KEY_DELETE:
1461                         items[citem].value=255;
1462                         kc_drawitem( &items[citem], 1 );
1463                         break;
1464                 case KEY_UP:            
1465                 case KEY_PAD8:
1466 #ifdef TABLE_CREATION
1467                         if (items[citem].u==-1) items[citem].u=find_next_item_up( items,nitems, citem);
1468 #endif
1469                         citem = items[citem].u; 
1470                         break;
1471                 
1472                 case KEY_DOWN:  
1473                 case KEY_PAD2:
1474 #ifdef TABLE_CREATION
1475                         if (items[citem].d==-1) items[citem].d=find_next_item_down( items,nitems, citem);
1476 #endif
1477                         citem = items[citem].d; 
1478                         break;
1479                 case KEY_LEFT:  
1480                 case KEY_PAD4:
1481 #ifdef TABLE_CREATION
1482                         if (items[citem].l==-1) items[citem].l=find_next_item_left( items,nitems, citem);
1483 #endif
1484                         citem = items[citem].l; 
1485                         break;
1486                 case KEY_RIGHT:         
1487                 case KEY_PAD6:
1488 #ifdef TABLE_CREATION
1489                         if (items[citem].r==-1) items[citem].r=find_next_item_right( items,nitems, citem);
1490 #endif
1491                         citem = items[citem].r; 
1492                         break;
1493                 case KEY_ENTER: 
1494                 case KEY_PADENTER:      
1495                         switch( items[citem].type )     {
1496                         case BT_KEY:            kc_change_key( &items[citem] ); break;
1497                         case BT_MOUSE_BUTTON:   kc_change_mousebutton( &items[citem] ); break;
1498                         case BT_MOUSE_AXIS:     kc_change_mouseaxis( &items[citem] ); break;
1499                         case BT_JOY_BUTTON:     kc_change_joybutton( &items[citem] ); break;
1500                         case BT_JOY_AXIS:       kc_change_joyaxis( &items[citem] ); break;
1501                         case BT_INVERT:         kc_change_invert( &items[citem] ); break;
1502                         }
1503                         break;
1504                 //the following case added by WraithX on 11/22/00 to work around the weird joystick bug...
1505                 case KEY_SPACEBAR:
1506                         switch(items[citem].type)
1507                         {
1508                         case BT_JOY_AXIS:
1509                                 kc_next_joyaxis(&items[citem]);
1510                                 break;
1511                         }
1512                         break;
1513                 //end addition by WraithX
1514                 case -2:        
1515                 case KEY_ESC:
1516                         grd_curcanv->cv_font    = save_font;
1517
1518                 WIN(DEFINE_SCREEN(old_bg_pcx));
1519
1520                 WINDOS(
1521                         dd_gr_set_current_canvas(save_canvas),
1522                         gr_set_current_canvas( save_canvas )
1523                 );                      
1524                         keyd_repeat = old_keyd_repeat;
1525                         game_flush_inputs();
1526                         newmenu_hide_cursor();
1527                         if (time_stopped)
1528                                 start_time();
1529                         return;
1530 #ifdef TABLE_CREATION
1531                 case KEY_DEBUGGED+KEY_F12:      {
1532                         FILE * fp;
1533                         for (i=0; i<NUM_KEY_CONTROLS; i++ )     {
1534                                 kc_keyboard[i].u = find_next_item_up( kc_keyboard,NUM_KEY_CONTROLS, i);
1535                                 kc_keyboard[i].d = find_next_item_down( kc_keyboard,NUM_KEY_CONTROLS, i);
1536                                 kc_keyboard[i].l = find_next_item_left( kc_keyboard,NUM_KEY_CONTROLS, i);
1537                                 kc_keyboard[i].r = find_next_item_right( kc_keyboard,NUM_KEY_CONTROLS, i);
1538                         }
1539                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1540                                 kc_joystick[i].u = find_next_item_up( kc_joystick,NUM_OTHER_CONTROLS, i);
1541                                 kc_joystick[i].d = find_next_item_down( kc_joystick,NUM_OTHER_CONTROLS, i);
1542                                 kc_joystick[i].l = find_next_item_left( kc_joystick,NUM_OTHER_CONTROLS, i);
1543                                 kc_joystick[i].r = find_next_item_right( kc_joystick,NUM_OTHER_CONTROLS, i);
1544                         }
1545                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1546                                 kc_mouse[i].u = find_next_item_up( kc_mouse,NUM_OTHER_CONTROLS, i);
1547                                 kc_mouse[i].d = find_next_item_down( kc_mouse,NUM_OTHER_CONTROLS, i);
1548                                 kc_mouse[i].l = find_next_item_left( kc_mouse,NUM_OTHER_CONTROLS, i);
1549                                 kc_mouse[i].r = find_next_item_right( kc_mouse,NUM_OTHER_CONTROLS, i);
1550                         }
1551                         fp = fopen( "kconfig.cod", "wt" );
1552
1553                         fprintf( fp, "ubyte default_kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS] = {\n" );
1554                         for (i=0; i<CONTROL_MAX_TYPES; i++ )    {
1555                                 int j;
1556                                 fprintf( fp, "{0x%x", kconfig_settings[i][0] );
1557                                 for (j=1; j<MAX_CONTROLS; j++ )
1558                                         fprintf( fp, ",0x%x", kconfig_settings[i][j] );
1559                                 fprintf( fp, "},\n" );
1560                         }
1561                         fprintf( fp, "};\n" );
1562                 
1563                         fprintf( fp, "\nkc_item kc_keyboard[NUM_KEY_CONTROLS] = {\n" );
1564                         for (i=0; i<NUM_KEY_CONTROLS; i++ )     {
1565                                 fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
1566                                         kc_keyboard[i].id, kc_keyboard[i].x, kc_keyboard[i].y, kc_keyboard[i].w1, kc_keyboard[i].w2,
1567                                         kc_keyboard[i].u, kc_keyboard[i].d, kc_keyboard[i].l, kc_keyboard[i].r,
1568                                         34, kc_keyboard[i].text, 34, btype_text[kc_keyboard[i].type] );
1569                         }
1570                         fprintf( fp, "};" );
1571
1572                         fprintf( fp, "\nkc_item kc_joystick[NUM_OTHER_CONTROLS] = {\n" );
1573                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1574                                 if (kc_joystick[i].type == BT_JOY_BUTTON)
1575                                         fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
1576                                                 kc_joystick[i].id, kc_joystick[i].x, kc_joystick[i].y, kc_joystick[i].w1, kc_joystick[i].w2,
1577                                                 kc_joystick[i].u, kc_joystick[i].d, kc_joystick[i].l, kc_joystick[i].r,
1578                                                 34, kc_joystick[i].text, 34, btype_text[kc_joystick[i].type] );
1579                 else
1580                                         fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
1581                                                 kc_joystick[i].id, kc_joystick[i].x, kc_joystick[i].y, kc_joystick[i].w1, kc_joystick[i].w2,
1582                                                 kc_joystick[i].u, kc_joystick[i].d, kc_joystick[i].l, kc_joystick[i].r,
1583                                                 34, kc_joystick[i].text, 34, btype_text[kc_joystick[i].type] );
1584                         }
1585                         fprintf( fp, "};" );
1586
1587                         fprintf( fp, "\nkc_item kc_mouse[NUM_OTHER_CONTROLS] = {\n" );
1588                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1589                                 fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
1590                                         kc_mouse[i].id, kc_mouse[i].x, kc_mouse[i].y, kc_mouse[i].w1, kc_mouse[i].w2,
1591                                         kc_mouse[i].u, kc_mouse[i].d, kc_mouse[i].l, kc_mouse[i].r,
1592                                         34, kc_mouse[i].text, 34, btype_text[kc_mouse[i].type] );
1593                         }
1594                         fprintf( fp, "};" );
1595
1596                         fclose(fp);
1597
1598                         }
1599                         break;
1600 #endif
1601                 }
1602
1603 #ifdef NEWMENU_MOUSE
1604                 if ( (mouse_state && !omouse_state) || (mouse_state && omouse_state) ) {
1605                         int item_height;
1606                         
1607                         mouse_get_pos(&mx, &my);
1608                         for (i=0; i<nitems; i++ )       {
1609                                 item_height = get_item_height( &items[i] );
1610                                 x1 = grd_curcanv->cv_bitmap.bm_x + LHX(items[i].x) + LHX(items[i].w1);
1611                                 x2 = x1 + LHX(items[i].w2);
1612                                 y1 = grd_curcanv->cv_bitmap.bm_y + LHY(items[i].y);
1613                                 y2 = y1 + LHX(item_height);
1614                                 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1615                                         citem = i;
1616                                         break;
1617                                 }
1618                         }
1619                 }
1620                 else if ( !mouse_state && omouse_state ) {
1621                         int item_height;
1622                         
1623                         mouse_get_pos(&mx, &my);
1624                         item_height = get_item_height( &items[citem] );
1625                         x1 = grd_curcanv->cv_bitmap.bm_x + LHX(items[citem].x) + LHX(items[citem].w1);
1626                         x2 = x1 + LHX(items[citem].w2);
1627                         y1 = grd_curcanv->cv_bitmap.bm_y + LHY(items[citem].y);
1628                         y2 = y1 + LHY(item_height);
1629                         if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1630                                 newmenu_hide_cursor();
1631                                 switch( items[citem].type )     {
1632                                 case BT_KEY:                            kc_change_key( &items[citem] ); break;
1633                                 case BT_MOUSE_BUTTON:   kc_change_mousebutton( &items[citem] ); break;
1634                                 case BT_MOUSE_AXIS:             kc_change_mouseaxis( &items[citem] ); break;
1635                                 case BT_JOY_BUTTON:             kc_change_joybutton( &items[citem] ); break;
1636                                 case BT_JOY_AXIS:               kc_change_joyaxis( &items[citem] ); break;
1637                                 case BT_INVERT:                         kc_change_invert( &items[citem] ); break;
1638                                 }
1639                                 newmenu_show_cursor();
1640                         } else {
1641                                 x1 = grd_curcanv->cv_bitmap.bm_x + close_x + LHX(1);
1642                                 x2 = x1 + close_size - LHX(1);
1643                                 y1 = grd_curcanv->cv_bitmap.bm_y + close_y + LHX(1);
1644                                 y2 = y1 + close_size - LHX(1);
1645                                 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1646                                         grd_curcanv->cv_font    = save_font;
1647                                         WINDOS(dd_gr_set_current_canvas( save_canvas ),
1648                                                         gr_set_current_canvas( save_canvas ));
1649                                         keyd_repeat = old_keyd_repeat;
1650                                         game_flush_inputs();
1651                                         newmenu_hide_cursor();
1652                                         if (time_stopped)
1653                                                 start_time();
1654                                         return;
1655                                 }
1656                         }
1657
1658                 }
1659 #endif // NEWMENU_MOUSE
1660
1661                 if (ocitem!=citem)      {
1662                         newmenu_hide_cursor();
1663                         kc_drawitem( &items[ocitem], 0 );
1664                         kc_drawitem( &items[citem], 1 );
1665                         newmenu_show_cursor();
1666                 }
1667         }
1668 }
1669
1670
1671 void kc_drawitem( kc_item *item, int is_current )
1672 {
1673         int x, w, h, aw;
1674         char btext[16];
1675 //      PA_DFX (pa_set_frontbuffer_current());
1676 WIN(DDGRLOCK(dd_grd_curcanv));
1677
1678         if (is_current)
1679                 gr_set_fontcolor( BM_XRGB(20,20,29), -1 );
1680         else
1681                 gr_set_fontcolor( BM_XRGB(15,15,24), -1 );
1682    gr_string( LHX(item->x), LHY(item->y), item->text );
1683 WIN(DDGRUNLOCK(dd_grd_curcanv));
1684
1685         if (item->value==255) {
1686                 strcpy( btext, "" );
1687         } else {
1688                 switch( item->type )    {
1689                         case BT_KEY:
1690                                 strncpy( btext, key_text[item->value], 10 ); break;
1691                         case BT_MOUSE_BUTTON:
1692                                 #ifndef MACINTOSH
1693                                 //strncpy( btext, Text_string[mousebutton_text[item->value]], 10 ); break;
1694                                 strncpy( btext, (item->value <= 3)?Text_string[mousebutton_text[item->value]]:mousebutton_textra[item->value-3], 10 ); break;
1695                                 #else
1696                                 strncpy( btext, mousebutton_text[item->value], 10 ); break;
1697                                 #endif
1698                         case BT_MOUSE_AXIS:
1699                                 strncpy( btext, Text_string[mouseaxis_text[item->value]], 10 ); break;
1700                         case BT_JOY_BUTTON:
1701 #ifdef USE_LINUX_JOY
1702                                 sprintf(btext, "J%d B%d", j_button[item->value].joydev, j_Get_joydev_button_number(item->value));
1703 #else
1704 # ifndef MACINTOSH
1705 #  ifdef WINDOWS
1706                                 if (joybutton_text[item->value] != -1) 
1707                                         strncpy( btext, Text_string[ joybutton_text[item->value]  ], 10 );
1708                                 else 
1709                                         sprintf( btext, "BTN%2d", item->value+1 );
1710 #  else
1711                                 if ( joybutton_text[item->value] !=-1 )
1712                                         strncpy( btext, Text_string[ joybutton_text[item->value]  ], 10 );
1713                                 else
1714                                         sprintf( btext, "BTN%d", item->value );
1715 #  endif
1716 # else
1717                                 strncpy( btext, joy_btn_name( item->value ), 10);
1718                                 if (btext == NULL)
1719                                         sprintf( btext, "BTN%d", item->value );
1720 # endif
1721 #endif
1722                                 break;
1723                         case BT_JOY_AXIS:
1724 #ifdef USE_LINUX_JOY
1725                                 sprintf(btext, "J%d A%d", j_axis[item->value].joydev, j_Get_joydev_axis_number(item->value));
1726 #else
1727                                 strncpy(btext, Text_string[joyaxis_text[item->value]], 10);
1728 #endif
1729                                 break;
1730                         case BT_INVERT:
1731                                 strncpy( btext, Text_string[invert_text[item->value]], 10 ); break;
1732                 }
1733         }
1734         if (item->w1) {
1735         WIN(DDGRLOCK(dd_grd_curcanv));
1736                 gr_get_string_size(btext, &w, &h, &aw  );
1737
1738                 if (is_current)
1739                         gr_setcolor( BM_XRGB(21,0,24) );
1740                 else
1741                         gr_setcolor( BM_XRGB(16,0,19) );
1742                 gr_urect( LHX(item->w1+item->x), LHY(item->y-1), LHX(item->w1+item->x+item->w2), LHY(item->y)+h );
1743                 
1744                 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1745
1746                 x = LHX(item->w1+item->x)+((LHX(item->w2)-w)/2);
1747         
1748                 gr_string( x, LHY(item->y), btext );
1749 //              PA_DFX (pa_set_backbuffer_current());
1750
1751         WIN(DDGRUNLOCK(dd_grd_curcanv));
1752         }
1753 }
1754
1755
1756 static int looper=0;
1757
1758 void kc_drawquestion( kc_item *item )
1759 {
1760         int c, x, w, h, aw;
1761
1762 WIN(DDGRLOCK(dd_grd_curcanv));  
1763   // PA_DFX (pa_set_frontbuffer_current());
1764
1765         gr_get_string_size("?", &w, &h, &aw  );
1766
1767         c = BM_XRGB(21,0,24);
1768
1769         //@@gr_setcolor( gr_fade_table[fades[looper]*256+c] );
1770         gr_setcolor(BM_XRGB(21*fades[looper]/31,0,24*fades[looper]/31));
1771         looper++;
1772         if (looper>63) looper=0;
1773
1774         gr_urect( LHX(item->w1+item->x), LHY(item->y-1), LHX(item->w1+item->x+item->w2), LHY(item->y)+h );
1775         
1776         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1777
1778         x = LHX(item->w1+item->x)+((LHX(item->w2)-w)/2);
1779    
1780         gr_string( x, LHY(item->y), "?" );
1781 //      PA_DFX (pa_set_backbuffer_current());
1782 WIN(DDGRUNLOCK(dd_grd_curcanv));
1783 gr_update();
1784 }
1785
1786 void kc_change_key( kc_item * item )
1787 {
1788         int i,n,f,k;
1789         ubyte keycode;
1790
1791 WIN(DDGRLOCK(dd_grd_curcanv));
1792         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1793         
1794         gr_string( 0x8000, LHY(INFO_Y), TXT_PRESS_NEW_KEY );
1795 WIN(DDGRUNLOCK(dd_grd_curcanv));        
1796
1797         game_flush_inputs();
1798         keycode=255;
1799         k=255;
1800         
1801         while( (k!=KEY_ESC) && (keycode==255) ) 
1802         {                               
1803         #ifdef WINDOWS
1804                 {
1805                         MSG msg;
1806
1807                         DoMessageStuff(&msg);
1808                         DDGRRESTORE;
1809                 
1810                 }
1811         #endif
1812
1813                 #ifdef NETWORK
1814                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1815                         multi_menu_poll();
1816                 #endif
1817 //              if ( Game_mode & GM_MULTI )
1818 //                      GameLoop( 0, 0 );                               // Continue
1819                 k = key_inkey();
1820                 timer_delay(f0_1/10);
1821                 kc_drawquestion( item );
1822         
1823                 for (i=0; i<256; i++ )  {
1824                         if (keyd_pressed[i] && (strlen(key_text[i])>0)) {
1825                                 f = 0;
1826                                 for (n=0; n<sizeof(system_keys); n++ )
1827                                         if ( system_keys[n] == i )
1828                                                 f=1;
1829                                 if (!f) 
1830                                         keycode=i;
1831                         }
1832                 }
1833         }
1834
1835         if (k!=KEY_ESC) {
1836                 for (i=0; i<Num_items; i++ )    {
1837                         n = item - All_items;
1838                         if ( (i!=n) && (All_items[i].type==BT_KEY) && (All_items[i].value==keycode) )           {
1839                                 All_items[i].value = 255;
1840                                 kc_drawitem( &All_items[i], 0 );
1841                         }
1842                 }
1843                 item->value = keycode;
1844         }
1845         kc_drawitem( item, 1 );
1846
1847 WIN(DDGRLOCK(dd_grd_curcanv));
1848         gr_set_fontcolor( BM_XRGB(28,28,28), BM_XRGB(0,0,0) );
1849 WIN(DDGRUNLOCK(dd_grd_curcanv));
1850
1851         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1852
1853         game_flush_inputs();
1854
1855 }
1856
1857 void kc_change_joybutton( kc_item * item )
1858 {
1859         int n,i,k;
1860         ubyte code;
1861
1862 WIN(DDGRLOCK(dd_grd_curcanv));
1863         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1864         
1865         gr_string( 0x8000, LHY(INFO_Y), TXT_PRESS_NEW_JBUTTON );
1866 WIN(DDGRUNLOCK(dd_grd_curcanv));        
1867
1868         game_flush_inputs();
1869         code=255;
1870         k=255;
1871         
1872         while( (k!=KEY_ESC) && (code==255))     
1873         {                               
1874         #ifdef WINDOWS
1875                 {
1876                         MSG msg;
1877                         DoMessageStuff(&msg);
1878                         DDGRRESTORE;
1879                 }
1880         #endif
1881
1882                 #ifdef NETWORK
1883                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1884                         multi_menu_poll();
1885                 #endif
1886 //              if ( Game_mode & GM_MULTI )
1887 //                      GameLoop( 0, 0 );                               // Continue
1888                 k = key_inkey();
1889                 timer_delay(f0_1/10);
1890
1891                 if (k == KEY_PRINT_SCREEN)
1892                         save_screen_shot(0);
1893
1894                 kc_drawquestion( item );
1895
1896                 WIN(code = joydefsw_do_button());
1897                 
1898 #ifdef MACINTOSH
1899                 code = joy_do_buttons();
1900 #endif
1901                 
1902 #if !defined(WINDOWS) && !defined(MACINTOSH)
1903                 if (Config_control_type==CONTROL_THRUSTMASTER_FCS)      {
1904                         int axis[4];
1905                         joystick_read_raw_axis( JOY_ALL_AXIS, axis );
1906                         kconfig_read_fcs( axis[3] );
1907                         if ( joy_get_button_state(7) ) code = 7;
1908                         if ( joy_get_button_state(11) ) code = 11;
1909                         if ( joy_get_button_state(15) ) code = 15;
1910                         if ( joy_get_button_state(19) ) code = 19;
1911                         for (i=0; i<4; i++ )    {
1912                                 if ( joy_get_button_state(i) )
1913                                         code = i;
1914                         }
1915                 } else if (Config_control_type==CONTROL_FLIGHTSTICK_PRO) {
1916                         for (i=4; i<20; i++ )   {
1917                                 if ( joy_get_button_state(i)  ) {
1918                                         code = i;
1919                                         mprintf(( 0, "JB: %d\n", code ));
1920                                 }
1921                         }
1922                 } else {
1923                         for (i=0; i<MAX_BUTTONS; i++ )  {
1924                                 if ( joy_get_button_state(i) )
1925                                         code = i;
1926                         }
1927                 }
1928 #endif
1929         }
1930         if (code!=255)  {
1931                 for (i=0; i<Num_items; i++ )    {
1932                         n = item - All_items;
1933                         if ( (i!=n) && (All_items[i].type==BT_JOY_BUTTON) && (All_items[i].value==code) ) {
1934                                 All_items[i].value = 255;
1935                                 kc_drawitem( &All_items[i], 0 );
1936                         }
1937                 }
1938                 item->value = code;
1939         }
1940         kc_drawitem( item, 1 );
1941         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1942         game_flush_inputs();
1943 }
1944
1945 void kc_change_mousebutton( kc_item * item )
1946 {
1947         int n,i,b,k;
1948         ubyte code;
1949
1950 WIN(DDGRLOCK(dd_grd_curcanv));
1951         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1952         
1953         gr_string( 0x8000, LHY(INFO_Y), TXT_PRESS_NEW_MBUTTON );
1954 WIN(DDGRUNLOCK(dd_grd_curcanv));        
1955
1956
1957         game_flush_inputs();
1958         code=255;
1959         k=255;
1960         
1961         while( (k!=KEY_ESC) && (code==255))     
1962         {                               
1963         #ifdef WINDOWS
1964                 {
1965                         MSG msg;
1966                         DoMessageStuff(&msg);
1967                         DDGRRESTORE;
1968                 }
1969         #endif
1970
1971                 #ifdef NETWORK
1972                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1973                         multi_menu_poll();
1974                 #endif
1975 //              if ( Game_mode & GM_MULTI )
1976 //                      GameLoop( 0, 0 );                               // Continue
1977                 k = key_inkey();
1978                 timer_delay(f0_1/10);
1979
1980                 if (k == KEY_PRINT_SCREEN)
1981                         save_screen_shot(0);
1982
1983                 kc_drawquestion( item );
1984
1985                 b = mouse_get_btns();
1986                 for (i = 0; i < 16; i++ ) {
1987                         if ( b & (1<<i) )       
1988                                 code = i;
1989                 }
1990         }
1991         if (code!=255)  {
1992                 for (i=0; i<Num_items; i++ )    {
1993                         n = item - All_items;
1994                         if ( (i!=n) && (All_items[i].type==BT_MOUSE_BUTTON) && (All_items[i].value==code) )             {
1995                                 All_items[i].value = 255;
1996                                 kc_drawitem( &All_items[i], 0 );
1997                         }
1998                 }
1999                 item->value = code;
2000         }
2001         kc_drawitem( item, 1 );
2002         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
2003         game_flush_inputs();
2004
2005 }
2006
2007
2008 // the following function added by WraithX on 11/22/00 to work around the weird joystick bug...
2009 void kc_next_joyaxis(kc_item *item)
2010 {
2011         int n, i, k;
2012         ubyte code = 0;
2013
2014         k = 255;
2015         n = 0;
2016         i = 0;
2017
2018         // I modelled this ifdef after the code in the kc_change_joyaxis method.
2019         // So, if somethin's not workin here, it might not be workin there either.
2020 #ifdef USE_LINUX_JOY
2021         code = (item->value + 1) % 32;
2022 #else
2023         code = (item->value + 1) % JOY_NUM_AXES;
2024 #endif
2025
2026         if (code != 255)
2027         {
2028                 for (i = 0; i < Num_items; i++)
2029                 {
2030                         n = item - All_items;
2031                         if ((i != n) && (All_items[i].type == BT_JOY_AXIS) && (All_items[i].value == code))
2032                         {
2033                                 All_items[i].value = 255;
2034                                 kc_drawitem(&All_items[i], 0);
2035                         }//end if
2036                 }//end for
2037
2038                 item->value = code;
2039         }//end if
2040
2041         kc_drawitem(item, 1);
2042         nm_restore_background(0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h);
2043         game_flush_inputs();
2044
2045 }//method kc_next_joyaxis
2046 //end addition by WraithX
2047
2048
2049 void kc_change_joyaxis( kc_item * item )
2050 {
2051 #ifdef USE_LINUX_JOY
2052         int axis[MAX_AXES];
2053         int old_axis[MAX_AXES];
2054         int numaxis = j_num_axes;
2055 #else
2056         int axis[JOY_NUM_AXES];
2057         int old_axis[JOY_NUM_AXES];
2058         int numaxis = JOY_NUM_AXES;
2059 #endif
2060         int n,i,k;
2061         ubyte code;
2062
2063 WIN(DDGRLOCK(dd_grd_curcanv));
2064         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
2065         
2066         gr_string( 0x8000, LHY(INFO_Y), TXT_MOVE_NEW_JOY_AXIS );
2067 WIN(DDGRUNLOCK(dd_grd_curcanv));        
2068
2069         game_flush_inputs();
2070         code=255;
2071         k=255;
2072
2073         WINDOS(
2074                 joystick_read_raw_axis( JOY_ALL_AXIS+JOY_EXT_AXIS, old_axis ),
2075                 joystick_read_raw_axis( JOY_ALL_AXIS, old_axis )
2076         );
2077
2078         while( (k!=KEY_ESC) && (code==255))     
2079         {                               
2080         #ifdef WINDOWS
2081                 {
2082                         MSG msg;
2083                         DoMessageStuff(&msg);
2084                         DDGRRESTORE;
2085                 }
2086         #endif
2087
2088                 #ifdef NETWORK
2089                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
2090                         multi_menu_poll();
2091                 #endif
2092 //              if ( Game_mode & GM_MULTI )
2093 //                      GameLoop( 0, 0 );                               // Continue
2094                 k = key_inkey();
2095                 timer_delay(f0_1/10);
2096
2097                 if (k == KEY_PRINT_SCREEN)
2098                         save_screen_shot(0);
2099
2100                 kc_drawquestion( item );
2101
2102                 WINDOS(
2103                         joystick_read_raw_axis( JOY_ALL_AXIS+JOY_EXT_AXIS, axis ),
2104                         joystick_read_raw_axis( JOY_ALL_AXIS, axis )
2105                 );
2106                 
2107                 for (i=0; i<numaxis; i++ )      {
2108 #if defined (MACINTOSH)
2109                         if ( abs(axis[i]-old_axis[i])>100 )     {
2110 #elif defined(WINDOWS)
2111                         if ( abs(axis[i]-old_axis[i])>1024 )    {
2112 #else 
2113                         if ( abs(axis[i]-old_axis[i])>200 )     {
2114 #endif
2115                                 code = i;
2116                                 con_printf(CON_DEBUG, "Axis Movement detected: Axis %i\n", i);
2117                         }
2118                         //old_axis[i] = axis[i];
2119                 }
2120                 for (i=0; i<Num_items; i++ )    
2121                  {
2122                         n = item - All_items;
2123                         if ( (i!=n) && (All_items[i].type==BT_JOY_AXIS) && (All_items[i].value==code) ) 
2124                                 code = 255;
2125                  }
2126         
2127         }
2128         if (code!=255)  {
2129                 for (i=0; i<Num_items; i++ )    {
2130                         n = item - All_items;
2131                         if ( (i!=n) && (All_items[i].type==BT_JOY_AXIS) && (All_items[i].value==code) ) {
2132                                 All_items[i].value = 255;
2133                                 kc_drawitem( &All_items[i], 0 );
2134                         }
2135                 }
2136
2137                 item->value = code;                                      
2138         }
2139         kc_drawitem( item, 1 );
2140         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
2141         game_flush_inputs();
2142
2143 }
2144
2145 void kc_change_mouseaxis( kc_item * item )
2146 {
2147         int i,n,k;
2148         ubyte code;
2149         int dx,dy;
2150 #ifdef SDL_INPUT
2151         int dz;
2152 #endif
2153
2154 WIN(DDGRLOCK(dd_grd_curcanv));
2155         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
2156         
2157         gr_string( 0x8000, LHY(INFO_Y), TXT_MOVE_NEW_MSE_AXIS );
2158 WIN(DDGRUNLOCK(dd_grd_curcanv));        
2159
2160         game_flush_inputs();
2161         code=255;
2162         k=255;
2163
2164         mouse_get_delta( &dx, &dy );
2165
2166         while( (k!=KEY_ESC) && (code==255))     
2167         {                               
2168         #ifdef WINDOWS
2169                 {
2170                         MSG msg;
2171                         DoMessageStuff(&msg);
2172                         DDGRRESTORE;
2173                 }
2174         #endif
2175
2176                 #ifdef NETWORK
2177                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
2178                         multi_menu_poll();
2179                 #endif
2180 //              if ( Game_mode & GM_MULTI )
2181 //                      GameLoop( 0, 0 );                               // Continue
2182                 k = key_inkey();
2183                 timer_delay(f0_1/10);
2184
2185                 if (k == KEY_PRINT_SCREEN)
2186                         save_screen_shot(0);
2187
2188                 kc_drawquestion( item );
2189
2190 #ifdef SDL_INPUT
2191                 mouse_get_delta_z( &dx, &dy, &dz );
2192 #else
2193                 mouse_get_delta( &dx, &dy );
2194 #endif
2195                 if ( abs(dx)>20 ) code = 0;
2196                 if ( abs(dy)>20 ) code = 1;
2197 #ifdef SDL_INPUT
2198                 if ( abs(dz)>20 ) code = 2;
2199 #endif
2200         }
2201         if (code!=255)  {
2202                 for (i=0; i<Num_items; i++ )    {
2203                         n = item - All_items;
2204                         if ( (i!=n) && (All_items[i].type==BT_MOUSE_AXIS) && (All_items[i].value==code) )               {
2205                                 All_items[i].value = 255;
2206                                 kc_drawitem( &All_items[i], 0 );
2207                         }
2208                 }
2209                 item->value = code;
2210         }
2211         kc_drawitem( item, 1 );
2212         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
2213         game_flush_inputs();
2214
2215 }
2216
2217
2218 void kc_change_invert( kc_item * item )
2219 {
2220         game_flush_inputs();
2221
2222         if (item->value)
2223                 item->value = 0;
2224         else 
2225                 item->value = 1;
2226
2227         kc_drawitem( item, 1 );
2228
2229 }
2230
2231 #include "screens.h"
2232
2233 void kconfig(int n, char * title)
2234 {
2235         int i;
2236         grs_bitmap *save_bm;
2237
2238         set_screen_mode( SCREEN_MENU );
2239
2240         kc_set_controls();
2241
2242         //save screen
2243         WIN(mouse_set_mode(0));
2244         WIN(dd_gr_set_current_canvas(NULL));
2245         
2246 #if defined(POLY_ACC)
2247         save_bm = gr_create_bitmap2( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2248 #else
2249         save_bm = gr_create_bitmap( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h );
2250 #endif
2251         Assert( save_bm != NULL );
2252         
2253         WIN(DDGRLOCK(dd_grd_curcanv));
2254                 gr_bm_bitblt(grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_w, 
2255                                                  0, 0, 0, 0, &grd_curcanv->cv_bitmap, save_bm );
2256         WIN(DDGRUNLOCK(dd_grd_curcanv));
2257
2258         switch(n)       {
2259         case 0:kconfig_sub( kc_keyboard, NUM_KEY_CONTROLS, title );break;
2260         case 1:kconfig_sub( kc_joystick, NUM_OTHER_CONTROLS, title );break;
2261         case 2:kconfig_sub( kc_mouse, NUM_OTHER_CONTROLS, title ); break;
2262         case 3:kconfig_sub( kc_superjoy, NUM_OTHER_CONTROLS, title); break;
2263 #ifdef D2X_KEYS
2264         //added on 2/4/99 by Victor Rachels for new keys menu
2265         case 4:kconfig_sub( kc_d2x, NUM_D2X_CONTROLS, title ); break;
2266         //end this section addition - VR
2267 #endif
2268         default:
2269                 Int3();
2270                 return;
2271         }
2272
2273         //restore screen
2274         WIN(mouse_set_mode(1));
2275         WIN(dd_gr_set_current_canvas(NULL));
2276         WIN(DDGRLOCK(dd_grd_curcanv));
2277                 gr_bitmap(0, 0, save_bm);
2278         WIN(DDGRUNLOCK(dd_grd_curcanv));
2279         gr_free_bitmap(save_bm);
2280
2281         reset_cockpit();                //force cockpit redraw next time
2282
2283         // Update save values...
2284         
2285         for (i=0; i<NUM_KEY_CONTROLS; i++ )     
2286                 kconfig_settings[0][i] = kc_keyboard[i].value;
2287
2288         if ( (Config_control_type>0) && (Config_control_type<5)) { 
2289                 for (i=0; i<NUM_OTHER_CONTROLS; i++ )   
2290                         kconfig_settings[Config_control_type][i] = kc_joystick[i].value;
2291         } else if (Config_control_type>4 && Config_control_type<CONTROL_WINJOYSTICK) {
2292                 for (i=0; i<NUM_OTHER_CONTROLS; i++ )   
2293                         kconfig_settings[Config_control_type][i] = kc_mouse[i].value;
2294         }
2295         else if (Config_control_type == CONTROL_WINJOYSTICK) {
2296                 for (i=0; i<NUM_OTHER_CONTROLS; i++ )   
2297                         kconfig_settings[Config_control_type][i] = kc_superjoy[i].value;
2298         }
2299
2300 #ifdef D2X_KEYS
2301         for (i=0; i<NUM_D2X_CONTROLS; i++)
2302                 kconfig_d2x_settings[i] = kc_d2x[i].value;
2303 #endif
2304 }
2305
2306
2307 void kconfig_read_fcs( int raw_axis )
2308 {
2309         int raw_button, button, axis_min[4], axis_center[4], axis_max[4];
2310
2311         if (Config_control_type!=CONTROL_THRUSTMASTER_FCS) return;
2312
2313         joy_get_cal_vals(axis_min, axis_center, axis_max);
2314
2315         if ( axis_max[3] > 1 )
2316                 raw_button = (raw_axis*100)/axis_max[3];
2317         else
2318                 raw_button = 0;
2319
2320         if ( raw_button > 88 )
2321                 button = 0;
2322         else if ( raw_button > 63 )
2323                 button = 7;
2324         else if ( raw_button > 39 )
2325                 button = 11;
2326         else if ( raw_button > 15 )
2327                 button = 15;
2328         else    
2329                 button = 19;
2330
2331         kconfig_set_fcs_button( 19, button );
2332         kconfig_set_fcs_button( 15, button );
2333         kconfig_set_fcs_button( 11, button );
2334         kconfig_set_fcs_button( 7, button );
2335 }
2336                 
2337
2338 void kconfig_set_fcs_button( int btn, int button )
2339 {
2340         int state,time_down,upcount,downcount;
2341         state = time_down = upcount = downcount = 0;
2342
2343         if ( joy_get_button_state(btn) ) {
2344                 if ( btn==button )      {
2345                         state = 1;
2346                         time_down = FrameTime;
2347                 } else {
2348                         upcount=1;
2349                 }
2350         } else {
2351                 if ( btn==button )      {
2352                         state = 1;
2353                         time_down = FrameTime;
2354                         downcount=1;
2355                 } else {
2356                         upcount=1;
2357                 }
2358         }                               
2359                         
2360         joy_set_btn_values( btn, state, time_down, downcount, upcount );
2361                                         
2362 }
2363
2364
2365
2366 fix Last_angles_p = 0;
2367 fix Last_angles_b = 0;
2368 fix Last_angles_h = 0;
2369 ubyte Last_angles_read = 0;
2370
2371 extern int                      VR_sensitivity;
2372                                                 
2373 int VR_sense_range[3] = { 25, 50, 75 };
2374
2375 #if 0 //ndef MACINTOSH
2376 read_head_tracker()
2377 {
2378 #ifndef WINDOWS
2379
2380         fix yaw, pitch, roll;
2381         int buttons;
2382
2383 //------ read vfx1 helmet --------
2384         if (vfx1_installed) {
2385                 vfx_get_data(&yaw,&pitch,&roll,&buttons);
2386         } else if (iglasses_headset_installed)  {
2387                 iglasses_read_headset( &yaw, &pitch, &roll );
2388         } else if (Victor_headset_installed)   {
2389                 victor_read_headset_filtered( &yaw, &pitch, &roll );
2390         } else {
2391                 return;
2392         }
2393
2394         Use_player_head_angles = 0;
2395         if ( Last_angles_read ) {
2396                 fix yaw1 = yaw;
2397                 
2398                 yaw1 = yaw;
2399                 if ( (Last_angles_h < (F1_0/4) ) && (yaw > ((F1_0*3)/4) ) )     
2400                         yaw1 -= F1_0;
2401                 else if ( (yaw < (F1_0/4) ) && (Last_angles_h > ((F1_0*3)/4) ) )        
2402                         yaw1 += F1_0;
2403         
2404                 Controls.pitch_time     += fixmul((pitch- Last_angles_p)*VR_sense_range[VR_sensitivity],FrameTime);
2405                 Controls.heading_time+= fixmul((yaw1 -  Last_angles_h)*VR_sense_range[VR_sensitivity],FrameTime);
2406                 Controls.bank_time      += fixmul((roll - Last_angles_b)*VR_sense_range[VR_sensitivity],FrameTime);
2407         }
2408         Last_angles_read = 1;
2409         Last_angles_p = pitch;
2410         Last_angles_h = yaw;
2411         Last_angles_b = roll;
2412 #endif
2413 }
2414 #endif
2415
2416 #define PH_SCALE        8
2417
2418 #ifndef __MSDOS__ // WINDOWS
2419 #define JOYSTICK_READ_TIME      (F1_0/40)               //      Read joystick at 40 Hz.
2420 #else
2421 #define JOYSTICK_READ_TIME      (F1_0/10)               //      Read joystick at 10 Hz.
2422 #endif
2423
2424 fix     LastReadTime = 0;
2425
2426 #ifdef USE_LINUX_JOY
2427 fix     joy_axis[MAX_AXES];
2428 #else
2429 fix     joy_axis[JOY_NUM_AXES];
2430 #endif
2431
2432 ubyte                   kc_use_external_control = 0;
2433 ubyte                           kc_enable_external_control = 0;
2434 ubyte                   kc_external_intno = 0;
2435 ext_control_info        *kc_external_control = NULL;
2436 ubyte                           *kc_external_name = NULL;
2437 ubyte                           kc_external_version = 0;
2438 extern int Automap_active;
2439
2440 void kconfig_init_external_controls(int intno, int address)
2441 {
2442         int i;
2443         kc_external_intno = intno;
2444         kc_external_control     = (ext_control_info *)address;
2445         kc_use_external_control = 1;
2446         kc_enable_external_control  = 1;
2447
2448         i = FindArg ( "-xname" );
2449         if ( i )        
2450                 kc_external_name = Args[i+1];
2451         else
2452                 kc_external_name = "External Controller";
2453
2454    for (i=0;i<strlen (kc_external_name);i++)
2455     if (kc_external_name[i]=='_')
2456           kc_external_name[i]=' '; 
2457
2458         i = FindArg ( "-xver" );
2459         if ( i )
2460                 kc_external_version = atoi(Args[i+1]);
2461         
2462         printf( "%s int: 0x%x, data: 0x%p, ver:%d\n", kc_external_name, kc_external_intno, kc_external_control, kc_external_version );
2463
2464 }
2465
2466 #if !defined(MACINTOSH)
2467 /*void kconfig_read_external_controls()
2468 {
2469         union REGS r;
2470
2471         if ( !kc_enable_external_control && !CybermouseActive) 
2472                 return;
2473
2474         if ( kc_external_version == 0 ) 
2475                 memset( kc_external_control, 0, sizeof(control_info) );
2476         else if ( kc_external_version > 0 )     {
2477                 memset( kc_external_control, 0, sizeof(control_info)+sizeof(vms_angvec) + 64 );
2478                 if ( kc_external_version > 1 ) {
2479                         // Write ship pos and angles to external controls...
2480                         ubyte *temp_ptr = (ubyte *)kc_external_control;
2481                         vms_vector *ship_pos;
2482                         vms_matrix *ship_orient;
2483                         memset( kc_external_control, 0, sizeof(control_info)+sizeof(vms_angvec) + 64 + sizeof(vms_vector)+sizeof(vms_matrix) );
2484                         temp_ptr += sizeof(control_info)+sizeof(vms_angvec) + 64;
2485                         ship_pos = (vms_vector *)temp_ptr;
2486                         temp_ptr += sizeof(vms_vector);
2487                         ship_orient = (vms_matrix *)temp_ptr;
2488                         // Fill in ship postion...
2489                         *ship_pos = Objects[Players[Player_num].objnum].pos;
2490                         // Fill in ship orientation...
2491                         *ship_orient = Objects[Players[Player_num].objnum].orient;
2492                 }
2493         }
2494
2495         if ( Automap_active )                    // (If in automap...)
2496                 kc_external_control->automap_state = 1;
2497         memset(&r,0,sizeof(r));
2498
2499 #ifndef WINDOWS
2500   
2501    if (!CybermouseActive)
2502         int386 ( kc_external_intno, &r, &r);            // Read external info...
2503 //      else
2504   //            ReadOWL (kc_external_control);
2505
2506 #endif
2507
2508         if ( Player_num > -1 )  {
2509                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_TURNROLL);    // Turn off roll when turning
2510                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_LEVELLING);   // Turn off leveling to nearest side.
2511                 Auto_leveling_on = 0;
2512
2513                 if ( kc_external_version > 0 ) {                
2514                         vms_matrix tempm, ViewMatrix;
2515                         vms_angvec * Kconfig_abs_movement;
2516                         char * oem_message;
2517         
2518                         Kconfig_abs_movement = (vms_angvec *)((uint)kc_external_control + sizeof(control_info));
2519         
2520                         if ( Kconfig_abs_movement->p || Kconfig_abs_movement->b || Kconfig_abs_movement->h )    {
2521                                 vm_angles_2_matrix(&tempm,Kconfig_abs_movement);
2522                                 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
2523                                 Objects[Players[Player_num].objnum].orient = ViewMatrix;                
2524                         }
2525                         oem_message = (char *)((uint)Kconfig_abs_movement + sizeof(vms_angvec));
2526                         if (oem_message[0] != '\0' )
2527                                 HUD_init_message( oem_message );
2528                 }
2529         }
2530
2531         Controls.pitch_time += fixmul(kc_external_control->pitch_time,FrameTime);                                               
2532         Controls.vertical_thrust_time += fixmul(kc_external_control->vertical_thrust_time,FrameTime);
2533         Controls.heading_time += fixmul(kc_external_control->heading_time,FrameTime);
2534         Controls.sideways_thrust_time += fixmul(kc_external_control->sideways_thrust_time ,FrameTime);
2535         Controls.bank_time += fixmul(kc_external_control->bank_time ,FrameTime);
2536         Controls.forward_thrust_time += fixmul(kc_external_control->forward_thrust_time ,FrameTime);
2537         Controls.rear_view_down_count += kc_external_control->rear_view_down_count;     
2538         Controls.rear_view_down_state |= kc_external_control->rear_view_down_state;     
2539         Controls.fire_primary_down_count += kc_external_control->fire_primary_down_count;
2540         Controls.fire_primary_state |= kc_external_control->fire_primary_state;
2541         Controls.fire_secondary_state |= kc_external_control->fire_secondary_state;
2542         Controls.fire_secondary_down_count += kc_external_control->fire_secondary_down_count;
2543         Controls.fire_flare_down_count += kc_external_control->fire_flare_down_count;
2544         Controls.drop_bomb_down_count += kc_external_control->drop_bomb_down_count;     
2545         Controls.automap_down_count += kc_external_control->automap_down_count;
2546         Controls.automap_state |= kc_external_control->automap_state;
2547 } */
2548 #endif
2549
2550 #ifdef WINDOWS
2551 void controls_read_all_win()
2552 {
2553         int i;
2554         int slide_on, bank_on;
2555         int dx, dy;
2556         fix ctime;
2557         fix mouse_axis[2];
2558         int raw_joy_axis[7];
2559         int mouse_buttons;
2560         fix k0, k1, k2, k3, kp;
2561         fix k4, k5, k6, k7, kh;
2562         ubyte channel_masks;
2563         int use_mouse, use_joystick;
2564         int speed_factor=1;
2565
2566         if (Game_turbo_mode)
2567                 speed_factor = 2;
2568         
2569         {
2570                 fix temp = Controls.heading_time;
2571                 fix temp1 = Controls.pitch_time;
2572                 memset( &Controls, 0, sizeof(control_info) );
2573                 Controls.heading_time = temp;
2574                 Controls.pitch_time = temp1;
2575         }
2576         slide_on = 0;
2577         bank_on = 0;
2578
2579         ctime = timer_get_fixed_seconds();
2580
2581 //      DO JOYSTICK (X,Y,Z  R,U,V)
2582 //      ----------------------------------------------------------------------------
2583         if ( (LastReadTime + JOYSTICK_READ_TIME) > ctime ) {
2584                 if ((ctime < 0) && (LastReadTime > 0))
2585                         LastReadTime = ctime;
2586                 use_joystick=1;
2587         } else if ((Config_control_type==CONTROL_WINJOYSTICK)) {
2588                 LastReadTime = ctime;
2589                 channel_masks = joystick_read_raw_axis( JOY_ALL_AXIS+JOY_EXT_AXIS, raw_joy_axis );
2590
2591                 for (i=0; i<7; i++ )    {
2592                         if (channel_masks&(1<<i))       {
2593                                 int joy_null_value = 28;
2594
2595                         // DO POV if joystick has a hat.
2596                         //      --------------------------------------------------------------------
2597                                 if (i == 3) {
2598                                         joydefsw_do_winjoybutton(raw_joy_axis);
2599                                 }
2600                                 else {
2601                                 // DO AXIS
2602                                 //      --------------------------------------------------------------------    
2603                                 //      mprintf((0, "(%d)=%d,", i, raw_joy_axis[i]));
2604                                         raw_joy_axis[i] = joy_get_scaled_reading( raw_joy_axis[i], i );
2605                                 //      mprintf((0, "%d  ",raw_joy_axis[i]));
2606                                 //      if (i%2) mprintf((0,"\n"));
2607
2608         
2609                                         if (kc_superjoy[23].value==i)           // If this is the throttle
2610                                                 joy_null_value = 32;                            // Then use a larger dead-zone
2611         
2612                                         if (raw_joy_axis[i] > (joy_null_value-2)) 
2613                                                 raw_joy_axis[i] = ((raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value);
2614                                         else if (raw_joy_axis[i] < -(joy_null_value+2))
2615                                                 raw_joy_axis[i] = ((raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value);
2616                                         else
2617                                                 raw_joy_axis[i] = 0;
2618                                         joy_axis[i]     = (raw_joy_axis[i]*FrameTime)/128;      
2619                                 }
2620                         } else {
2621                                 joy_axis[i] = 0;
2622                         }
2623                 }       
2624                 use_joystick=1;
2625
2626         } else {
2627                 for (i=0; i<6; i++ )
2628                         joy_axis[i] = 0;
2629                 use_joystick=0;
2630         }
2631
2632 //      DO MOUSE 
2633 //      ----------------------------------------------------------------------------
2634         if (Config_control_type==5) {
2635                 mouse_get_delta( &dx, &dy );
2636                 mouse_axis[0] = (dx*FrameTime)/35;
2637                 mouse_axis[1] = (dy*FrameTime)/25;
2638                 mouse_buttons = mouse_get_btns();
2639                 //mprintf(( 0, "Mouse %d,%d b:%d, 0x%x\n", mouse_axis[0], mouse_axis[1], mouse_buttons, FrameTime ));
2640                 use_mouse=1;
2641    } else {
2642                 mouse_axis[0] = 0;
2643                 mouse_axis[1] = 0;
2644                 mouse_buttons = 0;
2645                 use_mouse=0;
2646         }
2647
2648 //------------- Read slide_on -------------
2649         
2650         // From keyboard...
2651         if ( kc_keyboard[8].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[8].value ];
2652         if ( kc_keyboard[9].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[9].value ];
2653         // From joystick...
2654         if ((use_joystick)&&(kc_superjoy[5].value<255)) slide_on |= joy_get_button_state( kc_superjoy[5].value );
2655         // From mouse...
2656         if ((use_mouse)&&(kc_mouse[5].value<255)) slide_on |= mouse_buttons & (1<<kc_mouse[5].value);
2657
2658 //------------- Read bank_on ---------------
2659
2660         // From keyboard...
2661         if ( kc_keyboard[18].value < 255 ) bank_on |= keyd_pressed[ kc_keyboard[18].value ];
2662         if ( kc_keyboard[19].value < 255 ) bank_on |= keyd_pressed[ kc_keyboard[19].value ];
2663         // From joystick...
2664         if ( (use_joystick)&&(kc_superjoy[10].value < 255 )) bank_on |= joy_get_button_state( kc_superjoy[10].value );
2665         // From mouse...
2666         if ( (use_mouse)&&(kc_mouse[10].value < 255 )) bank_on |= mouse_buttons & (1<<kc_mouse[10].value);
2667
2668 //------------ Read pitch_time -----------
2669         if ( !slide_on )        {
2670                 // mprintf((0, "pitch: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
2671                 kp = 0;
2672                 k0 = speed_factor*key_down_time( kc_keyboard[0].value )/2;      // Divide by two since we want pitch to go slower
2673                 k1 = speed_factor*key_down_time( kc_keyboard[1].value )/2;
2674                 k2 = speed_factor*key_down_time( kc_keyboard[2].value )/2;
2675                 k3 = speed_factor*key_down_time( kc_keyboard[3].value )/2;
2676
2677                 // From keyboard...
2678                 if ( kc_keyboard[0].value < 255 ) kp += k0/PH_SCALE;
2679                 if ( kc_keyboard[1].value < 255 ) kp += k1/PH_SCALE;
2680                 if ( kc_keyboard[2].value < 255 ) kp -= k2/PH_SCALE;
2681                 if ( kc_keyboard[3].value < 255 ) kp -= k3/PH_SCALE;
2682
2683                 // From Cyberman...
2684                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2685                         kp += mouse_button_down_time(MB_PITCH_FORWARD)/(PH_SCALE*2);
2686                         kp -= mouse_button_down_time(MB_PITCH_BACKWARD)/(PH_SCALE*2);
2687                 }
2688         
2689                 if (kp == 0)
2690                         Controls.pitch_time = 0;
2691                 else if (kp > 0) {
2692                         if (Controls.pitch_time < 0)
2693                                 Controls.pitch_time = 0;
2694                 } else // kp < 0
2695                         if (Controls.pitch_time > 0)
2696                                 Controls.pitch_time = 0;
2697                 Controls.pitch_time += kp;
2698         
2699                 // From joystick...
2700                 if ( (use_joystick)&&(kc_superjoy[13].value < 255 ))    {
2701                         if ( !kc_superjoy[14].value )           // If not inverted...
2702                                 Controls.pitch_time -= (joy_axis[kc_superjoy[13].value]*Config_joystick_sensitivity)/8;
2703                         else
2704                                 Controls.pitch_time += (joy_axis[kc_superjoy[13].value]*Config_joystick_sensitivity)/8;
2705                 }
2706         
2707                 // From mouse...
2708                 //mprintf(( 0, "UM: %d, PV: %d\n", use_mouse, kc_mouse[13].value ));
2709                 if ( (use_mouse)&&(kc_mouse[13].value < 255) )  {
2710                         if ( !kc_mouse[14].value )              // If not inverted...
2711                                 Controls.pitch_time -= (mouse_axis[kc_mouse[13].value]*Config_joystick_sensitivity)/8;
2712                         else
2713                                 Controls.pitch_time += (mouse_axis[kc_mouse[13].value]*Config_joystick_sensitivity)/8;
2714                 }
2715         } else {
2716                 Controls.pitch_time = 0;
2717         }
2718
2719
2720 //----------- Read vertical_thrust_time -----------------
2721
2722         if ( slide_on ) {
2723                 k0 = speed_factor*key_down_time( kc_keyboard[0].value );
2724                 k1 = speed_factor*key_down_time( kc_keyboard[1].value );
2725                 k2 = speed_factor*key_down_time( kc_keyboard[2].value );
2726                 k3 = speed_factor*key_down_time( kc_keyboard[3].value );
2727
2728                 // From keyboard...
2729                 if ( kc_keyboard[0].value < 255 ) Controls.vertical_thrust_time += k0;
2730                 if ( kc_keyboard[1].value < 255 ) Controls.vertical_thrust_time += k1;
2731                 if ( kc_keyboard[2].value < 255 ) Controls.vertical_thrust_time -= k2;
2732                 if ( kc_keyboard[3].value < 255 ) Controls.vertical_thrust_time -= k3;
2733
2734                 // From Cyberman...
2735                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2736                         Controls.vertical_thrust_time -= mouse_button_down_time(MB_PITCH_FORWARD);
2737                         Controls.vertical_thrust_time += mouse_button_down_time(MB_PITCH_BACKWARD);
2738                 }
2739         
2740                 // From joystick...
2741                 if ((use_joystick)&&( kc_superjoy[13].value < 255 ))    {
2742                         if ( !kc_superjoy[14].value )           // If not inverted...
2743                                 Controls.vertical_thrust_time += joy_axis[kc_superjoy[13].value];
2744                         else
2745                                 Controls.vertical_thrust_time -= joy_axis[kc_superjoy[13].value];
2746                 }
2747         
2748                 // From mouse...
2749                 if ( (use_mouse)&&(kc_mouse[13].value < 255 ))  {
2750                         if ( !kc_mouse[14].value )              // If not inverted...
2751                                 Controls.vertical_thrust_time -= mouse_axis[kc_mouse[13].value];
2752                         else
2753                                 Controls.vertical_thrust_time += mouse_axis[kc_mouse[13].value];
2754                 }
2755         }
2756
2757         // From keyboard...
2758         if ( kc_keyboard[14].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[14].value );
2759         if ( kc_keyboard[15].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[15].value );
2760         if ( kc_keyboard[16].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[16].value );
2761         if ( kc_keyboard[17].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[17].value );
2762         
2763         // From joystick...
2764         if ((use_joystick)&&( kc_superjoy[19].value < 255 ))    {
2765                 if ( !kc_superjoy[20].value )           // If not inverted...
2766                         Controls.vertical_thrust_time += joy_axis[kc_superjoy[19].value];
2767                 else
2768                         Controls.vertical_thrust_time -= joy_axis[kc_superjoy[19].value];
2769         }
2770
2771         // From joystick buttons
2772         if ( (use_joystick)&&(kc_superjoy[8].value < 255 )) Controls.vertical_thrust_time += joy_get_button_down_time( kc_superjoy[8].value );
2773         if ( (use_joystick)&&(kc_superjoy[9].value < 255 )) Controls.vertical_thrust_time -= joy_get_button_down_time( kc_superjoy[9].value );
2774
2775         // From mouse buttons
2776         if ( (use_mouse)&&(kc_mouse[8].value < 255 )) Controls.vertical_thrust_time += mouse_button_down_time( kc_mouse[8].value );
2777         if ( (use_mouse)&&(kc_mouse[9].value < 255 )) Controls.vertical_thrust_time -= mouse_button_down_time( kc_mouse[9].value );
2778
2779         // From mouse...
2780         if ( (use_mouse)&&(kc_mouse[19].value < 255 ))  {
2781                 if ( !kc_mouse[20].value )              // If not inverted...
2782                         Controls.vertical_thrust_time += mouse_axis[kc_mouse[19].value];
2783                 else
2784                         Controls.vertical_thrust_time -= mouse_axis[kc_mouse[19].value];
2785         }
2786
2787         // From Cyberman...
2788         if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2789                 Controls.vertical_thrust_time += mouse_button_down_time(MB_Z_UP)/2;
2790                 Controls.vertical_thrust_time -= mouse_button_down_time(MB_Z_DOWN)/2;
2791         }
2792
2793 //---------- Read heading_time -----------
2794
2795         if (!slide_on && !bank_on)      {
2796                 //mprintf((0, "heading: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
2797                 kh = 0;
2798                 k4 = speed_factor*key_down_time( kc_keyboard[4].value );
2799                 k5 = speed_factor*key_down_time( kc_keyboard[5].value );
2800                 k6 = speed_factor*key_down_time( kc_keyboard[6].value );
2801                 k7 = speed_factor*key_down_time( kc_keyboard[7].value );
2802
2803                 // From keyboard...
2804                 if ( kc_keyboard[4].value < 255 ) kh -= k4/PH_SCALE;
2805                 if ( kc_keyboard[5].value < 255 ) kh -= k5/PH_SCALE;
2806                 if ( kc_keyboard[6].value < 255 ) kh += k6/PH_SCALE;
2807                 if ( kc_keyboard[7].value < 255 ) kh += k7/PH_SCALE;
2808
2809                 // From Cyberman...
2810                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2811                         kh -= mouse_button_down_time(MB_HEAD_LEFT)/PH_SCALE;
2812                         kh += mouse_button_down_time(MB_HEAD_RIGHT)/PH_SCALE;
2813                 }
2814         
2815                 if (kh == 0)
2816                         Controls.heading_time = 0;
2817                 else if (kh > 0) {
2818                         if (Controls.heading_time < 0)
2819                                 Controls.heading_time = 0;
2820                 } else // kh < 0
2821                         if (Controls.heading_time > 0)
2822                                 Controls.heading_time = 0;
2823                 Controls.heading_time += kh;
2824
2825                 // From joystick...
2826                 if ( (use_joystick)&&(kc_superjoy[15].value < 255 ))    {
2827                         if ( !kc_superjoy[16].value )           // If not inverted...
2828                                 Controls.heading_time += (joy_axis[kc_superjoy[15].value]*Config_joystick_sensitivity)/8;
2829                         else
2830                                 Controls.heading_time -= (joy_axis[kc_superjoy[15].value]*Config_joystick_sensitivity)/8;
2831                 }
2832         
2833                 // From mouse...
2834                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
2835                         if ( !kc_mouse[16].value )              // If not inverted...
2836                                 Controls.heading_time += (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
2837                         else
2838                                 Controls.heading_time -= (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
2839                 }
2840         } else {
2841                 Controls.heading_time = 0;
2842         }
2843
2844 //----------- Read sideways_thrust_time -----------------
2845
2846         if ( slide_on ) {
2847                 k0 = speed_factor*key_down_time( kc_keyboard[4].value );
2848                 k1 = speed_factor*key_down_time( kc_keyboard[5].value );
2849                 k2 = speed_factor*key_down_time( kc_keyboard[6].value );
2850                 k3 = speed_factor*key_down_time( kc_keyboard[7].value );
2851
2852                 // From keyboard...
2853                 if ( kc_keyboard[4].value < 255 ) Controls.sideways_thrust_time -= k0;
2854                 if ( kc_keyboard[5].value < 255 ) Controls.sideways_thrust_time -= k1;
2855                 if ( kc_keyboard[6].value < 255 ) Controls.sideways_thrust_time += k2;
2856                 if ( kc_keyboard[7].value < 255 ) Controls.sideways_thrust_time += k3;
2857         
2858                 // From joystick...
2859                 if ( (use_joystick)&&(kc_superjoy[15].value < 255 ))    {
2860                         if ( !kc_superjoy[16].value )           // If not inverted...
2861                                 Controls.sideways_thrust_time += joy_axis[kc_superjoy[15].value];
2862                         else
2863                                 Controls.sideways_thrust_time -= joy_axis[kc_superjoy[15].value];
2864                 }
2865                 
2866                 // From cyberman
2867                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2868                         Controls.sideways_thrust_time -= mouse_button_down_time(MB_HEAD_LEFT);
2869                         Controls.sideways_thrust_time += mouse_button_down_time(MB_HEAD_RIGHT);
2870                 }
2871         
2872                 // From mouse...
2873                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
2874                         if ( !kc_mouse[16].value )              // If not inverted...
2875                                 Controls.sideways_thrust_time += mouse_axis[kc_mouse[15].value];
2876                         else
2877                                 Controls.sideways_thrust_time -= mouse_axis[kc_mouse[15].value];
2878                 }
2879         }
2880
2881         // From keyboard...
2882         if ( kc_keyboard[10].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[10].value );
2883         if ( kc_keyboard[11].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[11].value );
2884         if ( kc_keyboard[12].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[12].value );
2885         if ( kc_keyboard[13].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[13].value );
2886         
2887         // From joystick...
2888         if ( (use_joystick)&&(kc_superjoy[17].value < 255 ))    {
2889                 if ( !kc_superjoy[18].value )           // If not inverted...
2890                         Controls.sideways_thrust_time -= joy_axis[kc_superjoy[17].value];
2891                 else
2892                         Controls.sideways_thrust_time += joy_axis[kc_superjoy[17].value];
2893         }
2894
2895         // From joystick buttons
2896         if ( (use_joystick)&&(kc_superjoy[6].value < 255 )) Controls.sideways_thrust_time -= joy_get_button_down_time( kc_superjoy[6].value );
2897         if ( (use_joystick)&&(kc_superjoy[7].value < 255 )) Controls.sideways_thrust_time += joy_get_button_down_time( kc_superjoy[7].value );
2898
2899         // From mouse buttons
2900         if ( (use_mouse)&&(kc_mouse[6].value < 255 )) Controls.sideways_thrust_time -= mouse_button_down_time( kc_mouse[6].value );
2901         if ( (use_mouse)&&(kc_mouse[7].value < 255 )) Controls.sideways_thrust_time += mouse_button_down_time( kc_mouse[7].value );
2902
2903         // From mouse...
2904         if ( (use_mouse)&&(kc_mouse[17].value < 255 ))  {
2905                 if ( !kc_mouse[18].value )              // If not inverted...
2906                         Controls.sideways_thrust_time += mouse_axis[kc_mouse[17].value];
2907                 else
2908                         Controls.sideways_thrust_time -= mouse_axis[kc_mouse[17].value];
2909         }
2910
2911 //----------- Read bank_time -----------------
2912
2913         if ( bank_on )  {
2914                 k0 = speed_factor*key_down_time( kc_keyboard[4].value );
2915                 k1 = speed_factor*key_down_time( kc_keyboard[5].value );
2916                 k2 = speed_factor*key_down_time( kc_keyboard[6].value );
2917                 k3 = speed_factor*key_down_time( kc_keyboard[7].value );
2918
2919                 // From keyboard...
2920                 if ( kc_keyboard[4].value < 255 ) Controls.bank_time += k0;
2921                 if ( kc_keyboard[5].value < 255 ) Controls.bank_time += k1;
2922                 if ( kc_keyboard[6].value < 255 ) Controls.bank_time -= k2;
2923                 if ( kc_keyboard[7].value < 255 ) Controls.bank_time -= k3;
2924
2925                 // From Cyberman...
2926                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2927                         Controls.bank_time -= mouse_button_down_time(MB_HEAD_LEFT);
2928                         Controls.bank_time += mouse_button_down_time(MB_HEAD_RIGHT);
2929                 }
2930
2931                 // From joystick...
2932                 if ( (use_joystick)&&(kc_superjoy[15].value < 255) )    {
2933                         if ( !kc_superjoy[16].value )           // If not inverted...
2934                                 Controls.bank_time -= (joy_axis[kc_superjoy[15].value]*Config_joystick_sensitivity)/8;
2935                         else
2936                                 Controls.bank_time += (joy_axis[kc_superjoy[15].value]*Config_joystick_sensitivity)/8;
2937                 }
2938         
2939                 // From mouse...
2940                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
2941                         if ( !kc_mouse[16].value )              // If not inverted...
2942                                 Controls.bank_time += (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
2943                         else
2944                                 Controls.bank_time -= (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
2945                 }
2946         }
2947
2948         // From keyboard...
2949         if ( kc_keyboard[20].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[20].value );
2950         if ( kc_keyboard[21].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[21].value );
2951         if ( kc_keyboard[22].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[22].value );
2952         if ( kc_keyboard[23].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[23].value );
2953
2954         // From joystick...
2955         if ( (use_joystick)&&(kc_superjoy[21].value < 255) )    {
2956                 if ( !kc_superjoy[22].value )           // If not inverted...
2957                         Controls.bank_time -= joy_axis[kc_superjoy[21].value];
2958                 else
2959                         Controls.bank_time += joy_axis[kc_superjoy[21].value];
2960         }
2961
2962         // From joystick buttons
2963         if ( (use_joystick)&&(kc_superjoy[11].value < 255 )) Controls.bank_time += joy_get_button_down_time( kc_superjoy[11].value );
2964         if ( (use_joystick)&&(kc_superjoy[12].value < 255 )) Controls.bank_time -= joy_get_button_down_time( kc_superjoy[12].value );
2965
2966         // From mouse buttons
2967         if ( (use_mouse)&&(kc_mouse[11].value < 255 )) Controls.bank_time += mouse_button_down_time( kc_mouse[11].value );
2968         if ( (use_mouse)&&(kc_mouse[12].value < 255 )) Controls.bank_time -= mouse_button_down_time( kc_mouse[12].value );
2969
2970         // From mouse...
2971         if ( (use_mouse)&&(kc_mouse[21].value < 255 ))  {
2972                 if ( !kc_mouse[22].value )              // If not inverted...
2973                         Controls.bank_time += mouse_axis[kc_mouse[21].value];
2974                 else
2975                         Controls.bank_time -= mouse_axis[kc_mouse[21].value];
2976         }
2977
2978         // From Cyberman
2979         if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2980                 Controls.bank_time += mouse_button_down_time(MB_BANK_LEFT);
2981                 Controls.bank_time -= mouse_button_down_time(MB_BANK_RIGHT);
2982         }
2983
2984 //----------- Read forward_thrust_time -------------
2985
2986         // From keyboard...
2987         if ( kc_keyboard[30].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[30].value );
2988         if ( kc_keyboard[31].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[31].value );
2989         if ( kc_keyboard[32].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[32].value );
2990         if ( kc_keyboard[33].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[33].value );
2991
2992         // From joystick...
2993         if ( (use_joystick)&&(kc_superjoy[23].value < 255 ))    {
2994                 if ( !kc_superjoy[24].value )           // If not inverted...
2995                         Controls.forward_thrust_time -= joy_axis[kc_superjoy[23].value];
2996                 else
2997                         Controls.forward_thrust_time += joy_axis[kc_superjoy[23].value];
2998         }
2999
3000         // From joystick buttons
3001         if ( (use_joystick)&&(kc_superjoy[2].value < 255 )) Controls.forward_thrust_time += joy_get_button_down_time( kc_superjoy[2].value );
3002         if ( (use_joystick)&&(kc_superjoy[3].value < 255 )) Controls.forward_thrust_time -= joy_get_button_down_time( kc_superjoy[3].value );
3003
3004         // From mouse...
3005         if ( (use_mouse)&&(kc_mouse[23].value < 255 ))  {
3006                 if ( !kc_mouse[24].value )              // If not inverted...
3007                         Controls.forward_thrust_time -= mouse_axis[kc_mouse[23].value];
3008                 else
3009                         Controls.forward_thrust_time += mouse_axis[kc_mouse[23].value];
3010         }
3011
3012         // From mouse buttons
3013         if ( (use_mouse)&&(kc_mouse[2].value < 255 )) Controls.forward_thrust_time += mouse_button_down_time( kc_mouse[2].value );
3014         if ( (use_mouse)&&(kc_mouse[3].value < 255 )) Controls.forward_thrust_time -= mouse_button_down_time( kc_mouse[3].value );
3015
3016 //----------- Read afterburner_state -------------
3017
3018         // From keyboard...
3019         if ( kc_keyboard[46].value < 255 ) Controls.afterburner_state |= keyd_pressed[kc_keyboard[46].value];
3020         if ( kc_keyboard[47].value < 255 ) Controls.afterburner_state |= keyd_pressed[kc_keyboard[47].value];
3021
3022         if ( (use_mouse)&&(kc_mouse[27].value < 255 )) Controls.afterburner_state |= mouse_button_state(kc_mouse[27].value);
3023
3024         if ( (use_joystick)&&(kc_superjoy[27].value < 255 )) Controls.afterburner_state |= joy_get_button_state(kc_superjoy[27].value);
3025
3026 //-------Read headlight key--------------------------
3027         if (kc_keyboard[52].value < 255 )
3028                    Controls.headlight_count=key_down_count(kc_keyboard[52].value);
3029         if (kc_keyboard[53].value < 255 )
3030                    Controls.headlight_count=key_down_count(kc_keyboard[53].value);
3031                   if ((use_joystick)&&(kc_superjoy[30].value < 255 )) 
3032          Controls.headlight_count=joy_get_button_down_cnt(kc_superjoy[30].value);
3033                  
3034 //--------Read Cycle Primary Key------------------
3035
3036                   if (kc_keyboard[48].value<255)
3037                          Controls.cycle_primary_count=key_down_count(kc_keyboard[48].value);
3038                   if (kc_keyboard[49].value<255)
3039                         Controls.cycle_primary_count+=key_down_count(kc_keyboard[49].value);
3040              if ((use_joystick)&&(kc_superjoy[28].value < 255 )) 
3041          Controls.cycle_primary_count+=joy_get_button_down_cnt(kc_superjoy[28].value);
3042
3043 //--------Read Cycle Secondary Key------------------
3044
3045                   if (kc_keyboard[50].value<255)
3046                          Controls.cycle_secondary_count=key_down_count(kc_keyboard[50].value);
3047                   if (kc_keyboard[51].value<255)
3048                         Controls.cycle_secondary_count+=key_down_count(kc_keyboard[51].value);
3049              if ((use_joystick)&&(kc_superjoy[29].value < 255 )) 
3050                         Controls.cycle_secondary_count=joy_get_button_down_cnt(kc_superjoy[29].value);
3051
3052 //--------Read Toggle Bomb key----------------------
3053
3054                   if (kc_keyboard[56].value<255 && key_down_count(kc_keyboard[56].value))
3055          {
3056           int bomb = Secondary_last_was_super[PROXIMITY_INDEX]?PROXIMITY_INDEX:SMART_MINE_INDEX;
3057
3058                          if (!Players[Player_num].secondary_ammo[PROXIMITY_INDEX] &&
3059                                   !Players[Player_num].secondary_ammo[SMART_MINE_INDEX])
3060                            {
3061                                  digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
3062                                  HUD_init_message ("No bombs available!");
3063                                 }
3064                          else
3065                                 {       
3066                                  if (Players[Player_num].secondary_ammo[bomb]==0)
3067                                         {
3068                                          digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
3069                                          HUD_init_message ("No %s available!",(bomb==SMART_MINE_INDEX)?"Smart mines":"Proximity bombs");
3070                                         }
3071                                   else
3072                                         {
3073                                Secondary_last_was_super[PROXIMITY_INDEX]=!Secondary_last_was_super[PROXIMITY_INDEX];
3074                                          digi_play_sample_once( SOUND_GOOD_SELECTION_SECONDARY, F1_0 );
3075                                         }
3076                                 }
3077                         }
3078           
3079 //---------Read Energy->Shield key----------
3080
3081         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[kc_keyboard[54].value])
3082                 transfer_energy_to_shield(key_down_time(kc_keyboard[54].value));
3083         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[kc_keyboard[55].value])
3084                 transfer_energy_to_shield(key_down_time(kc_keyboard[55].value));
3085
3086 //----------- Read fire_primary_down_count
3087         if (kc_keyboard[24].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[24].value);
3088         if (kc_keyboard[25].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[25].value);
3089         if ((use_joystick)&&(kc_superjoy[0].value < 255 )) Controls.fire_primary_down_count += joy_get_button_down_cnt(kc_superjoy[0].value);
3090         if ((use_mouse)&&(kc_mouse[0].value < 255 )) Controls.fire_primary_down_count += mouse_button_down_count(kc_mouse[0].value);
3091
3092 //----------- Read fire_primary_state
3093         if (kc_keyboard[24].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[24].value];
3094         if (kc_keyboard[25].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[25].value];
3095         if ((use_joystick)&&(kc_superjoy[0].value < 255 )) Controls.fire_primary_state |= joy_get_button_state(kc_superjoy[0].value);
3096         if ((use_mouse)&&(kc_mouse[0].value < 255) ) Controls.fire_primary_state |= mouse_button_state(kc_mouse[0].value);
3097
3098 //----------- Read fire_secondary_down_count
3099         if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[26].value);
3100         if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[27].value);
3101         if ((use_joystick)&&(kc_superjoy[1].value < 255 )) Controls.fire_secondary_down_count += joy_get_button_down_cnt(kc_superjoy[1].value);
3102         if ((use_mouse)&&(kc_mouse[1].value < 255 )) Controls.fire_secondary_down_count += mouse_button_down_count(kc_mouse[1].value);
3103
3104 //----------- Read fire_secondary_state
3105         if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[26].value];
3106         if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[27].value];
3107         if ((use_joystick)&&(kc_superjoy[1].value < 255 )) Controls.fire_secondary_state |= joy_get_button_state(kc_superjoy[1].value);
3108         if ((use_mouse)&&(kc_mouse[1].value < 255) ) Controls.fire_secondary_state |= mouse_button_state(kc_mouse[1].value);
3109
3110 //----------- Read fire_flare_down_count
3111         if (kc_keyboard[28].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[28].value);
3112         if (kc_keyboard[29].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[29].value);
3113         if ((use_joystick)&&(kc_superjoy[4].value < 255 )) Controls.fire_flare_down_count += joy_get_button_down_cnt(kc_superjoy[4].value);
3114         if ((use_mouse)&&(kc_mouse[4].value < 255 )) Controls.fire_flare_down_count += mouse_button_down_count(kc_mouse[4].value);
3115
3116 //----------- Read drop_bomb_down_count
3117         if (kc_keyboard[34].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[34].value);
3118         if (kc_keyboard[35].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[35].value);
3119         if ((use_joystick)&&(kc_superjoy[26].value < 255 )) Controls.drop_bomb_down_count += joy_get_button_down_cnt(kc_superjoy[26].value);
3120         if ((use_mouse)&&(kc_mouse[26].value < 255 )) Controls.drop_bomb_down_count += mouse_button_down_count(kc_mouse[26].value);
3121
3122 //----------- Read rear_view_down_count
3123         if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[36].value);
3124         if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[37].value);
3125         if ((use_joystick)&&(kc_superjoy[25].value < 255 )) Controls.rear_view_down_count += joy_get_button_down_cnt(kc_superjoy[25].value);
3126         if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_count += mouse_button_down_count(kc_mouse[25].value);
3127
3128 //----------- Read rear_view_down_state
3129         if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[36].value];
3130         if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[37].value];
3131         if ((use_joystick)&&(kc_superjoy[25].value < 255 )) Controls.rear_view_down_state |= joy_get_button_state(kc_superjoy[25].value);
3132         if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_state |= mouse_button_state(kc_mouse[25].value);
3133
3134 //----------- Read automap_down_count
3135         if (kc_keyboard[44].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[44].value);
3136         if (kc_keyboard[45].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[45].value);
3137
3138 //----------- Read automap_state
3139         if (kc_keyboard[44].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[44].value];
3140         if (kc_keyboard[45].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[45].value];
3141
3142 //----------- Read stupid-cruise-control-type of throttle.
3143         {
3144                 if ( kc_keyboard[38].value < 255 ) Cruise_speed += fixdiv(speed_factor*key_down_time(kc_keyboard[38].value)*5,FrameTime);
3145                 if ( kc_keyboard[39].value < 255 ) Cruise_speed += fixdiv(speed_factor*key_down_time(kc_keyboard[39].value)*5,FrameTime);
3146                 if ( kc_keyboard[40].value < 255 ) Cruise_speed -= fixdiv(speed_factor*key_down_time(kc_keyboard[40].value)*5,FrameTime);
3147                 if ( kc_keyboard[41].value < 255 ) Cruise_speed -= fixdiv(speed_factor*key_down_time(kc_keyboard[41].value)*5,FrameTime);
3148                 if ( (kc_keyboard[42].value < 255) && (key_down_count(kc_keyboard[42].value)) )
3149                         Cruise_speed = 0;
3150                 if ( (kc_keyboard[43].value < 255) && (key_down_count(kc_keyboard[43].value)) )
3151                         Cruise_speed = 0;
3152         
3153                 if (Cruise_speed > i2f(100) ) Cruise_speed = i2f(100);
3154                 if (Cruise_speed < 0 ) Cruise_speed = 0;
3155         
3156                 if (Controls.forward_thrust_time==0)
3157                         Controls.forward_thrust_time = fixmul(Cruise_speed,FrameTime)/100;
3158         }
3159
3160         //read_head_tracker();
3161
3162         // Read external controls
3163         if (kc_use_external_control || CybermouseActive)
3164                 kconfig_read_external_controls();
3165
3166 //----------- Clamp values between -FrameTime and FrameTime
3167         if (FrameTime > F1_0 )
3168                 mprintf( (1, "Bogus frame time of %.2f seconds\n", f2fl(FrameTime) ));
3169
3170         if (Controls.pitch_time > FrameTime/2 ) Controls.pitch_time = FrameTime/2;
3171         if (Controls.vertical_thrust_time > FrameTime ) Controls.vertical_thrust_time = FrameTime;
3172         if (Controls.heading_time > FrameTime ) Controls.heading_time = FrameTime;
3173         if (Controls.sideways_thrust_time > FrameTime ) Controls.sideways_thrust_time = FrameTime;
3174         if (Controls.bank_time > FrameTime ) Controls.bank_time = FrameTime;
3175         if (Controls.forward_thrust_time > FrameTime ) Controls.forward_thrust_time = FrameTime;
3176 //      if (Controls.afterburner_time > FrameTime ) Controls.afterburner_time = FrameTime;
3177
3178         if (Controls.pitch_time < -FrameTime/2 ) Controls.pitch_time = -FrameTime/2;
3179         if (Controls.vertical_thrust_time < -FrameTime ) Controls.vertical_thrust_time = -FrameTime;
3180         if (Controls.heading_time < -FrameTime ) Controls.heading_time = -FrameTime;
3181         if (Controls.sideways_thrust_time < -FrameTime ) Controls.sideways_thrust_time = -FrameTime;
3182         if (Controls.bank_time < -FrameTime ) Controls.bank_time = -FrameTime;
3183         if (Controls.forward_thrust_time < -FrameTime ) Controls.forward_thrust_time = -FrameTime;
3184 //      if (Controls.afterburner_time < -FrameTime ) Controls.afterburner_time = -FrameTime;
3185
3186
3187 //--------- Don't do anything if in debug mode
3188         #ifndef RELEASE
3189         if ( keyd_pressed[KEY_DELETE] ) {
3190                 memset( &Controls, 0, sizeof(control_info) );
3191         }
3192         #endif
3193 }
3194 #else
3195
3196
3197 fix Next_toggle_time[3]={0,0,0};
3198
3199 int allowed_to_toggle(int i)
3200 {
3201   //used for keeping tabs of when its ok to toggle headlight,primary,and secondary
3202  
3203         if (Next_toggle_time[i] > GameTime)
3204                 if (Next_toggle_time[i] < GameTime + (F1_0/8))  //      In case time is bogus, never wait > 1 second.
3205                         return 0;
3206
3207         Next_toggle_time[i] = GameTime + (F1_0/8);
3208
3209         return 1;
3210 }
3211
3212
3213 #ifdef D2X_KEYS
3214 //added on 2/7/99 by Victor Rachels for jostick state setting
3215 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};
3216 //end this section adition - VR
3217 #endif
3218
3219
3220 void controls_read_all()
3221 {
3222         int i;
3223         int slide_on, bank_on;
3224         int dx, dy;
3225 #ifdef SDL_INPUT
3226         int dz;
3227 #endif
3228         int idx, idy;
3229         fix ctime;
3230         fix mouse_axis[3] = {0,0,0};
3231 #ifdef USE_LINUX_JOY
3232         int raw_joy_axis[MAX_AXES];
3233 #else
3234         int raw_joy_axis[JOY_NUM_AXES];
3235 #endif
3236         int mouse_buttons;
3237         fix k0, k1, k2, k3, kp;
3238         fix k4, k5, k6, k7, kh;
3239         ubyte channel_masks;
3240         int use_mouse, use_joystick;
3241         int speed_factor=1;
3242
3243         mouse_buttons=0;
3244         use_mouse=0;
3245
3246         if (Game_turbo_mode)
3247                 speed_factor = 2;
3248         
3249         {
3250                 fix temp = Controls.heading_time;
3251                 fix temp1 = Controls.pitch_time;
3252                 memset( &Controls, 0, sizeof(control_info) );
3253                 Controls.heading_time = temp;
3254                 Controls.pitch_time = temp1;
3255         }
3256         slide_on = 0;
3257         bank_on = 0;
3258
3259         ctime = timer_get_fixed_seconds();
3260
3261         //---------  Read Joystick -----------
3262 #ifndef MACINTOSH
3263         if ( (LastReadTime + JOYSTICK_READ_TIME > ctime) && (Config_control_type!=CONTROL_THRUSTMASTER_FCS) ) {
3264 # ifndef __MSDOS__
3265                 if ((ctime < 0) && (LastReadTime >= 0))
3266 # else
3267                 if ((ctime < 0) && (LastReadTime > 0))
3268 # endif
3269                         LastReadTime = ctime;
3270                 use_joystick=1;
3271         } else if ((Config_control_type>0) && (Config_control_type<5) ) {
3272                 LastReadTime = ctime;
3273                 channel_masks = joystick_read_raw_axis( JOY_ALL_AXIS, raw_joy_axis );
3274                 
3275 # ifdef USE_LINUX_JOY
3276                 for (i = 0; i < j_num_axes; i++)
3277 # else
3278                 for (i = 0; i < JOY_NUM_AXES; i++)
3279 # endif
3280                 {
3281 #ifndef SDL_INPUT
3282                         if (channel_masks&(1<<i))       {
3283 #endif
3284                                 int joy_null_value = 10;
3285
3286                                 if ( (i==3) && (Config_control_type==CONTROL_THRUSTMASTER_FCS) )        {
3287                                         kconfig_read_fcs( raw_joy_axis[i] );
3288                                 } else {
3289                                         raw_joy_axis[i] = joy_get_scaled_reading( raw_joy_axis[i], i );
3290         
3291                                         if (kc_joystick[23].value==i)           // If this is the throttle
3292                                                 joy_null_value = 20;            // Then use a larger dead-zone
3293         
3294                                         if (raw_joy_axis[i] > joy_null_value) 
3295                                           raw_joy_axis[i] = ((raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value);
3296                                         else if (raw_joy_axis[i] < -joy_null_value)
3297                                           raw_joy_axis[i] = ((raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value);
3298                                         else
3299                                           raw_joy_axis[i] = 0;
3300                                         joy_axis[i]     = (raw_joy_axis[i]*FrameTime)/128;      
3301                                 }
3302 #ifndef SDL_INPUT
3303                         } else {
3304                                 joy_axis[i] = 0;
3305                         }
3306 #endif
3307                 }       
3308                 use_joystick=1;
3309         } else {
3310 #ifdef USE_LINUX_JOY
3311                 for (i = 0; i < j_num_axes; i++)
3312 #else
3313                 for (i = 0; i < JOY_NUM_AXES; i++)
3314 #endif
3315                         joy_axis[i] = 0;
3316                 use_joystick=0;
3317         }
3318 #else   // MACINTOSH
3319         //---------  Read Joystick -----------
3320         if ((Config_control_type>0) && (Config_control_type<5) ) {
3321                 channel_masks = joystick_read_raw_axis( JOY_ALL_AXIS, raw_joy_axis );
3322                 for (i=0; i<4; i++ )    {
3323                         if (channel_masks&(1<<i))       {
3324                                 int joy_null_value = 10;
3325
3326                                 raw_joy_axis[i] = joy_get_scaled_reading( raw_joy_axis[i], i );
3327
3328                                 if (kc_joystick[23].value==i)           // If this is the throttle
3329                                         joy_null_value = 20;                            // Then use a larger dead-zone
3330
3331                                 if (raw_joy_axis[i] > joy_null_value) 
3332                                         raw_joy_axis[i] = ((raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value);
3333                                 else if (raw_joy_axis[i] < -joy_null_value)
3334                                         raw_joy_axis[i] = ((raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value);
3335                                 else
3336                                         raw_joy_axis[i] = 0;
3337                                 joy_axis[i]     = (raw_joy_axis[i]*FrameTime)/128;      
3338                         } else {
3339                                 joy_axis[i] = 0;
3340                         }
3341                 }       
3342                 use_joystick=1;
3343         } else {
3344                 for (i=0; i<4; i++ )
3345                         joy_axis[i] = 0;
3346                 use_joystick=0;
3347         }
3348 #endif          // ifndef MACINTOSH
3349
3350         if (Config_control_type==5 && !CybermouseActive) {
3351                 //---------  Read Mouse -----------
3352 #ifdef SDL_INPUT
3353                 mouse_get_delta_z( &dx, &dy, &dz );
3354 #else
3355                 mouse_get_delta( &dx, &dy );
3356 #endif
3357                 mouse_axis[0] = (dx*FrameTime)/35;
3358                 mouse_axis[1] = (dy*FrameTime)/25;
3359 #ifdef SDL_INPUT
3360                 mouse_axis[2] = (dz*FrameTime);
3361 #endif
3362                 mouse_buttons = mouse_get_btns();
3363                 //mprintf(( 0, "Mouse %d,%d b:%d, 0x%x\n", mouse_axis[0], mouse_axis[1], mouse_buttons, FrameTime ));
3364                 use_mouse=1;
3365         } else if (Config_control_type==6 && !CybermouseActive) {
3366                 //---------  Read Cyberman -----------
3367                 mouse_get_cyberman_pos(&idx,&idy );
3368                 mouse_axis[0] = (idx*FrameTime)/128;
3369                 mouse_axis[1] = (idy*FrameTime)/128;
3370                 mouse_buttons = mouse_get_btns();
3371                 use_mouse=1;
3372         } else if (CybermouseActive) {
3373 //              ReadOWL (kc_external_control);
3374 //              CybermouseAdjust();
3375         } else {
3376                 mouse_axis[0] = 0;
3377                 mouse_axis[1] = 0;
3378                 mouse_buttons = 0;
3379                 use_mouse=0;
3380         }
3381
3382 #ifdef D2X_KEYS
3383         //added on 2/4/99 by Victor Rachels for d1x keys
3384         //--------- Read primary weapon select -------------
3385         //the following "if" added by WraithX to stop deadies from switchin weapons, 4/14/00
3386         if (!Player_is_dead)
3387         {
3388                 {
3389                         int d2x_joystick_state[10];
3390
3391                         for(i=0;i<10;i++)
3392                                 d2x_joystick_state[i] = joy_get_button_state(kc_d2x[i*2+1].value);
3393
3394
3395                         //----------------Weapon 1----------------
3396                         if(key_down_count(kc_d2x[0].value) ||
3397                            (joy_get_button_state(kc_d2x[1].value) &&
3398                                 (d2x_joystick_state[0]!=d2x_joystick_ostate[0]) ) )
3399                         {
3400                                 //int i, valu=0;
3401                                 do_weapon_select(0,0);
3402                                 /*
3403                                 for(i=MAX_PRIMARY_WEAPONS;i<MAX_PRIMARY_WEAPONS+NEWPRIMS;i++)
3404                                         if(primary_order[i]>primary_order[valu]&&player_has_weapon(i,0))
3405                                                 valu = i;
3406                                 LaserPowSelected = valu;
3407                                 */
3408                         }
3409                         //----------------Weapon 2----------------
3410                         if(key_down_count(kc_d2x[2].value) ||
3411                            (joy_get_button_state(kc_d2x[3].value) &&
3412                                 (d2x_joystick_state[1]!=d2x_joystick_ostate[1]) ) )
3413                                 do_weapon_select(1,0);
3414                         //----------------Weapon 3----------------
3415                         if(key_down_count(kc_d2x[4].value) ||
3416                            (joy_get_button_state(kc_d2x[5].value) &&
3417                                 (d2x_joystick_state[2]!=d2x_joystick_ostate[2]) ) )
3418                                 do_weapon_select(2,0);
3419                         //----------------Weapon 4----------------
3420                         if(key_down_count(kc_d2x[6].value) ||
3421                            (joy_get_button_state(kc_d2x[7].value) &&
3422                                 (d2x_joystick_state[3]!=d2x_joystick_ostate[3]) ) )
3423                                 do_weapon_select(3,0);
3424                         //----------------Weapon 5----------------
3425                         if(key_down_count(kc_d2x[8].value) ||
3426                            (joy_get_button_state(kc_d2x[9].value) &&
3427                                 (d2x_joystick_state[4]!=d2x_joystick_ostate[4]) ) )
3428                                 do_weapon_select(4,0);
3429  
3430                         //--------- Read secondary weapon select ----------
3431                         //----------------Weapon 6----------------
3432                         if(key_down_count(kc_d2x[10].value) ||
3433                            (joy_get_button_state(kc_d2x[11].value) &&
3434                                 (d2x_joystick_state[5]!=d2x_joystick_ostate[5]) ) )
3435                                 do_weapon_select(0,1);
3436                         //----------------Weapon 7----------------
3437                         if(key_down_count(kc_d2x[12].value) ||
3438                            (joy_get_button_state(kc_d2x[13].value) &&
3439                                 (d2x_joystick_state[6]!=d2x_joystick_ostate[6]) ) )
3440                                 do_weapon_select(1,1);
3441                         //----------------Weapon 8----------------
3442                         if(key_down_count(kc_d2x[14].value) ||
3443                            (joy_get_button_state(kc_d2x[15].value) &&
3444                                 (d2x_joystick_state[7]!=d2x_joystick_ostate[7]) ) )
3445                                 do_weapon_select(2,1);
3446                         //----------------Weapon 9----------------
3447                         if(key_down_count(kc_d2x[16].value) ||
3448                            (joy_get_button_state(kc_d2x[17].value) &&
3449                                 (d2x_joystick_state[8]!=d2x_joystick_ostate[8]) ) )
3450                                 do_weapon_select(3,1);
3451                         //----------------Weapon 0----------------
3452                         if(key_down_count(kc_d2x[18].value) ||
3453                            (joy_get_button_state(kc_d2x[19].value) &&
3454                                 (d2x_joystick_state[9]!=d2x_joystick_ostate[9]) ) )
3455                                 do_weapon_select(4,1);
3456                         memcpy(d2x_joystick_ostate,d2x_joystick_state,10*sizeof(int));
3457                 }
3458                 //end this section addition - VR
3459
3460
3461         }//end "if (!Player_is_dead)" - WraithX
3462 #endif
3463
3464
3465 //------------- Read slide_on -------------
3466         
3467         // From keyboard...
3468         if ( kc_keyboard[8].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[8].value ];
3469         if ( kc_keyboard[9].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[9].value ];
3470         // From joystick...
3471         if ((use_joystick)&&(kc_joystick[5].value<255)) slide_on |= joy_get_button_state( kc_joystick[5].value );
3472         // From mouse...
3473         if ((use_mouse)&&(kc_mouse[5].value<255)) slide_on |= mouse_buttons & (1<<kc_mouse[5].value);
3474
3475 //------------- Read bank_on ---------------
3476
3477         // From keyboard...
3478         if ( kc_keyboard[18].value < 255 ) bank_on |= keyd_pressed[ kc_keyboard[18].value ];
3479         if ( kc_keyboard[19].value < 255 ) bank_on |= keyd_pressed[ kc_keyboard[19].value ];
3480         // From joystick...
3481         if ( (use_joystick)&&(kc_joystick[10].value < 255 )) bank_on |= joy_get_button_state( kc_joystick[10].value );
3482         // From mouse...
3483         if ( (use_mouse)&&(kc_mouse[10].value < 255 )) bank_on |= mouse_buttons & (1<<kc_mouse[10].value);
3484
3485 //------------ Read pitch_time -----------
3486         if ( !slide_on )        {
3487                 // mprintf((0, "pitch: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
3488                 kp = 0;
3489                 k0 = speed_factor*key_down_time( kc_keyboard[0].value )/2;      // Divide by two since we want pitch to go slower
3490                 k1 = speed_factor*key_down_time( kc_keyboard[1].value )/2;
3491                 k2 = speed_factor*key_down_time( kc_keyboard[2].value )/2;
3492                 k3 = speed_factor*key_down_time( kc_keyboard[3].value )/2;
3493
3494                 // From keyboard...
3495                 if ( kc_keyboard[0].value < 255 ) kp += k0/PH_SCALE;
3496                 if ( kc_keyboard[1].value < 255 ) kp += k1/PH_SCALE;
3497                 if ( kc_keyboard[2].value < 255 ) kp -= k2/PH_SCALE;
3498                 if ( kc_keyboard[3].value < 255 ) kp -= k3/PH_SCALE;
3499
3500                 // From Cyberman...
3501                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3502                         kp += mouse_button_down_time(MB_PITCH_FORWARD)/(PH_SCALE*2);
3503                         kp -= mouse_button_down_time(MB_PITCH_BACKWARD)/(PH_SCALE*2);
3504                 }
3505         
3506                 if (kp == 0)
3507                         Controls.pitch_time = 0;
3508                 else if (kp > 0) {
3509                         if (Controls.pitch_time < 0)
3510                                 Controls.pitch_time = 0;
3511                 } else // kp < 0
3512                         if (Controls.pitch_time > 0)
3513                                 Controls.pitch_time = 0;
3514                 Controls.pitch_time += kp;
3515         
3516                 // From joystick...
3517                 if ( (use_joystick)&&(kc_joystick[13].value < 255 ))    {
3518                         if ( !kc_joystick[14].value )           // If not inverted...
3519                                 Controls.pitch_time -= (joy_axis[kc_joystick[13].value]*Config_joystick_sensitivity)/8;
3520                         else
3521                                 Controls.pitch_time += (joy_axis[kc_joystick[13].value]*Config_joystick_sensitivity)/8;
3522                 }
3523         
3524                 // From mouse...
3525                 //mprintf(( 0, "UM: %d, PV: %d\n", use_mouse, kc_mouse[13].value ));
3526                 if ( (use_mouse)&&(kc_mouse[13].value < 255) )  {
3527                         if ( !kc_mouse[14].value )              // If not inverted...
3528                                 Controls.pitch_time -= (mouse_axis[kc_mouse[13].value]*Config_joystick_sensitivity)/8;
3529                         else
3530                                 Controls.pitch_time += (mouse_axis[kc_mouse[13].value]*Config_joystick_sensitivity)/8;
3531                 }
3532         } else {
3533                 Controls.pitch_time = 0;
3534         }
3535
3536
3537 // the following "if" added by WraithX, 4/14/00
3538 // done so that dead players can't move
3539 if (!Player_is_dead)
3540 {
3541 //----------- Read vertical_thrust_time -----------------
3542
3543         if ( slide_on ) {
3544                 k0 = speed_factor*key_down_time( kc_keyboard[0].value );
3545                 k1 = speed_factor*key_down_time( kc_keyboard[1].value );
3546                 k2 = speed_factor*key_down_time( kc_keyboard[2].value );
3547                 k3 = speed_factor*key_down_time( kc_keyboard[3].value );
3548
3549                 // From keyboard...
3550                 if ( kc_keyboard[0].value < 255 ) Controls.vertical_thrust_time += k0;
3551                 if ( kc_keyboard[1].value < 255 ) Controls.vertical_thrust_time += k1;
3552                 if ( kc_keyboard[2].value < 255 ) Controls.vertical_thrust_time -= k2;
3553                 if ( kc_keyboard[3].value < 255 ) Controls.vertical_thrust_time -= k3;
3554
3555                 // From Cyberman...
3556                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3557                         Controls.vertical_thrust_time -= mouse_button_down_time(MB_PITCH_FORWARD);
3558                         Controls.vertical_thrust_time += mouse_button_down_time(MB_PITCH_BACKWARD);
3559                 }
3560         
3561                 // From joystick...
3562                 if ((use_joystick)&&( kc_joystick[13].value < 255 ))    {
3563                         if ( !kc_joystick[14].value )           // If not inverted...
3564                                 Controls.vertical_thrust_time += joy_axis[kc_joystick[13].value];
3565                         else
3566                                 Controls.vertical_thrust_time -= joy_axis[kc_joystick[13].value];
3567                 }
3568         
3569                 // From mouse...
3570                 if ( (use_mouse)&&(kc_mouse[13].value < 255 ))  {
3571                         if ( !kc_mouse[14].value )              // If not inverted...
3572                                 Controls.vertical_thrust_time -= mouse_axis[kc_mouse[13].value];
3573                         else
3574                                 Controls.vertical_thrust_time += mouse_axis[kc_mouse[13].value];
3575                 }
3576         }
3577
3578         // From keyboard...
3579         if ( kc_keyboard[14].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[14].value );
3580         if ( kc_keyboard[15].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[15].value );
3581         if ( kc_keyboard[16].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[16].value );
3582         if ( kc_keyboard[17].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[17].value );
3583         
3584         // From joystick...
3585         if ((use_joystick)&&( kc_joystick[19].value < 255 ))    {
3586                 if ( !kc_joystick[20].value )           // If not inverted...
3587                         Controls.vertical_thrust_time += joy_axis[kc_joystick[19].value];
3588                 else
3589                         Controls.vertical_thrust_time -= joy_axis[kc_joystick[19].value];
3590         }
3591
3592         // From joystick buttons
3593         if ( (use_joystick)&&(kc_joystick[8].value < 255 )) Controls.vertical_thrust_time += joy_get_button_down_time( kc_joystick[8].value );
3594         if ( (use_joystick)&&(kc_joystick[9].value < 255 )) Controls.vertical_thrust_time -= joy_get_button_down_time( kc_joystick[9].value );
3595
3596         // From mouse buttons
3597         if ( (use_mouse)&&(kc_mouse[8].value < 255 )) Controls.vertical_thrust_time += mouse_button_down_time( kc_mouse[8].value );
3598         if ( (use_mouse)&&(kc_mouse[9].value < 255 )) Controls.vertical_thrust_time -= mouse_button_down_time( kc_mouse[9].value );
3599
3600         // From mouse...
3601         if ( (use_mouse)&&(kc_mouse[19].value < 255 ))  {
3602                 if ( !kc_mouse[20].value )              // If not inverted...
3603                         Controls.vertical_thrust_time += mouse_axis[kc_mouse[19].value];
3604                 else
3605                         Controls.vertical_thrust_time -= mouse_axis[kc_mouse[19].value];
3606         }
3607
3608         // From Cyberman...
3609         if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3610                 Controls.vertical_thrust_time += mouse_button_down_time(MB_Z_UP)/2;
3611                 Controls.vertical_thrust_time -= mouse_button_down_time(MB_Z_DOWN)/2;
3612         }
3613 }// end "if" added by WraithX
3614
3615 //---------- Read heading_time -----------
3616
3617         if (!slide_on && !bank_on)      {
3618                 //mprintf((0, "heading: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
3619                 kh = 0;
3620                 k4 = speed_factor*key_down_time( kc_keyboard[4].value );
3621                 k5 = speed_factor*key_down_time( kc_keyboard[5].value );
3622                 k6 = speed_factor*key_down_time( kc_keyboard[6].value );
3623                 k7 = speed_factor*key_down_time( kc_keyboard[7].value );
3624
3625                 // From keyboard...
3626                 if ( kc_keyboard[4].value < 255 ) kh -= k4/PH_SCALE;
3627                 if ( kc_keyboard[5].value < 255 ) kh -= k5/PH_SCALE;
3628                 if ( kc_keyboard[6].value < 255 ) kh += k6/PH_SCALE;
3629                 if ( kc_keyboard[7].value < 255 ) kh += k7/PH_SCALE;
3630
3631                 // From Cyberman...
3632                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3633                         kh -= mouse_button_down_time(MB_HEAD_LEFT)/PH_SCALE;
3634                         kh += mouse_button_down_time(MB_HEAD_RIGHT)/PH_SCALE;
3635                 }
3636         
3637                 if (kh == 0)
3638                         Controls.heading_time = 0;
3639                 else if (kh > 0) {
3640                         if (Controls.heading_time < 0)
3641                                 Controls.heading_time = 0;
3642                 } else // kh < 0
3643                         if (Controls.heading_time > 0)
3644                                 Controls.heading_time = 0;
3645                 Controls.heading_time += kh;
3646
3647                 // From joystick...
3648                 if ( (use_joystick)&&(kc_joystick[15].value < 255 ))    {
3649                         if ( !kc_joystick[16].value )           // If not inverted...
3650                                 Controls.heading_time += (joy_axis[kc_joystick[15].value]*Config_joystick_sensitivity)/8;
3651                         else
3652                                 Controls.heading_time -= (joy_axis[kc_joystick[15].value]*Config_joystick_sensitivity)/8;
3653                 }
3654         
3655                 // From mouse...
3656                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
3657                         if ( !kc_mouse[16].value )              // If not inverted...
3658                                 Controls.heading_time += (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
3659                         else
3660                                 Controls.heading_time -= (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
3661                 }
3662         } else {
3663                 Controls.heading_time = 0;
3664         }
3665
3666 // the following "if" added by WraithX, 4/14/00
3667 // done so that dead players can't move
3668 if (!Player_is_dead)
3669 {
3670 //----------- Read sideways_thrust_time -----------------
3671
3672         if ( slide_on ) {
3673                 k0 = speed_factor*key_down_time( kc_keyboard[4].value );
3674                 k1 = speed_factor*key_down_time( kc_keyboard[5].value );
3675                 k2 = speed_factor*key_down_time( kc_keyboard[6].value );
3676                 k3 = speed_factor*key_down_time( kc_keyboard[7].value );
3677
3678                 // From keyboard...
3679                 if ( kc_keyboard[4].value < 255 ) Controls.sideways_thrust_time -= k0;
3680                 if ( kc_keyboard[5].value < 255 ) Controls.sideways_thrust_time -= k1;
3681                 if ( kc_keyboard[6].value < 255 ) Controls.sideways_thrust_time += k2;
3682                 if ( kc_keyboard[7].value < 255 ) Controls.sideways_thrust_time += k3;
3683         
3684                 // From joystick...
3685                 if ( (use_joystick)&&(kc_joystick[15].value < 255 ))    {
3686                         if ( !kc_joystick[16].value )           // If not inverted...
3687                                 Controls.sideways_thrust_time += joy_axis[kc_joystick[15].value];
3688                         else
3689                                 Controls.sideways_thrust_time -= joy_axis[kc_joystick[15].value];
3690                 }
3691                 
3692                 // From cyberman
3693                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3694                         Controls.sideways_thrust_time -= mouse_button_down_time(MB_HEAD_LEFT);
3695                         Controls.sideways_thrust_time += mouse_button_down_time(MB_HEAD_RIGHT);
3696                 }
3697         
3698                 // From mouse...
3699                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
3700                         if ( !kc_mouse[16].value )              // If not inverted...
3701                                 Controls.sideways_thrust_time += mouse_axis[kc_mouse[15].value];
3702                         else
3703                                 Controls.sideways_thrust_time -= mouse_axis[kc_mouse[15].value];
3704                 }
3705         }
3706
3707         // From keyboard...
3708         if ( kc_keyboard[10].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[10].value );
3709         if ( kc_keyboard[11].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[11].value );
3710         if ( kc_keyboard[12].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[12].value );
3711         if ( kc_keyboard[13].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[13].value );
3712         
3713         // From joystick...
3714         if ( (use_joystick)&&(kc_joystick[17].value < 255 ))    {
3715                 if ( !kc_joystick[18].value )           // If not inverted...
3716                         Controls.sideways_thrust_time -= joy_axis[kc_joystick[17].value];
3717                 else
3718                         Controls.sideways_thrust_time += joy_axis[kc_joystick[17].value];
3719         }
3720
3721         // From joystick buttons
3722         if ( (use_joystick)&&(kc_joystick[6].value < 255 )) Controls.sideways_thrust_time -= joy_get_button_down_time( kc_joystick[6].value );
3723         if ( (use_joystick)&&(kc_joystick[7].value < 255 )) Controls.sideways_thrust_time += joy_get_button_down_time( kc_joystick[7].value );
3724
3725         // From mouse buttons
3726         if ( (use_mouse)&&(kc_mouse[6].value < 255 )) Controls.sideways_thrust_time -= mouse_button_down_time( kc_mouse[6].value );
3727         if ( (use_mouse)&&(kc_mouse[7].value < 255 )) Controls.sideways_thrust_time += mouse_button_down_time( kc_mouse[7].value );
3728
3729         // From mouse...
3730         if ( (use_mouse)&&(kc_mouse[17].value < 255 ))  {
3731                 if ( !kc_mouse[18].value )              // If not inverted...
3732                         Controls.sideways_thrust_time += mouse_axis[kc_mouse[17].value];
3733                 else
3734                         Controls.sideways_thrust_time -= mouse_axis[kc_mouse[17].value];
3735         }
3736 }// end "if" added by WraithX
3737
3738 //----------- Read bank_time -----------------
3739
3740         if ( bank_on )  {
3741                 k0 = speed_factor*key_down_time( kc_keyboard[4].value );
3742                 k1 = speed_factor*key_down_time( kc_keyboard[5].value );
3743                 k2 = speed_factor*key_down_time( kc_keyboard[6].value );
3744                 k3 = speed_factor*key_down_time( kc_keyboard[7].value );
3745
3746                 // From keyboard...
3747                 if ( kc_keyboard[4].value < 255 ) Controls.bank_time += k0;
3748                 if ( kc_keyboard[5].value < 255 ) Controls.bank_time += k1;
3749                 if ( kc_keyboard[6].value < 255 ) Controls.bank_time -= k2;
3750                 if ( kc_keyboard[7].value < 255 ) Controls.bank_time -= k3;
3751
3752                 // From Cyberman...
3753                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3754                         Controls.bank_time -= mouse_button_down_time(MB_HEAD_LEFT);
3755                         Controls.bank_time += mouse_button_down_time(MB_HEAD_RIGHT);
3756                 }
3757
3758                 // From joystick...
3759                 if ( (use_joystick)&&(kc_joystick[15].value < 255) )    {
3760                         if ( !kc_joystick[16].value )           // If not inverted...
3761                                 Controls.bank_time -= (joy_axis[kc_joystick[15].value]*Config_joystick_sensitivity)/8;
3762                         else
3763                                 Controls.bank_time += (joy_axis[kc_joystick[15].value]*Config_joystick_sensitivity)/8;
3764                 }
3765         
3766                 // From mouse...
3767                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
3768                         if ( !kc_mouse[16].value )              // If not inverted...
3769                                 Controls.bank_time += (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
3770                         else
3771                                 Controls.bank_time -= (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
3772                 }
3773         }
3774
3775         // From keyboard...
3776         if ( kc_keyboard[20].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[20].value );
3777         if ( kc_keyboard[21].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[21].value );
3778         if ( kc_keyboard[22].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[22].value );
3779         if ( kc_keyboard[23].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[23].value );
3780
3781         // From joystick...
3782         if ( (use_joystick)&&(kc_joystick[21].value < 255) )    {
3783                 if ( !kc_joystick[22].value )           // If not inverted...
3784                         Controls.bank_time -= joy_axis[kc_joystick[21].value];
3785                 else
3786                         Controls.bank_time += joy_axis[kc_joystick[21].value];
3787         }
3788
3789         // From joystick buttons
3790         if ( (use_joystick)&&(kc_joystick[11].value < 255 )) Controls.bank_time += joy_get_button_down_time( kc_joystick[11].value );
3791         if ( (use_joystick)&&(kc_joystick[12].value < 255 )) Controls.bank_time -= joy_get_button_down_time( kc_joystick[12].value );
3792
3793         // From mouse buttons
3794         if ( (use_mouse)&&(kc_mouse[11].value < 255 )) Controls.bank_time += mouse_button_down_time( kc_mouse[11].value );
3795         if ( (use_mouse)&&(kc_mouse[12].value < 255 )) Controls.bank_time -= mouse_button_down_time( kc_mouse[12].value );
3796
3797         // From mouse...
3798         if ( (use_mouse)&&(kc_mouse[21].value < 255 ))  {
3799                 if ( !kc_mouse[22].value )              // If not inverted...
3800                         Controls.bank_time += mouse_axis[kc_mouse[21].value];
3801                 else
3802                         Controls.bank_time -= mouse_axis[kc_mouse[21].value];
3803         }
3804
3805         // From Cyberman
3806         if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3807                 Controls.bank_time += mouse_button_down_time(MB_BANK_LEFT);
3808                 Controls.bank_time -= mouse_button_down_time(MB_BANK_RIGHT);
3809         }
3810
3811 // the following "if" added by WraithX, 4/14/00
3812 // done so that dead players can't move
3813 if (!Player_is_dead)
3814 {
3815 //----------- Read forward_thrust_time -------------
3816
3817         // From keyboard...
3818         if ( kc_keyboard[30].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[30].value );
3819         if ( kc_keyboard[31].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[31].value );
3820         if ( kc_keyboard[32].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[32].value );
3821         if ( kc_keyboard[33].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[33].value );
3822
3823         // From joystick...
3824         if ( (use_joystick)&&(kc_joystick[23].value < 255 ))    {
3825                 if ( !kc_joystick[24].value )           // If not inverted...
3826                         Controls.forward_thrust_time -= joy_axis[kc_joystick[23].value];
3827                 else
3828                         Controls.forward_thrust_time += joy_axis[kc_joystick[23].value];
3829         }
3830
3831         // From joystick buttons
3832         if ( (use_joystick)&&(kc_joystick[2].value < 255 )) Controls.forward_thrust_time += joy_get_button_down_time( kc_joystick[2].value );
3833         if ( (use_joystick)&&(kc_joystick[3].value < 255 )) Controls.forward_thrust_time -= joy_get_button_down_time( kc_joystick[3].value );
3834
3835         // From mouse...
3836         if ( (use_mouse)&&(kc_mouse[23].value < 255 ))  {
3837                 if ( !kc_mouse[24].value )              // If not inverted...
3838                         Controls.forward_thrust_time -= mouse_axis[kc_mouse[23].value];
3839                 else
3840                         Controls.forward_thrust_time += mouse_axis[kc_mouse[23].value];
3841         }
3842
3843         // From mouse buttons
3844         if ( (use_mouse)&&(kc_mouse[2].value < 255 )) Controls.forward_thrust_time += mouse_button_down_time( kc_mouse[2].value );
3845         if ( (use_mouse)&&(kc_mouse[3].value < 255 )) Controls.forward_thrust_time -= mouse_button_down_time( kc_mouse[3].value );
3846
3847 //----------- Read afterburner_state -------------
3848
3849         // From keyboard...
3850         if ( kc_keyboard[46].value < 255 ) Controls.afterburner_state |= keyd_pressed[kc_keyboard[46].value];
3851         if ( kc_keyboard[47].value < 255 ) Controls.afterburner_state |= keyd_pressed[kc_keyboard[47].value];
3852
3853         if ( (use_mouse)&&(kc_mouse[27].value < 255 )) Controls.afterburner_state |= mouse_button_state(kc_mouse[27].value);
3854
3855         if ( (use_joystick)&&(kc_joystick[27].value < 255 )) Controls.afterburner_state |= joy_get_button_state(kc_joystick[27].value);
3856
3857 //-------Read headlight key--------------------------
3858
3859         if (kc_keyboard[52].value < 255 )
3860                    Controls.headlight_count=key_down_count(kc_keyboard[52].value);
3861         if (kc_keyboard[53].value < 255 )
3862                    Controls.headlight_count+=key_down_count(kc_keyboard[53].value);
3863                   if ((use_joystick)&&(kc_joystick[30].value < 255 )) 
3864                Controls.headlight_count+=joy_get_button_down_cnt(kc_joystick[30].value);
3865
3866 //--------Read Cycle Primary Key------------------
3867
3868                   if (kc_keyboard[48].value<255)
3869                          Controls.cycle_primary_count=key_down_count(kc_keyboard[48].value);
3870                   if (kc_keyboard[49].value<255)
3871                         Controls.cycle_primary_count+=key_down_count(kc_keyboard[49].value);
3872              if ((use_joystick)&&(kc_joystick[28].value < 255 )) 
3873          Controls.cycle_primary_count+=joy_get_button_down_cnt(kc_joystick[28].value);
3874
3875
3876 //--------Read Cycle Secondary Key------------------
3877
3878                   if (kc_keyboard[50].value<255)
3879                          Controls.cycle_secondary_count=key_down_count(kc_keyboard[50].value);
3880                   if (kc_keyboard[51].value<255)
3881                         Controls.cycle_secondary_count+=key_down_count(kc_keyboard[51].value);
3882              if ((use_joystick)&&(kc_joystick[29].value < 255 )) 
3883                         Controls.cycle_secondary_count=joy_get_button_down_cnt(kc_joystick[29].value);
3884
3885 //--------Read Toggle Bomb key----------------------
3886
3887                   if (kc_keyboard[56].value<255 && key_down_count(kc_keyboard[56].value))
3888          {
3889           int bomb = Secondary_last_was_super[PROXIMITY_INDEX]?PROXIMITY_INDEX:SMART_MINE_INDEX;
3890
3891                          if (!Players[Player_num].secondary_ammo[PROXIMITY_INDEX] &&
3892                                   !Players[Player_num].secondary_ammo[SMART_MINE_INDEX])
3893                            {
3894                                  digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
3895                                  HUD_init_message ("No bombs available!");
3896                                 }
3897                          else
3898                                 {       
3899                                  if (Players[Player_num].secondary_ammo[bomb]==0)
3900                                         {
3901                                          digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
3902                                          HUD_init_message ("No %s available!",(bomb==SMART_MINE_INDEX)?"Smart mines":"Proximity bombs");
3903                                         }
3904                                   else
3905                                         {
3906                                Secondary_last_was_super[PROXIMITY_INDEX]=!Secondary_last_was_super[PROXIMITY_INDEX];
3907                                          digi_play_sample_once( SOUND_GOOD_SELECTION_SECONDARY, F1_0 );
3908                                         }
3909                                 }
3910                         }
3911           
3912 //---------Read Energy->Shield key----------
3913
3914         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[kc_keyboard[54].value])
3915                 transfer_energy_to_shield(key_down_time(kc_keyboard[54].value));
3916         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[kc_keyboard[55].value])
3917                 transfer_energy_to_shield(key_down_time(kc_keyboard[55].value));
3918
3919 //----------- Read fire_primary_down_count
3920         if (kc_keyboard[24].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[24].value);
3921         if (kc_keyboard[25].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[25].value);
3922         if ((use_joystick)&&(kc_joystick[0].value < 255 )) Controls.fire_primary_down_count += joy_get_button_down_cnt(kc_joystick[0].value);
3923         if ((use_mouse)&&(kc_mouse[0].value < 255 )) Controls.fire_primary_down_count += mouse_button_down_count(kc_mouse[0].value);
3924
3925 //----------- Read fire_primary_state
3926         if (kc_keyboard[24].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[24].value];
3927         if (kc_keyboard[25].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[25].value];
3928         if ((use_joystick)&&(kc_joystick[0].value < 255 )) Controls.fire_primary_state |= joy_get_button_state(kc_joystick[0].value);
3929         if ((use_mouse)&&(kc_mouse[0].value < 255) ) Controls.fire_primary_state |= mouse_button_state(kc_mouse[0].value);
3930
3931 //----------- Read fire_secondary_down_count
3932         if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[26].value);
3933         if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[27].value);
3934         if ((use_joystick)&&(kc_joystick[1].value < 255 )) Controls.fire_secondary_down_count += joy_get_button_down_cnt(kc_joystick[1].value);
3935         if ((use_mouse)&&(kc_mouse[1].value < 255 )) Controls.fire_secondary_down_count += mouse_button_down_count(kc_mouse[1].value);
3936
3937 //----------- Read fire_secondary_state
3938         if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[26].value];
3939         if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[27].value];
3940         if ((use_joystick)&&(kc_joystick[1].value < 255 )) Controls.fire_secondary_state |= joy_get_button_state(kc_joystick[1].value);
3941         if ((use_mouse)&&(kc_mouse[1].value < 255) ) Controls.fire_secondary_state |= mouse_button_state(kc_mouse[1].value);
3942
3943 //----------- Read fire_flare_down_count
3944         if (kc_keyboard[28].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[28].value);
3945         if (kc_keyboard[29].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[29].value);
3946         if ((use_joystick)&&(kc_joystick[4].value < 255 )) Controls.fire_flare_down_count += joy_get_button_down_cnt(kc_joystick[4].value);
3947         if ((use_mouse)&&(kc_mouse[4].value < 255 )) Controls.fire_flare_down_count += mouse_button_down_count(kc_mouse[4].value);
3948
3949 //----------- Read drop_bomb_down_count
3950         if (kc_keyboard[34].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[34].value);
3951         if (kc_keyboard[35].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[35].value);
3952         if ((use_joystick)&&(kc_joystick[26].value < 255 )) Controls.drop_bomb_down_count += joy_get_button_down_cnt(kc_joystick[26].value);
3953         if ((use_mouse)&&(kc_mouse[26].value < 255 )) Controls.drop_bomb_down_count += mouse_button_down_count(kc_mouse[26].value);
3954
3955 //----------- Read rear_view_down_count
3956         if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[36].value);
3957         if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[37].value);
3958         if ((use_joystick)&&(kc_joystick[25].value < 255 )) Controls.rear_view_down_count += joy_get_button_down_cnt(kc_joystick[25].value);
3959         if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_count += mouse_button_down_count(kc_mouse[25].value);
3960
3961 //----------- Read rear_view_down_state
3962         if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[36].value];
3963         if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[37].value];
3964         if ((use_joystick)&&(kc_joystick[25].value < 255 )) Controls.rear_view_down_state |= joy_get_button_state(kc_joystick[25].value);
3965         if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_state |= mouse_button_state(kc_mouse[25].value);
3966
3967 }//end "if" added by WraithX
3968
3969 //----------- Read automap_down_count
3970         if (kc_keyboard[44].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[44].value);
3971         if (kc_keyboard[45].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[45].value);
3972
3973 //----------- Read automap_state
3974         if (kc_keyboard[44].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[44].value];
3975         if (kc_keyboard[45].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[45].value];
3976
3977 //----------- Read stupid-cruise-control-type of throttle.
3978         {
3979                 if ( kc_keyboard[38].value < 255 ) Cruise_speed += fixdiv(speed_factor*key_down_time(kc_keyboard[38].value)*5,FrameTime);
3980                 if ( kc_keyboard[39].value < 255 ) Cruise_speed += fixdiv(speed_factor*key_down_time(kc_keyboard[39].value)*5,FrameTime);
3981                 if ( kc_keyboard[40].value < 255 ) Cruise_speed -= fixdiv(speed_factor*key_down_time(kc_keyboard[40].value)*5,FrameTime);
3982                 if ( kc_keyboard[41].value < 255 ) Cruise_speed -= fixdiv(speed_factor*key_down_time(kc_keyboard[41].value)*5,FrameTime);
3983                 if ( (kc_keyboard[42].value < 255) && (key_down_count(kc_keyboard[42].value)) )
3984                         Cruise_speed = 0;
3985                 if ( (kc_keyboard[43].value < 255) && (key_down_count(kc_keyboard[43].value)) )
3986                         Cruise_speed = 0;
3987         
3988                 if (Cruise_speed > i2f(100) ) Cruise_speed = i2f(100);
3989                 if (Cruise_speed < 0 ) Cruise_speed = 0;
3990         
3991                 if (Controls.forward_thrust_time==0)
3992                         Controls.forward_thrust_time = fixmul(Cruise_speed,FrameTime)/100;
3993         }
3994
3995 #if !defined(MACINTOSH)
3996         //read_head_tracker();
3997
3998         // Read external controls
3999         // if (kc_use_external_control || CybermouseActive)
4000         //      kconfig_read_external_controls();
4001 #endif
4002
4003 //----------- Clamp values between -FrameTime and FrameTime
4004         if (FrameTime > F1_0 )
4005                 mprintf( (1, "Bogus frame time of %.2f seconds\n", f2fl(FrameTime) ));
4006
4007         if (Controls.pitch_time > FrameTime/2 ) Controls.pitch_time = FrameTime/2;
4008         if (Controls.vertical_thrust_time > FrameTime ) Controls.vertical_thrust_time = FrameTime;
4009         if (Controls.heading_time > FrameTime ) Controls.heading_time = FrameTime;
4010         if (Controls.sideways_thrust_time > FrameTime ) Controls.sideways_thrust_time = FrameTime;
4011         if (Controls.bank_time > FrameTime ) Controls.bank_time = FrameTime;
4012         if (Controls.forward_thrust_time > FrameTime ) Controls.forward_thrust_time = FrameTime;
4013 //      if (Controls.afterburner_time > FrameTime ) Controls.afterburner_time = FrameTime;
4014
4015         if (Controls.pitch_time < -FrameTime/2 ) Controls.pitch_time = -FrameTime/2;
4016         if (Controls.vertical_thrust_time < -FrameTime ) Controls.vertical_thrust_time = -FrameTime;
4017         if (Controls.heading_time < -FrameTime ) Controls.heading_time = -FrameTime;
4018         if (Controls.sideways_thrust_time < -FrameTime ) Controls.sideways_thrust_time = -FrameTime;
4019         if (Controls.bank_time < -FrameTime ) Controls.bank_time = -FrameTime;
4020         if (Controls.forward_thrust_time < -FrameTime ) Controls.forward_thrust_time = -FrameTime;
4021 //      if (Controls.afterburner_time < -FrameTime ) Controls.afterburner_time = -FrameTime;
4022
4023
4024 //--------- Don't do anything if in debug mode
4025         #ifndef RELEASE
4026         if ( keyd_pressed[KEY_DELETE] ) {
4027                 memset( &Controls, 0, sizeof(control_info) );
4028         }
4029         #endif
4030 }
4031 #endif
4032
4033 void reset_cruise(void)
4034 {
4035         Cruise_speed=0;
4036 }
4037
4038
4039 void kc_set_controls()
4040 {
4041         int i;
4042
4043         for (i=0; i<NUM_KEY_CONTROLS; i++ )     
4044                 kc_keyboard[i].value = kconfig_settings[0][i];
4045
4046         if ( (Config_control_type>0) && (Config_control_type<5)) {
4047                 for (i=0; i<NUM_OTHER_CONTROLS; i++ ) {
4048                         kc_joystick[i].value = kconfig_settings[Config_control_type][i];
4049                         if (kc_joystick[i].type == BT_INVERT )  {
4050                                 if (kc_joystick[i].value!=1)
4051                                         kc_joystick[i].value    = 0;
4052                                 kconfig_settings[Config_control_type][i] = kc_joystick[i].value;
4053                         }
4054                 }
4055         } else if (Config_control_type>4 && Config_control_type<CONTROL_WINJOYSTICK) {
4056                 for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
4057                         kc_mouse[i].value = kconfig_settings[Config_control_type][i];
4058                         if (kc_mouse[i].type == BT_INVERT )     {
4059                                 if (kc_mouse[i].value!=1)
4060                                         kc_mouse[i].value       = 0;
4061                                 kconfig_settings[Config_control_type][i] = kc_mouse[i].value;
4062                         }
4063                 }
4064         } else if (Config_control_type == CONTROL_WINJOYSTICK) {
4065                 for (i=0; i<NUM_OTHER_CONTROLS; i++ ) {
4066                         kc_superjoy[i].value = kconfig_settings[Config_control_type][i];
4067                         if (kc_superjoy[i].type == BT_INVERT )  {
4068                                 if (kc_superjoy[i].value!=1)
4069                                         kc_superjoy[i].value    = 0;
4070                                 kconfig_settings[Config_control_type][i] = kc_superjoy[i].value;
4071                         }
4072                 }
4073         }
4074
4075 #ifdef D2X_KEYS
4076         for (i=0; i<NUM_D2X_CONTROLS; i++ )
4077                 kc_d2x[i].value = kconfig_d2x_settings[i];
4078 #endif
4079 }
4080
4081 #if 0 //ndef MACINTOSH  // no mac support for vr headset
4082
4083 void kconfig_center_headset()
4084 {
4085 #ifndef WINDOWS
4086         if (vfx1_installed)
4087                 vfx_center_headset();
4088 #endif
4089 //      } else if (iglasses_headset_installed)  {
4090 //      } else if (Victor_headset_installed)   {
4091 //      } else {
4092 //      }
4093
4094 }
4095
4096 #endif  // end of #ifndef MACINTOSH for kconfig_center_headset
4097
4098 void CybermouseAdjust ()
4099  {
4100 /*      if ( Player_num > -1 )  {
4101                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_TURNROLL);    // Turn off roll when turning
4102                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_LEVELLING);   // Turn off leveling to nearest side.
4103                 Auto_leveling_on = 0;
4104
4105                 if ( kc_external_version > 0 ) {                
4106                         vms_matrix tempm, ViewMatrix;
4107                         vms_angvec * Kconfig_abs_movement;
4108                         char * oem_message;
4109         
4110                         Kconfig_abs_movement = (vms_angvec *)((uint)kc_external_control + sizeof(control_info));
4111         
4112                         if ( Kconfig_abs_movement->p || Kconfig_abs_movement->b || Kconfig_abs_movement->h )    {
4113                                 vm_angles_2_matrix(&tempm,Kconfig_abs_movement);
4114                                 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
4115                                 Objects[Players[Player_num].objnum].orient = ViewMatrix;                
4116                         }
4117                         oem_message = (char *)((uint)Kconfig_abs_movement + sizeof(vms_angvec));
4118                         if (oem_message[0] != '\0' )
4119                                 HUD_init_message( oem_message );
4120                 }
4121         }*/
4122
4123         Controls.pitch_time += fixmul(kc_external_control->pitch_time,FrameTime);                                               
4124         Controls.vertical_thrust_time += fixmul(kc_external_control->vertical_thrust_time,FrameTime);
4125         Controls.heading_time += fixmul(kc_external_control->heading_time,FrameTime);
4126         Controls.sideways_thrust_time += fixmul(kc_external_control->sideways_thrust_time ,FrameTime);
4127         Controls.bank_time += fixmul(kc_external_control->bank_time ,FrameTime);
4128         Controls.forward_thrust_time += fixmul(kc_external_control->forward_thrust_time ,FrameTime);
4129 //      Controls.rear_view_down_count += kc_external_control->rear_view_down_count;     
4130 //      Controls.rear_view_down_state |= kc_external_control->rear_view_down_state;     
4131         Controls.fire_primary_down_count += kc_external_control->fire_primary_down_count;
4132         Controls.fire_primary_state |= kc_external_control->fire_primary_state;
4133         Controls.fire_secondary_state |= kc_external_control->fire_secondary_state;
4134         Controls.fire_secondary_down_count += kc_external_control->fire_secondary_down_count;
4135         Controls.fire_flare_down_count += kc_external_control->fire_flare_down_count;
4136         Controls.drop_bomb_down_count += kc_external_control->drop_bomb_down_count;     
4137 //      Controls.automap_down_count += kc_external_control->automap_down_count;
4138 //      Controls.automap_state |= kc_external_control->automap_state;
4139   } 
4140
4141 char GetKeyValue (char key)
4142   {
4143         mprintf ((0,"Returning %c!\n",kc_keyboard[(int)key].value));
4144         return (kc_keyboard[(int)key].value);
4145   }
4146
4147 #if !defined(MACINTOSH)
4148
4149
4150 extern object *obj_find_first_of_type (int);
4151 void kconfig_read_external_controls()
4152 {
4153         //union REGS r;
4154    int i;
4155
4156         if ( !kc_enable_external_control ) return;
4157
4158         if ( kc_external_version == 0 ) 
4159                 memset( kc_external_control, 0, sizeof(ext_control_info));
4160         else if ( kc_external_version > 0 )     {
4161         
4162                 if (kc_external_version>=4)
4163                         memset( kc_external_control, 0, sizeof(advanced_ext_control_info));
4164       else if (kc_external_version>0)     
4165                         memset( kc_external_control, 0, sizeof(ext_control_info)+sizeof(vms_angvec) + 64 );
4166                 else if (kc_external_version>2)
4167                         memset( kc_external_control, 0, sizeof(ext_control_info)+sizeof(vms_angvec) + 64 + sizeof(vms_vector) + sizeof(vms_matrix) +4 );
4168
4169                 if ( kc_external_version > 1 ) {
4170                         // Write ship pos and angles to external controls...
4171                         ubyte *temp_ptr = (ubyte *)kc_external_control;
4172                         vms_vector *ship_pos;
4173                         vms_matrix *ship_orient;
4174                         memset( kc_external_control, 0, sizeof(ext_control_info)+sizeof(vms_angvec) + 64 + sizeof(vms_vector)+sizeof(vms_matrix) );
4175                         temp_ptr += sizeof(ext_control_info) + sizeof(vms_angvec) + 64;
4176                         ship_pos = (vms_vector *)temp_ptr;
4177                         temp_ptr += sizeof(vms_vector);
4178                         ship_orient = (vms_matrix *)temp_ptr;
4179                         // Fill in ship postion...
4180                         *ship_pos = Objects[Players[Player_num].objnum].pos;
4181                         // Fill in ship orientation...
4182                         *ship_orient = Objects[Players[Player_num].objnum].orient;
4183                 }
4184     if (kc_external_version>=4)
4185           {
4186            advanced_ext_control_info *temp_ptr=(advanced_ext_control_info *)kc_external_control;
4187  
4188       temp_ptr->headlight_state=(Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON);
4189                 temp_ptr->primary_weapon_flags=Players[Player_num].primary_weapon_flags;
4190                 temp_ptr->secondary_weapon_flags=Players[Player_num].secondary_weapon_flags;
4191       temp_ptr->current_primary_weapon=Primary_weapon;
4192       temp_ptr->current_secondary_weapon=Secondary_weapon;
4193
4194       temp_ptr->current_guidebot_command=Escort_goal_object;
4195
4196            temp_ptr->force_vector=ExtForceVec;
4197                 temp_ptr->force_matrix=ExtApplyForceMatrix;
4198            for (i=0;i<3;i++)
4199        temp_ptr->joltinfo[i]=ExtJoltInfo[i];  
4200       for (i=0;i<2;i++)
4201                    temp_ptr->x_vibrate_info[i]=ExtXVibrateInfo[i];
4202                 temp_ptr->x_vibrate_clear=ExtXVibrateClear;
4203            temp_ptr->game_status=ExtGameStatus;
4204    
4205       memset ((void *)&ExtForceVec,0,sizeof(vms_vector));
4206       memset ((void *)&ExtApplyForceMatrix,0,sizeof(vms_matrix));
4207       
4208       for (i=0;i<3;i++)
4209                  ExtJoltInfo[i]=0;
4210       for (i=0;i<2;i++)
4211                  ExtXVibrateInfo[i]=0;
4212       ExtXVibrateClear=0;
4213      }
4214         }
4215
4216         if ( Automap_active )                   // (If in automap...)
4217                 kc_external_control->automap_state = 1;
4218         //memset(&r,0,sizeof(r));
4219
4220   #if 0
4221  
4222         int386 ( kc_external_intno, &r, &r);            // Read external info...
4223
4224   #endif 
4225
4226         if ( Player_num > -1 )  {
4227                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_TURNROLL);    // Turn off roll when turning
4228                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_LEVELLING);   // Turn off leveling to nearest side.
4229                 Auto_leveling_on = 0;
4230
4231                 if ( kc_external_version > 0 ) {                
4232                         vms_matrix tempm, ViewMatrix;
4233                         vms_angvec * Kconfig_abs_movement;
4234                         char * oem_message;
4235         
4236                         Kconfig_abs_movement = (vms_angvec *)((uint)kc_external_control + sizeof(ext_control_info));
4237         
4238                         if ( Kconfig_abs_movement->p || Kconfig_abs_movement->b || Kconfig_abs_movement->h )    {
4239                                 vm_angles_2_matrix(&tempm,Kconfig_abs_movement);
4240                                 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
4241                                 Objects[Players[Player_num].objnum].orient = ViewMatrix;                
4242                         }
4243                         oem_message = (char *)((uint)Kconfig_abs_movement + sizeof(vms_angvec));
4244                         if (oem_message[0] != '\0' )
4245                                 HUD_init_message( oem_message );
4246                 }
4247         }
4248
4249         Controls.pitch_time += fixmul(kc_external_control->pitch_time,FrameTime);                                               
4250         Controls.vertical_thrust_time += fixmul(kc_external_control->vertical_thrust_time,FrameTime);
4251         Controls.heading_time += fixmul(kc_external_control->heading_time,FrameTime);
4252         Controls.sideways_thrust_time += fixmul(kc_external_control->sideways_thrust_time ,FrameTime);
4253         Controls.bank_time += fixmul(kc_external_control->bank_time ,FrameTime);
4254         Controls.forward_thrust_time += fixmul(kc_external_control->forward_thrust_time ,FrameTime);
4255         Controls.rear_view_down_count += kc_external_control->rear_view_down_count;     
4256         Controls.rear_view_down_state |= kc_external_control->rear_view_down_state;     
4257         Controls.fire_primary_down_count += kc_external_control->fire_primary_down_count;
4258         Controls.fire_primary_state |= kc_external_control->fire_primary_state;
4259         Controls.fire_secondary_state |= kc_external_control->fire_secondary_state;
4260         Controls.fire_secondary_down_count += kc_external_control->fire_secondary_down_count;
4261         Controls.fire_flare_down_count += kc_external_control->fire_flare_down_count;
4262         Controls.drop_bomb_down_count += kc_external_control->drop_bomb_down_count;     
4263         Controls.automap_down_count += kc_external_control->automap_down_count;
4264         Controls.automap_state |= kc_external_control->automap_state;
4265         
4266    if (kc_external_version>=3)
4267          {
4268                 ubyte *temp_ptr = (ubyte *)kc_external_control;
4269                 temp_ptr += (sizeof(ext_control_info) + sizeof(vms_angvec) + 64 + sizeof(vms_vector) + sizeof (vms_matrix));
4270   
4271            if (*(temp_ptr))
4272                  Controls.cycle_primary_count=(*(temp_ptr));
4273            if (*(temp_ptr+1))
4274                  Controls.cycle_secondary_count=(*(temp_ptr+1));
4275
4276                 if (*(temp_ptr+2))
4277                  Controls.afterburner_state=(*(temp_ptr+2));
4278                 if (*(temp_ptr+3))
4279                  Controls.headlight_count=(*(temp_ptr+3));
4280          }
4281    if (kc_external_version>=4)
4282          {
4283      int i;
4284           advanced_ext_control_info *temp_ptr=(advanced_ext_control_info *)kc_external_control;
4285      
4286      for (i=0;i<128;i++)
4287            if (temp_ptr->keyboard[i])
4288                         key_putkey (i);
4289
4290      if (temp_ptr->Reactor_blown)
4291       {
4292        if (Game_mode & GM_MULTI)
4293                     net_destroy_controlcen (obj_find_first_of_type (OBJ_CNTRLCEN));
4294                  else
4295                          do_controlcen_destroyed_stuff(obj_find_first_of_type (OBJ_CNTRLCEN));
4296            }
4297     }
4298   
4299 }
4300 #endif
4301