1 /* Catacomb Armageddon 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
27 // This module handles dealing with the various input devices
\r
29 // Depends on: Memory Mgr (for demo recording), Sound Mgr (for timing stuff),
\r
30 // User Mgr (for command line parms)
\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
38 //#include "ID_HEADS.H"
\r
42 #define KeyInt 9 // The keyboard ISR number
\r
44 // Stuff for the joystick
\r
45 #define JoyScaleMax 32768
\r
46 #define JoyScaleShift 8
\r
47 #define MaxJoyValue 5000
\r
50 boolean JoystickCalibrated=false; // MDM (GAMERS EDGE) - added
\r
51 ControlType ControlTypeUsed; // MDM (GAMERS EDGE) - added
\r
53 boolean Keyboard[NumCodes],
\r
54 JoysPresent[MaxJoys],
\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
63 // Demo DemoMode = demo_Off;
\r
64 // byte /*_1seg*/ *DemoBuffer;
\r
65 // word DemoOffset,DemoSize;
\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
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
83 far ShiftNames[] = // Shifted ASCII for scan codes
\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
95 far SpecialNames[] = // ASCII for 0xe0 prefixed codes
\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
109 *ScanNames[] = // Scan code names with single chars
\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
122 far ExtScanCodes[] = // Scan codes with >1 char names
\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
130 *ExtScanNames[] = // Names corresponding to ExtScanCodes
\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
138 static Direction DirTable[] = // Quick lookup for total direction
\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
145 static void (*INL_KeyHook)(void);
\r
146 static void interrupt (*OldKeyVect)(void);
\r
148 static char *ParmStrings[] = {"nojoys","nomouse",nil};
\r
150 // Internal routines
\r
152 ///////////////////////////////////////////////////////////////////////////
\r
154 // INL_KeyService() - Handles a keyboard interrupt (key up/down)
\r
156 ///////////////////////////////////////////////////////////////////////////
\r
157 static void interrupt
\r
158 INL_KeyService(void)
\r
160 static boolean special;
\r
164 k = inp(0x60); // Get the scan code
\r
166 // Tell the XT keyboard controller to clear the key
\r
167 outp(0x61,(temp = inp(0x61)) | 0x80);
\r
170 if (k == 0xe0) // Special key prefix
\r
172 else if (k == 0xe1) // Handle Pause key
\r
176 if (k & 0x80) // Break code
\r
180 // DEBUG - handle special keys: ctl-alt-delete, print scrn
\r
182 Keyboard[k] = false;
\r
186 LastCode = CurCode;
\r
187 CurCode = LastScan = k;
\r
188 Keyboard[k] = true;
\r
191 c = SpecialNames[k];
\r
194 if (k == sc_CapsLock)
\r
197 // DEBUG - make caps lock light work
\r
200 if (Keyboard[sc_LShift] || Keyboard[sc_RShift]) // If shifted
\r
203 if ((c >= 'A') && (c <= 'Z') && CapsLock)
\r
209 if ((c >= 'a') && (c <= 'z') && CapsLock)
\r
220 if (INL_KeyHook && !special)
\r
229 int86(MouseInt,&CPURegs,&CPURegs);
\r
232 ///////////////////////////////////////////////////////////////////////////
\r
234 // INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
\r
237 ///////////////////////////////////////////////////////////////////////////
\r
239 INL_GetMouseDelta(int *x,int *y)
\r
246 ///////////////////////////////////////////////////////////////////////////
\r
248 // INL_GetMouseButtons() - Gets the status of the mouse buttons from the
\r
251 ///////////////////////////////////////////////////////////////////////////
\r
253 INL_GetMouseButtons(void)
\r
258 buttons = CPURegs.x.bx;
\r
262 ///////////////////////////////////////////////////////////////////////////
\r
264 // IN_GetJoyAbs() - Reads the absolute position of the specified joystick
\r
266 ///////////////////////////////////////////////////////////////////////////
\r
268 IN_GetJoyAbs(word joy,word *xp,word *yp)
\r
275 xs = joy? 2 : 0; // Find shift value for x axis
\r
276 xb = 1 << xs; // Use shift value to get x bit mask
\r
277 ys = joy? 3 : 1; // Do the same for y axis
\r
280 // Read the absolute joystick values
\r
283 pushf // Save some registers
\r
286 cli // Make sure an interrupt doesn't screw the timings
\r
291 out dx,al // Clear the resistors
\r
293 mov ah,[xb] // Get masks into registers
\r
296 xor si,si // Clear count registers
\r
298 xor bh,bh // Clear high byte of bx for later
\r
300 push bp // Don't mess up stack frame
\r
304 in al,dx // Get bits indicating whether all are finished
\r
306 dec bp // Check bounding register
\r
307 jz done // We have a silly value - abort
\r
309 mov bl,al // Duplicate the bits
\r
310 and bl,ah // Mask off useless bits (in [xb])
\r
311 add si,bx // Possibly increment count register
\r
312 mov cl,bl // Save for testing later
\r
319 jnz loop // If both bits were 0, drop out
\r
324 mov cl,[xs] // Get the number of bits to shift
\r
325 shr si,cl // and shift the count that many times
\r
330 mov [x],si // Store the values into the variables
\r
335 popf // Restore the registers
\r
342 ///////////////////////////////////////////////////////////////////////////
\r
344 // INL_GetJoyDelta() - Returns the relative movement of the specified
\r
345 // joystick (from +/-127, scaled adaptively)
\r
347 ///////////////////////////////////////////////////////////////////////////
\r
349 INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)
\r
354 static dword lasttime;
\r
356 IN_GetJoyAbs(joy,&x,&y);
\r
357 def = JoyDefs + joy;
\r
359 if (x < def->threshMinX)
\r
361 if (x < def->joyMinX)
\r
364 x = -(x - def->threshMinX);
\r
365 x *= def->joyMultXL;
\r
366 x >>= JoyScaleShift;
\r
367 *dx = (x > 127)? -127 : -x;
\r
369 else if (x > def->threshMaxX)
\r
371 if (x > def->joyMaxX)
\r
374 x = x - def->threshMaxX;
\r
375 x *= def->joyMultXH;
\r
376 x >>= JoyScaleShift;
\r
377 *dx = (x > 127)? 127 : x;
\r
382 if (y < def->threshMinY)
\r
384 if (y < def->joyMinY)
\r
387 y = -(y - def->threshMinY);
\r
388 y *= def->joyMultYL;
\r
389 y >>= JoyScaleShift;
\r
390 *dy = (y > 127)? -127 : -y;
\r
392 else if (y > def->threshMaxY)
\r
394 if (y > def->joyMaxY)
\r
397 y = y - def->threshMaxY;
\r
398 y *= def->joyMultYH;
\r
399 y >>= JoyScaleShift;
\r
400 *dy = (y > 127)? 127 : y;
\r
407 time = (TimeCount - lasttime) / 2;
\r
416 lasttime = TimeCount;
\r
419 ///////////////////////////////////////////////////////////////////////////
\r
421 // INL_GetJoyButtons() - Returns the button status of the specified
\r
424 ///////////////////////////////////////////////////////////////////////////
\r
426 INL_GetJoyButtons(word joy)
\r
428 register word result;
\r
430 result = inp(0x201); // Get all the joystick buttons
\r
431 result >>= joy? 6 : 4; // Shift into bits 0-1
\r
432 result &= 3; // Mask off the useless bits
\r
437 ///////////////////////////////////////////////////////////////////////////
\r
439 // IN_GetJoyButtonsDB() - Returns the de-bounced button status of the
\r
440 // specified joystick
\r
442 ///////////////////////////////////////////////////////////////////////////
\r
444 IN_GetJoyButtonsDB(word joy)
\r
447 word result1,result2;
\r
451 result1 = INL_GetJoyButtons(joy);
\r
452 lasttime = TimeCount;
\r
453 while(TimeCount == lasttime)
\r
455 result2 = INL_GetJoyButtons(joy);
\r
456 } while(result1 != result2);
\r
460 ///////////////////////////////////////////////////////////////////////////
\r
462 // INL_StartKbd() - Sets up my keyboard stuff for use
\r
464 ///////////////////////////////////////////////////////////////////////////
\r
468 INL_KeyHook = 0; // Clear key hook
\r
470 IN_ClearKeysDown();
\r
472 OldKeyVect = _dos_getvect(KeyInt);
\r
473 _dos_setvect(KeyInt,INL_KeyService);
\r
476 ///////////////////////////////////////////////////////////////////////////
\r
478 // INL_ShutKbd() - Restores keyboard control to the BIOS
\r
480 ///////////////////////////////////////////////////////////////////////////
\r
484 poke(0x40,0x17,peek(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags
\r
486 _dos_setvect(KeyInt,OldKeyVect);
\r
489 ///////////////////////////////////////////////////////////////////////////
\r
491 // INL_StartMouse() - Detects and sets up the mouse
\r
493 ///////////////////////////////////////////////////////////////////////////
\r
495 INL_StartMouse(void)
\r
497 if(_dos_getvect(MouseInt))
\r
500 if(CPURegs.x.ax == 0xffff)
\r
506 ///////////////////////////////////////////////////////////////////////////
\r
508 // INL_ShutMouse() - Cleans up after the mouse
\r
510 ///////////////////////////////////////////////////////////////////////////
\r
512 INL_ShutMouse(void)
\r
517 // INL_SetJoyScale() - Sets up scaling values for the specified joystick
\r
520 INL_SetJoyScale(word joy)
\r
524 def = &JoyDefs[joy];
\r
525 def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
\r
526 def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
\r
527 def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
\r
528 def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);
\r
531 ///////////////////////////////////////////////////////////////////////////
\r
533 // IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
\r
534 // to set up scaling values
\r
536 ///////////////////////////////////////////////////////////////////////////
\r
538 IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
\r
543 def = &JoyDefs[joy];
\r
545 def->joyMinX = minx;
\r
546 def->joyMaxX = maxx;
\r
549 def->threshMinX = ((r / 2) - d) + minx;
\r
550 def->threshMaxX = ((r / 2) + d) + minx;
\r
552 def->joyMinY = miny;
\r
553 def->joyMaxY = maxy;
\r
556 def->threshMinY = ((r / 2) - d) + miny;
\r
557 def->threshMaxY = ((r / 2) + d) + miny;
\r
559 INL_SetJoyScale(joy);
\r
562 ///////////////////////////////////////////////////////////////////////////
\r
564 // INL_StartJoy() - Detects & auto-configures the specified joystick
\r
565 // The auto-config assumes the joystick is centered
\r
567 ///////////////////////////////////////////////////////////////////////////
\r
569 INL_StartJoy(word joy)
\r
573 IN_GetJoyAbs(joy,&x,&y);
\r
577 ((x == 0) || (x > MaxJoyValue - 10))
\r
578 || ((y == 0) || (y > MaxJoyValue - 10))
\r
583 IN_SetupJoy(joy,0,x * 2,0,y * 2);
\r
588 ///////////////////////////////////////////////////////////////////////////
\r
590 // INL_ShutJoy() - Cleans up the joystick stuff
\r
592 ///////////////////////////////////////////////////////////////////////////
\r
594 INL_ShutJoy(word joy)
\r
596 JoysPresent[joy] = false;
\r
601 ///////////////////////////////////////////////////////////////////////////
\r
603 // IN_Startup() - Starts up the Input Mgr
\r
605 ///////////////////////////////////////////////////////////////////////////
\r
609 boolean checkjoys,checkmouse;
\r
617 for (i = 1;i < _argc;i++)
\r
619 switch (US_CheckParm(_argv[i],ParmStrings))
\r
625 checkmouse = false;
\r
631 MousePresent = checkmouse? INL_StartMouse() : false;
\r
633 for (i = 0;i < MaxJoys;i++)
\r
634 JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
\r
639 ///////////////////////////////////////////////////////////////////////////
\r
641 // IN_Default() - Sets up default conditions for the Input Mgr
\r
643 ///////////////////////////////////////////////////////////////////////////
\r
645 IN_Default(boolean gotit,ControlType in)
\r
650 || ((in == ctrl_Joystick1) && !JoysPresent[0])
\r
651 || ((in == ctrl_Joystick2) && !JoysPresent[1])
\r
652 || ((in == ctrl_Mouse) && !MousePresent)
\r
654 in = ctrl_Keyboard1;
\r
655 IN_SetControlType(0,in);
\r
658 ///////////////////////////////////////////////////////////////////////////
\r
660 // IN_Shutdown() - Shuts down the Input Mgr
\r
662 ///////////////////////////////////////////////////////////////////////////
\r
672 for (i = 0;i < MaxJoys;i++)
\r
676 IN_Started = false;
\r
679 ///////////////////////////////////////////////////////////////////////////
\r
681 // IN_SetKeyHook() - Sets the routine that gets called by INL_KeyService()
\r
682 // everytime a real make/break code gets hit
\r
684 ///////////////////////////////////////////////////////////////////////////
\r
686 IN_SetKeyHook(void (*hook)())
\r
688 INL_KeyHook = hook;
\r
691 ///////////////////////////////////////////////////////////////////////////
\r
693 // IN_ClearKeyDown() - Clears the keyboard array
\r
695 ///////////////////////////////////////////////////////////////////////////
\r
697 IN_ClearKeysDown(void)
\r
701 LastScan = sc_None;
\r
702 LastASCII = key_None;
\r
703 for (i = 0;i < NumCodes;i++)
\r
704 Keyboard[i] = false;
\r
707 ///////////////////////////////////////////////////////////////////////////
\r
709 // INL_AdjustCursor() - Internal routine of common code from IN_ReadCursor()
\r
711 ///////////////////////////////////////////////////////////////////////////
\r
713 INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
\r
715 if (buttons & (1 << 0))
\r
716 info->button0 = true;
\r
717 if (buttons & (1 << 1))
\r
718 info->button1 = true;
\r
724 ///////////////////////////////////////////////////////////////////////////
\r
726 // IN_ReadCursor() - Reads the input devices and fills in the cursor info
\r
729 ///////////////////////////////////////////////////////////////////////////
\r
731 IN_ReadCursor(CursorInfo *info)
\r
737 info->x = info->y = 0;
\r
738 info->button0 = info->button1 = false;
\r
742 buttons = INL_GetMouseButtons();
\r
743 INL_GetMouseDelta(&dx,&dy);
\r
744 INL_AdjustCursor(info,buttons,dx,dy);
\r
747 for (i = 0;i < MaxJoys;i++)
\r
749 if (!JoysPresent[i])
\r
752 buttons = INL_GetJoyButtons(i);
\r
753 INL_GetJoyDelta(i,&dx,&dy,true);
\r
756 INL_AdjustCursor(info,buttons,dx,dy);
\r
760 ///////////////////////////////////////////////////////////////////////////
\r
762 // IN_ReadControl() - Reads the device associated with the specified
\r
763 // player and fills in the control info struct
\r
765 ///////////////////////////////////////////////////////////////////////////
\r
767 IN_ReadControl(int player,ControlInfo *info)
\r
769 boolean realdelta=false; // MDM (GAMERS EDGE)
\r
775 register KeyboardDef *def;
\r
778 mx = my = motion_None;
\r
782 if (DemoMode == demo_Playback)
\r
784 dbyte = DemoBuffer[DemoOffset + 1];
\r
785 my = (dbyte & 3) - 1;
\r
786 mx = ((dbyte >> 2) & 3) - 1;
\r
787 buttons = (dbyte >> 4) & 3;
\r
789 if (!(--DemoBuffer[DemoOffset]))
\r
792 if (DemoOffset >= DemoSize)
\r
793 DemoMode = demo_PlayDone;
\r
798 else if (DemoMode == demo_PlayDone)
\r
799 Quit("Demo playback exceeded");
\r
803 // MDM begin (GAMERS EDGE) - added this block
\r
804 ControlTypeUsed = ctrl_None;
\r
806 // Handle mouse input...
\r
808 if ((MousePresent) && (ControlTypeUsed == ctrl_None))
\r
810 INL_GetMouseDelta(&dx,&dy);
\r
811 buttons = INL_GetMouseButtons();
\r
813 if (dx || dy || buttons)
\r
814 ControlTypeUsed = ctrl_Mouse;
\r
817 // Handle joystick input...
\r
819 if ((JoystickCalibrated) && (ControlTypeUsed == ctrl_None))
\r
821 type = ctrl_Joystick1;
\r
822 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);
\r
823 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
\r
825 if (dx || dy || buttons)
\r
826 ControlTypeUsed = ctrl_Joystick;
\r
829 // Handle keyboard input...
\r
831 if (ControlTypeUsed == ctrl_None)
\r
833 type = ctrl_Keyboard1;
\r
834 def = &KbdDefs[type - ctrl_Keyboard];
\r
836 if (Keyboard[def->upleft])
\r
837 mx = motion_Left,my = motion_Up;
\r
838 else if (Keyboard[def->upright])
\r
839 mx = motion_Right,my = motion_Up;
\r
840 else if (Keyboard[def->downleft])
\r
841 mx = motion_Left,my = motion_Down;
\r
842 else if (Keyboard[def->downright])
\r
843 mx = motion_Right,my = motion_Down;
\r
845 if (Keyboard[def->up])
\r
847 else if (Keyboard[def->down])
\r
850 if (Keyboard[def->left])
\r
852 else if (Keyboard[def->right])
\r
855 if (Keyboard[def->button0])
\r
857 if (Keyboard[def->button1])
\r
860 if (mx || my || buttons)
\r
861 ControlTypeUsed = ctrl_Keyboard;
\r
862 } // MDM end (GAMERS EDGE)
\r
867 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
\r
868 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
\r
880 info->button0 = buttons & (1 << 0);
\r
881 info->button1 = buttons & (1 << 1);
\r
882 info->dir = DirTable[((my + 1) * 3) + (mx + 1)];
\r
885 if (DemoMode == demo_Record)
\r
887 // Pack the control info into a byte
\r
888 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);
\r
892 (DemoBuffer[DemoOffset + 1] == dbyte)
\r
893 && (DemoBuffer[DemoOffset] < 255)
\r
895 (DemoBuffer[DemoOffset])++;
\r
898 if (DemoOffset || DemoBuffer[DemoOffset])
\r
901 if (DemoOffset >= DemoSize)
\r
902 Quit("Demo buffer overflow");
\r
904 DemoBuffer[DemoOffset] = 1;
\r
905 DemoBuffer[DemoOffset + 1] = dbyte;
\r
912 ///////////////////////////////////////////////////////////////////////////
\r
914 // IN_ReadControl() - Reads the device associated with the specified
\r
915 // player and fills in the control info struct
\r
917 ///////////////////////////////////////////////////////////////////////////
\r
919 IN_ReadControl(int player,ControlInfo *info)
\r
927 register KeyboardDef *def;
\r
930 mx = my = motion_None;
\r
934 if (DemoMode == demo_Playback)
\r
936 dbyte = DemoBuffer[DemoOffset + 1];
\r
937 my = (dbyte & 3) - 1;
\r
938 mx = ((dbyte >> 2) & 3) - 1;
\r
939 buttons = (dbyte >> 4) & 3;
\r
941 if (!(--DemoBuffer[DemoOffset]))
\r
944 if (DemoOffset >= DemoSize)
\r
945 DemoMode = demo_PlayDone;
\r
950 else if (DemoMode == demo_PlayDone)
\r
951 Quit("Demo playback exceeded");
\r
955 switch (type = Controls[player])
\r
957 case ctrl_Keyboard1:
\r
958 case ctrl_Keyboard2:
\r
959 def = &KbdDefs[type - ctrl_Keyboard];
\r
961 if (Keyboard[def->upleft])
\r
962 mx = motion_Left,my = motion_Up;
\r
963 else if (Keyboard[def->upright])
\r
964 mx = motion_Right,my = motion_Up;
\r
965 else if (Keyboard[def->downleft])
\r
966 mx = motion_Left,my = motion_Down;
\r
967 else if (Keyboard[def->downright])
\r
968 mx = motion_Right,my = motion_Down;
\r
970 if (Keyboard[def->up])
\r
972 else if (Keyboard[def->down])
\r
975 if (Keyboard[def->left])
\r
977 else if (Keyboard[def->right])
\r
980 if (Keyboard[def->button0])
\r
982 if (Keyboard[def->button1])
\r
986 case ctrl_Joystick1:
\r
987 case ctrl_Joystick2:
\r
988 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);
\r
989 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
\r
993 INL_GetMouseDelta(&dx,&dy);
\r
994 buttons = INL_GetMouseButtons();
\r
1002 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
\r
1003 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
\r
1015 info->button0 = buttons & (1 << 0);
\r
1016 info->button1 = buttons & (1 << 1);
\r
1017 info->dir = DirTable[((my + 1) * 3) + (mx + 1)];
\r
1020 if (DemoMode == demo_Record)
\r
1022 // Pack the control info into a byte
\r
1023 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);
\r
1027 (DemoBuffer[DemoOffset + 1] == dbyte)
\r
1028 && (DemoBuffer[DemoOffset] < 255)
\r
1030 (DemoBuffer[DemoOffset])++;
\r
1033 if (DemoOffset || DemoBuffer[DemoOffset])
\r
1036 if (DemoOffset >= DemoSize)
\r
1037 Quit("Demo buffer overflow");
\r
1039 DemoBuffer[DemoOffset] = 1;
\r
1040 DemoBuffer[DemoOffset + 1] = dbyte;
\r
1047 ///////////////////////////////////////////////////////////////////////////
\r
1049 // IN_SetControlType() - Sets the control type to be used by the specified
\r
1052 ///////////////////////////////////////////////////////////////////////////
\r
1054 IN_SetControlType(int player,ControlType type)
\r
1056 // DEBUG - check that requested type is present?
\r
1057 Controls[player] = type;
\r
1061 ///////////////////////////////////////////////////////////////////////////
\r
1063 // IN_StartDemoRecord() - Starts the demo recording, using a buffer the
\r
1064 // size passed. Returns if the buffer allocation was successful
\r
1066 ///////////////////////////////////////////////////////////////////////////
\r
1068 IN_StartDemoRecord(word bufsize)
\r
1073 MM_GetPtr((memptr *)&DemoBuffer,bufsize);
\r
1074 DemoMode = demo_Record;
\r
1075 DemoSize = bufsize & ~1;
\r
1077 DemoBuffer[0] = DemoBuffer[1] = 0;
\r
1082 ///////////////////////////////////////////////////////////////////////////
\r
1084 // IN_StartDemoPlayback() - Plays back the demo pointed to of the given size
\r
1086 ///////////////////////////////////////////////////////////////////////////
\r
1088 IN_StartDemoPlayback(byte /*_1seg*/ *buffer,word bufsize)
\r
1090 DemoBuffer = buffer;
\r
1091 DemoMode = demo_Playback;
\r
1092 DemoSize = bufsize & ~1;
\r
1096 ///////////////////////////////////////////////////////////////////////////
\r
1098 // IN_StopDemo() - Turns off demo mode
\r
1100 ///////////////////////////////////////////////////////////////////////////
\r
1104 if ((DemoMode == demo_Record) && DemoOffset)
\r
1107 DemoMode = demo_Off;
\r
1110 ///////////////////////////////////////////////////////////////////////////
\r
1112 // IN_FreeDemoBuffer() - Frees the demo buffer, if it's been allocated
\r
1114 ///////////////////////////////////////////////////////////////////////////
\r
1116 IN_FreeDemoBuffer(void)
\r
1119 MM_FreePtr((memptr *)&DemoBuffer);
\r
1125 ///////////////////////////////////////////////////////////////////////////
\r
1127 // IN_GetScanName() - Returns a string containing the name of the
\r
1128 // specified scan code
\r
1130 ///////////////////////////////////////////////////////////////////////////
\r
1132 IN_GetScanName(ScanCode scan)
\r
1137 for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)
\r
1141 return(ScanNames[scan]);
\r
1146 ///////////////////////////////////////////////////////////////////////////
\r
1148 // IN_WaitForKey() - Waits for a scan code, then clears LastScan and
\r
1149 // returns the scan code
\r
1151 ///////////////////////////////////////////////////////////////////////////
\r
1153 IN_WaitForKey(void)
\r
1157 while (!(result = LastScan))
\r
1163 ///////////////////////////////////////////////////////////////////////////
\r
1165 // IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and
\r
1166 // returns the ASCII value
\r
1168 ///////////////////////////////////////////////////////////////////////////
\r
1170 IN_WaitForASCII(void)
\r
1174 while (!(result = LastASCII))
\r
1180 ///////////////////////////////////////////////////////////////////////////
\r
1182 // IN_AckBack() - Waits for either an ASCII keypress or a button press
\r
1184 ///////////////////////////////////////////////////////////////////////////
\r
1194 if (INL_GetMouseButtons())
\r
1196 while (INL_GetMouseButtons())
\r
1202 for (i = 0;i < MaxJoys;i++)
\r
1204 if (JoysPresent[i])
\r
1206 if (IN_GetJoyButtonsDB(i))
\r
1208 while (IN_GetJoyButtonsDB(i))
\r
1216 IN_ClearKey(LastScan);
\r
1217 LastScan = sc_None;
\r
1220 ///////////////////////////////////////////////////////////////////////////
\r
1222 // IN_Ack() - Clears user input & then calls IN_AckBack()
\r
1224 ///////////////////////////////////////////////////////////////////////////
\r
1230 IN_ClearKey(LastScan);
\r
1231 LastScan = sc_None;
\r
1234 while (INL_GetMouseButtons())
\r
1236 for (i = 0;i < MaxJoys;i++)
\r
1237 if (JoysPresent[i])
\r
1238 while (IN_GetJoyButtonsDB(i))
\r
1244 ///////////////////////////////////////////////////////////////////////////
\r
1246 // IN_IsUserInput() - Returns true if a key has been pressed or a button
\r
1249 ///////////////////////////////////////////////////////////////////////////
\r
1251 IN_IsUserInput(void)
\r
1256 result = LastScan;
\r
1259 if (INL_GetMouseButtons())
\r
1262 for (i = 0;i < MaxJoys;i++)
\r
1263 if (JoysPresent[i])
\r
1264 if (INL_GetJoyButtons(i))
\r
1270 ///////////////////////////////////////////////////////////////////////////
\r
1272 // IN_UserInput() - Waits for the specified delay time (in ticks) or the
\r
1273 // user pressing a key or a mouse button. If the clear flag is set, it
\r
1274 // then either clears the key or waits for the user to let the mouse
\r
1277 ///////////////////////////////////////////////////////////////////////////
\r
1279 IN_UserInput(dword delay,boolean clear)
\r
1283 lasttime = TimeCount;
\r
1286 if (IN_IsUserInput())
\r
1292 } while (TimeCount - lasttime < delay);
\r