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"
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
225 ///////////////////////////////////////////////////////////////////////////
\r
227 // INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
\r
230 ///////////////////////////////////////////////////////////////////////////
\r
232 INL_GetMouseDelta(int *x,int *y)
\r
239 ///////////////////////////////////////////////////////////////////////////
\r
241 // INL_GetMouseButtons() - Gets the status of the mouse buttons from the
\r
244 ///////////////////////////////////////////////////////////////////////////
\r
246 INL_GetMouseButtons(void)
\r
255 ///////////////////////////////////////////////////////////////////////////
\r
257 // IN_GetJoyAbs() - Reads the absolute position of the specified joystick
\r
259 ///////////////////////////////////////////////////////////////////////////
\r
261 IN_GetJoyAbs(word joy,word *xp,word *yp)
\r
268 xs = joy? 2 : 0; // Find shift value for x axis
\r
269 xb = 1 << xs; // Use shift value to get x bit mask
\r
270 ys = joy? 3 : 1; // Do the same for y axis
\r
273 // Read the absolute joystick values
276 pushf // Save some registers
\r
279 cli // Make sure an interrupt doesn't screw the timings
\r
284 out dx,al // Clear the resistors
\r
286 mov ah,[xb] // Get masks into registers
\r
289 xor si,si // Clear count registers
\r
291 xor bh,bh // Clear high byte of bx for later
\r
293 push bp // Don't mess up stack frame
\r
297 in al,dx // Get bits indicating whether all are finished
\r
299 dec bp // Check bounding register
\r
300 jz done // We have a silly value - abort
\r
302 mov bl,al // Duplicate the bits
\r
303 and bl,ah // Mask off useless bits (in [xb])
\r
304 add si,bx // Possibly increment count register
\r
305 mov cl,bl // Save for testing later
\r
312 jnz loop // If both bits were 0, drop out
\r
317 mov cl,[xs] // Get the number of bits to shift
\r
318 shr si,cl // and shift the count that many times
\r
323 mov [x],si // Store the values into the variables
\r
328 popf // Restore the registers
335 ///////////////////////////////////////////////////////////////////////////
\r
337 // INL_GetJoyDelta() - Returns the relative movement of the specified
\r
338 // joystick (from +/-127, scaled adaptively)
\r
340 ///////////////////////////////////////////////////////////////////////////
\r
342 INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)
\r
347 static dword lasttime;
\r
349 IN_GetJoyAbs(joy,&x,&y);
\r
350 def = JoyDefs + joy;
\r
352 if (x < def->threshMinX)
\r
354 if (x < def->joyMinX)
\r
357 x = -(x - def->threshMinX);
\r
358 x *= def->joyMultXL;
\r
359 x >>= JoyScaleShift;
\r
360 *dx = (x > 127)? -127 : -x;
\r
362 else if (x > def->threshMaxX)
\r
364 if (x > def->joyMaxX)
\r
367 x = x - def->threshMaxX;
\r
368 x *= def->joyMultXH;
\r
369 x >>= JoyScaleShift;
\r
370 *dx = (x > 127)? 127 : x;
\r
375 if (y < def->threshMinY)
\r
377 if (y < def->joyMinY)
\r
380 y = -(y - def->threshMinY);
\r
381 y *= def->joyMultYL;
\r
382 y >>= JoyScaleShift;
\r
383 *dy = (y > 127)? -127 : -y;
\r
385 else if (y > def->threshMaxY)
\r
387 if (y > def->joyMaxY)
\r
390 y = y - def->threshMaxY;
\r
391 y *= def->joyMultYH;
\r
392 y >>= JoyScaleShift;
\r
393 *dy = (y > 127)? 127 : y;
\r
400 time = (TimeCount - lasttime) / 2;
\r
409 lasttime = TimeCount;
\r
412 ///////////////////////////////////////////////////////////////////////////
\r
414 // INL_GetJoyButtons() - Returns the button status of the specified
\r
417 ///////////////////////////////////////////////////////////////////////////
\r
419 INL_GetJoyButtons(word joy)
\r
421 register word result;
\r
423 result = inp(0x201); // Get all the joystick buttons
\r
424 result >>= joy? 6 : 4; // Shift into bits 0-1
\r
425 result &= 3; // Mask off the useless bits
\r
430 ///////////////////////////////////////////////////////////////////////////
\r
432 // IN_GetJoyButtonsDB() - Returns the de-bounced button status of the
\r
433 // specified joystick
\r
435 ///////////////////////////////////////////////////////////////////////////
\r
437 IN_GetJoyButtonsDB(word joy)
\r
440 word result1,result2;
\r
444 result1 = INL_GetJoyButtons(joy);
\r
445 lasttime = TimeCount;
\r
446 while (TimeCount == lasttime)
\r
448 result2 = INL_GetJoyButtons(joy);
\r
449 } while (result1 != result2);
\r
453 ///////////////////////////////////////////////////////////////////////////
\r
455 // INL_StartKbd() - Sets up my keyboard stuff for use
\r
457 ///////////////////////////////////////////////////////////////////////////
\r
461 INL_KeyHook = 0; // Clear key hook
\r
463 IN_ClearKeysDown();
\r
465 OldKeyVect = getvect(KeyInt);
\r
466 setvect(KeyInt,INL_KeyService);
\r
469 ///////////////////////////////////////////////////////////////////////////
\r
471 // INL_ShutKbd() - Restores keyboard control to the BIOS
\r
473 ///////////////////////////////////////////////////////////////////////////
\r
477 poke(0x40,0x17,peek(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags
\r
479 setvect(KeyInt,OldKeyVect);
\r
482 ///////////////////////////////////////////////////////////////////////////
\r
484 // INL_StartMouse() - Detects and sets up the mouse
\r
486 ///////////////////////////////////////////////////////////////////////////
\r
488 INL_StartMouse(void)
\r
490 if (getvect(MouseInt))
\r
499 ///////////////////////////////////////////////////////////////////////////
\r
501 // INL_ShutMouse() - Cleans up after the mouse
\r
503 ///////////////////////////////////////////////////////////////////////////
\r
505 INL_ShutMouse(void)
\r
510 // INL_SetJoyScale() - Sets up scaling values for the specified joystick
\r
513 INL_SetJoyScale(word joy)
\r
517 def = &JoyDefs[joy];
\r
518 def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
\r
519 def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
\r
520 def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
\r
521 def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);
\r
524 ///////////////////////////////////////////////////////////////////////////
\r
526 // IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
\r
527 // to set up scaling values
\r
529 ///////////////////////////////////////////////////////////////////////////
\r
531 IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
\r
536 def = &JoyDefs[joy];
\r
538 def->joyMinX = minx;
\r
539 def->joyMaxX = maxx;
\r
542 def->threshMinX = ((r / 2) - d) + minx;
\r
543 def->threshMaxX = ((r / 2) + d) + minx;
\r
545 def->joyMinY = miny;
\r
546 def->joyMaxY = maxy;
\r
549 def->threshMinY = ((r / 2) - d) + miny;
\r
550 def->threshMaxY = ((r / 2) + d) + miny;
\r
552 INL_SetJoyScale(joy);
\r
555 ///////////////////////////////////////////////////////////////////////////
\r
557 // INL_StartJoy() - Detects & auto-configures the specified joystick
\r
558 // The auto-config assumes the joystick is centered
\r
560 ///////////////////////////////////////////////////////////////////////////
\r
562 INL_StartJoy(word joy)
\r
566 IN_GetJoyAbs(joy,&x,&y);
\r
570 ((x == 0) || (x > MaxJoyValue - 10))
\r
571 || ((y == 0) || (y > MaxJoyValue - 10))
\r
576 IN_SetupJoy(joy,0,x * 2,0,y * 2);
\r
581 ///////////////////////////////////////////////////////////////////////////
\r
583 // INL_ShutJoy() - Cleans up the joystick stuff
\r
585 ///////////////////////////////////////////////////////////////////////////
\r
587 INL_ShutJoy(word joy)
\r
589 JoysPresent[joy] = false;
\r
594 ///////////////////////////////////////////////////////////////////////////
\r
596 // IN_Startup() - Starts up the Input Mgr
\r
598 ///////////////////////////////////////////////////////////////////////////
\r
602 boolean checkjoys,checkmouse;
\r
610 for (i = 1;i < _argc;i++)
\r
612 switch (US_CheckParm(_argv[i],ParmStrings))
\r
618 checkmouse = false;
\r
624 MousePresent = checkmouse? INL_StartMouse() : false;
\r
626 for (i = 0;i < MaxJoys;i++)
\r
627 JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
\r
632 ///////////////////////////////////////////////////////////////////////////
\r
634 // IN_Default() - Sets up default conditions for the Input Mgr
\r
636 ///////////////////////////////////////////////////////////////////////////
\r
638 IN_Default(boolean gotit,ControlType in)
\r
643 || ((in == ctrl_Joystick1) && !JoysPresent[0])
\r
644 || ((in == ctrl_Joystick2) && !JoysPresent[1])
\r
645 || ((in == ctrl_Mouse) && !MousePresent)
\r
647 in = ctrl_Keyboard1;
\r
648 IN_SetControlType(0,in);
\r
651 ///////////////////////////////////////////////////////////////////////////
\r
653 // IN_Shutdown() - Shuts down the Input Mgr
\r
655 ///////////////////////////////////////////////////////////////////////////
\r
665 for (i = 0;i < MaxJoys;i++)
\r
669 IN_Started = false;
\r
672 ///////////////////////////////////////////////////////////////////////////
\r
674 // IN_SetKeyHook() - Sets the routine that gets called by INL_KeyService()
\r
675 // everytime a real make/break code gets hit
\r
677 ///////////////////////////////////////////////////////////////////////////
\r
679 IN_SetKeyHook(void (*hook)())
\r
681 INL_KeyHook = hook;
\r
684 ///////////////////////////////////////////////////////////////////////////
\r
686 // IN_ClearKeyDown() - Clears the keyboard array
\r
688 ///////////////////////////////////////////////////////////////////////////
\r
690 IN_ClearKeysDown(void)
\r
694 LastScan = sc_None;
\r
695 LastASCII = key_None;
\r
696 for (i = 0;i < NumCodes;i++)
\r
697 Keyboard[i] = false;
\r
700 ///////////////////////////////////////////////////////////////////////////
\r
702 // INL_AdjustCursor() - Internal routine of common code from IN_ReadCursor()
\r
704 ///////////////////////////////////////////////////////////////////////////
\r
706 INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
\r
708 if (buttons & (1 << 0))
\r
709 info->button0 = true;
\r
710 if (buttons & (1 << 1))
\r
711 info->button1 = true;
\r
717 ///////////////////////////////////////////////////////////////////////////
\r
719 // IN_ReadCursor() - Reads the input devices and fills in the cursor info
\r
722 ///////////////////////////////////////////////////////////////////////////
\r
724 IN_ReadCursor(CursorInfo *info)
\r
730 info->x = info->y = 0;
\r
731 info->button0 = info->button1 = false;
\r
735 buttons = INL_GetMouseButtons();
\r
736 INL_GetMouseDelta(&dx,&dy);
\r
737 INL_AdjustCursor(info,buttons,dx,dy);
\r
740 for (i = 0;i < MaxJoys;i++)
\r
742 if (!JoysPresent[i])
\r
745 buttons = INL_GetJoyButtons(i);
\r
746 INL_GetJoyDelta(i,&dx,&dy,true);
\r
749 INL_AdjustCursor(info,buttons,dx,dy);
\r
753 ///////////////////////////////////////////////////////////////////////////
\r
755 // IN_ReadControl() - Reads the device associated with the specified
\r
756 // player and fills in the control info struct
\r
758 ///////////////////////////////////////////////////////////////////////////
\r
760 IN_ReadControl(int player,ControlInfo *info)
\r
762 boolean realdelta=false; // MDM (GAMERS EDGE)
\r
768 register KeyboardDef *def;
\r
771 mx = my = motion_None;
\r
775 if (DemoMode == demo_Playback)
\r
777 dbyte = DemoBuffer[DemoOffset + 1];
\r
778 my = (dbyte & 3) - 1;
\r
779 mx = ((dbyte >> 2) & 3) - 1;
\r
780 buttons = (dbyte >> 4) & 3;
\r
782 if (!(--DemoBuffer[DemoOffset]))
\r
785 if (DemoOffset >= DemoSize)
\r
786 DemoMode = demo_PlayDone;
\r
791 else if (DemoMode == demo_PlayDone)
\r
792 Quit("Demo playback exceeded");
\r
796 // MDM begin (GAMERS EDGE) - added this block
\r
797 ControlTypeUsed = ctrl_None;
\r
799 // Handle mouse input...
\r
801 if ((MousePresent) && (ControlTypeUsed == ctrl_None))
\r
803 INL_GetMouseDelta(&dx,&dy);
\r
804 buttons = INL_GetMouseButtons();
\r
806 if (dx || dy || buttons)
\r
807 ControlTypeUsed = ctrl_Mouse;
\r
810 // Handle joystick input...
\r
812 if ((JoystickCalibrated) && (ControlTypeUsed == ctrl_None))
\r
814 type = ctrl_Joystick1;
\r
815 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);
\r
816 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
\r
818 if (dx || dy || buttons)
\r
819 ControlTypeUsed = ctrl_Joystick;
\r
822 // Handle keyboard input...
\r
824 if (ControlTypeUsed == ctrl_None)
\r
826 type = ctrl_Keyboard1;
\r
827 def = &KbdDefs[type - ctrl_Keyboard];
\r
829 if (Keyboard[def->upleft])
\r
830 mx = motion_Left,my = motion_Up;
\r
831 else if (Keyboard[def->upright])
\r
832 mx = motion_Right,my = motion_Up;
\r
833 else if (Keyboard[def->downleft])
\r
834 mx = motion_Left,my = motion_Down;
\r
835 else if (Keyboard[def->downright])
\r
836 mx = motion_Right,my = motion_Down;
\r
838 if (Keyboard[def->up])
\r
840 else if (Keyboard[def->down])
\r
843 if (Keyboard[def->left])
\r
845 else if (Keyboard[def->right])
\r
848 if (Keyboard[def->button0])
\r
850 if (Keyboard[def->button1])
\r
853 if (mx || my || buttons)
\r
854 ControlTypeUsed = ctrl_Keyboard;
\r
855 } // MDM end (GAMERS EDGE)
\r
860 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
\r
861 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
\r
873 info->button0 = buttons & (1 << 0);
\r
874 info->button1 = buttons & (1 << 1);
\r
875 info->dir = DirTable[((my + 1) * 3) + (mx + 1)];
\r
878 if (DemoMode == demo_Record)
\r
880 // Pack the control info into a byte
\r
881 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);
\r
885 (DemoBuffer[DemoOffset + 1] == dbyte)
\r
886 && (DemoBuffer[DemoOffset] < 255)
\r
888 (DemoBuffer[DemoOffset])++;
\r
891 if (DemoOffset || DemoBuffer[DemoOffset])
\r
894 if (DemoOffset >= DemoSize)
\r
895 Quit("Demo buffer overflow");
\r
897 DemoBuffer[DemoOffset] = 1;
\r
898 DemoBuffer[DemoOffset + 1] = dbyte;
\r
905 ///////////////////////////////////////////////////////////////////////////
\r
907 // IN_ReadControl() - Reads the device associated with the specified
\r
908 // player and fills in the control info struct
\r
910 ///////////////////////////////////////////////////////////////////////////
\r
912 IN_ReadControl(int player,ControlInfo *info)
\r
920 register KeyboardDef *def;
\r
923 mx = my = motion_None;
\r
927 if (DemoMode == demo_Playback)
\r
929 dbyte = DemoBuffer[DemoOffset + 1];
\r
930 my = (dbyte & 3) - 1;
\r
931 mx = ((dbyte >> 2) & 3) - 1;
\r
932 buttons = (dbyte >> 4) & 3;
\r
934 if (!(--DemoBuffer[DemoOffset]))
\r
937 if (DemoOffset >= DemoSize)
\r
938 DemoMode = demo_PlayDone;
\r
943 else if (DemoMode == demo_PlayDone)
\r
944 Quit("Demo playback exceeded");
\r
948 switch (type = Controls[player])
\r
950 case ctrl_Keyboard1:
\r
951 case ctrl_Keyboard2:
\r
952 def = &KbdDefs[type - ctrl_Keyboard];
\r
954 if (Keyboard[def->upleft])
\r
955 mx = motion_Left,my = motion_Up;
\r
956 else if (Keyboard[def->upright])
\r
957 mx = motion_Right,my = motion_Up;
\r
958 else if (Keyboard[def->downleft])
\r
959 mx = motion_Left,my = motion_Down;
\r
960 else if (Keyboard[def->downright])
\r
961 mx = motion_Right,my = motion_Down;
\r
963 if (Keyboard[def->up])
\r
965 else if (Keyboard[def->down])
\r
968 if (Keyboard[def->left])
\r
970 else if (Keyboard[def->right])
\r
973 if (Keyboard[def->button0])
\r
975 if (Keyboard[def->button1])
\r
979 case ctrl_Joystick1:
\r
980 case ctrl_Joystick2:
\r
981 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);
\r
982 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
\r
986 INL_GetMouseDelta(&dx,&dy);
\r
987 buttons = INL_GetMouseButtons();
\r
995 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
\r
996 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
\r
1008 info->button0 = buttons & (1 << 0);
\r
1009 info->button1 = buttons & (1 << 1);
\r
1010 info->dir = DirTable[((my + 1) * 3) + (mx + 1)];
\r
1013 if (DemoMode == demo_Record)
\r
1015 // Pack the control info into a byte
\r
1016 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);
\r
1020 (DemoBuffer[DemoOffset + 1] == dbyte)
\r
1021 && (DemoBuffer[DemoOffset] < 255)
\r
1023 (DemoBuffer[DemoOffset])++;
\r
1026 if (DemoOffset || DemoBuffer[DemoOffset])
\r
1029 if (DemoOffset >= DemoSize)
\r
1030 Quit("Demo buffer overflow");
\r
1032 DemoBuffer[DemoOffset] = 1;
\r
1033 DemoBuffer[DemoOffset + 1] = dbyte;
\r
1040 ///////////////////////////////////////////////////////////////////////////
\r
1042 // IN_SetControlType() - Sets the control type to be used by the specified
\r
1045 ///////////////////////////////////////////////////////////////////////////
\r
1047 IN_SetControlType(int player,ControlType type)
\r
1049 // DEBUG - check that requested type is present?
\r
1050 Controls[player] = type;
\r
1054 ///////////////////////////////////////////////////////////////////////////
\r
1056 // IN_StartDemoRecord() - Starts the demo recording, using a buffer the
\r
1057 // size passed. Returns if the buffer allocation was successful
\r
1059 ///////////////////////////////////////////////////////////////////////////
\r
1061 IN_StartDemoRecord(word bufsize)
\r
1066 MM_GetPtr((memptr *)&DemoBuffer,bufsize);
\r
1067 DemoMode = demo_Record;
\r
1068 DemoSize = bufsize & ~1;
\r
1070 DemoBuffer[0] = DemoBuffer[1] = 0;
\r
1075 ///////////////////////////////////////////////////////////////////////////
\r
1077 // IN_StartDemoPlayback() - Plays back the demo pointed to of the given size
\r
1079 ///////////////////////////////////////////////////////////////////////////
\r
1081 IN_StartDemoPlayback(byte /*_1seg*/ *buffer,word bufsize)
\r
1083 DemoBuffer = buffer;
\r
1084 DemoMode = demo_Playback;
\r
1085 DemoSize = bufsize & ~1;
\r
1089 ///////////////////////////////////////////////////////////////////////////
\r
1091 // IN_StopDemo() - Turns off demo mode
\r
1093 ///////////////////////////////////////////////////////////////////////////
\r
1097 if ((DemoMode == demo_Record) && DemoOffset)
\r
1100 DemoMode = demo_Off;
\r
1103 ///////////////////////////////////////////////////////////////////////////
\r
1105 // IN_FreeDemoBuffer() - Frees the demo buffer, if it's been allocated
\r
1107 ///////////////////////////////////////////////////////////////////////////
\r
1109 IN_FreeDemoBuffer(void)
\r
1112 MM_FreePtr((memptr *)&DemoBuffer);
\r
1118 ///////////////////////////////////////////////////////////////////////////
\r
1120 // IN_GetScanName() - Returns a string containing the name of the
\r
1121 // specified scan code
\r
1123 ///////////////////////////////////////////////////////////////////////////
\r
1125 IN_GetScanName(ScanCode scan)
\r
1130 for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)
\r
1134 return(ScanNames[scan]);
\r
1139 ///////////////////////////////////////////////////////////////////////////
\r
1141 // IN_WaitForKey() - Waits for a scan code, then clears LastScan and
\r
1142 // returns the scan code
\r
1144 ///////////////////////////////////////////////////////////////////////////
\r
1146 IN_WaitForKey(void)
\r
1150 while (!(result = LastScan))
\r
1156 ///////////////////////////////////////////////////////////////////////////
\r
1158 // IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and
\r
1159 // returns the ASCII value
\r
1161 ///////////////////////////////////////////////////////////////////////////
\r
1163 IN_WaitForASCII(void)
\r
1167 while (!(result = LastASCII))
\r
1173 ///////////////////////////////////////////////////////////////////////////
\r
1175 // IN_AckBack() - Waits for either an ASCII keypress or a button press
\r
1177 ///////////////////////////////////////////////////////////////////////////
\r
1187 if (INL_GetMouseButtons())
\r
1189 while (INL_GetMouseButtons())
\r
1195 for (i = 0;i < MaxJoys;i++)
\r
1197 if (JoysPresent[i])
\r
1199 if (IN_GetJoyButtonsDB(i))
\r
1201 while (IN_GetJoyButtonsDB(i))
\r
1209 IN_ClearKey(LastScan);
\r
1210 LastScan = sc_None;
\r
1213 ///////////////////////////////////////////////////////////////////////////
\r
1215 // IN_Ack() - Clears user input & then calls IN_AckBack()
\r
1217 ///////////////////////////////////////////////////////////////////////////
\r
1223 IN_ClearKey(LastScan);
\r
1224 LastScan = sc_None;
\r
1227 while (INL_GetMouseButtons())
\r
1229 for (i = 0;i < MaxJoys;i++)
\r
1230 if (JoysPresent[i])
\r
1231 while (IN_GetJoyButtonsDB(i))
\r
1237 ///////////////////////////////////////////////////////////////////////////
\r
1239 // IN_IsUserInput() - Returns true if a key has been pressed or a button
\r
1242 ///////////////////////////////////////////////////////////////////////////
\r
1244 IN_IsUserInput(void)
\r
1249 result = LastScan;
\r
1252 if (INL_GetMouseButtons())
\r
1255 for (i = 0;i < MaxJoys;i++)
\r
1256 if (JoysPresent[i])
\r
1257 if (INL_GetJoyButtons(i))
\r
1263 ///////////////////////////////////////////////////////////////////////////
\r
1265 // IN_UserInput() - Waits for the specified delay time (in ticks) or the
\r
1266 // user pressing a key or a mouse button. If the clear flag is set, it
\r
1267 // then either clears the key or waits for the user to let the mouse
\r
1270 ///////////////////////////////////////////////////////////////////////////
\r
1272 IN_UserInput(dword delay,boolean clear)
\r
1276 lasttime = TimeCount;
\r
1279 if (IN_IsUserInput())
\r
1285 } while (TimeCount - lasttime < delay);
\r