]> 4ch.mooo.com Git - 16.git/blob - 16/cawat/16_in.c
67e02e29f9ea347bbafcf455856742b9c5456015
[16.git] / 16 / cawat / 16_in.c
1 /* Catacomb Armageddon Source Code\r
2  * Copyright (C) 1993-2014 Flat Rock Software\r
3  *\r
4  * This program is free software; you can redistribute it and/or modify\r
5  * it under the terms of the GNU General Public License as published by\r
6  * the Free Software Foundation; either version 2 of the License, or\r
7  * (at your option) any later version.\r
8  *\r
9  * This program is distributed in the hope that it will be useful,\r
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12  * GNU General Public License for more details.\r
13  *\r
14  * You should have received a copy of the GNU General Public License along\r
15  * with this program; if not, write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
17  */\r
18 \r
19 //\r
20 //      ID Engine\r
21 //      ID_IN.c - Input Manager\r
22 //      v1.0d1\r
23 //      By Jason Blochowiak\r
24 //\r
25 \r
26 //\r
27 //      This module handles dealing with the various input devices\r
28 //\r
29 //      Depends on: Memory Mgr (for demo recording), Sound Mgr (for timing stuff),\r
30 //                              User Mgr (for command line parms)\r
31 //\r
32 //      Globals:\r
33 //              LastScan - The keyboard scan code of the last key pressed\r
34 //              LastASCII - The ASCII value of the last key pressed\r
35 //      DEBUG - there are more globals\r
36 //\r
37 \r
38 //#include "ID_HEADS.H"
39 #include "16_in.h"\r
40 //#pragma       hdrstop\r
41 \r
42 #define KeyInt  9       // The keyboard ISR number\r
43 \r
44 // Stuff for the joystick\r
45 #define JoyScaleMax             32768\r
46 #define JoyScaleShift   8\r
47 #define MaxJoyValue             5000\r
48 \r
49 //      Global variables\r
50                 boolean JoystickCalibrated=false;               // MDM (GAMERS EDGE) - added\r
51                 ControlType ControlTypeUsed;                            // MDM (GAMERS EDGE) - added\r
52 \r
53                 boolean         Keyboard[NumCodes],\r
54                                         JoysPresent[MaxJoys],\r
55                                         MousePresent;\r
56                 boolean         Paused;\r
57                 char            LastASCII;\r
58                 ScanCode        LastScan;\r
59                 KeyboardDef     KbdDefs[MaxKbds] = {{0x1d,0x38,0x47,0x48,0x49,0x4b,0x4d,0x4f,0x50,0x51}};\r
60                 JoystickDef     JoyDefs[MaxJoys];\r
61                 ControlType     Controls[MaxPlayers];\r
62 \r
63 //              Demo            DemoMode = demo_Off;\r
64 //              byte /*_1seg*/  *DemoBuffer;\r
65 //              word            DemoOffset,DemoSize;\r
66 \r
67 //      Internal variables\r
68 static  boolean         IN_Started;\r
69 static  boolean         CapsLock;\r
70 static  ScanCode        CurCode,LastCode;\r
71 static  byte        far ASCIINames[] =          // Unshifted ASCII for scan codes\r
72                                         {\r
73 //       0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F\r
74         0  ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8  ,9  ,        // 0\r
75         'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0  ,'a','s',        // 1\r
76         'd','f','g','h','j','k','l',';',39 ,'`',0  ,92 ,'z','x','c','v',        // 2\r
77         'b','n','m',',','.','/',0  ,'*',0  ,' ',0  ,0  ,0  ,0  ,0  ,0  ,        // 3\r
78         0  ,0  ,0  ,0  ,0  ,0  ,0  ,'7','8','9','-','4','5','6','+','1',        // 4\r
79         '2','3','0',127,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 5\r
80         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 6\r
81         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0           // 7\r
82                                         },\r
83                                         far ShiftNames[] =              // Shifted ASCII for scan codes\r
84                                         {\r
85 //       0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F\r
86         0  ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8  ,9  ,        // 0\r
87         'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0  ,'A','S',        // 1\r
88         'D','F','G','H','J','K','L',':',34 ,'~',0  ,'|','Z','X','C','V',        // 2\r
89         'B','N','M','<','>','?',0  ,'*',0  ,' ',0  ,0  ,0  ,0  ,0  ,0  ,        // 3\r
90         0  ,0  ,0  ,0  ,0  ,0  ,0  ,'7','8','9','-','4','5','6','+','1',        // 4\r
91         '2','3','0',127,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 5\r
92         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 6\r
93         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0           // 7\r
94                                         },\r
95                                         far SpecialNames[] =    // ASCII for 0xe0 prefixed codes\r
96                                         {\r
97 //       0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F\r
98         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 0\r
99         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,13 ,0  ,0  ,0  ,        // 1\r
100         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 2\r
101         0  ,0  ,0  ,0  ,0  ,'/',0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 3\r
102         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 4\r
103         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 5\r
104         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 6\r
105         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0           // 7\r
106                                         },\r
107 \r
108 #if 0\r
109                                         *ScanNames[] =          // Scan code names with single chars\r
110                                         {\r
111         "?","?","1","2","3","4","5","6","7","8","9","0","-","+","?","?",\r
112         "Q","W","E","R","T","Y","U","I","O","P","[","]","|","?","A","S",\r
113         "D","F","G","H","J","K","L",";","\"","?","?","?","Z","X","C","V",\r
114         "B","N","M",",",".","/","?","?","?","?","?","?","?","?","?","?",\r
115         "?","?","?","?","?","?","?","?","\xf","?","-","\x15","5","\x11","+","?",\r
116         "\x13","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",\r
117         "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",\r
118         "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"\r
119                                         },      // DEBUG - consolidate these\r
120 #endif\r
121 \r
122                                         far ExtScanCodes[] =    // Scan codes with >1 char names\r
123                                         {\r
124         1,0xe,0xf,0x1d,0x2a,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,\r
125         0x3f,0x40,0x41,0x42,0x43,0x44,0x57,0x59,0x46,0x1c,0x36,\r
126         0x37,0x38,0x47,0x49,0x4f,0x51,0x52,0x53,0x45,0x48,\r
127         0x50,0x4b,0x4d,0x00\r
128                                         };\r
129 #if 0\r
130                                         *ExtScanNames[] =       // Names corresponding to ExtScanCodes\r
131                                         {\r
132         "Esc","BkSp","Tab","Ctrl","LShft","Space","CapsLk","F1","F2","F3","F4",\r
133         "F5","F6","F7","F8","F9","F10","F11","F12","ScrlLk","Enter","RShft",\r
134         "PrtSc","Alt","Home","PgUp","End","PgDn","Ins","Del","NumLk","Up",\r
135         "Down","Left","Right",""\r
136                                         };\r
137 #endif\r
138 static  Direction       DirTable[] =            // Quick lookup for total direction\r
139                                         {\r
140                                                 dir_NorthWest,  dir_North,      dir_NorthEast,\r
141                                                 dir_West,               dir_None,       dir_East,\r
142                                                 dir_SouthWest,  dir_South,      dir_SouthEast\r
143                                         };\r
144 \r
145 static  void                    (*INL_KeyHook)(void);\r
146 static  void interrupt  (*OldKeyVect)(void);\r
147 \r
148 static  char                    *ParmStrings[] = {"nojoys","nomouse",nil};\r
149 \r
150 //      Internal routines\r
151 \r
152 ///////////////////////////////////////////////////////////////////////////\r
153 //\r
154 //      INL_KeyService() - Handles a keyboard interrupt (key up/down)\r
155 //\r
156 ///////////////////////////////////////////////////////////////////////////\r
157 static void interrupt\r
158 INL_KeyService(void)\r
159 {\r
160 static  boolean special;\r
161                 byte    k,c,\r
162                                 temp;\r
163 \r
164         k = inp(0x60);  // Get the scan code\r
165 \r
166         // Tell the XT keyboard controller to clear the key\r
167         outp(0x61,(temp = inp(0x61)) | 0x80);\r
168         outp(0x61,temp);\r
169 \r
170         if (k == 0xe0)          // Special key prefix\r
171                 special = true;\r
172         else if (k == 0xe1)     // Handle Pause key\r
173                 Paused = true;\r
174         else\r
175         {\r
176                 if (k & 0x80)   // Break code\r
177                 {\r
178                         k &= 0x7f;\r
179 \r
180 // DEBUG - handle special keys: ctl-alt-delete, print scrn\r
181 \r
182                         Keyboard[k] = false;\r
183                 }\r
184                 else                    // Make code\r
185                 {\r
186                         LastCode = CurCode;\r
187                         CurCode = LastScan = k;\r
188                         Keyboard[k] = true;\r
189 \r
190                         if (special)\r
191                                 c = SpecialNames[k];\r
192                         else\r
193                         {\r
194                                 if (k == sc_CapsLock)\r
195                                 {\r
196                                         CapsLock ^= true;\r
197                                         // DEBUG - make caps lock light work\r
198                                 }\r
199 \r
200                                 if (Keyboard[sc_LShift] || Keyboard[sc_RShift]) // If shifted\r
201                                 {\r
202                                         c = ShiftNames[k];\r
203                                         if ((c >= 'A') && (c <= 'Z') && CapsLock)\r
204                                                 c += 'a' - 'A';\r
205                                 }\r
206                                 else\r
207                                 {\r
208                                         c = ASCIINames[k];\r
209                                         if ((c >= 'a') && (c <= 'z') && CapsLock)\r
210                                                 c -= 'a' - 'A';\r
211                                 }\r
212                         }\r
213                         if (c)\r
214                                 LastASCII = c;\r
215                 }\r
216 \r
217                 special = false;\r
218         }\r
219 \r
220         if (INL_KeyHook && !special)\r
221                 INL_KeyHook();\r
222         outp(0x20,0x20);\r
223 }\r
224 \r
225 ///////////////////////////////////////////////////////////////////////////\r
226 //\r
227 //      INL_GetMouseDelta() - Gets the amount that the mouse has moved from the\r
228 //              mouse driver\r
229 //\r
230 ///////////////////////////////////////////////////////////////////////////\r
231 static void\r
232 INL_GetMouseDelta(int *x,int *y)\r
233 {\r
234         Mouse(MDelta);\r
235         *x = _CX;\r
236         *y = _DX;\r
237 }\r
238 \r
239 ///////////////////////////////////////////////////////////////////////////\r
240 //\r
241 //      INL_GetMouseButtons() - Gets the status of the mouse buttons from the\r
242 //              mouse driver\r
243 //\r
244 ///////////////////////////////////////////////////////////////////////////\r
245 static word\r
246 INL_GetMouseButtons(void)\r
247 {\r
248         word    buttons;\r
249 \r
250         Mouse(MButtons);\r
251         buttons = _BX;\r
252         return(buttons);\r
253 }\r
254 \r
255 ///////////////////////////////////////////////////////////////////////////\r
256 //\r
257 //      IN_GetJoyAbs() - Reads the absolute position of the specified joystick\r
258 //\r
259 ///////////////////////////////////////////////////////////////////////////\r
260 void\r
261 IN_GetJoyAbs(word joy,word *xp,word *yp)\r
262 {\r
263         byte    xb,yb,\r
264                         xs,ys;\r
265         word    x,y;\r
266 \r
267         x = y = 0;\r
268         xs = joy? 2 : 0;                // Find shift value for x axis\r
269         xb = 1 << xs;                   // Use shift value to get x bit mask\r
270         ys = joy? 3 : 1;                // Do the same for y axis\r
271         yb = 1 << ys;\r
272 \r
273 // Read the absolute joystick values
274         __asm
275         {\r
276                 pushf                           // Save some registers\r
277                 push    si\r
278                 push    di\r
279                 cli                                     // Make sure an interrupt doesn't screw the timings\r
280 \r
281 \r
282                 mov             dx,0x201\r
283                 in              al,dx\r
284                 out             dx,al           // Clear the resistors\r
285 \r
286                 mov             ah,[xb]         // Get masks into registers\r
287                 mov             ch,[yb]\r
288 \r
289                 xor             si,si           // Clear count registers\r
290                 xor             di,di\r
291                 xor             bh,bh           // Clear high byte of bx for later\r
292
293                 push    bp                      // Don't mess up stack frame\r
294                 mov             bp,MaxJoyValue\r
295 \r
296 loop:\r
297                 in              al,dx           // Get bits indicating whether all are finished\r
298 \r
299                 dec             bp                      // Check bounding register\r
300                 jz              done            // We have a silly value - abort\r
301 \r
302                 mov             bl,al           // Duplicate the bits\r
303                 and             bl,ah           // Mask off useless bits (in [xb])\r
304                 add             si,bx           // Possibly increment count register\r
305                 mov             cl,bl           // Save for testing later\r
306 \r
307                 mov             bl,al\r
308                 and             bl,ch           // [yb]\r
309                 add             di,bx\r
310 \r
311                 add             cl,bl\r
312                 jnz             loop            // If both bits were 0, drop out\r
313 \r
314 done:\r
315      pop                bp\r
316
317                 mov             cl,[xs]         // Get the number of bits to shift\r
318                 shr             si,cl           //  and shift the count that many times\r
319 \r
320                 mov             cl,[ys]\r
321                 shr             di,cl\r
322 \r
323                 mov             [x],si          // Store the values into the variables\r
324                 mov             [y],di\r
325
326                 pop             di\r
327                 pop             si\r
328                 popf                            // Restore the registers
329         }\r
330 \r
331         *xp = x;\r
332         *yp = y;\r
333 }\r
334 \r
335 ///////////////////////////////////////////////////////////////////////////\r
336 //\r
337 //      INL_GetJoyDelta() - Returns the relative movement of the specified\r
338 //              joystick (from +/-127, scaled adaptively)\r
339 //\r
340 ///////////////////////////////////////////////////////////////////////////\r
341 static void\r
342 INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)\r
343 {\r
344         word            x,y;\r
345         dword   time;\r
346         JoystickDef     *def;\r
347 static  dword   lasttime;\r
348 \r
349         IN_GetJoyAbs(joy,&x,&y);\r
350         def = JoyDefs + joy;\r
351 \r
352         if (x < def->threshMinX)\r
353         {\r
354                 if (x < def->joyMinX)\r
355                         x = def->joyMinX;\r
356 \r
357                 x = -(x - def->threshMinX);\r
358                 x *= def->joyMultXL;\r
359                 x >>= JoyScaleShift;\r
360                 *dx = (x > 127)? -127 : -x;\r
361         }\r
362         else if (x > def->threshMaxX)\r
363         {\r
364                 if (x > def->joyMaxX)\r
365                         x = def->joyMaxX;\r
366 \r
367                 x = x - def->threshMaxX;\r
368                 x *= def->joyMultXH;\r
369                 x >>= JoyScaleShift;\r
370                 *dx = (x > 127)? 127 : x;\r
371         }\r
372         else\r
373                 *dx = 0;\r
374 \r
375         if (y < def->threshMinY)\r
376         {\r
377                 if (y < def->joyMinY)\r
378                         y = def->joyMinY;\r
379 \r
380                 y = -(y - def->threshMinY);\r
381                 y *= def->joyMultYL;\r
382                 y >>= JoyScaleShift;\r
383                 *dy = (y > 127)? -127 : -y;\r
384         }\r
385         else if (y > def->threshMaxY)\r
386         {\r
387                 if (y > def->joyMaxY)\r
388                         y = def->joyMaxY;\r
389 \r
390                 y = y - def->threshMaxY;\r
391                 y *= def->joyMultYH;\r
392                 y >>= JoyScaleShift;\r
393                 *dy = (y > 127)? 127 : y;\r
394         }\r
395         else\r
396                 *dy = 0;\r
397 \r
398         if (adaptive)\r
399         {\r
400                 time = (TimeCount - lasttime) / 2;\r
401                 if (time)\r
402                 {\r
403                         if (time > 8)\r
404                                 time = 8;\r
405                         *dx *= time;\r
406                         *dy *= time;\r
407                 }\r
408         }\r
409         lasttime = TimeCount;\r
410 }\r
411 \r
412 ///////////////////////////////////////////////////////////////////////////\r
413 //\r
414 //      INL_GetJoyButtons() - Returns the button status of the specified\r
415 //              joystick\r
416 //\r
417 ///////////////////////////////////////////////////////////////////////////\r
418 static word\r
419 INL_GetJoyButtons(word joy)\r
420 {\r
421 register        word    result;\r
422 \r
423         result = inp(0x201);    // Get all the joystick buttons\r
424         result >>= joy? 6 : 4;  // Shift into bits 0-1\r
425         result &= 3;                            // Mask off the useless bits\r
426         result ^= 3;\r
427         return(result);\r
428 }\r
429 \r
430 ///////////////////////////////////////////////////////////////////////////\r
431 //\r
432 //      IN_GetJoyButtonsDB() - Returns the de-bounced button status of the\r
433 //              specified joystick\r
434 //\r
435 ///////////////////////////////////////////////////////////////////////////\r
436 word\r
437 IN_GetJoyButtonsDB(word joy)\r
438 {\r
439         dword   lasttime;\r
440         word            result1,result2;\r
441 \r
442         do\r
443         {\r
444                 result1 = INL_GetJoyButtons(joy);\r
445                 lasttime = TimeCount;\r
446                 while (TimeCount == lasttime)\r
447                         ;\r
448                 result2 = INL_GetJoyButtons(joy);\r
449         } while (result1 != result2);\r
450         return(result1);\r
451 }\r
452 \r
453 ///////////////////////////////////////////////////////////////////////////\r
454 //\r
455 //      INL_StartKbd() - Sets up my keyboard stuff for use\r
456 //\r
457 ///////////////////////////////////////////////////////////////////////////\r
458 static void\r
459 INL_StartKbd(void)\r
460 {\r
461         INL_KeyHook = 0;        // Clear key hook\r
462 \r
463         IN_ClearKeysDown();\r
464 \r
465         OldKeyVect = getvect(KeyInt);\r
466         setvect(KeyInt,INL_KeyService);\r
467 }\r
468 \r
469 ///////////////////////////////////////////////////////////////////////////\r
470 //\r
471 //      INL_ShutKbd() - Restores keyboard control to the BIOS\r
472 //\r
473 ///////////////////////////////////////////////////////////////////////////\r
474 static void\r
475 INL_ShutKbd(void)\r
476 {\r
477         poke(0x40,0x17,peek(0x40,0x17) & 0xfaf0);       // Clear ctrl/alt/shift flags\r
478 \r
479         setvect(KeyInt,OldKeyVect);\r
480 }\r
481 \r
482 ///////////////////////////////////////////////////////////////////////////\r
483 //\r
484 //      INL_StartMouse() - Detects and sets up the mouse\r
485 //\r
486 ///////////////////////////////////////////////////////////////////////////\r
487 static boolean\r
488 INL_StartMouse(void)\r
489 {\r
490         if (getvect(MouseInt))\r
491         {\r
492                 Mouse(MReset);\r
493                 if (_AX == 0xffff)\r
494                         return(true);\r
495         }\r
496         return(false);\r
497 }\r
498 \r
499 ///////////////////////////////////////////////////////////////////////////\r
500 //\r
501 //      INL_ShutMouse() - Cleans up after the mouse\r
502 //\r
503 ///////////////////////////////////////////////////////////////////////////\r
504 static void\r
505 INL_ShutMouse(void)\r
506 {\r
507 }\r
508 \r
509 //\r
510 //      INL_SetJoyScale() - Sets up scaling values for the specified joystick\r
511 //\r
512 static void\r
513 INL_SetJoyScale(word joy)\r
514 {\r
515         JoystickDef     *def;\r
516 \r
517         def = &JoyDefs[joy];\r
518         def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);\r
519         def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);\r
520         def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);\r
521         def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);\r
522 }\r
523 \r
524 ///////////////////////////////////////////////////////////////////////////\r
525 //\r
526 //      IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()\r
527 //              to set up scaling values\r
528 //\r
529 ///////////////////////////////////////////////////////////////////////////\r
530 void\r
531 IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)\r
532 {\r
533         word            d,r;\r
534         JoystickDef     *def;\r
535 \r
536         def = &JoyDefs[joy];\r
537 \r
538         def->joyMinX = minx;\r
539         def->joyMaxX = maxx;\r
540         r = maxx - minx;\r
541         d = r / 5;\r
542         def->threshMinX = ((r / 2) - d) + minx;\r
543         def->threshMaxX = ((r / 2) + d) + minx;\r
544 \r
545         def->joyMinY = miny;\r
546         def->joyMaxY = maxy;\r
547         r = maxy - miny;\r
548         d = r / 5;\r
549         def->threshMinY = ((r / 2) - d) + miny;\r
550         def->threshMaxY = ((r / 2) + d) + miny;\r
551 \r
552         INL_SetJoyScale(joy);\r
553 }\r
554 \r
555 ///////////////////////////////////////////////////////////////////////////\r
556 //\r
557 //      INL_StartJoy() - Detects & auto-configures the specified joystick\r
558 //                                      The auto-config assumes the joystick is centered\r
559 //\r
560 ///////////////////////////////////////////////////////////////////////////\r
561 static boolean\r
562 INL_StartJoy(word joy)\r
563 {\r
564         word            x,y;\r
565 \r
566         IN_GetJoyAbs(joy,&x,&y);\r
567 \r
568         if\r
569         (\r
570                 ((x == 0) || (x > MaxJoyValue - 10))\r
571         ||      ((y == 0) || (y > MaxJoyValue - 10))\r
572         )\r
573                 return(false);\r
574         else\r
575         {\r
576                 IN_SetupJoy(joy,0,x * 2,0,y * 2);\r
577                 return(true);\r
578         }\r
579 }\r
580 \r
581 ///////////////////////////////////////////////////////////////////////////\r
582 //\r
583 //      INL_ShutJoy() - Cleans up the joystick stuff\r
584 //\r
585 ///////////////////////////////////////////////////////////////////////////\r
586 static void\r
587 INL_ShutJoy(word joy)\r
588 {\r
589         JoysPresent[joy] = false;\r
590 }\r
591 \r
592 //      Public routines\r
593 \r
594 ///////////////////////////////////////////////////////////////////////////\r
595 //\r
596 //      IN_Startup() - Starts up the Input Mgr\r
597 //\r
598 ///////////////////////////////////////////////////////////////////////////\r
599 void\r
600 IN_Startup(void)\r
601 {\r
602         boolean checkjoys,checkmouse;\r
603         word    i;\r
604 \r
605         if (IN_Started)\r
606                 return;\r
607 \r
608         checkjoys = true;\r
609         checkmouse = true;\r
610         for (i = 1;i < _argc;i++)\r
611         {\r
612                 switch (US_CheckParm(_argv[i],ParmStrings))\r
613                 {\r
614                 case 0:\r
615                         checkjoys = false;\r
616                         break;\r
617                 case 1:\r
618                         checkmouse = false;\r
619                         break;\r
620                 }\r
621         }\r
622 \r
623         INL_StartKbd();\r
624         MousePresent = checkmouse? INL_StartMouse() : false;\r
625 \r
626         for (i = 0;i < MaxJoys;i++)\r
627                 JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;\r
628 \r
629         IN_Started = true;\r
630 }\r
631 \r
632 ///////////////////////////////////////////////////////////////////////////\r
633 //\r
634 //      IN_Default() - Sets up default conditions for the Input Mgr\r
635 //\r
636 ///////////////////////////////////////////////////////////////////////////\r
637 void\r
638 IN_Default(boolean gotit,ControlType in)\r
639 {\r
640         if\r
641         (\r
642                 (!gotit)\r
643         ||      ((in == ctrl_Joystick1) && !JoysPresent[0])\r
644         ||      ((in == ctrl_Joystick2) && !JoysPresent[1])\r
645         ||      ((in == ctrl_Mouse) && !MousePresent)\r
646         )\r
647                 in = ctrl_Keyboard1;\r
648         IN_SetControlType(0,in);\r
649 }\r
650 \r
651 ///////////////////////////////////////////////////////////////////////////\r
652 //\r
653 //      IN_Shutdown() - Shuts down the Input Mgr\r
654 //\r
655 ///////////////////////////////////////////////////////////////////////////\r
656 void\r
657 IN_Shutdown(void)\r
658 {\r
659         word    i;\r
660 \r
661         if (!IN_Started)\r
662                 return;\r
663 \r
664         INL_ShutMouse();\r
665         for (i = 0;i < MaxJoys;i++)\r
666                 INL_ShutJoy(i);\r
667         INL_ShutKbd();\r
668 \r
669         IN_Started = false;\r
670 }\r
671 \r
672 ///////////////////////////////////////////////////////////////////////////\r
673 //\r
674 //      IN_SetKeyHook() - Sets the routine that gets called by INL_KeyService()\r
675 //                      everytime a real make/break code gets hit\r
676 //\r
677 ///////////////////////////////////////////////////////////////////////////\r
678 void\r
679 IN_SetKeyHook(void (*hook)())\r
680 {\r
681         INL_KeyHook = hook;\r
682 }\r
683 \r
684 ///////////////////////////////////////////////////////////////////////////\r
685 //\r
686 //      IN_ClearKeyDown() - Clears the keyboard array\r
687 //\r
688 ///////////////////////////////////////////////////////////////////////////\r
689 void\r
690 IN_ClearKeysDown(void)\r
691 {\r
692         int     i;\r
693 \r
694         LastScan = sc_None;\r
695         LastASCII = key_None;\r
696         for (i = 0;i < NumCodes;i++)\r
697                 Keyboard[i] = false;\r
698 }\r
699 \r
700 ///////////////////////////////////////////////////////////////////////////\r
701 //\r
702 //      INL_AdjustCursor() - Internal routine of common code from IN_ReadCursor()\r
703 //\r
704 ///////////////////////////////////////////////////////////////////////////\r
705 static void\r
706 INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)\r
707 {\r
708         if (buttons & (1 << 0))\r
709                 info->button0 = true;\r
710         if (buttons & (1 << 1))\r
711                 info->button1 = true;\r
712 \r
713         info->x += dx;\r
714         info->y += dy;\r
715 }\r
716 \r
717 ///////////////////////////////////////////////////////////////////////////\r
718 //\r
719 //      IN_ReadCursor() - Reads the input devices and fills in the cursor info\r
720 //              struct\r
721 //\r
722 ///////////////////////////////////////////////////////////////////////////\r
723 void\r
724 IN_ReadCursor(CursorInfo *info)\r
725 {\r
726         word    i,\r
727                         buttons;\r
728         int             dx,dy;\r
729 \r
730         info->x = info->y = 0;\r
731         info->button0 = info->button1 = false;\r
732 \r
733         if (MousePresent)\r
734         {\r
735                 buttons = INL_GetMouseButtons();\r
736                 INL_GetMouseDelta(&dx,&dy);\r
737                 INL_AdjustCursor(info,buttons,dx,dy);\r
738         }\r
739 \r
740         for (i = 0;i < MaxJoys;i++)\r
741         {\r
742                 if (!JoysPresent[i])\r
743                         continue;\r
744 \r
745                 buttons = INL_GetJoyButtons(i);\r
746                 INL_GetJoyDelta(i,&dx,&dy,true);\r
747                 dx /= 64;\r
748                 dy /= 64;\r
749                 INL_AdjustCursor(info,buttons,dx,dy);\r
750         }\r
751 }\r
752 \r
753 ///////////////////////////////////////////////////////////////////////////\r
754 //\r
755 //      IN_ReadControl() - Reads the device associated with the specified\r
756 //              player and fills in the control info struct\r
757 //\r
758 ///////////////////////////////////////////////////////////////////////////\r
759 void\r
760 IN_ReadControl(int player,ControlInfo *info)\r
761 {\r
762                         boolean         realdelta=false;                                // MDM (GAMERS EDGE)\r
763                         byte            dbyte;\r
764                         word            buttons;\r
765                         int                     dx,dy;\r
766                         Motion          mx,my;\r
767                         ControlType     type;\r
768 register        KeyboardDef     *def;\r
769 \r
770         dx = dy = 0;\r
771         mx = my = motion_None;\r
772         buttons = 0;\r
773 \r
774 #if 0\r
775         if (DemoMode == demo_Playback)\r
776         {\r
777                 dbyte = DemoBuffer[DemoOffset + 1];\r
778                 my = (dbyte & 3) - 1;\r
779                 mx = ((dbyte >> 2) & 3) - 1;\r
780                 buttons = (dbyte >> 4) & 3;\r
781 \r
782                 if (!(--DemoBuffer[DemoOffset]))\r
783                 {\r
784                         DemoOffset += 2;\r
785                         if (DemoOffset >= DemoSize)\r
786                                 DemoMode = demo_PlayDone;\r
787                 }\r
788 \r
789                 realdelta = false;\r
790         }\r
791         else if (DemoMode == demo_PlayDone)\r
792                 Quit("Demo playback exceeded");\r
793         else\r
794 #endif\r
795         {\r
796                                                                                                                         // MDM begin (GAMERS EDGE) - added this block\r
797                 ControlTypeUsed = ctrl_None;\r
798 \r
799                 // Handle mouse input...\r
800                 //\r
801                 if ((MousePresent) && (ControlTypeUsed == ctrl_None))\r
802                 {\r
803                         INL_GetMouseDelta(&dx,&dy);\r
804                         buttons = INL_GetMouseButtons();\r
805                         realdelta = true;\r
806                         if (dx || dy || buttons)\r
807                                 ControlTypeUsed = ctrl_Mouse;\r
808                 }\r
809 \r
810                 // Handle joystick input...\r
811                 //\r
812                 if ((JoystickCalibrated) && (ControlTypeUsed == ctrl_None))\r
813                 {\r
814                         type = ctrl_Joystick1;\r
815                         INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);\r
816                         buttons = INL_GetJoyButtons(type - ctrl_Joystick);\r
817                         realdelta = true;\r
818                         if (dx || dy || buttons)\r
819                                 ControlTypeUsed = ctrl_Joystick;\r
820                 }\r
821 \r
822                 // Handle keyboard input...\r
823                 //\r
824                 if (ControlTypeUsed == ctrl_None)\r
825                 {\r
826                         type = ctrl_Keyboard1;\r
827                         def = &KbdDefs[type - ctrl_Keyboard];\r
828 \r
829                         if (Keyboard[def->upleft])\r
830                                 mx = motion_Left,my = motion_Up;\r
831                         else if (Keyboard[def->upright])\r
832                                 mx = motion_Right,my = motion_Up;\r
833                         else if (Keyboard[def->downleft])\r
834                                 mx = motion_Left,my = motion_Down;\r
835                         else if (Keyboard[def->downright])\r
836                                 mx = motion_Right,my = motion_Down;\r
837 \r
838                         if (Keyboard[def->up])\r
839                                 my = motion_Up;\r
840                         else if (Keyboard[def->down])\r
841                                 my = motion_Down;\r
842 \r
843                         if (Keyboard[def->left])\r
844                                 mx = motion_Left;\r
845                         else if (Keyboard[def->right])\r
846                                 mx = motion_Right;\r
847 \r
848                         if (Keyboard[def->button0])\r
849                                 buttons += 1 << 0;\r
850                         if (Keyboard[def->button1])\r
851                                 buttons += 1 << 1;\r
852                         realdelta = false;\r
853                         if (mx || my || buttons)\r
854                                 ControlTypeUsed = ctrl_Keyboard;\r
855                 }                                                                                                       // MDM end (GAMERS EDGE)\r
856         }\r
857 \r
858         if (realdelta)\r
859         {\r
860                 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);\r
861                 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);\r
862         }\r
863         else\r
864         {\r
865                 dx = mx * 127;\r
866                 dy = my * 127;\r
867         }\r
868 \r
869         info->x = dx;\r
870         info->xaxis = mx;\r
871         info->y = dy;\r
872         info->yaxis = my;\r
873         info->button0 = buttons & (1 << 0);\r
874         info->button1 = buttons & (1 << 1);\r
875         info->dir = DirTable[((my + 1) * 3) + (mx + 1)];\r
876 \r
877 #if 0\r
878         if (DemoMode == demo_Record)\r
879         {\r
880                 // Pack the control info into a byte\r
881                 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);\r
882 \r
883                 if\r
884                 (\r
885                         (DemoBuffer[DemoOffset + 1] == dbyte)\r
886                 &&      (DemoBuffer[DemoOffset] < 255)\r
887                 )\r
888                         (DemoBuffer[DemoOffset])++;\r
889                 else\r
890                 {\r
891                         if (DemoOffset || DemoBuffer[DemoOffset])\r
892                                 DemoOffset += 2;\r
893 \r
894                         if (DemoOffset >= DemoSize)\r
895                                 Quit("Demo buffer overflow");\r
896 \r
897                         DemoBuffer[DemoOffset] = 1;\r
898                         DemoBuffer[DemoOffset + 1] = dbyte;\r
899                 }\r
900         }\r
901 #endif\r
902 }\r
903 \r
904 #if 0\r
905 ///////////////////////////////////////////////////////////////////////////\r
906 //\r
907 //      IN_ReadControl() - Reads the device associated with the specified\r
908 //              player and fills in the control info struct\r
909 //\r
910 ///////////////////////////////////////////////////////////////////////////\r
911 void\r
912 IN_ReadControl(int player,ControlInfo *info)\r
913 {\r
914                         boolean         realdelta;\r
915                         byte            dbyte;\r
916                         word            buttons;\r
917                         int                     dx,dy;\r
918                         Motion          mx,my;\r
919                         ControlType     type;\r
920 register        KeyboardDef     *def;\r
921 \r
922         dx = dy = 0;\r
923         mx = my = motion_None;\r
924         buttons = 0;\r
925 \r
926 #if 0\r
927         if (DemoMode == demo_Playback)\r
928         {\r
929                 dbyte = DemoBuffer[DemoOffset + 1];\r
930                 my = (dbyte & 3) - 1;\r
931                 mx = ((dbyte >> 2) & 3) - 1;\r
932                 buttons = (dbyte >> 4) & 3;\r
933 \r
934                 if (!(--DemoBuffer[DemoOffset]))\r
935                 {\r
936                         DemoOffset += 2;\r
937                         if (DemoOffset >= DemoSize)\r
938                                 DemoMode = demo_PlayDone;\r
939                 }\r
940 \r
941                 realdelta = false;\r
942         }\r
943         else if (DemoMode == demo_PlayDone)\r
944                 Quit("Demo playback exceeded");\r
945         else\r
946 #endif\r
947         {\r
948                 switch (type = Controls[player])\r
949                 {\r
950                 case ctrl_Keyboard1:\r
951                 case ctrl_Keyboard2:\r
952                         def = &KbdDefs[type - ctrl_Keyboard];\r
953 \r
954                         if (Keyboard[def->upleft])\r
955                                 mx = motion_Left,my = motion_Up;\r
956                         else if (Keyboard[def->upright])\r
957                                 mx = motion_Right,my = motion_Up;\r
958                         else if (Keyboard[def->downleft])\r
959                                 mx = motion_Left,my = motion_Down;\r
960                         else if (Keyboard[def->downright])\r
961                                 mx = motion_Right,my = motion_Down;\r
962 \r
963                         if (Keyboard[def->up])\r
964                                 my = motion_Up;\r
965                         else if (Keyboard[def->down])\r
966                                 my = motion_Down;\r
967 \r
968                         if (Keyboard[def->left])\r
969                                 mx = motion_Left;\r
970                         else if (Keyboard[def->right])\r
971                                 mx = motion_Right;\r
972 \r
973                         if (Keyboard[def->button0])\r
974                                 buttons += 1 << 0;\r
975                         if (Keyboard[def->button1])\r
976                                 buttons += 1 << 1;\r
977                         realdelta = false;\r
978                         break;\r
979                 case ctrl_Joystick1:\r
980                 case ctrl_Joystick2:\r
981                         INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);\r
982                         buttons = INL_GetJoyButtons(type - ctrl_Joystick);\r
983                         realdelta = true;\r
984                         break;\r
985                 case ctrl_Mouse:\r
986                         INL_GetMouseDelta(&dx,&dy);\r
987                         buttons = INL_GetMouseButtons();\r
988                         realdelta = true;\r
989                         break;\r
990                 }\r
991         }\r
992 \r
993         if (realdelta)\r
994         {\r
995                 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);\r
996                 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);\r
997         }\r
998         else\r
999         {\r
1000                 dx = mx * 127;\r
1001                 dy = my * 127;\r
1002         }\r
1003 \r
1004         info->x = dx;\r
1005         info->xaxis = mx;\r
1006         info->y = dy;\r
1007         info->yaxis = my;\r
1008         info->button0 = buttons & (1 << 0);\r
1009         info->button1 = buttons & (1 << 1);\r
1010         info->dir = DirTable[((my + 1) * 3) + (mx + 1)];\r
1011 \r
1012 #if 0\r
1013         if (DemoMode == demo_Record)\r
1014         {\r
1015                 // Pack the control info into a byte\r
1016                 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);\r
1017 \r
1018                 if\r
1019                 (\r
1020                         (DemoBuffer[DemoOffset + 1] == dbyte)\r
1021                 &&      (DemoBuffer[DemoOffset] < 255)\r
1022                 )\r
1023                         (DemoBuffer[DemoOffset])++;\r
1024                 else\r
1025                 {\r
1026                         if (DemoOffset || DemoBuffer[DemoOffset])\r
1027                                 DemoOffset += 2;\r
1028 \r
1029                         if (DemoOffset >= DemoSize)\r
1030                                 Quit("Demo buffer overflow");\r
1031 \r
1032                         DemoBuffer[DemoOffset] = 1;\r
1033                         DemoBuffer[DemoOffset + 1] = dbyte;\r
1034                 }\r
1035         }\r
1036 #endif\r
1037 }\r
1038 #endif\r
1039 \r
1040 ///////////////////////////////////////////////////////////////////////////\r
1041 //\r
1042 //      IN_SetControlType() - Sets the control type to be used by the specified\r
1043 //              player\r
1044 //\r
1045 ///////////////////////////////////////////////////////////////////////////\r
1046 void\r
1047 IN_SetControlType(int player,ControlType type)\r
1048 {\r
1049         // DEBUG - check that requested type is present?\r
1050         Controls[player] = type;\r
1051 }\r
1052 \r
1053 #if 0\r
1054 ///////////////////////////////////////////////////////////////////////////\r
1055 //\r
1056 //      IN_StartDemoRecord() - Starts the demo recording, using a buffer the\r
1057 //              size passed. Returns if the buffer allocation was successful\r
1058 //\r
1059 ///////////////////////////////////////////////////////////////////////////\r
1060 boolean\r
1061 IN_StartDemoRecord(word bufsize)\r
1062 {\r
1063         if (!bufsize)\r
1064                 return(false);\r
1065 \r
1066         MM_GetPtr((memptr *)&DemoBuffer,bufsize);\r
1067         DemoMode = demo_Record;\r
1068         DemoSize = bufsize & ~1;\r
1069         DemoOffset = 0;\r
1070         DemoBuffer[0] = DemoBuffer[1] = 0;\r
1071 \r
1072         return(true);\r
1073 }\r
1074 \r
1075 ///////////////////////////////////////////////////////////////////////////\r
1076 //\r
1077 //      IN_StartDemoPlayback() - Plays back the demo pointed to of the given size\r
1078 //\r
1079 ///////////////////////////////////////////////////////////////////////////\r
1080 void\r
1081 IN_StartDemoPlayback(byte /*_1seg*/ *buffer,word bufsize)\r
1082 {\r
1083         DemoBuffer = buffer;\r
1084         DemoMode = demo_Playback;\r
1085         DemoSize = bufsize & ~1;\r
1086         DemoOffset = 0;\r
1087 }\r
1088 \r
1089 ///////////////////////////////////////////////////////////////////////////\r
1090 //\r
1091 //      IN_StopDemo() - Turns off demo mode\r
1092 //\r
1093 ///////////////////////////////////////////////////////////////////////////\r
1094 void\r
1095 IN_StopDemo(void)\r
1096 {\r
1097         if ((DemoMode == demo_Record) && DemoOffset)\r
1098                 DemoOffset += 2;\r
1099 \r
1100         DemoMode = demo_Off;\r
1101 }\r
1102 \r
1103 ///////////////////////////////////////////////////////////////////////////\r
1104 //\r
1105 //      IN_FreeDemoBuffer() - Frees the demo buffer, if it's been allocated\r
1106 //\r
1107 ///////////////////////////////////////////////////////////////////////////\r
1108 void\r
1109 IN_FreeDemoBuffer(void)\r
1110 {\r
1111         if (DemoBuffer)\r
1112                 MM_FreePtr((memptr *)&DemoBuffer);\r
1113 }\r
1114 #endif\r
1115 \r
1116 \r
1117 #if 0\r
1118 ///////////////////////////////////////////////////////////////////////////\r
1119 //\r
1120 //      IN_GetScanName() - Returns a string containing the name of the\r
1121 //              specified scan code\r
1122 //\r
1123 ///////////////////////////////////////////////////////////////////////////\r
1124 byte *\r
1125 IN_GetScanName(ScanCode scan)\r
1126 {\r
1127         byte            **p;\r
1128         ScanCode        far *s;\r
1129 \r
1130         for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)\r
1131                 if (*s == scan)\r
1132                         return(*p);\r
1133 \r
1134         return(ScanNames[scan]);\r
1135 }\r
1136 #endif\r
1137 \r
1138 \r
1139 ///////////////////////////////////////////////////////////////////////////\r
1140 //\r
1141 //      IN_WaitForKey() - Waits for a scan code, then clears LastScan and\r
1142 //              returns the scan code\r
1143 //\r
1144 ///////////////////////////////////////////////////////////////////////////\r
1145 ScanCode\r
1146 IN_WaitForKey(void)\r
1147 {\r
1148         ScanCode        result;\r
1149 \r
1150         while (!(result = LastScan))\r
1151                 ;\r
1152         LastScan = 0;\r
1153         return(result);\r
1154 }\r
1155 \r
1156 ///////////////////////////////////////////////////////////////////////////\r
1157 //\r
1158 //      IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and\r
1159 //              returns the ASCII value\r
1160 //\r
1161 ///////////////////////////////////////////////////////////////////////////\r
1162 char\r
1163 IN_WaitForASCII(void)\r
1164 {\r
1165         char            result;\r
1166 \r
1167         while (!(result = LastASCII))\r
1168                 ;\r
1169         LastASCII = '\0';\r
1170         return(result);\r
1171 }\r
1172 \r
1173 ///////////////////////////////////////////////////////////////////////////\r
1174 //\r
1175 //      IN_AckBack() - Waits for either an ASCII keypress or a button press\r
1176 //\r
1177 ///////////////////////////////////////////////////////////////////////////\r
1178 void\r
1179 IN_AckBack(void)\r
1180 {\r
1181         word    i;\r
1182 \r
1183         while (!LastScan)\r
1184         {\r
1185                 if (MousePresent)\r
1186                 {\r
1187                         if (INL_GetMouseButtons())\r
1188                         {\r
1189                                 while (INL_GetMouseButtons())\r
1190                                         ;\r
1191                                 return;\r
1192                         }\r
1193                 }\r
1194 \r
1195                 for (i = 0;i < MaxJoys;i++)\r
1196                 {\r
1197                         if (JoysPresent[i])\r
1198                         {\r
1199                                 if (IN_GetJoyButtonsDB(i))\r
1200                                 {\r
1201                                         while (IN_GetJoyButtonsDB(i))\r
1202                                                 ;\r
1203                                         return;\r
1204                                 }\r
1205                         }\r
1206                 }\r
1207         }\r
1208 \r
1209         IN_ClearKey(LastScan);\r
1210         LastScan = sc_None;\r
1211 }\r
1212 \r
1213 ///////////////////////////////////////////////////////////////////////////\r
1214 //\r
1215 //      IN_Ack() - Clears user input & then calls IN_AckBack()\r
1216 //\r
1217 ///////////////////////////////////////////////////////////////////////////\r
1218 void\r
1219 IN_Ack(void)\r
1220 {\r
1221         word    i;\r
1222 \r
1223         IN_ClearKey(LastScan);\r
1224         LastScan = sc_None;\r
1225 \r
1226         if (MousePresent)\r
1227                 while (INL_GetMouseButtons())\r
1228                                         ;\r
1229         for (i = 0;i < MaxJoys;i++)\r
1230                 if (JoysPresent[i])\r
1231                         while (IN_GetJoyButtonsDB(i))\r
1232                                 ;\r
1233 \r
1234         IN_AckBack();\r
1235 }\r
1236 \r
1237 ///////////////////////////////////////////////////////////////////////////\r
1238 //\r
1239 //      IN_IsUserInput() - Returns true if a key has been pressed or a button\r
1240 //              is down\r
1241 //\r
1242 ///////////////////////////////////////////////////////////////////////////\r
1243 boolean\r
1244 IN_IsUserInput(void)\r
1245 {\r
1246         boolean result;\r
1247         word    i;\r
1248 \r
1249         result = LastScan;\r
1250 \r
1251         if (MousePresent)\r
1252                 if (INL_GetMouseButtons())\r
1253                         result = true;\r
1254 \r
1255         for (i = 0;i < MaxJoys;i++)\r
1256                 if (JoysPresent[i])\r
1257                         if (INL_GetJoyButtons(i))\r
1258                                 result = true;\r
1259 \r
1260         return(result);\r
1261 }\r
1262 \r
1263 ///////////////////////////////////////////////////////////////////////////\r
1264 //\r
1265 //      IN_UserInput() - Waits for the specified delay time (in ticks) or the\r
1266 //              user pressing a key or a mouse button. If the clear flag is set, it\r
1267 //              then either clears the key or waits for the user to let the mouse\r
1268 //              button up.\r
1269 //\r
1270 ///////////////////////////////////////////////////////////////////////////\r
1271 boolean\r
1272 IN_UserInput(dword delay,boolean clear)\r
1273 {\r
1274         dword   lasttime;\r
1275 \r
1276         lasttime = TimeCount;\r
1277         do\r
1278         {\r
1279                 if (IN_IsUserInput())\r
1280                 {\r
1281                         if (clear)\r
1282                                 IN_AckBack();\r
1283                         return(true);\r
1284                 }\r
1285         } while (TimeCount - lasttime < delay);\r
1286         return(false);\r
1287 }\r