1 /* Catacomb Apocalypse Source Code
\r
2 * Copyright (C) 1993-2014 Flat Rock Software
\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
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
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
21 // ID_IN.c - Input Manager
\r
23 // By Jason Blochowiak
\r
24 // Open Watcom port by sparky4
\r
28 // This module handles dealing with the various input devices
\r
30 // Depends on: Memory Mgr (for demo recording), Sound Mgr (for timing stuff),
\r
31 // User Mgr (for command line parms)
\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
39 #include "src/lib/16_in_.h"
\r
43 =============================================================================
\r
47 =============================================================================
\r
49 // moved to 16_tdef.h
\r
52 =============================================================================
\r
56 =============================================================================
\r
59 #ifdef __cplusplus /* Function must be declared C style */
\r
63 static void (*INL_KeyHook)(void);
\r
64 static void interrupt (*OldKeyVect)(void);
\r
65 static char *ParmStringsIN[] = {"nojoys","nomouse",nil};
\r
67 static byte far ASCIINames[] = // Unshifted ASCII for scan codes
\r
69 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
70 0 ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8 ,9 , // 0
\r
71 'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0 ,'a','s', // 1
\r
72 'd','f','g','h','j','k','l',';',39 ,'`',0 ,92 ,'z','x','c','v', // 2
\r
73 'b','n','m',',','.','/',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
74 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
75 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
76 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
77 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
79 far ShiftNames[] = // Shifted ASCII for scan codes
\r
81 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
82 0 ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8 ,9 , // 0
\r
83 'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0 ,'A','S', // 1
\r
84 'D','F','G','H','J','K','L',':',34 ,'~',0 ,'|','Z','X','C','V', // 2
\r
85 'B','N','M','<','>','?',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
86 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
87 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
88 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
89 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
91 far SpecialNames[] = // ASCII for 0xe0 prefixed codes
\r
93 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
94 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 0
\r
95 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,13 ,0 ,0 ,0 , // 1
\r
96 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 2
\r
97 0 ,0 ,0 ,0 ,0 ,'/',0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
98 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 4
\r
99 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
100 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
101 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
105 *ScanNames[] = // Scan code names with single chars
\r
107 "?","?","1","2","3","4","5","6","7","8","9","0","-","+","?","?",
\r
108 "Q","W","E","R","T","Y","U","I","O","P","[","]","|","?","A","S",
\r
109 "D","F","G","H","J","K","L",";","\"","?","?","?","Z","X","C","V",
\r
110 "B","N","M",",",".","/","?","?","?","?","?","?","?","?","?","?",
\r
111 "?","?","?","?","?","?","?","?","\xf","?","-","\x15","5","\x11","+","?",
\r
112 "\x13","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
113 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
114 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"
\r
115 }, // DEBUG - consolidate these
\r
118 far ExtScanCodes[] = // Scan codes with >1 char names
\r
120 1,0xe,0xf,0x1d,0x2a,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,
\r
121 0x3f,0x40,0x41,0x42,0x43,0x44,0x57,0x59,0x46,0x1c,0x36,
\r
122 0x37,0x38,0x47,0x49,0x4f,0x51,0x52,0x53,0x45,0x48,
\r
123 0x50,0x4b,0x4d,0x00
\r
125 *ExtScanNames[] = // Names corresponding to ExtScanCodes
\r
127 "Esc","BkSp","Tab","Ctrl","LShft","Space","CapsLk","F1","F2","F3","F4",
\r
128 "F5","F6","F7","F8","F9","F10","F11","F12","ScrlLk","Enter","RShft",
\r
129 "PrtSc","Alt","Home","PgUp","End","PgDn","Ins","Del","NumLk","Up",
\r
130 "Down","Left","Right",""
\r
133 static Direction DirTable[] = // Quick lookup for total direction
\r
135 /*dir_NorthWest, */dir_North,/* dir_NorthEast,*/
\r
136 dir_West, dir_None, dir_East,
\r
137 /*dir_SouthWest, */dir_South/*, dir_SouthEast*/
\r
144 // Internal routines
\r
146 ///////////////////////////////////////////////////////////////////////////
\r
148 // INL_KeyService() - Handles a keyboard interrupt (key up/down)
\r
150 ///////////////////////////////////////////////////////////////////////////
\r
151 /*static */void interrupt
\r
152 INL_KeyService(global_game_variables_t *gvar)
\r
154 static boolean special;
\r
158 k = inp(0x60); // Get the scan code
\r
160 // Tell the XT keyboard controller to clear the key
\r
161 outp(0x61,(temp = inp(0x61)) | 0x80);
\r
164 if (k == 0xe0) // Special key prefix
\r
166 else if (k == 0xe1) // Handle Pause key
\r
167 gvar->in.Paused = true;
\r
170 if (k & 0x80) // Break code
\r
174 // DEBUG - handle special keys: ctl-alt-delete, print scrn
\r
176 gvar->in.Keyboard[k] = false;
\r
180 gvar->in.LastCode = gvar->in.CurCode;
\r
181 gvar->in.CurCode = gvar->in.LastScan = k;
\r
182 gvar->in.Keyboard[k] = true;
\r
185 c = SpecialNames[k];
\r
188 if (k == sc_CapsLock)
\r
190 gvar->in.CapsLock ^= true;
\r
191 // DEBUG - make caps lock light work
\r
194 if (gvar->in.Keyboard[sc_LShift] || gvar->in.Keyboard[sc_RShift]) // If shifted
\r
197 if ((c >= 'A') && (c <= 'Z') && gvar->in.CapsLock)
\r
203 if ((c >= 'a') && (c <= 'z') && gvar->in.CapsLock)
\r
208 gvar->in.LastASCII = c;
\r
214 if (INL_KeyHook && !special)
\r
216 #ifdef __DEBUG_InputMgr__
\r
217 if(dbg_testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, gvar->in.Keyboard[k]);
\r
225 //union REGS CPURegs;
\r
226 //x = CPURegs.x.ax;
\r
231 //int86(MouseInt,&CPURegs,&CPURegs);
\r
234 ///////////////////////////////////////////////////////////////////////////
\r
236 // INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
\r
239 ///////////////////////////////////////////////////////////////////////////
\r
241 INL_GetMouseDelta(int *x,int *y)
\r
243 union REGS CPURegs;
\r
249 ///////////////////////////////////////////////////////////////////////////
\r
251 // INL_GetMouseButtons() - Gets the status of the mouse buttons from the
\r
254 ///////////////////////////////////////////////////////////////////////////
\r
256 INL_GetMouseButtons(void)
\r
258 union REGS CPURegs;
\r
262 buttons = CPURegs.x.bx;
\r
266 ///////////////////////////////////////////////////////////////////////////
\r
268 // IN_GetJoyAbs() - Reads the absolute position of the specified joystick
\r
270 ///////////////////////////////////////////////////////////////////////////
\r
272 IN_GetJoyAbs(word joy,word *xp,word *yp)
\r
279 xs = joy? 2 : 0; // Find shift value for x axis
\r
280 xb = 1 << xs; // Use shift value to get x bit mask
\r
281 ys = joy? 3 : 1; // Do the same for y axis
\r
284 // Read the absolute joystick values
\r
286 pushf // Save some registers
\r
289 cli // Make sure an interrupt doesn't screw the timings
\r
294 out dx,al // Clear the resistors
\r
296 mov ah,[xb] // Get masks into registers
\r
299 xor si,si // Clear count registers
\r
301 xor bh,bh // Clear high byte of bx for later
\r
303 push bp // Don't mess up stack frame
\r
305 #ifdef __BORLANDC__
\r
309 #ifdef __BORLANDC__
\r
312 in al,dx // Get bits indicating whether all are finished
\r
314 dec bp // Check bounding register
\r
315 jz done // We have a silly value - abort
\r
317 mov bl,al // Duplicate the bits
\r
318 and bl,ah // Mask off useless bits (in [xb])
\r
319 add si,bx // Possibly increment count register
\r
320 mov cl,bl // Save for testing later
\r
327 jnz loo // If both bits were 0, drop out
\r
328 #ifdef __BORLANDC__
\r
332 #ifdef __BORLANDC__
\r
337 mov cl,[xs] // Get the number of bits to shift
\r
338 shr si,cl // and shift the count that many times
\r
343 mov [x],si // Store the values into the variables
\r
348 popf // Restore the registers
\r
355 ///////////////////////////////////////////////////////////////////////////
\r
357 // INL_GetJoyDelta() - Returns the relative movement of the specified
\r
358 // joystick (from +/-127, scaled adaptively)
\r
360 ///////////////////////////////////////////////////////////////////////////
\r
362 INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive, global_game_variables_t *gvar)
\r
366 word TimeCount = gvar->kurokku.clock_start;
\r
368 static word lasttime;
\r
370 IN_GetJoyAbs(joy,&x,&y);
\r
371 def = gvar->in.JoyDefs + joy;
\r
373 if (x < def->threshMinX)
\r
375 if (x < def->joyMinX)
\r
378 x = -(x - def->threshMinX);
\r
379 x *= def->joyMultXL;
\r
380 x >>= JoyScaleShift;
\r
381 *dx = (x > 127)? -127 : -x;
\r
383 else if (x > def->threshMaxX)
\r
385 if (x > def->joyMaxX)
\r
388 x = x - def->threshMaxX;
\r
389 x *= def->joyMultXH;
\r
390 x >>= JoyScaleShift;
\r
391 *dx = (x > 127)? 127 : x;
\r
396 if (y < def->threshMinY)
\r
398 if (y < def->joyMinY)
\r
401 y = -(y - def->threshMinY);
\r
402 y *= def->joyMultYL;
\r
403 y >>= JoyScaleShift;
\r
404 *dy = (y > 127)? -127 : -y;
\r
406 else if (y > def->threshMaxY)
\r
408 if (y > def->joyMaxY)
\r
411 y = y - def->threshMaxY;
\r
412 y *= def->joyMultYH;
\r
413 y >>= JoyScaleShift;
\r
414 *dy = (y > 127)? 127 : y;
\r
421 time = (TimeCount - lasttime) / 2;
\r
430 lasttime = TimeCount;
\r
433 ///////////////////////////////////////////////////////////////////////////
\r
435 // INL_GetJoyButtons() - Returns the button status of the specified
\r
438 ///////////////////////////////////////////////////////////////////////////
\r
440 INL_GetJoyButtons(word joy)
\r
442 register word result;
\r
444 result = inp(0x201); // Get all the joystick buttons
\r
445 result >>= joy? 6 : 4; // Shift into bits 0-1
\r
446 result &= 3; // Mask off the useless bits
\r
451 ///////////////////////////////////////////////////////////////////////////
\r
453 // IN_GetJoyButtonsDB() - Returns the de-bounced button status of the
\r
454 // specified joystick
\r
456 ///////////////////////////////////////////////////////////////////////////
\r
458 IN_GetJoyButtonsDB(word joy, global_game_variables_t *gvar)
\r
460 word TimeCount = gvar->kurokku.clock_start;
\r
462 word result1,result2;
\r
466 result1 = INL_GetJoyButtons(joy);
\r
467 lasttime = TimeCount;
\r
468 while(TimeCount == lasttime)
\r
469 result2 = INL_GetJoyButtons(joy);
\r
470 } while(result1 != result2);
\r
474 ///////////////////////////////////////////////////////////////////////////
\r
476 // INL_StartKbd() - Sets up my keyboard stuff for use
\r
478 ///////////////////////////////////////////////////////////////////////////
\r
480 INL_StartKbd(global_game_variables_t *gvar)
\r
482 byte far *lock_key;
\r
483 INL_KeyHook = 0; // Clear key hook
\r
485 IN_ClearKeysDown(gvar);
\r
487 OldKeyVect = _dos_getvect(KeyInt);
\r
489 // turn off num-lock via BIOS
\r
490 lock_key = MK_FP(0x040, 0x017); // Pointing to the address of the bios shift state keys
\r
491 *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
492 OldKeyVect(); // call BIOS keyhandler to change keyboard lights
\r
493 _dos_setvect(KeyInt,INL_KeyService);
\r
496 ///////////////////////////////////////////////////////////////////////////
\r
498 // INL_ShutKbd() - Restores keyboard control to the BIOS
\r
500 ///////////////////////////////////////////////////////////////////////////
\r
504 pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags
\r
506 _dos_setvect(KeyInt,OldKeyVect);
\r
509 ///////////////////////////////////////////////////////////////////////////
\r
511 // INL_StartMouse() - Detects and sets up the mouse
\r
513 ///////////////////////////////////////////////////////////////////////////
\r
515 INL_StartMouse(void)
\r
517 union REGS CPURegs;
\r
518 if(_dos_getvect(MouseInt))
\r
521 if(CPURegs.x.ax == 0xffff)
\r
527 ///////////////////////////////////////////////////////////////////////////
\r
529 // INL_ShutMouse() - Cleans up after the mouse
\r
531 ///////////////////////////////////////////////////////////////////////////
\r
533 INL_ShutMouse(void)
\r
538 // INL_SetJoyScale() - Sets up scaling values for the specified joystick
\r
541 INL_SetJoyScale(word joy, global_game_variables_t *gvar)
\r
545 def = &(gvar->in.JoyDefs[joy]);
\r
546 def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
\r
547 def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
\r
548 def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
\r
549 def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);
\r
552 ///////////////////////////////////////////////////////////////////////////
\r
554 // IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
\r
555 // to set up scaling values
\r
557 ///////////////////////////////////////////////////////////////////////////
\r
559 IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy, global_game_variables_t *gvar)
\r
564 def = &(gvar->in.JoyDefs[joy]);
\r
566 def->joyMinX = minx;
\r
567 def->joyMaxX = maxx;
\r
570 def->threshMinX = ((r / 2) - d) + minx;
\r
571 def->threshMaxX = ((r / 2) + d) + minx;
\r
573 def->joyMinY = miny;
\r
574 def->joyMaxY = maxy;
\r
577 def->threshMinY = ((r / 2) - d) + miny;
\r
578 def->threshMaxY = ((r / 2) + d) + miny;
\r
580 INL_SetJoyScale(joy, gvar);
\r
583 ///////////////////////////////////////////////////////////////////////////
\r
585 // INL_StartJoy() - Detects & auto-configures the specified joystick
\r
586 // The auto-config assumes the joystick is centered
\r
588 ///////////////////////////////////////////////////////////////////////////
\r
590 INL_StartJoy(word joy, global_game_variables_t *gvar)
\r
594 IN_GetJoyAbs(joy,&x,&y);
\r
598 ((x == 0) || (x > MaxJoyValue - 10))
\r
599 || ((y == 0) || (y > MaxJoyValue - 10))
\r
604 IN_SetupJoy(joy,0,x * 2,0,y * 2, gvar);
\r
609 ///////////////////////////////////////////////////////////////////////////
\r
611 // INL_ShutJoy() - Cleans up the joystick stuff
\r
613 ///////////////////////////////////////////////////////////////////////////
\r
615 INL_ShutJoy(word joy, global_game_variables_t *gvar)
\r
617 gvar->in.JoysPresent[joy] = false;
\r
622 ///////////////////////////////////////////////////////////////////////////
\r
624 // IN_Startup() - Starts up the Input Mgr
\r
626 ///////////////////////////////////////////////////////////////////////////
\r
628 IN_Startup(global_game_variables_t *gvar)
\r
630 boolean checkjoys,checkmouse;
\r
633 if (gvar->in.IN_Started)
\r
638 for (i = 1;i < _argc;i++)
\r
640 switch (US_CheckParm(_argv[i],ParmStringsIN))
\r
646 checkmouse = false;
\r
651 INL_StartKbd(gvar);
\r
652 gvar->in.MousePresent = checkmouse? INL_StartMouse() : false;
\r
654 for (i = 0;i < MaxJoys;i++)
\r
655 gvar->in.JoysPresent[i] = checkjoys? INL_StartJoy(i, gvar) : false;
\r
657 //for (i = 0;i < MaxKbds;i++)
\r
658 // gvar->in.KbdDefs[i] = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
\r
660 gvar->in.IN_Started = true;
\r
664 ///////////////////////////////////////////////////////////////////////////
\r
666 // IN_Default() - Sets up default conditions for the Input Mgr
\r
668 ///////////////////////////////////////////////////////////////////////////
\r
670 IN_Default(boolean gotit,player_t *player,ControlType nt, global_game_variables_t *gvar)
\r
676 || ((nt == ctrl_Joystick1) && !gvar->in.JoysPresent[0])
\r
677 || ((nt == ctrl_Joystick2) && !gvar->in.JoysPresent[1])
\r
678 || ((nt == ctrl_Mouse) && !gvar->in.MousePresent)
\r
680 nt = ctrl_Keyboard1;
\r
681 gvar->in.KbdDefs[0].button0 = 0x1c;
\r
682 gvar->in.KbdDefs[0].button1 = 0x38;
\r
683 //in.KbdDefs[0].upleft = 0x47;
\r
684 gvar->in.KbdDefs[0].up = 0x48;
\r
685 //in.KbdDefs[0].upright = 0x49;
\r
686 gvar->in.KbdDefs[0].left = 0x4b;
\r
687 gvar->in.KbdDefs[0].right = 0x4d;
\r
688 //in.KbdDefs[0].downleft = 0x4f;
\r
689 gvar->in.KbdDefs[0].down = 0x50;
\r
690 //in.KbdDefs[0].downright = 0x51;
\r
691 IN_SetControlType(0,player,nt);
\r
692 for(i=0; i>MaxPlayers;i++)
\r
693 player[i].enti.d =2;
\r
696 ///////////////////////////////////////////////////////////////////////////
\r
698 // IN_Shutdown() - Shuts down the Input Mgr
\r
700 ///////////////////////////////////////////////////////////////////////////
\r
702 IN_Shutdown(global_game_variables_t *gvar)
\r
706 if (!gvar->in.IN_Started)
\r
710 for (i = 0;i < MaxJoys;i++)
\r
711 INL_ShutJoy(i, gvar);
\r
714 gvar->in.IN_Started = false;
\r
717 ///////////////////////////////////////////////////////////////////////////
\r
719 // IN_SetKeyHook() - Sets the routine that gets called by INL_KeyService()
\r
720 // everytime a real make/break code gets hit
\r
722 ///////////////////////////////////////////////////////////////////////////
\r
724 IN_SetKeyHook(void (*hook)())
\r
726 INL_KeyHook = hook;
\r
729 ///////////////////////////////////////////////////////////////////////////
\r
731 // IN_ClearKeyDown() - Clears the keyboard array
\r
733 ///////////////////////////////////////////////////////////////////////////
\r
735 IN_ClearKeysDown(global_game_variables_t *gvar)
\r
739 gvar->in.LastScan = sc_None;
\r
740 gvar->in.LastASCII = key_None;
\r
741 memset (gvar->in.Keyboard,0,sizeof(gvar->in.Keyboard));
\r
744 ///////////////////////////////////////////////////////////////////////////
\r
746 // INL_AdjustCursor() - Internal routine of common code from IN_ReadCursor()
\r
748 ///////////////////////////////////////////////////////////////////////////
\r
750 INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
\r
752 if (buttons & (1 << 0))
\r
753 info->button0 = true;
\r
754 if (buttons & (1 << 1))
\r
755 info->button1 = true;
\r
761 ///////////////////////////////////////////////////////////////////////////
\r
763 // IN_ReadCursor() - Reads the input devices and fills in the cursor info
\r
766 ///////////////////////////////////////////////////////////////////////////
\r
768 IN_ReadCursor(CursorInfo *info, global_game_variables_t *gvar)
\r
774 info->x = info->y = 0;
\r
775 info->button0 = info->button1 = false;
\r
777 if (gvar->in.MousePresent)
\r
779 buttons = INL_GetMouseButtons();
\r
780 INL_GetMouseDelta(&dx,&dy);
\r
781 INL_AdjustCursor(info,buttons,dx,dy);
\r
784 for (i = 0;i < MaxJoys;i++)
\r
786 if (!gvar->in.JoysPresent[i])
\r
789 buttons = INL_GetJoyButtons(i);
\r
790 INL_GetJoyDelta(i,&dx,&dy,true, gvar);
\r
793 INL_AdjustCursor(info,buttons,dx,dy);
\r
797 ///////////////////////////////////////////////////////////////////////////
\r
799 // IN_ReadControl() - Reads the device associated with the specified
\r
800 // player and fills in the control info struct
\r
802 ///////////////////////////////////////////////////////////////////////////
\r
804 IN_ReadControl(word pn, player_t *player, global_game_variables_t *gvar)
\r
815 byte dir=DirTable[2];
\r
816 register KeyboardDef *def;
\r
819 mx = my = motion_None;
\r
823 if (DemoMode == demo_Playback)
\r
825 dbyte = DemoBuffer[DemoOffset + 1];
\r
826 my = (dbyte & 3) - 1;
\r
827 mx = ((dbyte >> 2) & 3) - 1;
\r
828 buttons = (dbyte >> 4) & 3;
\r
830 if (!(--DemoBuffer[DemoOffset]))
\r
833 if (DemoOffset >= DemoSize)
\r
834 DemoMode = demo_PlayDone;
\r
839 else if (DemoMode == demo_PlayDone)
\r
840 Quit ("Demo playback exceeded");
\r
844 switch (type = player[pn].Controls)
\r
846 case ctrl_Keyboard1:
\r
847 case ctrl_Keyboard2:
\r
848 def = &(gvar->in.KbdDefs[type - ctrl_Keyboard]);
\r
850 /* if (Keyboard[def->upleft])
\r
851 mx = motion_Left,my = motion_Up;
\r
852 else if (Keyboard[def->upright])
\r
853 mx = motion_Right,my = motion_Up;
\r
854 else if (Keyboard[def->downleft])
\r
855 mx = motion_Left,my = motion_Down;
\r
856 else if (Keyboard[def->downright])
\r
857 mx = motion_Right,my = motion_Down;*/
\r
858 //TODO: make this into a function that the joystick AND keyboard can use wwww
\r
859 if(DIRECTIONIFELSE)//(player[pn].info.dir == 2)
\r
861 if(!gvar->in.Keyboard[def->left] && !gvar->in.Keyboard[def->right]){
\r
862 if((gvar->in.Keyboard[def->up] && !gvar->in.Keyboard[def->down]))
\r
864 if((gvar->in.Keyboard[def->down] && !gvar->in.Keyboard[def->up]))
\r
866 }else if(!gvar->in.Keyboard[def->up] && !gvar->in.Keyboard[def->down]){
\r
867 if((gvar->in.Keyboard[def->left] && !gvar->in.Keyboard[def->right]))
\r
869 if((gvar->in.Keyboard[def->right] && !gvar->in.Keyboard[def->left]))
\r
871 }else{ //2 keys pressed
\r
872 switch (player[pn].pdir)
\r
876 if((gvar->in.Keyboard[def->left] && !gvar->in.Keyboard[def->right])){ dir = DirTable[1]; }//mx = motion_Left; }
\r
877 else if((gvar->in.Keyboard[def->right] && !gvar->in.Keyboard[def->left])){ dir = DirTable[3]; }//mx = motion_Right; }
\r
881 if((gvar->in.Keyboard[def->up] && !gvar->in.Keyboard[def->down])){ dir = DirTable[0]; }//my = motion_Up; }
\r
882 else if((gvar->in.Keyboard[def->down] && !gvar->in.Keyboard[def->up])){ dir = DirTable[4]; }//my = motion_Down; }
\r
887 #ifdef __DEBUG_InputMgr__
\r
888 //if(dbg_testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c ", dirchar(player[pn].pdir)); }
\r
892 //input from player
\r
893 if (gvar->in.Keyboard[def->button0])
\r
895 if (gvar->in.Keyboard[def->button1])
\r
899 case ctrl_Joystick1:
\r
900 case ctrl_Joystick2:
\r
901 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false, gvar);
\r
902 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
\r
906 INL_GetMouseDelta(&dx,&dy);
\r
907 buttons = INL_GetMouseButtons();
\r
917 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
\r
918 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
\r
926 player[pn].info.x = dx;
\r
927 player[pn].info.xaxis = mx;
\r
928 player[pn].info.y = dy;
\r
929 player[pn].info.yaxis = my;
\r
930 player[pn].info.button0 = buttons & (1 << 0);
\r
931 player[pn].info.button1 = buttons & (1 << 1);
\r
932 player[pn].info.button2 = buttons & (1 << 2);
\r
933 player[pn].info.button3 = buttons & (1 << 3);
\r
934 // player[pn].info.dir = DirTable[((my + 1) * 3) + (mx + 1)];
\r
935 conpee=(((my + 1) * 2) + (mx + 1))-1;
\r
936 player[pn].info.dir = DirTable[conpee];
\r
938 if(DirTable[conpee]!=2) player[pn].pdir=DirTable[conpee];
\r
939 if(player[pn].enti.q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None)))
\r
941 if(dir==2) player[pn].enti.d = player[pn].info.dir;
\r
942 else player[pn].enti.d = DirTable[dir];
\r
946 if (DemoMode == demo_Record)
\r
948 // Pack the control info into a byte
\r
949 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);
\r
953 (DemoBuffer[DemoOffset + 1] == dbyte)
\r
954 && (DemoBuffer[DemoOffset] < 255)
\r
956 (DemoBuffer[DemoOffset])++;
\r
959 if (DemoOffset || DemoBuffer[DemoOffset])
\r
962 if (DemoOffset >= DemoSize)
\r
963 Quit ("Demo buffer overflow");
\r
965 DemoBuffer[DemoOffset] = 1;
\r
966 DemoBuffer[DemoOffset + 1] = dbyte;
\r
970 #ifdef __DEBUG_InputMgr__
\r
971 if(dbg_testcontrolnoisy > 0)
\r
972 if(player[pn].info.dir!=2/*(gvar->in.Keyboard[def->up] || gvar->in.Keyboard[def->down] || gvar->in.Keyboard[def->left] || gvar->in.Keyboard[def->right])*/ || player[pn].enti.q>1)
\r
974 //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
975 //printf("q=%d ", player[pn].enti.q);
\r
976 //printf("cpee=%c ", dirchar(conpee));
\r
977 printf("pdir=%c d=%c dir=%c ", dirchar(player[pn].pdir), dirchar(player[pn].enti.d), dirchar(player[pn].info.dir));
\r
978 /*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
979 //else if(!realdelta) printf("%c%d %c%d %c%d %c%d", dirchar(0), gvar->in.Keyboard[def->up], dirchar(4), gvar->in.Keyboard[def->down], dirchar(1), gvar->in.Keyboard[def->left], dirchar(3), gvar->in.Keyboard[def->right]);
\r
985 ///////////////////////////////////////////////////////////////////////////
\r
987 // IN_SetControlType() - Sets the control type to be used by the specified
\r
990 ///////////////////////////////////////////////////////////////////////////
\r
992 IN_SetControlType(word pn,player_t *player,ControlType type)
\r
994 // DEBUG - check that requested type is present?
\r
995 player[pn].Controls = type;
\r
999 ///////////////////////////////////////////////////////////////////////////
\r
1001 // IN_StartDemoRecord() - Starts the demo recording, using a buffer the
\r
1002 // size passed. Returns if the buffer allocation was successful
\r
1004 ///////////////////////////////////////////////////////////////////////////
\r
1006 IN_StartDemoRecord(word bufsize)
\r
1011 MM_GetPtr((memptr *)&DemoBuffer,bufsize);
\r
1012 DemoMode = demo_Record;
\r
1013 DemoSize = bufsize & ~1;
\r
1015 DemoBuffer[0] = DemoBuffer[1] = 0;
\r
1020 ///////////////////////////////////////////////////////////////////////////
\r
1022 // IN_StartDemoPlayback() - Plays back the demo pointed to of the given size
\r
1024 ///////////////////////////////////////////////////////////////////////////
\r
1026 IN_StartDemoPlayback(byte /*__segment*/ *buffer,word bufsize)
\r
1028 DemoBuffer = buffer;
\r
1029 DemoMode = demo_Playback;
\r
1030 DemoSize = bufsize & ~1;
\r
1034 ///////////////////////////////////////////////////////////////////////////
\r
1036 // IN_StopDemo() - Turns off demo mode
\r
1038 ///////////////////////////////////////////////////////////////////////////
\r
1042 if ((DemoMode == demo_Record) && DemoOffset)
\r
1045 DemoMode = demo_Off;
\r
1048 ///////////////////////////////////////////////////////////////////////////
\r
1050 // IN_FreeDemoBuffer() - Frees the demo buffer, if it's been allocated
\r
1052 ///////////////////////////////////////////////////////////////////////////
\r
1054 IN_FreeDemoBuffer(void)
\r
1057 MM_FreePtr((memptr *)&DemoBuffer);
\r
1062 ///////////////////////////////////////////////////////////////////////////
\r
1064 // IN_GetScanName() - Returns a string containing the name of the
\r
1065 // specified scan code
\r
1067 ///////////////////////////////////////////////////////////////////////////
\r
1069 IN_GetScanName(ScanCode scan)
\r
1074 for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)
\r
1078 return(ScanNames[scan]);
\r
1081 ///////////////////////////////////////////////////////////////////////////
\r
1083 // IN_WaitForKey() - Waits for a scan code, then clears LastScan and
\r
1084 // returns the scan code
\r
1086 ///////////////////////////////////////////////////////////////////////////
\r
1088 IN_WaitForKey(global_game_variables_t *gvar)
\r
1092 while (!(result = gvar->in.LastScan))
\r
1094 gvar->in.LastScan = 0;
\r
1098 ///////////////////////////////////////////////////////////////////////////
\r
1100 // IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and
\r
1101 // returns the ASCII value
\r
1103 ///////////////////////////////////////////////////////////////////////////
\r
1105 IN_WaitForASCII(global_game_variables_t *gvar)
\r
1109 while (!(result = gvar->in.LastASCII))
\r
1111 gvar->in.LastASCII = '\0';
\r
1115 ///////////////////////////////////////////////////////////////////////////
\r
1117 // IN_AckBack() - Waits for either an ASCII keypress or a button press
\r
1119 ///////////////////////////////////////////////////////////////////////////
\r
1121 IN_AckBack(global_game_variables_t *gvar)
\r
1125 while (!gvar->in.LastScan)
\r
1127 if (gvar->in.MousePresent)
\r
1129 if (INL_GetMouseButtons())
\r
1131 while (INL_GetMouseButtons())
\r
1137 for (i = 0;i < MaxJoys;i++)
\r
1139 if (gvar->in.JoysPresent[i])
\r
1141 if (IN_GetJoyButtonsDB(i, gvar))
\r
1143 while (IN_GetJoyButtonsDB(i, gvar))
\r
1151 IN_ClearKey(gvar->in.LastScan, gvar);
\r
1152 gvar->in.LastScan = sc_None;
\r
1155 ///////////////////////////////////////////////////////////////////////////
\r
1157 // IN_Ack() - Clears user input & then calls IN_AckBack()
\r
1159 ///////////////////////////////////////////////////////////////////////////
\r
1161 IN_Ack(global_game_variables_t *gvar)
\r
1165 if (!gvar->in.IN_Started)
\r
1168 IN_ClearKey(gvar->in.LastScan, gvar);
\r
1169 gvar->in.LastScan = sc_None;
\r
1171 if (gvar->in.MousePresent)
\r
1172 while (INL_GetMouseButtons())
\r
1174 for (i = 0;i < MaxJoys;i++)
\r
1175 if (gvar->in.JoysPresent[i])
\r
1176 while (IN_GetJoyButtonsDB(i, gvar))
\r
1182 ///////////////////////////////////////////////////////////////////////////
\r
1184 // IN_IsUserInput() - Returns true if a key has been pressed or a button
\r
1187 ///////////////////////////////////////////////////////////////////////////
\r
1189 IN_IsUserInput(global_game_variables_t *gvar)
\r
1194 result = gvar->in.LastScan;
\r
1196 if (gvar->in.MousePresent)
\r
1197 if (INL_GetMouseButtons())
\r
1200 for (i = 0;i < MaxJoys;i++)
\r
1201 if (gvar->in.JoysPresent[i])
\r
1202 if (INL_GetJoyButtons(i))
\r
1208 ///////////////////////////////////////////////////////////////////////////
\r
1210 // IN_UserInput() - Waits for the specified delay time (in ticks) or the
\r
1211 // user pressing a key or a mouse button. If the clear flag is set, it
\r
1212 // then either clears the key or waits for the user to let the mouse
\r
1215 ///////////////////////////////////////////////////////////////////////////
\r
1217 IN_UserInput(dword delay,boolean clear, global_game_variables_t *gvar)
\r
1219 word TimeCount = gvar->kurokku.clock_start;
\r
1222 lasttime = TimeCount;
\r
1225 if (IN_IsUserInput(gvar))
\r
1231 } while (TimeCount - lasttime < delay);
\r
1235 //===========================================================================
\r
1238 ===================
\r
1242 ===================
\r
1245 byte IN_MouseButtons (global_game_variables_t *gvar)
\r
1247 union REGS CPURegs;
\r
1248 if (gvar->in.MousePresent)
\r
1251 return CPURegs.x.bx;
\r
1259 ===================
\r
1263 ===================
\r
1266 byte IN_JoyButtons (void)
\r
1270 joybits = inp(0x201); // Get all the joystick buttons
\r
1271 joybits >>= 4; // only the high bits are useful
\r
1272 joybits ^= 15; // return with 1=pressed
\r
1277 boolean IN_KeyDown(byte code, global_game_variables_t *gvar)
\r
1279 #ifdef __DEBUG_InputMgr__
\r
1282 return gvar->in.Keyboard[code];
\r
1283 #ifdef __DEBUG_InputMgr__
\r
1285 if(dbg_nointest && kbhit())
\r
1292 void IN_ClearKey(byte code, global_game_variables_t *gvar)
\r
1294 gvar->in.Keyboard[code] = false;
\r
1295 if(code == gvar->in.LastScan)
\r
1296 gvar->in.LastScan = sc_None;
\r
1299 boolean IN_qb(byte kee, global_game_variables_t *gvar)
\r
1301 #ifdef __DEBUG_InputMgr__
\r
1302 if(dbg_testkeyin) printf("%u\n", gvar->in.Keyboard[kee]);
\r
1304 if(gvar->in.Keyboard[kee]==true) return 1;
\r
1308 ScanCode IN_GetLastScan(global_game_variables_t *gvar)
\r
1310 return gvar->in.LastScan;
\r
1313 ScanCode IN_GetCurCode(global_game_variables_t *gvar)
\r
1315 return gvar->in.CurCode;
\r