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