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