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