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
23 // By Jason Blochowiak
24 // Open Watcom port by sparky4
28 // This module handles dealing with the various input devices
30 // Depends on: Memory Mgr (for demo recording), Sound Mgr (for timing stuff),
31 // User Mgr (for command line parms)
34 // LastScan - The keyboard scan code of the last key pressed
35 // LastASCII - The ASCII value of the last key pressed
36 // DEBUG - there are more globals
39 #include "src/lib/16_in.h"
42 =============================================================================
\r
46 =============================================================================
\r
50 boolean MousePresent;
\r
51 boolean JoysPresent[MaxJoys];
\r
52 boolean JoyPadPresent[MaxPads];
53 boolean Keyboard[NumCodes];
\r
58 KeyboardDef KbdDefs[MaxKbds];// = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
59 JoystickDef JoyDefs[MaxJoys];
60 JoypadDef JoypadDefs[MaxPads];
63 //inpu.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
66 =============================================================================
\r
70 =============================================================================
\r
73 #ifdef __cplusplus /* Function must be declared C style */
77 static struct instat {
80 ScanCode CurCode,LastCode;
83 static void (*INL_KeyHook)(void);
84 static void interrupt (*OldKeyVect)(void);
85 static char *ParmStringsIN[] = {"nojoys","nomouse",nil};
87 static byte far ASCIINames[] = // Unshifted ASCII for scan codes
\r
89 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
90 0 ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8 ,9 , // 0
\r
91 'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0 ,'a','s', // 1
\r
92 'd','f','g','h','j','k','l',';',39 ,'`',0 ,92 ,'z','x','c','v', // 2
\r
93 'b','n','m',',','.','/',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
94 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
95 '2','3','0',127,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
99 far ShiftNames[] = // Shifted ASCII for scan codes
\r
101 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
102 0 ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8 ,9 , // 0
\r
103 'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0 ,'A','S', // 1
\r
104 'D','F','G','H','J','K','L',':',34 ,'~',0 ,'|','Z','X','C','V', // 2
\r
105 'B','N','M','<','>','?',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
106 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
107 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
108 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
109 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
111 far SpecialNames[] = // ASCII for 0xe0 prefixed codes
\r
113 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
114 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 0
\r
115 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,13 ,0 ,0 ,0 , // 1
\r
116 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 2
\r
117 0 ,0 ,0 ,0 ,0 ,'/',0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
118 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 4
\r
119 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
120 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
121 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
123 *ScanNames[] = // Scan code names with single chars
\r
125 "?","?","1","2","3","4","5","6","7","8","9","0","-","+","?","?",
\r
126 "Q","W","E","R","T","Y","U","I","O","P","[","]","|","?","A","S",
\r
127 "D","F","G","H","J","K","L",";","\"","?","?","?","Z","X","C","V",
\r
128 "B","N","M",",",".","/","?","?","?","?","?","?","?","?","?","?",
\r
129 "?","?","?","?","?","?","?","?","\xf","?","-","\x15","5","\x11","+","?",
\r
130 "\x13","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
131 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
132 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"
\r
133 }, // DEBUG - consolidate these
\r
134 far ExtScanCodes[] = // Scan codes with >1 char names
\r
136 1,0xe,0xf,0x1d,0x2a,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,
\r
137 0x3f,0x40,0x41,0x42,0x43,0x44,0x57,0x59,0x46,0x1c,0x36,
\r
138 0x37,0x38,0x47,0x49,0x4f,0x51,0x52,0x53,0x45,0x48,
\r
139 0x50,0x4b,0x4d,0x00
\r
141 *ExtScanNames[] = // Names corresponding to ExtScanCodes
\r
143 "Esc","BkSp","Tab","Ctrl","LShft","Space","CapsLk","F1","F2","F3","F4",
\r
144 "F5","F6","F7","F8","F9","F10","F11","F12","ScrlLk","Enter","RShft",
\r
145 "PrtSc","Alt","Home","PgUp","End","PgDn","Ins","Del","NumLk","Up",
\r
146 "Down","Left","Right",""
\r
149 static Direction DirTable[] = // Quick lookup for total direction
\r
154 dir_West, dir_None, dir_East,
\r
156 dir_South//,dir_SouthEast
\r
163 ///////////////////////////////////////////////////////////////////////////
165 // INL_KeyService() - Handles a keyboard interrupt (key up/down)
167 ///////////////////////////////////////////////////////////////////////////
171 static boolean special;
175 k = inp(0x60); // Get the scan code
177 // Tell the XT keyboard controller to clear the key
178 outp(0x61,(temp = inp(0x61)) | 0x80);
181 if (k == 0xe0) // Special key prefix
183 else if (k == 0xe1) // Handle Pause key
187 if (k & 0x80) // Break code
191 // DEBUG - handle special keys: ctl-alt-delete, print scrn
193 inpu.Keyboard[k] = false;
197 inst.LastCode = inst.CurCode;
198 inst.CurCode = inpu.LastScan = k;
199 inpu.Keyboard[k] = true;
205 if (k == sc_CapsLock)
207 inst.CapsLock ^= true;
208 // DEBUG - make caps lock light work
211 if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift]) // If shifted
214 if ((c >= 'A') && (c <= 'Z') && inst.CapsLock)
220 if ((c >= 'a') && (c <= 'z') && inst.CapsLock)
231 if (INL_KeyHook && !special)
234 printf("%c %x %u\n", c, k, inpu.Keyboard[k]);
244 int86(MouseInt,&CPURegs,&CPURegs);
247 ///////////////////////////////////////////////////////////////////////////
249 // INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
252 ///////////////////////////////////////////////////////////////////////////
254 INL_GetMouseDelta(int *x,int *y)
262 ///////////////////////////////////////////////////////////////////////////
264 // INL_GetMouseButtons() - Gets the status of the mouse buttons from the
267 ///////////////////////////////////////////////////////////////////////////
269 INL_GetMouseButtons(void)
275 buttons = CPURegs.x.bx;
279 ///////////////////////////////////////////////////////////////////////////
281 // IN_GetJoyAbs() - Reads the absolute position of the specified joystick
283 ///////////////////////////////////////////////////////////////////////////
285 IN_GetJoyAbs(word joy,word *xp,word *yp)
292 xs = joy? 2 : 0; // Find shift value for x axis
293 xb = 1 << xs; // Use shift value to get x bit mask
294 ys = joy? 3 : 1; // Do the same for y axis
297 // Read the absolute joystick values
300 pushf // Save some registers
303 cli // Make sure an interrupt doesn't screw the timings
308 out dx,al // Clear the resistors
310 mov ah,[xb] // Get masks into registers
313 xor si,si // Clear count registers
315 xor bh,bh // Clear high byte of bx for later
317 push bp // Don't mess up stack frame
321 in al,dx // Get bits indicating whether all are finished
323 dec bp // Check bounding register
324 jz done // We have a silly value - abort
326 mov bl,al // Duplicate the bits
327 and bl,ah // Mask off useless bits (in [xb])
328 add si,bx // Possibly increment count register
329 mov cl,bl // Save for testing later
336 jnz loo // If both bits were 0, drop out
341 mov cl,[xs] // Get the number of bits to shift
342 shr si,cl // and shift the count that many times
347 mov [x],si // Store the values into the variables
352 popf // Restore the registers
359 ///////////////////////////////////////////////////////////////////////////
361 // INL_GetJoyDelta() - Returns the relative movement of the specified
362 // joystick (from +/-127, scaled adaptively)
364 ///////////////////////////////////////////////////////////////////////////
366 INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)
370 dword TimeCount = *clockdw;
372 static dword lasttime;
374 IN_GetJoyAbs(joy,&x,&y);
375 def = inpu.JoyDefs + joy;
377 if (x < def->threshMinX)
379 if (x < def->joyMinX)
382 x = -(x - def->threshMinX);
385 *dx = (x > 127)? -127 : -x;
387 else if (x > def->threshMaxX)
389 if (x > def->joyMaxX)
392 x = x - def->threshMaxX;
395 *dx = (x > 127)? 127 : x;
400 if (y < def->threshMinY)
402 if (y < def->joyMinY)
405 y = -(y - def->threshMinY);
408 *dy = (y > 127)? -127 : -y;
410 else if (y > def->threshMaxY)
412 if (y > def->joyMaxY)
415 y = y - def->threshMaxY;
418 *dy = (y > 127)? 127 : y;
425 time = (TimeCount - lasttime) / 2;
434 lasttime = TimeCount;
437 ///////////////////////////////////////////////////////////////////////////
439 // INL_GetJoyButtons() - Returns the button status of the specified
442 ///////////////////////////////////////////////////////////////////////////
444 INL_GetJoyButtons(word joy)
446 register word result;
448 result = inp(0x201); // Get all the joystick buttons
449 result >>= joy? 6 : 4; // Shift into bits 0-1
450 result &= 3; // Mask off the useless bits
455 ///////////////////////////////////////////////////////////////////////////
457 // IN_GetJoyButtonsDB() - Returns the de-bounced button status of the
458 // specified joystick
460 ///////////////////////////////////////////////////////////////////////////
462 IN_GetJoyButtonsDB(word joy)
464 dword TimeCount = *clockdw;
466 word result1,result2;
470 result1 = INL_GetJoyButtons(joy);
471 lasttime = TimeCount;
472 while(TimeCount == lasttime)
473 result2 = INL_GetJoyButtons(joy);
474 } while(result1 != result2);
478 ///////////////////////////////////////////////////////////////////////////
480 // INL_StartKbd() - Sets up my keyboard stuff for use
482 ///////////////////////////////////////////////////////////////////////////
486 INL_KeyHook = 0; // Clear key hook
490 OldKeyVect = _dos_getvect(KeyInt);
491 _dos_setvect(KeyInt,INL_KeyService);
494 ///////////////////////////////////////////////////////////////////////////
496 // INL_ShutKbd() - Restores keyboard control to the BIOS
498 ///////////////////////////////////////////////////////////////////////////
502 pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags
504 _dos_setvect(KeyInt,OldKeyVect);
507 ///////////////////////////////////////////////////////////////////////////
509 // INL_StartMouse() - Detects and sets up the mouse
511 ///////////////////////////////////////////////////////////////////////////
516 if(_dos_getvect(MouseInt))
519 if(CPURegs.x.ax == 0xffff)
525 ///////////////////////////////////////////////////////////////////////////
527 // INL_ShutMouse() - Cleans up after the mouse
529 ///////////////////////////////////////////////////////////////////////////
536 // INL_SetJoyScale() - Sets up scaling values for the specified joystick
539 INL_SetJoyScale(word joy)
543 def = &(inpu.JoyDefs[joy]);
544 def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
545 def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
546 def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
547 def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);
550 ///////////////////////////////////////////////////////////////////////////
552 // IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
553 // to set up scaling values
555 ///////////////////////////////////////////////////////////////////////////
557 IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
562 def = &(inpu.JoyDefs[joy]);
568 def->threshMinX = ((r / 2) - d) + minx;
569 def->threshMaxX = ((r / 2) + d) + minx;
575 def->threshMinY = ((r / 2) - d) + miny;
576 def->threshMaxY = ((r / 2) + d) + miny;
578 INL_SetJoyScale(joy);
581 ///////////////////////////////////////////////////////////////////////////
583 // INL_StartJoy() - Detects & auto-configures the specified joystick
584 // The auto-config assumes the joystick is centered
586 ///////////////////////////////////////////////////////////////////////////
588 INL_StartJoy(word joy)
592 IN_GetJoyAbs(joy,&x,&y);
596 ((x == 0) || (x > MaxJoyValue - 10))
597 || ((y == 0) || (y > MaxJoyValue - 10))
602 IN_SetupJoy(joy,0,x * 2,0,y * 2);
607 ///////////////////////////////////////////////////////////////////////////
609 // INL_ShutJoy() - Cleans up the joystick stuff
611 ///////////////////////////////////////////////////////////////////////////
613 INL_ShutJoy(word joy)
615 inpu.JoysPresent[joy] = false;
620 ///////////////////////////////////////////////////////////////////////////
622 // IN_Startup() - Starts up the Input Mgr
624 ///////////////////////////////////////////////////////////////////////////
628 boolean checkjoys,checkmouse;
636 for (i = 1;i < __argc;i++)
638 switch (US_CheckParm(__argv[i],ParmStringsIN))
650 inpu.MousePresent = checkmouse? INL_StartMouse() : false;
652 for (i = 0;i < MaxJoys;i++)
653 inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
655 inst.IN_Started = true;
658 ///////////////////////////////////////////////////////////////////////////
660 // IN_Default() - Sets up default conditions for the Input Mgr
662 ///////////////////////////////////////////////////////////////////////////
664 IN_Default(boolean gotit,player_t *player,ControlType nt)
669 || ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0])
670 || ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1])
671 || ((nt == ctrl_Mouse) && !inpu.MousePresent)
672 || ((nt == ctrl_Joypad1) && !inpu.JoyPadPresent[0])
673 || ((nt == ctrl_Joypad2) && !inpu.JoyPadPresent[1])
676 IN_SetControlType(0,player,nt);
679 ///////////////////////////////////////////////////////////////////////////
681 // IN_Shutdown() - Shuts down the Input Mgr
683 ///////////////////////////////////////////////////////////////////////////
689 if (!inst.IN_Started)
693 for (i = 0;i < MaxJoys;i++)
697 inst.IN_Started = false;
700 ///////////////////////////////////////////////////////////////////////////
702 // IN_SetKeyHook() - Sets the routine that gets called by INL_KeyService()
703 // everytime a real make/break code gets hit
705 ///////////////////////////////////////////////////////////////////////////
707 IN_SetKeyHook(void (*hook)())
712 ///////////////////////////////////////////////////////////////////////////
714 // IN_ClearKeyDown() - Clears the keyboard array
716 ///////////////////////////////////////////////////////////////////////////
722 inpu.LastScan = sc_None;
723 inpu.LastASCII = key_None;
724 memset (inpu.Keyboard,0,sizeof(inpu.Keyboard));
727 ///////////////////////////////////////////////////////////////////////////
729 // INL_AdjustCursor() - Internal routine of common code from IN_ReadCursor()
731 ///////////////////////////////////////////////////////////////////////////
733 INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
735 if (buttons & (1 << 0))
736 info->button0 = true;
737 if (buttons & (1 << 1))
738 info->button1 = true;
744 ///////////////////////////////////////////////////////////////////////////
746 // IN_ReadCursor() - Reads the input devices and fills in the cursor info
749 ///////////////////////////////////////////////////////////////////////////
751 IN_ReadCursor(CursorInfo *info)
757 info->x = info->y = 0;
758 info->button0 = info->button1 = false;
760 if (inpu.MousePresent)
762 buttons = INL_GetMouseButtons();
763 INL_GetMouseDelta(&dx,&dy);
764 INL_AdjustCursor(info,buttons,dx,dy);
767 for (i = 0;i < MaxJoys;i++)
769 if (!inpu.JoysPresent[i])
772 buttons = INL_GetJoyButtons(i);
773 INL_GetJoyDelta(i,&dx,&dy,true);
776 INL_AdjustCursor(info,buttons,dx,dy);
780 ///////////////////////////////////////////////////////////////////////////
782 // IN_ReadControl() - Reads the device associated with the specified
783 // player and fills in the control info struct
785 ///////////////////////////////////////////////////////////////////////////
787 IN_ReadControl(int playnum,player_t *player)
795 register KeyboardDef *def;
798 mx = my = motion_None;
802 if (DemoMode == demo_Playback)
804 dbyte = DemoBuffer[DemoOffset + 1];
805 my = (dbyte & 3) - 1;
806 mx = ((dbyte >> 2) & 3) - 1;
807 buttons = (dbyte >> 4) & 3;
809 if (!(--DemoBuffer[DemoOffset]))
812 if (DemoOffset >= DemoSize)
813 DemoMode = demo_PlayDone;
818 else if (DemoMode == demo_PlayDone)
819 Quit("Demo playback exceeded");
823 switch (type = player[playnum].Controls)
827 def = &(inpu.KbdDefs[type - ctrl_Keyboard]);
829 /* if (Keyboard[def->upleft])
830 mx = motion_Left,my = motion_Up;
831 else if (Keyboard[def->upright])
832 mx = motion_Right,my = motion_Up;
833 else if (Keyboard[def->downleft])
834 mx = motion_Left,my = motion_Down;
835 else if (Keyboard[def->downright])
836 mx = motion_Right,my = motion_Down;*/
838 if (inpu.Keyboard[def->up])
840 else if (inpu.Keyboard[def->down])
843 if (inpu.Keyboard[def->left])
845 else if (inpu.Keyboard[def->right])
848 if (inpu.Keyboard[def->button0])
850 if (inpu.Keyboard[def->button1])
856 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);
857 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
861 INL_GetMouseDelta(&dx,&dy);
862 buttons = INL_GetMouseButtons();
876 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
877 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
885 player[playnum].info.x = dx;
886 player[playnum].info.xaxis = mx;
887 player[playnum].info.y = dy;
888 player[playnum].info.yaxis = my;
889 player[playnum].info.button0 = buttons & (1 << 0);
890 player[playnum].info.button1 = buttons & (1 << 1);
891 player[playnum].info.button2 = buttons & (1 << 2);
892 player[playnum].info.button3 = buttons & (1 << 3);
893 player[playnum].info.dir = DirTable[((my + 1) * 3) + (mx + 1)];
896 if (DemoMode == demo_Record)
898 // Pack the control info into a byte
899 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);
903 (DemoBuffer[DemoOffset + 1] == dbyte)
904 && (DemoBuffer[DemoOffset] < 255)
906 (DemoBuffer[DemoOffset])++;
909 if (DemoOffset || DemoBuffer[DemoOffset])
912 if (DemoOffset >= DemoSize)
913 Quit("Demo buffer overflow");
915 DemoBuffer[DemoOffset] = 1;
916 DemoBuffer[DemoOffset + 1] = dbyte;
922 ///////////////////////////////////////////////////////////////////////////
924 // IN_SetControlType() - Sets the control type to be used by the specified
927 ///////////////////////////////////////////////////////////////////////////
929 IN_SetControlType(word playnum,player_t *player,ControlType type)
931 // DEBUG - check that requested type is present?
932 player[playnum].Controls = type;
936 ///////////////////////////////////////////////////////////////////////////
938 // IN_StartDemoRecord() - Starts the demo recording, using a buffer the
939 // size passed. Returns if the buffer allocation was successful
941 ///////////////////////////////////////////////////////////////////////////
943 IN_StartDemoRecord(word bufsize)
948 MM_GetPtr((memptr *)&DemoBuffer,bufsize);
949 DemoMode = demo_Record;
950 DemoSize = bufsize & ~1;
952 DemoBuffer[0] = DemoBuffer[1] = 0;
957 ///////////////////////////////////////////////////////////////////////////
959 // IN_StartDemoPlayback() - Plays back the demo pointed to of the given size
961 ///////////////////////////////////////////////////////////////////////////
963 IN_StartDemoPlayback(byte /*__segment*/ *buffer,word bufsize)
966 DemoMode = demo_Playback;
967 DemoSize = bufsize & ~1;
971 ///////////////////////////////////////////////////////////////////////////
973 // IN_StopDemo() - Turns off demo mode
975 ///////////////////////////////////////////////////////////////////////////
979 if ((DemoMode == demo_Record) && DemoOffset)
985 ///////////////////////////////////////////////////////////////////////////
987 // IN_FreeDemoBuffer() - Frees the demo buffer, if it's been allocated
989 ///////////////////////////////////////////////////////////////////////////
991 IN_FreeDemoBuffer(void)
994 MM_FreePtr((memptr *)&DemoBuffer);
999 ///////////////////////////////////////////////////////////////////////////
1001 // IN_GetScanName() - Returns a string containing the name of the
1002 // specified scan code
1004 ///////////////////////////////////////////////////////////////////////////
1006 IN_GetScanName(ScanCode scan)
1011 for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)
1015 return(ScanNames[scan]);
1018 ///////////////////////////////////////////////////////////////////////////
1020 // IN_WaitForKey() - Waits for a scan code, then clears LastScan and
1021 // returns the scan code
1023 ///////////////////////////////////////////////////////////////////////////
1029 while (!(result = inpu.LastScan))
1035 ///////////////////////////////////////////////////////////////////////////
1037 // IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and
1038 // returns the ASCII value
1040 ///////////////////////////////////////////////////////////////////////////
1046 while (!(result = inpu.LastASCII))
1048 inpu.LastASCII = '\0';
1052 ///////////////////////////////////////////////////////////////////////////
1054 // IN_AckBack() - Waits for either an ASCII keypress or a button press
1056 ///////////////////////////////////////////////////////////////////////////
1062 while (!inpu.LastScan)
1064 if (inpu.MousePresent)
1066 if (INL_GetMouseButtons())
1068 while (INL_GetMouseButtons())
1074 for (i = 0;i < MaxJoys;i++)
1076 if (inpu.JoysPresent[i])
1078 if (IN_GetJoyButtonsDB(i))
1080 while (IN_GetJoyButtonsDB(i))
1088 IN_ClearKey(inpu.LastScan);
1089 inpu.LastScan = sc_None;
1092 ///////////////////////////////////////////////////////////////////////////
1094 // IN_Ack() - Clears user input & then calls IN_AckBack()
1096 ///////////////////////////////////////////////////////////////////////////
1102 IN_ClearKey(inpu.LastScan);
1103 inpu.LastScan = sc_None;
1105 if (inpu.MousePresent)
1106 while (INL_GetMouseButtons())
1108 for (i = 0;i < MaxJoys;i++)
1109 if (inpu.JoysPresent[i])
1110 while (IN_GetJoyButtonsDB(i))
1116 ///////////////////////////////////////////////////////////////////////////
1118 // IN_IsUserInput() - Returns true if a key has been pressed or a button
1121 ///////////////////////////////////////////////////////////////////////////
1128 result = inpu.LastScan;
1130 if (inpu.MousePresent)
1131 if (INL_GetMouseButtons())
1134 for (i = 0;i < MaxJoys;i++)
1135 if (inpu.JoysPresent[i])
1136 if (INL_GetJoyButtons(i))
1142 ///////////////////////////////////////////////////////////////////////////
1144 // IN_UserInput() - Waits for the specified delay time (in ticks) or the
1145 // user pressing a key or a mouse button. If the clear flag is set, it
1146 // then either clears the key or waits for the user to let the mouse
1149 ///////////////////////////////////////////////////////////////////////////
1151 IN_UserInput(dword delay,boolean clear)
1153 dword TimeCount = *clockdw;
1156 lasttime = TimeCount;
1159 if (IN_IsUserInput())
1165 } while (TimeCount - lasttime < delay);
1169 boolean IN_KeyDown(byte code)
1171 return inpu.Keyboard[code];
1174 void IN_ClearKey(byte code)
1176 inpu.Keyboard[code] = false;
1177 if(code == inpu.LastScan)
1178 inpu.LastScan = sc_None;
1181 boolean IN_qb(byte kee)
1183 printf("%u\n", inpu.Keyboard[kee]);
1184 if(inpu.Keyboard[kee]==true) return 1;