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];
65 //inpu.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
68 =============================================================================
\r
72 =============================================================================
\r
75 #ifdef __cplusplus /* Function must be declared C style */
79 static struct instat {
82 ScanCode CurCode,LastCode;
85 static void (*INL_KeyHook)(void);
86 static void interrupt (*OldKeyVect)(void);
87 static char *ParmStringsIN[] = {"nojoys","nomouse",nil};
89 static byte far ASCIINames[] = // Unshifted ASCII for scan codes
\r
91 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
92 0 ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8 ,9 , // 0
\r
93 'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0 ,'a','s', // 1
\r
94 'd','f','g','h','j','k','l',';',39 ,'`',0 ,92 ,'z','x','c','v', // 2
\r
95 'b','n','m',',','.','/',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
96 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
97 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
98 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
99 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
101 far ShiftNames[] = // Shifted ASCII for scan codes
\r
103 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
104 0 ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8 ,9 , // 0
\r
105 'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0 ,'A','S', // 1
\r
106 'D','F','G','H','J','K','L',':',34 ,'~',0 ,'|','Z','X','C','V', // 2
\r
107 'B','N','M','<','>','?',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
108 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
109 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
110 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
111 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
113 far SpecialNames[] = // ASCII for 0xe0 prefixed codes
\r
115 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
116 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 0
\r
117 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,13 ,0 ,0 ,0 , // 1
\r
118 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 2
\r
119 0 ,0 ,0 ,0 ,0 ,'/',0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
120 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 4
\r
121 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
122 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
123 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
125 *ScanNames[] = // Scan code names with single chars
\r
127 "?","?","1","2","3","4","5","6","7","8","9","0","-","+","?","?",
\r
128 "Q","W","E","R","T","Y","U","I","O","P","[","]","|","?","A","S",
\r
129 "D","F","G","H","J","K","L",";","\"","?","?","?","Z","X","C","V",
\r
130 "B","N","M",",",".","/","?","?","?","?","?","?","?","?","?","?",
\r
131 "?","?","?","?","?","?","?","?","\xf","?","-","\x15","5","\x11","+","?",
\r
132 "\x13","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
133 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
134 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"
\r
135 }, // DEBUG - consolidate these
\r
136 far ExtScanCodes[] = // Scan codes with >1 char names
\r
138 1,0xe,0xf,0x1d,0x2a,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,
\r
139 0x3f,0x40,0x41,0x42,0x43,0x44,0x57,0x59,0x46,0x1c,0x36,
\r
140 0x37,0x38,0x47,0x49,0x4f,0x51,0x52,0x53,0x45,0x48,
\r
141 0x50,0x4b,0x4d,0x00
\r
143 *ExtScanNames[] = // Names corresponding to ExtScanCodes
\r
145 "Esc","BkSp","Tab","Ctrl","LShft","Space","CapsLk","F1","F2","F3","F4",
\r
146 "F5","F6","F7","F8","F9","F10","F11","F12","ScrlLk","Enter","RShft",
\r
147 "PrtSc","Alt","Home","PgUp","End","PgDn","Ins","Del","NumLk","Up",
\r
148 "Down","Left","Right",""
\r
151 static Direction DirTable[] = // Quick lookup for total direction
\r
156 dir_West, dir_None, dir_East,
\r
158 dir_South//,dir_SouthEast
\r
165 ///////////////////////////////////////////////////////////////////////////
167 // INL_KeyService() - Handles a keyboard interrupt (key up/down)
169 ///////////////////////////////////////////////////////////////////////////
173 static boolean special;
177 k = inp(0x60); // Get the scan code
179 // Tell the XT keyboard controller to clear the key
180 outp(0x61,(temp = inp(0x61)) | 0x80);
183 if (k == 0xe0) // Special key prefix
185 else if (k == 0xe1) // Handle Pause key
189 if (k & 0x80) // Break code
193 // DEBUG - handle special keys: ctl-alt-delete, print scrn
195 inpu.Keyboard[k] = false;
199 inst.LastCode = inst.CurCode;
200 inst.CurCode = inpu.LastScan = k;
201 inpu.Keyboard[k] = true;
207 if (k == sc_CapsLock)
209 inst.CapsLock ^= true;
210 // DEBUG - make caps lock light work
213 if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift]) // If shifted
216 if ((c >= 'A') && (c <= 'Z') && inst.CapsLock)
222 if ((c >= 'a') && (c <= 'z') && inst.CapsLock)
233 if (INL_KeyHook && !special)
236 printf("%c %x %u\n", c, k, inpu.Keyboard[k]);
246 int86(MouseInt,&CPURegs,&CPURegs);
249 ///////////////////////////////////////////////////////////////////////////
251 // INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
254 ///////////////////////////////////////////////////////////////////////////
256 INL_GetMouseDelta(int *x,int *y)
264 ///////////////////////////////////////////////////////////////////////////
266 // INL_GetMouseButtons() - Gets the status of the mouse buttons from the
269 ///////////////////////////////////////////////////////////////////////////
271 INL_GetMouseButtons(void)
277 buttons = CPURegs.x.bx;
281 ///////////////////////////////////////////////////////////////////////////
283 // IN_GetJoyAbs() - Reads the absolute position of the specified joystick
285 ///////////////////////////////////////////////////////////////////////////
287 IN_GetJoyAbs(word joy,word *xp,word *yp)
294 xs = joy? 2 : 0; // Find shift value for x axis
295 xb = 1 << xs; // Use shift value to get x bit mask
296 ys = joy? 3 : 1; // Do the same for y axis
299 // Read the absolute joystick values
302 pushf // Save some registers
305 cli // Make sure an interrupt doesn't screw the timings
310 out dx,al // Clear the resistors
312 mov ah,[xb] // Get masks into registers
315 xor si,si // Clear count registers
317 xor bh,bh // Clear high byte of bx for later
319 push bp // Don't mess up stack frame
323 in al,dx // Get bits indicating whether all are finished
325 dec bp // Check bounding register
326 jz done // We have a silly value - abort
328 mov bl,al // Duplicate the bits
329 and bl,ah // Mask off useless bits (in [xb])
330 add si,bx // Possibly increment count register
331 mov cl,bl // Save for testing later
338 jnz loo // If both bits were 0, drop out
343 mov cl,[xs] // Get the number of bits to shift
344 shr si,cl // and shift the count that many times
349 mov [x],si // Store the values into the variables
354 popf // Restore the registers
361 ///////////////////////////////////////////////////////////////////////////
363 // INL_GetJoyDelta() - Returns the relative movement of the specified
364 // joystick (from +/-127, scaled adaptively)
366 ///////////////////////////////////////////////////////////////////////////
368 INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)
372 dword TimeCount = *clockdw;
374 static dword lasttime;
376 IN_GetJoyAbs(joy,&x,&y);
377 def = inpu.JoyDefs + joy;
379 if (x < def->threshMinX)
381 if (x < def->joyMinX)
384 x = -(x - def->threshMinX);
387 *dx = (x > 127)? -127 : -x;
389 else if (x > def->threshMaxX)
391 if (x > def->joyMaxX)
394 x = x - def->threshMaxX;
397 *dx = (x > 127)? 127 : x;
402 if (y < def->threshMinY)
404 if (y < def->joyMinY)
407 y = -(y - def->threshMinY);
410 *dy = (y > 127)? -127 : -y;
412 else if (y > def->threshMaxY)
414 if (y > def->joyMaxY)
417 y = y - def->threshMaxY;
420 *dy = (y > 127)? 127 : y;
427 time = (TimeCount - lasttime) / 2;
436 lasttime = TimeCount;
439 ///////////////////////////////////////////////////////////////////////////
441 // INL_GetJoyButtons() - Returns the button status of the specified
444 ///////////////////////////////////////////////////////////////////////////
446 INL_GetJoyButtons(word joy)
448 register word result;
450 result = inp(0x201); // Get all the joystick buttons
451 result >>= joy? 6 : 4; // Shift into bits 0-1
452 result &= 3; // Mask off the useless bits
457 ///////////////////////////////////////////////////////////////////////////
459 // IN_GetJoyButtonsDB() - Returns the de-bounced button status of the
460 // specified joystick
462 ///////////////////////////////////////////////////////////////////////////
464 IN_GetJoyButtonsDB(word joy)
466 dword TimeCount = *clockdw;
468 word result1,result2;
472 result1 = INL_GetJoyButtons(joy);
473 lasttime = TimeCount;
474 while(TimeCount == lasttime)
475 result2 = INL_GetJoyButtons(joy);
476 } while(result1 != result2);
480 ///////////////////////////////////////////////////////////////////////////
482 // INL_StartKbd() - Sets up my keyboard stuff for use
484 ///////////////////////////////////////////////////////////////////////////
488 INL_KeyHook = 0; // Clear key hook
492 OldKeyVect = _dos_getvect(KeyInt);
493 _dos_setvect(KeyInt,INL_KeyService);
496 ///////////////////////////////////////////////////////////////////////////
498 // INL_ShutKbd() - Restores keyboard control to the BIOS
500 ///////////////////////////////////////////////////////////////////////////
504 pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags
506 _dos_setvect(KeyInt,OldKeyVect);
509 ///////////////////////////////////////////////////////////////////////////
511 // INL_StartMouse() - Detects and sets up the mouse
513 ///////////////////////////////////////////////////////////////////////////
518 if(_dos_getvect(MouseInt))
521 if(CPURegs.x.ax == 0xffff)
527 ///////////////////////////////////////////////////////////////////////////
529 // INL_ShutMouse() - Cleans up after the mouse
531 ///////////////////////////////////////////////////////////////////////////
538 // INL_SetJoyScale() - Sets up scaling values for the specified joystick
541 INL_SetJoyScale(word joy)
545 def = &(inpu.JoyDefs[joy]);
546 def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
547 def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
548 def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
549 def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);
552 ///////////////////////////////////////////////////////////////////////////
554 // IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
555 // to set up scaling values
557 ///////////////////////////////////////////////////////////////////////////
559 IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
564 def = &(inpu.JoyDefs[joy]);
570 def->threshMinX = ((r / 2) - d) + minx;
571 def->threshMaxX = ((r / 2) + d) + minx;
577 def->threshMinY = ((r / 2) - d) + miny;
578 def->threshMaxY = ((r / 2) + d) + miny;
580 INL_SetJoyScale(joy);
583 ///////////////////////////////////////////////////////////////////////////
585 // INL_StartJoy() - Detects & auto-configures the specified joystick
586 // The auto-config assumes the joystick is centered
588 ///////////////////////////////////////////////////////////////////////////
590 INL_StartJoy(word joy)
594 IN_GetJoyAbs(joy,&x,&y);
598 ((x == 0) || (x > MaxJoyValue - 10))
599 || ((y == 0) || (y > MaxJoyValue - 10))
604 IN_SetupJoy(joy,0,x * 2,0,y * 2);
609 ///////////////////////////////////////////////////////////////////////////
611 // INL_ShutJoy() - Cleans up the joystick stuff
613 ///////////////////////////////////////////////////////////////////////////
615 INL_ShutJoy(word joy)
617 inpu.JoysPresent[joy] = false;
622 ///////////////////////////////////////////////////////////////////////////
624 // IN_Startup() - Starts up the Input Mgr
626 ///////////////////////////////////////////////////////////////////////////
630 boolean checkjoys,checkmouse;
638 for (i = 1;i < __argc;i++)
640 switch (US_CheckParm(__argv[i],ParmStringsIN))
652 inpu.MousePresent = checkmouse? INL_StartMouse() : false;
654 for (i = 0;i < MaxJoys;i++)
655 inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
657 inst.IN_Started = true;
660 ///////////////////////////////////////////////////////////////////////////
662 // IN_Default() - Sets up default conditions for the Input Mgr
664 ///////////////////////////////////////////////////////////////////////////
666 IN_Default(boolean gotit,player_t *player,ControlType nt)
671 || ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0])
672 || ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1])
673 || ((nt == ctrl_Mouse) && !inpu.MousePresent)
674 || ((nt == ctrl_Joypad1) && !inpu.JoyPadPresent[0])
675 || ((nt == ctrl_Joypad2) && !inpu.JoyPadPresent[1])
678 IN_SetControlType(0,player,nt);
681 ///////////////////////////////////////////////////////////////////////////
683 // IN_Shutdown() - Shuts down the Input Mgr
685 ///////////////////////////////////////////////////////////////////////////
691 if (!inst.IN_Started)
695 for (i = 0;i < MaxJoys;i++)
699 inst.IN_Started = false;
702 ///////////////////////////////////////////////////////////////////////////
704 // IN_SetKeyHook() - Sets the routine that gets called by INL_KeyService()
705 // everytime a real make/break code gets hit
707 ///////////////////////////////////////////////////////////////////////////
709 IN_SetKeyHook(void (*hook)())
714 ///////////////////////////////////////////////////////////////////////////
716 // IN_ClearKeyDown() - Clears the keyboard array
718 ///////////////////////////////////////////////////////////////////////////
724 inpu.LastScan = sc_None;
725 inpu.LastASCII = key_None;
726 memset (inpu.Keyboard,0,sizeof(inpu.Keyboard));
729 ///////////////////////////////////////////////////////////////////////////
731 // INL_AdjustCursor() - Internal routine of common code from IN_ReadCursor()
733 ///////////////////////////////////////////////////////////////////////////
735 INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
737 if (buttons & (1 << 0))
738 info->button0 = true;
739 if (buttons & (1 << 1))
740 info->button1 = true;
746 ///////////////////////////////////////////////////////////////////////////
748 // IN_ReadCursor() - Reads the input devices and fills in the cursor info
751 ///////////////////////////////////////////////////////////////////////////
753 IN_ReadCursor(CursorInfo *info)
759 info->x = info->y = 0;
760 info->button0 = info->button1 = false;
762 if (inpu.MousePresent)
764 buttons = INL_GetMouseButtons();
765 INL_GetMouseDelta(&dx,&dy);
766 INL_AdjustCursor(info,buttons,dx,dy);
769 for (i = 0;i < MaxJoys;i++)
771 if (!inpu.JoysPresent[i])
774 buttons = INL_GetJoyButtons(i);
775 INL_GetJoyDelta(i,&dx,&dy,true);
778 INL_AdjustCursor(info,buttons,dx,dy);
782 ///////////////////////////////////////////////////////////////////////////
784 // IN_ReadControl() - Reads the device associated with the specified
785 // player and fills in the control info struct
787 ///////////////////////////////////////////////////////////////////////////
789 IN_ReadControl(int playnum,player_t *player)
797 register KeyboardDef *def;
800 mx = my = motion_None;
804 if (DemoMode == demo_Playback)
806 dbyte = DemoBuffer[DemoOffset + 1];
807 my = (dbyte & 3) - 1;
808 mx = ((dbyte >> 2) & 3) - 1;
809 buttons = (dbyte >> 4) & 3;
811 if (!(--DemoBuffer[DemoOffset]))
814 if (DemoOffset >= DemoSize)
815 DemoMode = demo_PlayDone;
820 else if (DemoMode == demo_PlayDone)
821 Quit("Demo playback exceeded");
825 switch (type = player[playnum].Controls)
829 def = &(inpu.KbdDefs[type - ctrl_Keyboard]);
831 /* if (Keyboard[def->upleft])
832 mx = motion_Left,my = motion_Up;
833 else if (Keyboard[def->upright])
834 mx = motion_Right,my = motion_Up;
835 else if (Keyboard[def->downleft])
836 mx = motion_Left,my = motion_Down;
837 else if (Keyboard[def->downright])
838 mx = motion_Right,my = motion_Down;*/
840 if (inpu.Keyboard[def->up])
842 else if (inpu.Keyboard[def->down])
845 if (inpu.Keyboard[def->left])
847 else if (inpu.Keyboard[def->right])
850 if (inpu.Keyboard[def->button0])
852 if (inpu.Keyboard[def->button1])
858 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);
859 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
863 INL_GetMouseDelta(&dx,&dy);
864 buttons = INL_GetMouseButtons();
878 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
879 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
887 player[playnum].info.x = dx;
888 player[playnum].info.xaxis = mx;
889 player[playnum].info.y = dy;
890 player[playnum].info.yaxis = my;
891 player[playnum].info.button0 = buttons & (1 << 0);
892 player[playnum].info.button1 = buttons & (1 << 1);
893 player[playnum].info.button2 = buttons & (1 << 2);
894 player[playnum].info.button3 = buttons & (1 << 3);
895 player[playnum].info.dir = DirTable[((my + 1) * 3) + (mx + 1)];
898 if (DemoMode == demo_Record)
900 // Pack the control info into a byte
901 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);
905 (DemoBuffer[DemoOffset + 1] == dbyte)
906 && (DemoBuffer[DemoOffset] < 255)
908 (DemoBuffer[DemoOffset])++;
911 if (DemoOffset || DemoBuffer[DemoOffset])
914 if (DemoOffset >= DemoSize)
915 Quit("Demo buffer overflow");
917 DemoBuffer[DemoOffset] = 1;
918 DemoBuffer[DemoOffset + 1] = dbyte;
924 ///////////////////////////////////////////////////////////////////////////
926 // IN_SetControlType() - Sets the control type to be used by the specified
929 ///////////////////////////////////////////////////////////////////////////
931 IN_SetControlType(word playnum,player_t *player,ControlType type)
933 // DEBUG - check that requested type is present?
934 player[playnum].Controls = type;
938 ///////////////////////////////////////////////////////////////////////////
940 // IN_StartDemoRecord() - Starts the demo recording, using a buffer the
941 // size passed. Returns if the buffer allocation was successful
943 ///////////////////////////////////////////////////////////////////////////
945 IN_StartDemoRecord(word bufsize)
950 MM_GetPtr((memptr *)&DemoBuffer,bufsize);
951 DemoMode = demo_Record;
952 DemoSize = bufsize & ~1;
954 DemoBuffer[0] = DemoBuffer[1] = 0;
959 ///////////////////////////////////////////////////////////////////////////
961 // IN_StartDemoPlayback() - Plays back the demo pointed to of the given size
963 ///////////////////////////////////////////////////////////////////////////
965 IN_StartDemoPlayback(byte /*__segment*/ *buffer,word bufsize)
968 DemoMode = demo_Playback;
969 DemoSize = bufsize & ~1;
973 ///////////////////////////////////////////////////////////////////////////
975 // IN_StopDemo() - Turns off demo mode
977 ///////////////////////////////////////////////////////////////////////////
981 if ((DemoMode == demo_Record) && DemoOffset)
987 ///////////////////////////////////////////////////////////////////////////
989 // IN_FreeDemoBuffer() - Frees the demo buffer, if it's been allocated
991 ///////////////////////////////////////////////////////////////////////////
993 IN_FreeDemoBuffer(void)
996 MM_FreePtr((memptr *)&DemoBuffer);
1001 ///////////////////////////////////////////////////////////////////////////
1003 // IN_GetScanName() - Returns a string containing the name of the
1004 // specified scan code
1006 ///////////////////////////////////////////////////////////////////////////
1008 IN_GetScanName(ScanCode scan)
1013 for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)
1017 return(ScanNames[scan]);
1020 ///////////////////////////////////////////////////////////////////////////
1022 // IN_WaitForKey() - Waits for a scan code, then clears LastScan and
1023 // returns the scan code
1025 ///////////////////////////////////////////////////////////////////////////
1031 while (!(result = inpu.LastScan))
1037 ///////////////////////////////////////////////////////////////////////////
1039 // IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and
1040 // returns the ASCII value
1042 ///////////////////////////////////////////////////////////////////////////
1048 while (!(result = inpu.LastASCII))
1050 inpu.LastASCII = '\0';
1054 ///////////////////////////////////////////////////////////////////////////
1056 // IN_AckBack() - Waits for either an ASCII keypress or a button press
1058 ///////////////////////////////////////////////////////////////////////////
1064 while (!inpu.LastScan)
1066 if (inpu.MousePresent)
1068 if (INL_GetMouseButtons())
1070 while (INL_GetMouseButtons())
1076 for (i = 0;i < MaxJoys;i++)
1078 if (inpu.JoysPresent[i])
1080 if (IN_GetJoyButtonsDB(i))
1082 while (IN_GetJoyButtonsDB(i))
1090 IN_ClearKey(inpu.LastScan);
1091 inpu.LastScan = sc_None;
1094 ///////////////////////////////////////////////////////////////////////////
1096 // IN_Ack() - Clears user input & then calls IN_AckBack()
1098 ///////////////////////////////////////////////////////////////////////////
1104 IN_ClearKey(inpu.LastScan);
1105 inpu.LastScan = sc_None;
1107 if (inpu.MousePresent)
1108 while (INL_GetMouseButtons())
1110 for (i = 0;i < MaxJoys;i++)
1111 if (inpu.JoysPresent[i])
1112 while (IN_GetJoyButtonsDB(i))
1118 ///////////////////////////////////////////////////////////////////////////
1120 // IN_IsUserInput() - Returns true if a key has been pressed or a button
1123 ///////////////////////////////////////////////////////////////////////////
1130 result = inpu.LastScan;
1132 if (inpu.MousePresent)
1133 if (INL_GetMouseButtons())
1136 for (i = 0;i < MaxJoys;i++)
1137 if (inpu.JoysPresent[i])
1138 if (INL_GetJoyButtons(i))
1144 ///////////////////////////////////////////////////////////////////////////
1146 // IN_UserInput() - Waits for the specified delay time (in ticks) or the
1147 // user pressing a key or a mouse button. If the clear flag is set, it
1148 // then either clears the key or waits for the user to let the mouse
1151 ///////////////////////////////////////////////////////////////////////////
1153 IN_UserInput(dword delay,boolean clear)
1155 dword TimeCount = *clockdw;
1158 lasttime = TimeCount;
1161 if (IN_IsUserInput())
1167 } while (TimeCount - lasttime < delay);
1171 boolean IN_KeyDown(byte code)
1173 return inpu.Keyboard[code];
1176 void IN_ClearKey(byte code)
1178 inpu.Keyboard[code] = false;
1179 if(code == inpu.LastScan)
1180 inpu.LastScan = sc_None;
1183 boolean IN_qb(byte kee)
1185 printf("%u\n", inpu.Keyboard[kee]);
1186 if(inpu.Keyboard[kee]==true) return 1;