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