Skip to content
Newer
Older
100644 458 lines (389 sloc) 10.2 KB
95189b3 Import
paul authored Jul 29, 2007
1 #include "wl_def.h"
2
3 /*
4 =============================================================================
5
6 GLOBAL VARIABLES
7
8 =============================================================================
9 */
10
11 //
12 // configuration variables
13 //
7b8550a Remove mouse code.
paul authored Aug 19, 2007
14 #ifdef ENABLE_MOUSE
95189b3 Import
paul authored Jul 29, 2007
15 boolean MousePresent;
7b8550a Remove mouse code.
paul authored Aug 19, 2007
16 #endif
17 #ifdef ENABLE_JOYSTICK
95189b3 Import
paul authored Jul 29, 2007
18 boolean JoysPresent[MaxJoys];
c7090d3 Remove joystick code.
paul authored Aug 12, 2007
19 #endif
95189b3 Import
paul authored Jul 29, 2007
20
21 // Global variables
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
22 uint32_t Keyboard[NumCodes >> 5];
95189b3 Import
paul authored Jul 29, 2007
23 boolean Paused;
24 char LastASCII;
25 ScanCode LastScan;
4a6e324 Luminary board port.
paul authored Aug 7, 2007
26 unsigned long LastEventTime;
95189b3 Import
paul authored Jul 29, 2007
27
28 KeyboardDef KbdDefs = {sc_Control, sc_Alt, sc_Home, sc_UpArrow, sc_PgUp, sc_LeftArrow, sc_RightArrow, sc_End, sc_DownArrow, sc_PgDn};
29
30 ControlType Controls[MaxPlayers];
31
32 /*
33 =============================================================================
34
35 LOCAL VARIABLES
36
37 =============================================================================
38 */
4db5f89 Disable ascii character recognition.
paul authored Aug 19, 2007
39 #ifndef EMBEDDED
95189b3 Import
paul authored Jul 29, 2007
40 static const byte ASCIINames[] = // Unshifted ASCII for scan codes
41 {
42 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
43 0 ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8 ,9 , // 0
44 'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0 ,'a','s', // 1
45 'd','f','g','h','j','k','l',';',39 ,'`',0 ,92 ,'z','x','c','v', // 2
46 'b','n','m',',','.','/',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
47 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
48 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
49 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
50 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
51 },
52 ShiftNames[] = // Shifted ASCII for scan codes
53 {
54 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
55 0 ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8 ,9 , // 0
56 'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0 ,'A','S', // 1
57 'D','F','G','H','J','K','L',':',34 ,'~',0 ,'|','Z','X','C','V', // 2
58 'B','N','M','<','>','?',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
59 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
60 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
61 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
62 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
63 };
4db5f89 Disable ascii character recognition.
paul authored Aug 19, 2007
64 #endif
95189b3 Import
paul authored Jul 29, 2007
65
66 static boolean IN_Started;
4db5f89 Disable ascii character recognition.
paul authored Aug 19, 2007
67 #ifndef EMBEDDED
95189b3 Import
paul authored Jul 29, 2007
68 static boolean CapsLock;
4db5f89 Disable ascii character recognition.
paul authored Aug 19, 2007
69 #endif
95189b3 Import
paul authored Jul 29, 2007
70 static ScanCode CurCode,LastCode;
71
72 static const Direction DirTable[] = // Quick lookup for total direction
73 {
74 dir_NorthWest, dir_North, dir_NorthEast,
75 dir_West, dir_None, dir_East,
76 dir_SouthWest, dir_South, dir_SouthEast
77 };
78
7b8550a Remove mouse code.
paul authored Aug 19, 2007
79 #ifndef KBD_ONLY
95189b3 Import
paul authored Jul 29, 2007
80 static boolean btnstate[8];
7b8550a Remove mouse code.
paul authored Aug 19, 2007
81 #endif
95189b3 Import
paul authored Jul 29, 2007
82
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
83 #define GetKey(code) \
84 ((Keyboard[(code >> 5)] & (1 << (code & 31))) != 0)
85 #define SetKey(code) \
86 Keyboard[(code >> 5)] |= (1 << (code & 31))
87 #define ClearKey(code) \
88 Keyboard[(code >> 5)] &= ~(1 << (code & 31))
0933d39 Reduce object memory use.
paul authored Jul 29, 2007
89 void keyboard_handler(myint code, myint press)
95189b3 Import
paul authored Jul 29, 2007
90 {
4db5f89 Disable ascii character recognition.
paul authored Aug 19, 2007
91 byte k;
92 #ifndef EMBEDDED
93 byte c = 0;
94 #endif
95189b3 Import
paul authored Jul 29, 2007
95
4a6e324 Luminary board port.
paul authored Aug 7, 2007
96 LastEventTime = get_TimeCount();
97
95189b3 Import
paul authored Jul 29, 2007
98 k = code;
99
100 if (k == 0xe1) // Handle Pause key
101 Paused = true;
102 else
103 {
104 if (press == 0)
105 {
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
106 ClearKey(k);
95189b3 Import
paul authored Jul 29, 2007
107 }
108 else // Make code
109 {
110 LastCode = CurCode;
111 CurCode = LastScan = k;
112
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
113 SetKey(k);
95189b3 Import
paul authored Jul 29, 2007
114
4db5f89 Disable ascii character recognition.
paul authored Aug 19, 2007
115 #ifndef EMBEDDED
95189b3 Import
paul authored Jul 29, 2007
116 if (k == sc_CapsLock)
117 {
118 CapsLock ^= true;
119 }
120
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
121 if (GetKey(sc_LShift) || GetKey(sc_RShift)) // If shifted
95189b3 Import
paul authored Jul 29, 2007
122 {
123 c = ShiftNames[k];
124 if ((c >= 'A') && (c <= 'Z') && CapsLock)
125 c += 'a' - 'A';
126 }
127 else
128 {
129 c = ASCIINames[k];
130 if ((c >= 'a') && (c <= 'z') && CapsLock)
131 c -= 'a' - 'A';
132 }
133
134 if (c)
135 LastASCII = c;
4db5f89 Disable ascii character recognition.
paul authored Aug 19, 2007
136 #endif
95189b3 Import
paul authored Jul 29, 2007
137 }
138 }
139 }
140
0db07d2 Disable dead code.
paul authored Nov 25, 2007
141 #ifndef EMBEDDED
95189b3 Import
paul authored Jul 29, 2007
142 ///////////////////////////////////////////////////////////////////////////
143 //
144 // IN_UserInput() - Waits for the specified delay time (in ticks) or the
145 // user pressing a key or a mouse button. If the clear flag is set, it
146 // then either clears the key or waits for the user to let the mouse
147 // button up.
148 //
149 ///////////////////////////////////////////////////////////////////////////
150 boolean IN_UserInput(longword delay)
151 {
152 longword lasttime;
153
154 lasttime = get_TimeCount();
155
156 IN_StartAck();
157 do {
158 if (IN_CheckAck())
159 return true;
160 } while ( (get_TimeCount() - lasttime) < delay );
161
162 return false;
163 }
0db07d2 Disable dead code.
paul authored Nov 25, 2007
164 #endif
95189b3 Import
paul authored Jul 29, 2007
165
166 //===========================================================================
167
168 ///////////////////////////////////////////////////////////////////////////
169 //
170 // INL_StartKbd() - Sets up my keyboard stuff for use
171 //
172 ///////////////////////////////////////////////////////////////////////////
173 static void INL_StartKbd(void)
174 {
175 IN_ClearKeysDown();
176 }
177
a5ee03f Remove dead code.
paul authored Jul 5, 2008
178 #ifndef EMBEDDED
95189b3 Import
paul authored Jul 29, 2007
179 ///////////////////////////////////////////////////////////////////////////
180 //
181 // INL_ShutKbd() - Restores keyboard control to the BIOS
182 //
183 ///////////////////////////////////////////////////////////////////////////
184 static void INL_ShutKbd(void)
185 {
186 }
187
188 ///////////////////////////////////////////////////////////////////////////
189 //
190 // INL_ShutMouse() - Cleans up after the mouse
191 //
192 ///////////////////////////////////////////////////////////////////////////
193 static void INL_ShutMouse(void)
194 {
195 }
a5ee03f Remove dead code.
paul authored Jul 5, 2008
196 #endif
95189b3 Import
paul authored Jul 29, 2007
197
c7090d3 Remove joystick code.
paul authored Aug 12, 2007
198 #ifdef ENABLE_JOYSTICK
95189b3 Import
paul authored Jul 29, 2007
199 ///////////////////////////////////////////////////////////////////////////
200 //
201 // INL_StartJoy() - Detects & auto-configures the specified joystick
202 // The auto-config assumes the joystick is centered
203 //
204 ///////////////////////////////////////////////////////////////////////////
205 static boolean INL_StartJoy(word joy)
206 {
207 return false;
208 }
209
210 ///////////////////////////////////////////////////////////////////////////
211 //
212 // INL_ShutJoy() - Cleans up the joystick stuff
213 //
214 ///////////////////////////////////////////////////////////////////////////
215 static void INL_ShutJoy(word joy)
216 {
217 JoysPresent[joy] = false;
218 }
c7090d3 Remove joystick code.
paul authored Aug 12, 2007
219 #endif
95189b3 Import
paul authored Jul 29, 2007
220
221
222 ///////////////////////////////////////////////////////////////////////////
223 //
224 // IN_Startup() - Starts up the Input Mgr
225 //
226 ///////////////////////////////////////////////////////////////////////////
227 void IN_Startup(void)
228 {
c7090d3 Remove joystick code.
paul authored Aug 12, 2007
229 #ifdef ENABLE_JOYSTICK
95189b3 Import
paul authored Jul 29, 2007
230 boolean checkjoys;
231 word i;
c7090d3 Remove joystick code.
paul authored Aug 12, 2007
232 #endif
95189b3 Import
paul authored Jul 29, 2007
233
234 if (IN_Started)
235 return;
236
bc5d5b7 Remove C library dependencies.
paul authored Aug 5, 2007
237 #ifndef EMBEDDED
95189b3 Import
paul authored Jul 29, 2007
238 checkjoys = true;
239
240 if (MS_CheckParm("nojoy"))
241 checkjoys = false;
242 if (MS_CheckParm("nomouse"))
243 MousePresent = false;
244 else
245 MousePresent = true;
bc5d5b7 Remove C library dependencies.
paul authored Aug 5, 2007
246 #endif
95189b3 Import
paul authored Jul 29, 2007
247
248 INL_StartKbd();
249
de44c88 Hardcode GAMEEXT.
paul authored Aug 11, 2007
250 #ifdef ENABLE_JOYSTICK
95189b3 Import
paul authored Jul 29, 2007
251 for (i = 0;i < MaxJoys;i++)
252 JoysPresent[i] = checkjoys ? INL_StartJoy(i) : false;
de44c88 Hardcode GAMEEXT.
paul authored Aug 11, 2007
253 #endif
95189b3 Import
paul authored Jul 29, 2007
254
255 IN_Started = true;
256 }
257
a5ee03f Remove dead code.
paul authored Jul 5, 2008
258 #ifndef EMBEDDED
95189b3 Import
paul authored Jul 29, 2007
259 ///////////////////////////////////////////////////////////////////////////
260 //
261 // IN_Shutdown() - Shuts down the Input Mgr
262 //
263 ///////////////////////////////////////////////////////////////////////////
264 void IN_Shutdown(void)
265 {
c7090d3 Remove joystick code.
paul authored Aug 12, 2007
266 #ifdef ENABLE_JOYSTICK
95189b3 Import
paul authored Jul 29, 2007
267 word i;
c7090d3 Remove joystick code.
paul authored Aug 12, 2007
268 #endif
95189b3 Import
paul authored Jul 29, 2007
269
270 if (!IN_Started)
271 return;
272
273 INL_ShutMouse();
c7090d3 Remove joystick code.
paul authored Aug 12, 2007
274 #ifdef ENABLE_JOYSTICK
95189b3 Import
paul authored Jul 29, 2007
275 for (i = 0;i < MaxJoys;i++)
276 INL_ShutJoy(i);
c7090d3 Remove joystick code.
paul authored Aug 12, 2007
277 #endif
95189b3 Import
paul authored Jul 29, 2007
278 INL_ShutKbd();
279
280 IN_Started = false;
281 }
a5ee03f Remove dead code.
paul authored Jul 5, 2008
282 #endif
95189b3 Import
paul authored Jul 29, 2007
283
284 ///////////////////////////////////////////////////////////////////////////
285 //
286 // IN_ClearKeysDown() - Clears the keyboard array
287 //
288 ///////////////////////////////////////////////////////////////////////////
289 void IN_ClearKeysDown(void)
290 {
291 LastScan = sc_None;
292 LastASCII = key_None;
293 memset(Keyboard, 0, sizeof(Keyboard));
294 }
295
d6bf851 Strip out unused demo code.
paul authored Nov 25, 2007
296 #ifndef EMBEDDED
95189b3 Import
paul authored Jul 29, 2007
297 ///////////////////////////////////////////////////////////////////////////
298 //
299 // IN_ReadControl() - Reads the device associated with the specified
300 // player and fills in the control info struct
301 //
302 ///////////////////////////////////////////////////////////////////////////
0933d39 Reduce object memory use.
paul authored Jul 29, 2007
303 void IN_ReadControl(myint player,ControlInfo *info)
95189b3 Import
paul authored Jul 29, 2007
304 {
305 boolean realdelta = false;
306 word buttons;
0933d39 Reduce object memory use.
paul authored Jul 29, 2007
307 myint dx,dy;
95189b3 Import
paul authored Jul 29, 2007
308 Motion mx,my;
309 ControlType type;
310 KeyboardDef *def;
311
312 dx = dy = 0;
313 mx = my = motion_None;
314 buttons = 0;
315
316 IN_CheckAck();
317
318 switch (type = Controls[player])
319 {
320 case ctrl_Keyboard:
321 def = &KbdDefs;
322
d6bf851 Strip out unused demo code.
paul authored Nov 25, 2007
323 #ifndef EMBEDDED
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
324 if (GetKey(def->upleft))
95189b3 Import
paul authored Jul 29, 2007
325 mx = motion_Left,my = motion_Up;
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
326 else if (GetKey(def->upright))
95189b3 Import
paul authored Jul 29, 2007
327 mx = motion_Right,my = motion_Up;
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
328 else if (GetKey(def->downleft))
95189b3 Import
paul authored Jul 29, 2007
329 mx = motion_Left,my = motion_Down;
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
330 else if (GetKey(def->downright))
95189b3 Import
paul authored Jul 29, 2007
331 mx = motion_Right,my = motion_Down;
d6bf851 Strip out unused demo code.
paul authored Nov 25, 2007
332 #endif
95189b3 Import
paul authored Jul 29, 2007
333
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
334 if (GetKey(def->up))
95189b3 Import
paul authored Jul 29, 2007
335 my = motion_Up;
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
336 else if (GetKey(def->down))
95189b3 Import
paul authored Jul 29, 2007
337 my = motion_Down;
338
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
339 if (GetKey(def->left))
95189b3 Import
paul authored Jul 29, 2007
340 mx = motion_Left;
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
341 else if (GetKey(def->right))
95189b3 Import
paul authored Jul 29, 2007
342 mx = motion_Right;
343
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
344 if (GetKey(def->button0))
95189b3 Import
paul authored Jul 29, 2007
345 buttons += 1 << 0;
d905433 Shrink keyboard table.
paul authored Aug 1, 2007
346 if (GetKey(def->button1))
95189b3 Import
paul authored Jul 29, 2007
347 buttons += 1 << 1;
348 realdelta = false;
349 break;
7b8550a Remove mouse code.
paul authored Aug 19, 2007
350 #ifdef ENABLE_JOYSTICK
95189b3 Import
paul authored Jul 29, 2007
351 case ctrl_Joystick1:
352 case ctrl_Joystick2:
353 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy);
354 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
355 realdelta = true;
356 break;
7b8550a Remove mouse code.
paul authored Aug 19, 2007
357 #endif
358 #ifdef ENABLE_MOUSE
95189b3 Import
paul authored Jul 29, 2007
359 case ctrl_Mouse:
360 IN_GetMouseDelta(&dx,&dy);
361 buttons = IN_MouseButtons();
362 realdelta = true;
363 break;
7b8550a Remove mouse code.
paul authored Aug 19, 2007
364 #endif
95189b3 Import
paul authored Jul 29, 2007
365 }
366
367 if (realdelta)
368 {
369 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
370 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
371 }
372 else
373 {
374 dx = mx * 127;
375 dy = my * 127;
376 }
377
378 info->x = dx;
379 info->xaxis = mx;
380 info->y = dy;
381 info->yaxis = my;
382 info->button0 = buttons & (1 << 0);
383 info->button1 = buttons & (1 << 1);
384 info->button2 = buttons & (1 << 2);
385 info->button3 = buttons & (1 << 3);
386 info->dir = DirTable[((my + 1) * 3) + (mx + 1)];
387 }
d6bf851 Strip out unused demo code.
paul authored Nov 25, 2007
388 #endif
95189b3 Import
paul authored Jul 29, 2007
389
0db07d2 Disable dead code.
paul authored Nov 25, 2007
390 #ifndef EMBEDDED
95189b3 Import
paul authored Jul 29, 2007
391 ///////////////////////////////////////////////////////////////////////////
392 //
393 // IN_Ack() - waits for a button or key press. If a button is down, upon
394 // calling, it must be released for it to be recognized
395 //
396 ///////////////////////////////////////////////////////////////////////////
397
398 void IN_StartAck(void)
399 {
7b8550a Remove mouse code.
paul authored Aug 19, 2007
400 #ifndef KBD_ONLY
95189b3 Import
paul authored Jul 29, 2007
401 unsigned i,buttons;
7b8550a Remove mouse code.
paul authored Aug 19, 2007
402 #endif
403
95189b3 Import
paul authored Jul 29, 2007
404
405 //
406 // get initial state of everything
407 //
408 IN_ClearKeysDown();
7b8550a Remove mouse code.
paul authored Aug 19, 2007
409 #ifndef KBD_ONLY
95189b3 Import
paul authored Jul 29, 2007
410 memset (btnstate,0,sizeof(btnstate));
411
412 buttons = IN_JoyButtons () << 4;
413 if (MousePresent)
414 buttons |= IN_MouseButtons ();
415
416 for (i=0;i<8;i++,buttons>>=1)
417 if (buttons&1)
418 btnstate[i] = true;
7b8550a Remove mouse code.
paul authored Aug 19, 2007
419 #endif
95189b3 Import
paul authored Jul 29, 2007
420 }
421
422 boolean IN_CheckAck()
423 {
7b8550a Remove mouse code.
paul authored Aug 19, 2007
424 #ifndef KBD_ONLY
95189b3 Import
paul authored Jul 29, 2007
425 unsigned i, buttons;
7b8550a Remove mouse code.
paul authored Aug 19, 2007
426 #endif
95189b3 Import
paul authored Jul 29, 2007
427
428 INL_Update();
429
430 if (LastScan)
431 return true;
432
7b8550a Remove mouse code.
paul authored Aug 19, 2007
433 #ifndef KBD_ONLY
95189b3 Import
paul authored Jul 29, 2007
434 buttons = IN_JoyButtons () << 4;
435 if (MousePresent)
436 buttons |= IN_MouseButtons ();
437
438 for (i=0;i<8;i++,buttons>>=1)
439 if ( buttons&1 )
440 {
441 if (!btnstate[i])
442 return true;
443 }
444 else
445 btnstate[i]=false;
7b8550a Remove mouse code.
paul authored Aug 19, 2007
446 #endif
95189b3 Import
paul authored Jul 29, 2007
447
448 return false;
449 }
450
451 void IN_Ack()
452 {
453 IN_StartAck();
454
455 while(!IN_CheckAck()) ;
456 }
0db07d2 Disable dead code.
paul authored Nov 25, 2007
457 #endif
Something went wrong with that request. Please try again.