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];
59 JoystickDef JoyDefs[MaxJoys];
60 JoypadDef JoypadDefs[MaxPads];
63 //extern inconfig inpu;
64 //inpu.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
67 =============================================================================
\r
71 =============================================================================
\r
74 #ifdef __cplusplus /* Function must be declared C style */
78 static struct instat {
81 ScanCode CurCode,LastCode;
84 static void (*INL_KeyHook)(void);
85 static void interrupt (*OldKeyVect)(void);
86 static char *ParmStringsIN[] = {"nojoys","nomouse",nil};
88 static byte far ASCIINames[] = // Unshifted ASCII for scan codes
\r
90 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
91 0 ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8 ,9 , // 0
\r
92 'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0 ,'a','s', // 1
\r
93 'd','f','g','h','j','k','l',';',39 ,'`',0 ,92 ,'z','x','c','v', // 2
\r
94 'b','n','m',',','.','/',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
95 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
96 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
97 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
98 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
100 far ShiftNames[] = // Shifted ASCII for scan codes
\r
102 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
103 0 ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8 ,9 , // 0
\r
104 'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0 ,'A','S', // 1
\r
105 'D','F','G','H','J','K','L',':',34 ,'~',0 ,'|','Z','X','C','V', // 2
\r
106 'B','N','M','<','>','?',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
107 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
108 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
109 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
110 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
112 far SpecialNames[] = // ASCII for 0xe0 prefixed codes
\r
114 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
115 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 0
\r
116 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,13 ,0 ,0 ,0 , // 1
\r
117 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 2
\r
118 0 ,0 ,0 ,0 ,0 ,'/',0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
119 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 4
\r
120 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
121 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
122 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
124 *ScanNames[] = // Scan code names with single chars
\r
126 "?","?","1","2","3","4","5","6","7","8","9","0","-","+","?","?",
\r
127 "Q","W","E","R","T","Y","U","I","O","P","[","]","|","?","A","S",
\r
128 "D","F","G","H","J","K","L",";","\"","?","?","?","Z","X","C","V",
\r
129 "B","N","M",",",".","/","?","?","?","?","?","?","?","?","?","?",
\r
130 "?","?","?","?","?","?","?","?","\xf","?","-","\x15","5","\x11","+","?",
\r
131 "\x13","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
132 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
133 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"
\r
134 }, // DEBUG - consolidate these
\r
135 far ExtScanCodes[] = // Scan codes with >1 char names
\r
137 1,0xe,0xf,0x1d,0x2a,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,
\r
138 0x3f,0x40,0x41,0x42,0x43,0x44,0x57,0x59,0x46,0x1c,0x36,
\r
139 0x37,0x38,0x47,0x49,0x4f,0x51,0x52,0x53,0x45,0x48,
\r
140 0x50,0x4b,0x4d,0x00
\r
142 *ExtScanNames[] = // Names corresponding to ExtScanCodes
\r
144 "Esc","BkSp","Tab","Ctrl","LShft","Space","CapsLk","F1","F2","F3","F4",
\r
145 "F5","F6","F7","F8","F9","F10","F11","F12","ScrlLk","Enter","RShft",
\r
146 "PrtSc","Alt","Home","PgUp","End","PgDn","Ins","Del","NumLk","Up",
\r
147 "Down","Left","Right",""
\r
150 static Direction DirTable[] = // Quick lookup for total direction
\r
155 dir_West, dir_None, dir_East,
\r
157 dir_South//,dir_SouthEast
\r
164 ///////////////////////////////////////////////////////////////////////////
166 // INL_KeyService() - Handles a keyboard interrupt (key up/down)
168 ///////////////////////////////////////////////////////////////////////////
172 static boolean special;
176 k = inp(0x60); // Get the scan code
178 // Tell the XT keyboard controller to clear the key
179 outp(0x61,(temp = inp(0x61)) | 0x80);
182 if (k == 0xe0) // Special key prefix
184 else if (k == 0xe1) // Handle Pause key
188 if (k & 0x80) // Break code
192 // DEBUG - handle special keys: ctl-alt-delete, print scrn
194 inpu.Keyboard[k] = false;
198 inst.LastCode = inst.CurCode;
199 inst.CurCode = inpu.LastScan = k;
200 inpu.Keyboard[k] = true;
206 if (k == sc_CapsLock)
208 inst.CapsLock ^= true;
209 // DEBUG - make caps lock light work
212 if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift]) // If shifted
215 if ((c >= 'A') && (c <= 'Z') && inst.CapsLock)
221 if ((c >= 'a') && (c <= 'z') && inst.CapsLock)
232 if (INL_KeyHook && !special)
235 printf("%c %x %u\n", c, k, inpu.Keyboard[k]);
245 int86(MouseInt,&CPURegs,&CPURegs);
248 ///////////////////////////////////////////////////////////////////////////
250 // INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
253 ///////////////////////////////////////////////////////////////////////////
255 INL_GetMouseDelta(int *x,int *y)
263 ///////////////////////////////////////////////////////////////////////////
265 // INL_GetMouseButtons() - Gets the status of the mouse buttons from the
268 ///////////////////////////////////////////////////////////////////////////
270 INL_GetMouseButtons(void)
276 buttons = CPURegs.x.bx;
280 ///////////////////////////////////////////////////////////////////////////
282 // IN_GetJoyAbs() - Reads the absolute position of the specified joystick
284 ///////////////////////////////////////////////////////////////////////////
286 IN_GetJoyAbs(word joy,word *xp,word *yp)
293 xs = joy? 2 : 0; // Find shift value for x axis
294 xb = 1 << xs; // Use shift value to get x bit mask
295 ys = joy? 3 : 1; // Do the same for y axis
298 // Read the absolute joystick values
301 pushf // Save some registers
304 cli // Make sure an interrupt doesn't screw the timings
309 out dx,al // Clear the resistors
311 mov ah,[xb] // Get masks into registers
314 xor si,si // Clear count registers
316 xor bh,bh // Clear high byte of bx for later
318 push bp // Don't mess up stack frame
322 in al,dx // Get bits indicating whether all are finished
324 dec bp // Check bounding register
325 jz done // We have a silly value - abort
327 mov bl,al // Duplicate the bits
328 and bl,ah // Mask off useless bits (in [xb])
329 add si,bx // Possibly increment count register
330 mov cl,bl // Save for testing later
337 jnz loo // If both bits were 0, drop out
342 mov cl,[xs] // Get the number of bits to shift
343 shr si,cl // and shift the count that many times
348 mov [x],si // Store the values into the variables
353 popf // Restore the registers
360 ///////////////////////////////////////////////////////////////////////////
362 // INL_GetJoyDelta() - Returns the relative movement of the specified
363 // joystick (from +/-127, scaled adaptively)
365 ///////////////////////////////////////////////////////////////////////////
367 INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)
371 dword TimeCount = *clockdw;
373 static dword lasttime;
375 IN_GetJoyAbs(joy,&x,&y);
376 def = inpu.JoyDefs + joy;
378 if (x < def->threshMinX)
380 if (x < def->joyMinX)
383 x = -(x - def->threshMinX);
386 *dx = (x > 127)? -127 : -x;
388 else if (x > def->threshMaxX)
390 if (x > def->joyMaxX)
393 x = x - def->threshMaxX;
396 *dx = (x > 127)? 127 : x;
401 if (y < def->threshMinY)
403 if (y < def->joyMinY)
406 y = -(y - def->threshMinY);
409 *dy = (y > 127)? -127 : -y;
411 else if (y > def->threshMaxY)
413 if (y > def->joyMaxY)
416 y = y - def->threshMaxY;
419 *dy = (y > 127)? 127 : y;
426 time = (TimeCount - lasttime) / 2;
435 lasttime = TimeCount;
438 ///////////////////////////////////////////////////////////////////////////
440 // INL_GetJoyButtons() - Returns the button status of the specified
443 ///////////////////////////////////////////////////////////////////////////
445 INL_GetJoyButtons(word joy)
447 register word result;
449 result = inp(0x201); // Get all the joystick buttons
450 result >>= joy? 6 : 4; // Shift into bits 0-1
451 result &= 3; // Mask off the useless bits
456 ///////////////////////////////////////////////////////////////////////////
458 // IN_GetJoyButtonsDB() - Returns the de-bounced button status of the
459 // specified joystick
461 ///////////////////////////////////////////////////////////////////////////
463 IN_GetJoyButtonsDB(word joy)
465 dword TimeCount = *clockdw;
467 word result1,result2;
471 result1 = INL_GetJoyButtons(joy);
472 lasttime = TimeCount;
473 while(TimeCount == lasttime)
474 result2 = INL_GetJoyButtons(joy);
475 } while(result1 != result2);
479 ///////////////////////////////////////////////////////////////////////////
481 // INL_StartKbd() - Sets up my keyboard stuff for use
483 ///////////////////////////////////////////////////////////////////////////
487 INL_KeyHook = 0; // Clear key hook
491 OldKeyVect = _dos_getvect(KeyInt);
492 _dos_setvect(KeyInt,INL_KeyService);
495 ///////////////////////////////////////////////////////////////////////////
497 // INL_ShutKbd() - Restores keyboard control to the BIOS
499 ///////////////////////////////////////////////////////////////////////////
503 pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags
505 _dos_setvect(KeyInt,OldKeyVect);
508 ///////////////////////////////////////////////////////////////////////////
510 // INL_StartMouse() - Detects and sets up the mouse
512 ///////////////////////////////////////////////////////////////////////////
517 if(_dos_getvect(MouseInt))
520 if(CPURegs.x.ax == 0xffff)
526 ///////////////////////////////////////////////////////////////////////////
528 // INL_ShutMouse() - Cleans up after the mouse
530 ///////////////////////////////////////////////////////////////////////////
537 // INL_SetJoyScale() - Sets up scaling values for the specified joystick
540 INL_SetJoyScale(word joy)
544 def = &(inpu.JoyDefs[joy]);
545 def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
546 def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
547 def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
548 def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);
551 ///////////////////////////////////////////////////////////////////////////
553 // IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
554 // to set up scaling values
556 ///////////////////////////////////////////////////////////////////////////
558 IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
563 def = &(inpu.JoyDefs[joy]);
569 def->threshMinX = ((r / 2) - d) + minx;
570 def->threshMaxX = ((r / 2) + d) + minx;
576 def->threshMinY = ((r / 2) - d) + miny;
577 def->threshMaxY = ((r / 2) + d) + miny;
579 INL_SetJoyScale(joy);
582 ///////////////////////////////////////////////////////////////////////////
584 // INL_StartJoy() - Detects & auto-configures the specified joystick
585 // The auto-config assumes the joystick is centered
587 ///////////////////////////////////////////////////////////////////////////
589 INL_StartJoy(word joy)
593 IN_GetJoyAbs(joy,&x,&y);
597 ((x == 0) || (x > MaxJoyValue - 10))
598 || ((y == 0) || (y > MaxJoyValue - 10))
603 IN_SetupJoy(joy,0,x * 2,0,y * 2);
608 ///////////////////////////////////////////////////////////////////////////
610 // INL_ShutJoy() - Cleans up the joystick stuff
612 ///////////////////////////////////////////////////////////////////////////
614 INL_ShutJoy(word joy)
616 inpu.JoysPresent[joy] = false;
621 ///////////////////////////////////////////////////////////////////////////
623 // IN_Startup() - Starts up the Input Mgr
625 ///////////////////////////////////////////////////////////////////////////
629 boolean checkjoys,checkmouse;
637 for (i = 1;i < __argc;i++)
639 switch (US_CheckParm(__argv[i],ParmStringsIN))
651 inpu.MousePresent = checkmouse? INL_StartMouse() : false;
653 for (i = 0;i < MaxJoys;i++)
654 inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
656 inst.IN_Started = true;
659 ///////////////////////////////////////////////////////////////////////////
661 // IN_Default() - Sets up default conditions for the Input Mgr
663 ///////////////////////////////////////////////////////////////////////////
665 IN_Default(boolean gotit,player_t *player,ControlType nt)
670 || ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0])
671 || ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1])
672 || ((nt == ctrl_Mouse) && !inpu.MousePresent)
673 || ((nt == ctrl_Joypad1) && !inpu.JoyPadPresent[0])
674 || ((nt == ctrl_Joypad2) && !inpu.JoyPadPresent[1])
677 inpu.KbdDefs[0].button0 = 0x1d;
678 inpu.KbdDefs[0].button1 = 0x38;
679 //in.KbdDefs[0].upleft = 0x47;
680 inpu.KbdDefs[0].up = 0x48;
681 //in.KbdDefs[0].upright = 0x49;
682 inpu.KbdDefs[0].left = 0x4b;
683 inpu.KbdDefs[0].right = 0x4d;
684 //in.KbdDefs[0].downleft = 0x4f;
685 inpu.KbdDefs[0].down = 0x50;
686 //in.KbdDefs[0].downright = 0x51;
687 IN_SetControlType(0,player,nt);
690 ///////////////////////////////////////////////////////////////////////////
692 // IN_Shutdown() - Shuts down the Input Mgr
694 ///////////////////////////////////////////////////////////////////////////
700 if (!inst.IN_Started)
704 for (i = 0;i < MaxJoys;i++)
708 inst.IN_Started = false;
711 ///////////////////////////////////////////////////////////////////////////
713 // IN_SetKeyHook() - Sets the routine that gets called by INL_KeyService()
714 // everytime a real make/break code gets hit
716 ///////////////////////////////////////////////////////////////////////////
718 IN_SetKeyHook(void (*hook)())
723 ///////////////////////////////////////////////////////////////////////////
725 // IN_ClearKeyDown() - Clears the keyboard array
727 ///////////////////////////////////////////////////////////////////////////
733 inpu.LastScan = sc_None;
734 inpu.LastASCII = key_None;
735 memset (inpu.Keyboard,0,sizeof(inpu.Keyboard));
738 ///////////////////////////////////////////////////////////////////////////
740 // INL_AdjustCursor() - Internal routine of common code from IN_ReadCursor()
742 ///////////////////////////////////////////////////////////////////////////
744 INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
746 if (buttons & (1 << 0))
747 info->button0 = true;
748 if (buttons & (1 << 1))
749 info->button1 = true;
755 ///////////////////////////////////////////////////////////////////////////
757 // IN_ReadCursor() - Reads the input devices and fills in the cursor info
760 ///////////////////////////////////////////////////////////////////////////
762 IN_ReadCursor(CursorInfo *info)
768 info->x = info->y = 0;
769 info->button0 = info->button1 = false;
771 if (inpu.MousePresent)
773 buttons = INL_GetMouseButtons();
774 INL_GetMouseDelta(&dx,&dy);
775 INL_AdjustCursor(info,buttons,dx,dy);
778 for (i = 0;i < MaxJoys;i++)
780 if (!inpu.JoysPresent[i])
783 buttons = INL_GetJoyButtons(i);
784 INL_GetJoyDelta(i,&dx,&dy,true);
787 INL_AdjustCursor(info,buttons,dx,dy);
791 ///////////////////////////////////////////////////////////////////////////
793 // IN_ReadControl() - Reads the device associated with the specified
794 // player and fills in the control info struct
796 ///////////////////////////////////////////////////////////////////////////
798 IN_ReadControl(int playnum,player_t *player)
806 register KeyboardDef *def;
809 mx = my = motion_None;
813 if (DemoMode == demo_Playback)
815 dbyte = DemoBuffer[DemoOffset + 1];
816 my = (dbyte & 3) - 1;
817 mx = ((dbyte >> 2) & 3) - 1;
818 buttons = (dbyte >> 4) & 3;
820 if (!(--DemoBuffer[DemoOffset]))
823 if (DemoOffset >= DemoSize)
824 DemoMode = demo_PlayDone;
829 else if (DemoMode == demo_PlayDone)
830 Quit("Demo playback exceeded");
834 switch (type = player[playnum].Controls)
838 def = &(inpu.KbdDefs[type - ctrl_Keyboard]);
840 /* if (Keyboard[def->upleft])
841 mx = motion_Left,my = motion_Up;
842 else if (Keyboard[def->upright])
843 mx = motion_Right,my = motion_Up;
844 else if (Keyboard[def->downleft])
845 mx = motion_Left,my = motion_Down;
846 else if (Keyboard[def->downright])
847 mx = motion_Right,my = motion_Down;*/
849 if (inpu.Keyboard[def->up])
851 else if (inpu.Keyboard[def->down])
854 if (inpu.Keyboard[def->left])
856 else if (inpu.Keyboard[def->right])
859 if (inpu.Keyboard[def->button0])
861 if (inpu.Keyboard[def->button1])
867 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);
868 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
872 INL_GetMouseDelta(&dx,&dy);
873 buttons = INL_GetMouseButtons();
887 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
888 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
896 player[playnum].info.x = dx;
897 player[playnum].info.xaxis = mx;
898 player[playnum].info.y = dy;
899 player[playnum].info.yaxis = my;
900 player[playnum].info.button0 = buttons & (1 << 0);
901 player[playnum].info.button1 = buttons & (1 << 1);
902 player[playnum].info.button2 = buttons & (1 << 2);
903 player[playnum].info.button3 = buttons & (1 << 3);
904 player[playnum].info.dir = DirTable[((my + 1) * 3) + (mx + 1)];
907 if (DemoMode == demo_Record)
909 // Pack the control info into a byte
910 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);
914 (DemoBuffer[DemoOffset + 1] == dbyte)
915 && (DemoBuffer[DemoOffset] < 255)
917 (DemoBuffer[DemoOffset])++;
920 if (DemoOffset || DemoBuffer[DemoOffset])
923 if (DemoOffset >= DemoSize)
924 Quit("Demo buffer overflow");
926 DemoBuffer[DemoOffset] = 1;
927 DemoBuffer[DemoOffset + 1] = dbyte;
933 ///////////////////////////////////////////////////////////////////////////
935 // IN_SetControlType() - Sets the control type to be used by the specified
938 ///////////////////////////////////////////////////////////////////////////
940 IN_SetControlType(word playnum,player_t *player,ControlType type)
942 // DEBUG - check that requested type is present?
943 player[playnum].Controls = type;
947 ///////////////////////////////////////////////////////////////////////////
949 // IN_StartDemoRecord() - Starts the demo recording, using a buffer the
950 // size passed. Returns if the buffer allocation was successful
952 ///////////////////////////////////////////////////////////////////////////
954 IN_StartDemoRecord(word bufsize)
959 MM_GetPtr((memptr *)&DemoBuffer,bufsize);
960 DemoMode = demo_Record;
961 DemoSize = bufsize & ~1;
963 DemoBuffer[0] = DemoBuffer[1] = 0;
968 ///////////////////////////////////////////////////////////////////////////
970 // IN_StartDemoPlayback() - Plays back the demo pointed to of the given size
972 ///////////////////////////////////////////////////////////////////////////
974 IN_StartDemoPlayback(byte /*__segment*/ *buffer,word bufsize)
977 DemoMode = demo_Playback;
978 DemoSize = bufsize & ~1;
982 ///////////////////////////////////////////////////////////////////////////
984 // IN_StopDemo() - Turns off demo mode
986 ///////////////////////////////////////////////////////////////////////////
990 if ((DemoMode == demo_Record) && DemoOffset)
996 ///////////////////////////////////////////////////////////////////////////
998 // IN_FreeDemoBuffer() - Frees the demo buffer, if it's been allocated
1000 ///////////////////////////////////////////////////////////////////////////
1002 IN_FreeDemoBuffer(void)
1005 MM_FreePtr((memptr *)&DemoBuffer);
1010 ///////////////////////////////////////////////////////////////////////////
1012 // IN_GetScanName() - Returns a string containing the name of the
1013 // specified scan code
1015 ///////////////////////////////////////////////////////////////////////////
1017 IN_GetScanName(ScanCode scan)
1022 for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)
1026 return(ScanNames[scan]);
1029 ///////////////////////////////////////////////////////////////////////////
1031 // IN_WaitForKey() - Waits for a scan code, then clears LastScan and
1032 // returns the scan code
1034 ///////////////////////////////////////////////////////////////////////////
1040 while (!(result = inpu.LastScan))
1046 ///////////////////////////////////////////////////////////////////////////
1048 // IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and
1049 // returns the ASCII value
1051 ///////////////////////////////////////////////////////////////////////////
1057 while (!(result = inpu.LastASCII))
1059 inpu.LastASCII = '\0';
1063 ///////////////////////////////////////////////////////////////////////////
1065 // IN_AckBack() - Waits for either an ASCII keypress or a button press
1067 ///////////////////////////////////////////////////////////////////////////
1073 while (!inpu.LastScan)
1075 if (inpu.MousePresent)
1077 if (INL_GetMouseButtons())
1079 while (INL_GetMouseButtons())
1085 for (i = 0;i < MaxJoys;i++)
1087 if (inpu.JoysPresent[i])
1089 if (IN_GetJoyButtonsDB(i))
1091 while (IN_GetJoyButtonsDB(i))
1099 IN_ClearKey(inpu.LastScan);
1100 inpu.LastScan = sc_None;
1103 ///////////////////////////////////////////////////////////////////////////
1105 // IN_Ack() - Clears user input & then calls IN_AckBack()
1107 ///////////////////////////////////////////////////////////////////////////
1113 IN_ClearKey(inpu.LastScan);
1114 inpu.LastScan = sc_None;
1116 if (inpu.MousePresent)
1117 while (INL_GetMouseButtons())
1119 for (i = 0;i < MaxJoys;i++)
1120 if (inpu.JoysPresent[i])
1121 while (IN_GetJoyButtonsDB(i))
1127 ///////////////////////////////////////////////////////////////////////////
1129 // IN_IsUserInput() - Returns true if a key has been pressed or a button
1132 ///////////////////////////////////////////////////////////////////////////
1139 result = inpu.LastScan;
1141 if (inpu.MousePresent)
1142 if (INL_GetMouseButtons())
1145 for (i = 0;i < MaxJoys;i++)
1146 if (inpu.JoysPresent[i])
1147 if (INL_GetJoyButtons(i))
1153 ///////////////////////////////////////////////////////////////////////////
1155 // IN_UserInput() - Waits for the specified delay time (in ticks) or the
1156 // user pressing a key or a mouse button. If the clear flag is set, it
1157 // then either clears the key or waits for the user to let the mouse
1160 ///////////////////////////////////////////////////////////////////////////
1162 IN_UserInput(dword delay,boolean clear)
1164 dword TimeCount = *clockdw;
1167 lasttime = TimeCount;
1170 if (IN_IsUserInput())
1176 } while (TimeCount - lasttime < delay);
1180 boolean IN_KeyDown(byte code)
1182 return inpu.Keyboard[code];
1185 void IN_ClearKey(byte code)
1187 inpu.Keyboard[code] = false;
1188 if(code == inpu.LastScan)
1189 inpu.LastScan = sc_None;
1192 boolean IN_qb(byte kee)
1194 printf("%u\n", inpu.Keyboard[kee]);
1195 if(inpu.Keyboard[kee]==true) return 1;