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
\r
23 // By Jason Blochowiak
\r
24 // Open Watcom port by sparky4
\r
28 // This module handles dealing with the various input devices
\r
30 // Depends on: Memory Mgr (for demo recording), Sound Mgr (for timing stuff),
\r
31 // User Mgr (for command line parms)
\r
34 // LastScan - The keyboard scan code of the last key pressed
\r
35 // LastASCII - The ASCII value of the last key pressed
\r
36 // DEBUG - there are more globals
\r
39 #include "src/lib/16_in.h"
\r
41 byte testkeyin=0,testcontrolnoisy=0;
\r
44 =============================================================================
\r
48 =============================================================================
\r
52 boolean MousePresent;
\r
53 boolean JoysPresent[MaxJoys];
\r
54 boolean JoyPadPresent[MaxPads];
\r
55 boolean Keyboard[NumCodes];
\r
60 KeyboardDef KbdDefs[MaxKbds];
\r
61 JoystickDef JoyDefs[MaxJoys];
\r
62 JoypadDef JoypadDefs[MaxPads];
\r
65 //extern inconfig inpu;
\r
66 //inpu.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
\r
69 =============================================================================
\r
73 =============================================================================
\r
76 #ifdef __cplusplus /* Function must be declared C style */
\r
80 static struct instat {
\r
83 ScanCode CurCode,LastCode;
\r
86 static void (*INL_KeyHook)(void);
\r
87 static void interrupt (*OldKeyVect)(void);
\r
88 static char *ParmStringsIN[] = {"nojoys","nomouse",nil};
\r
90 static byte far ASCIINames[] = // Unshifted ASCII for scan codes
\r
92 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
93 0 ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8 ,9 , // 0
\r
94 'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0 ,'a','s', // 1
\r
95 'd','f','g','h','j','k','l',';',39 ,'`',0 ,92 ,'z','x','c','v', // 2
\r
96 'b','n','m',',','.','/',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
97 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
98 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
99 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
100 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
102 far ShiftNames[] = // Shifted ASCII for scan codes
\r
104 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
105 0 ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8 ,9 , // 0
\r
106 'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0 ,'A','S', // 1
\r
107 'D','F','G','H','J','K','L',':',34 ,'~',0 ,'|','Z','X','C','V', // 2
\r
108 'B','N','M','<','>','?',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
109 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
110 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
111 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
112 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
114 far SpecialNames[] = // ASCII for 0xe0 prefixed codes
\r
116 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
117 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 0
\r
118 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,13 ,0 ,0 ,0 , // 1
\r
119 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 2
\r
120 0 ,0 ,0 ,0 ,0 ,'/',0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
121 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 4
\r
122 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
123 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
124 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
126 *ScanNames[] = // Scan code names with single chars
\r
128 "?","?","1","2","3","4","5","6","7","8","9","0","-","+","?","?",
\r
129 "Q","W","E","R","T","Y","U","I","O","P","[","]","|","?","A","S",
\r
130 "D","F","G","H","J","K","L",";","\"","?","?","?","Z","X","C","V",
\r
131 "B","N","M",",",".","/","?","?","?","?","?","?","?","?","?","?",
\r
132 "?","?","?","?","?","?","?","?","\xf","?","-","\x15","5","\x11","+","?",
\r
133 "\x13","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
134 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
135 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"
\r
136 }, // DEBUG - consolidate these
\r
137 far ExtScanCodes[] = // Scan codes with >1 char names
\r
139 1,0xe,0xf,0x1d,0x2a,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,
\r
140 0x3f,0x40,0x41,0x42,0x43,0x44,0x57,0x59,0x46,0x1c,0x36,
\r
141 0x37,0x38,0x47,0x49,0x4f,0x51,0x52,0x53,0x45,0x48,
\r
142 0x50,0x4b,0x4d,0x00
\r
144 *ExtScanNames[] = // Names corresponding to ExtScanCodes
\r
146 "Esc","BkSp","Tab","Ctrl","LShft","Space","CapsLk","F1","F2","F3","F4",
\r
147 "F5","F6","F7","F8","F9","F10","F11","F12","ScrlLk","Enter","RShft",
\r
148 "PrtSc","Alt","Home","PgUp","End","PgDn","Ins","Del","NumLk","Up",
\r
149 "Down","Left","Right",""
\r
152 static Direction DirTable[] = // Quick lookup for total direction
\r
168 // Internal routines
\r
169 ///////////////////////////////////////////////////////////////////////////
\r
171 // INL_KeyService() - Handles a keyboard interrupt (key up/down)
\r
173 ///////////////////////////////////////////////////////////////////////////
\r
177 static boolean special;
\r
179 register byte temp;
\r
181 k = inp(0x60); // Get the scan code
\r
183 // Tell the XT keyboard controller to clear the key
\r
184 outp(0x61,(temp = inp(0x61)) | 0x80);
\r
187 if (k == 0xe0) // Special key prefix
\r
189 else if (k == 0xe1) // Handle Pause key
\r
190 inpu.Paused = true;
\r
193 if (k & 0x80) // Break code
\r
197 // DEBUG - handle special keys: ctl-alt-delete, print scrn
\r
199 inpu.Keyboard[k] = false;
\r
203 inst.LastCode = inst.CurCode;
\r
204 inst.CurCode = inpu.LastScan = k;
\r
205 inpu.Keyboard[k] = true;
\r
208 c = SpecialNames[k];
\r
211 if (k == sc_CapsLock)
\r
213 inst.CapsLock ^= true;
\r
214 // DEBUG - make caps lock light work
\r
217 if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift]) // If shifted
\r
220 if ((c >= 'A') && (c <= 'Z') && inst.CapsLock)
\r
226 if ((c >= 'a') && (c <= 'z') && inst.CapsLock)
\r
231 inpu.LastASCII = c;
\r
237 if (INL_KeyHook && !special)
\r
240 if(testkeyin > 0) printf("%c [0x%x %u] %u\n", c, k, k, inpu.Keyboard[k]);
\r
248 union REGS CPURegs;
\r
250 int86(MouseInt,&CPURegs,&CPURegs);
\r
253 ///////////////////////////////////////////////////////////////////////////
\r
255 // INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
\r
258 ///////////////////////////////////////////////////////////////////////////
\r
260 INL_GetMouseDelta(int *x,int *y)
\r
262 union REGS CPURegs;
\r
268 ///////////////////////////////////////////////////////////////////////////
\r
270 // INL_GetMouseButtons() - Gets the status of the mouse buttons from the
\r
273 ///////////////////////////////////////////////////////////////////////////
\r
275 INL_GetMouseButtons(void)
\r
277 union REGS CPURegs;
\r
281 buttons = CPURegs.x.bx;
\r
285 ///////////////////////////////////////////////////////////////////////////
\r
287 // IN_GetJoyAbs() - Reads the absolute position of the specified joystick
\r
289 ///////////////////////////////////////////////////////////////////////////
\r
291 IN_GetJoyAbs(word joy,word *xp,word *yp)
\r
298 xs = joy? 2 : 0; // Find shift value for x axis
\r
299 xb = 1 << xs; // Use shift value to get x bit mask
\r
300 ys = joy? 3 : 1; // Do the same for y axis
\r
303 // Read the absolute joystick values
\r
306 pushf // Save some registers
\r
309 cli // Make sure an interrupt doesn't screw the timings
\r
314 out dx,al // Clear the resistors
\r
316 mov ah,[xb] // Get masks into registers
\r
319 xor si,si // Clear count registers
\r
321 xor bh,bh // Clear high byte of bx for later
\r
323 push bp // Don't mess up stack frame
\r
327 in al,dx // Get bits indicating whether all are finished
\r
329 dec bp // Check bounding register
\r
330 jz done // We have a silly value - abort
\r
332 mov bl,al // Duplicate the bits
\r
333 and bl,ah // Mask off useless bits (in [xb])
\r
334 add si,bx // Possibly increment count register
\r
335 mov cl,bl // Save for testing later
\r
342 jnz loo // If both bits were 0, drop out
\r
347 mov cl,[xs] // Get the number of bits to shift
\r
348 shr si,cl // and shift the count that many times
\r
353 mov [x],si // Store the values into the variables
\r
358 popf // Restore the registers
\r
365 ///////////////////////////////////////////////////////////////////////////
\r
367 // INL_GetJoyDelta() - Returns the relative movement of the specified
\r
368 // joystick (from +/-127, scaled adaptively)
\r
370 ///////////////////////////////////////////////////////////////////////////
\r
372 INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)
\r
376 word TimeCount = *clockw;
\r
378 static word lasttime;
\r
380 IN_GetJoyAbs(joy,&x,&y);
\r
381 def = inpu.JoyDefs + joy;
\r
383 if (x < def->threshMinX)
\r
385 if (x < def->joyMinX)
\r
388 x = -(x - def->threshMinX);
\r
389 x *= def->joyMultXL;
\r
390 x >>= JoyScaleShift;
\r
391 *dx = (x > 127)? -127 : -x;
\r
393 else if (x > def->threshMaxX)
\r
395 if (x > def->joyMaxX)
\r
398 x = x - def->threshMaxX;
\r
399 x *= def->joyMultXH;
\r
400 x >>= JoyScaleShift;
\r
401 *dx = (x > 127)? 127 : x;
\r
406 if (y < def->threshMinY)
\r
408 if (y < def->joyMinY)
\r
411 y = -(y - def->threshMinY);
\r
412 y *= def->joyMultYL;
\r
413 y >>= JoyScaleShift;
\r
414 *dy = (y > 127)? -127 : -y;
\r
416 else if (y > def->threshMaxY)
\r
418 if (y > def->joyMaxY)
\r
421 y = y - def->threshMaxY;
\r
422 y *= def->joyMultYH;
\r
423 y >>= JoyScaleShift;
\r
424 *dy = (y > 127)? 127 : y;
\r
431 time = (TimeCount - lasttime) / 2;
\r
440 lasttime = TimeCount;
\r
443 ///////////////////////////////////////////////////////////////////////////
\r
445 // INL_GetJoyButtons() - Returns the button status of the specified
\r
448 ///////////////////////////////////////////////////////////////////////////
\r
450 INL_GetJoyButtons(word joy)
\r
452 register word result;
\r
454 result = inp(0x201); // Get all the joystick buttons
\r
455 result >>= joy? 6 : 4; // Shift into bits 0-1
\r
456 result &= 3; // Mask off the useless bits
\r
461 ///////////////////////////////////////////////////////////////////////////
\r
463 // IN_GetJoyButtonsDB() - Returns the de-bounced button status of the
\r
464 // specified joystick
\r
466 ///////////////////////////////////////////////////////////////////////////
\r
468 IN_GetJoyButtonsDB(word joy)
\r
470 word TimeCount = *clockw;
\r
472 word result1,result2;
\r
476 result1 = INL_GetJoyButtons(joy);
\r
477 lasttime = TimeCount;
\r
478 while(TimeCount == lasttime)
\r
479 result2 = INL_GetJoyButtons(joy);
\r
480 } while(result1 != result2);
\r
484 ///////////////////////////////////////////////////////////////////////////
\r
486 // INL_StartKbd() - Sets up my keyboard stuff for use
\r
488 ///////////////////////////////////////////////////////////////////////////
\r
492 INL_KeyHook = 0; // Clear key hook
\r
494 IN_ClearKeysDown();
\r
496 OldKeyVect = _dos_getvect(KeyInt);
\r
497 _dos_setvect(KeyInt,INL_KeyService);
\r
500 ///////////////////////////////////////////////////////////////////////////
\r
502 // INL_ShutKbd() - Restores keyboard control to the BIOS
\r
504 ///////////////////////////////////////////////////////////////////////////
\r
508 pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags
\r
510 _dos_setvect(KeyInt,OldKeyVect);
\r
513 ///////////////////////////////////////////////////////////////////////////
\r
515 // INL_StartMouse() - Detects and sets up the mouse
\r
517 ///////////////////////////////////////////////////////////////////////////
\r
519 INL_StartMouse(void)
\r
521 union REGS CPURegs;
\r
522 if(_dos_getvect(MouseInt))
\r
525 if(CPURegs.x.ax == 0xffff)
\r
531 ///////////////////////////////////////////////////////////////////////////
\r
533 // INL_ShutMouse() - Cleans up after the mouse
\r
535 ///////////////////////////////////////////////////////////////////////////
\r
537 INL_ShutMouse(void)
\r
542 // INL_SetJoyScale() - Sets up scaling values for the specified joystick
\r
545 INL_SetJoyScale(word joy)
\r
549 def = &(inpu.JoyDefs[joy]);
\r
550 def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
\r
551 def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
\r
552 def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
\r
553 def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);
\r
556 ///////////////////////////////////////////////////////////////////////////
\r
558 // IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
\r
559 // to set up scaling values
\r
561 ///////////////////////////////////////////////////////////////////////////
\r
563 IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
\r
568 def = &(inpu.JoyDefs[joy]);
\r
570 def->joyMinX = minx;
\r
571 def->joyMaxX = maxx;
\r
574 def->threshMinX = ((r / 2) - d) + minx;
\r
575 def->threshMaxX = ((r / 2) + d) + minx;
\r
577 def->joyMinY = miny;
\r
578 def->joyMaxY = maxy;
\r
581 def->threshMinY = ((r / 2) - d) + miny;
\r
582 def->threshMaxY = ((r / 2) + d) + miny;
\r
584 INL_SetJoyScale(joy);
\r
587 ///////////////////////////////////////////////////////////////////////////
\r
589 // INL_StartJoy() - Detects & auto-configures the specified joystick
\r
590 // The auto-config assumes the joystick is centered
\r
592 ///////////////////////////////////////////////////////////////////////////
\r
594 INL_StartJoy(word joy)
\r
598 IN_GetJoyAbs(joy,&x,&y);
\r
602 ((x == 0) || (x > MaxJoyValue - 10))
\r
603 || ((y == 0) || (y > MaxJoyValue - 10))
\r
608 IN_SetupJoy(joy,0,x * 2,0,y * 2);
\r
613 ///////////////////////////////////////////////////////////////////////////
\r
615 // INL_ShutJoy() - Cleans up the joystick stuff
\r
617 ///////////////////////////////////////////////////////////////////////////
\r
619 INL_ShutJoy(word joy)
\r
621 inpu.JoysPresent[joy] = false;
\r
626 ///////////////////////////////////////////////////////////////////////////
\r
628 // IN_Startup() - Starts up the Input Mgr
\r
630 ///////////////////////////////////////////////////////////////////////////
\r
634 boolean checkjoys,checkmouse;
\r
637 if (inst.IN_Started)
\r
642 for (i = 1;i < __argc;i++)
\r
644 switch (US_CheckParm(__argv[i],ParmStringsIN))
\r
650 checkmouse = false;
\r
656 inpu.MousePresent = checkmouse? INL_StartMouse() : false;
\r
658 for (i = 0;i < MaxJoys;i++)
\r
659 inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
\r
661 inst.IN_Started = true;
\r
664 ///////////////////////////////////////////////////////////////////////////
\r
666 // IN_Default() - Sets up default conditions for the Input Mgr
\r
668 ///////////////////////////////////////////////////////////////////////////
\r
670 IN_Default(boolean gotit,player_t *player,ControlType nt)
\r
676 || ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0])
\r
677 || ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1])
\r
678 || ((nt == ctrl_Mouse) && !inpu.MousePresent)
\r
679 || ((nt == ctrl_Joypad1) && !inpu.JoyPadPresent[0])
\r
680 || ((nt == ctrl_Joypad2) && !inpu.JoyPadPresent[1])
\r
682 nt = ctrl_Keyboard1;
\r
683 inpu.KbdDefs[0].button0 = 0x1c;
\r
684 inpu.KbdDefs[0].button1 = 0x38;
\r
685 //in.KbdDefs[0].upleft = 0x47;
\r
686 inpu.KbdDefs[0].up = 0x48;
\r
687 //in.KbdDefs[0].upright = 0x49;
\r
688 inpu.KbdDefs[0].left = 0x4b;
\r
689 inpu.KbdDefs[0].right = 0x4d;
\r
690 //in.KbdDefs[0].downleft = 0x4f;
\r
691 inpu.KbdDefs[0].down = 0x50;
\r
692 //in.KbdDefs[0].downright = 0x51;
\r
693 IN_SetControlType(0,player,nt);
\r
694 for(i=0; i>MaxPlayers;i++)
\r
698 ///////////////////////////////////////////////////////////////////////////
\r
700 // IN_Shutdown() - Shuts down the Input Mgr
\r
702 ///////////////////////////////////////////////////////////////////////////
\r
708 if (!inst.IN_Started)
\r
712 for (i = 0;i < MaxJoys;i++)
\r
716 inst.IN_Started = false;
\r
719 ///////////////////////////////////////////////////////////////////////////
\r
721 // IN_SetKeyHook() - Sets the routine that gets called by INL_KeyService()
\r
722 // everytime a real make/break code gets hit
\r
724 ///////////////////////////////////////////////////////////////////////////
\r
726 IN_SetKeyHook(void (*hook)())
\r
728 INL_KeyHook = hook;
\r
731 ///////////////////////////////////////////////////////////////////////////
\r
733 // IN_ClearKeyDown() - Clears the keyboard array
\r
735 ///////////////////////////////////////////////////////////////////////////
\r
741 inpu.LastScan = sc_None;
\r
742 inpu.LastASCII = key_None;
\r
743 memset (inpu.Keyboard,0,sizeof(inpu.Keyboard));
\r
746 ///////////////////////////////////////////////////////////////////////////
\r
748 // INL_AdjustCursor() - Internal routine of common code from IN_ReadCursor()
\r
750 ///////////////////////////////////////////////////////////////////////////
\r
752 INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
\r
754 if (buttons & (1 << 0))
\r
755 info->button0 = true;
\r
756 if (buttons & (1 << 1))
\r
757 info->button1 = true;
\r
763 ///////////////////////////////////////////////////////////////////////////
\r
765 // IN_ReadCursor() - Reads the input devices and fills in the cursor info
\r
768 ///////////////////////////////////////////////////////////////////////////
\r
770 IN_ReadCursor(CursorInfo *info)
\r
776 info->x = info->y = 0;
\r
777 info->button0 = info->button1 = false;
\r
779 if (inpu.MousePresent)
\r
781 buttons = INL_GetMouseButtons();
\r
782 INL_GetMouseDelta(&dx,&dy);
\r
783 INL_AdjustCursor(info,buttons,dx,dy);
\r
786 for (i = 0;i < MaxJoys;i++)
\r
788 if (!inpu.JoysPresent[i])
\r
791 buttons = INL_GetJoyButtons(i);
\r
792 INL_GetJoyDelta(i,&dx,&dy,true);
\r
795 INL_AdjustCursor(info,buttons,dx,dy);
\r
799 ///////////////////////////////////////////////////////////////////////////
\r
801 // IN_ReadControl() - Reads the device associated with the specified
\r
802 // player and fills in the control info struct
\r
804 ///////////////////////////////////////////////////////////////////////////
\r
806 IN_ReadControl(int pn,player_t *player)
\r
815 byte dir=DirTable[2];
\r
816 register KeyboardDef *def;
\r
819 mx = my = motion_None;
\r
823 if (DemoMode == demo_Playback)
\r
825 dbyte = DemoBuffer[DemoOffset + 1];
\r
826 my = (dbyte & 3) - 1;
\r
827 mx = ((dbyte >> 2) & 3) - 1;
\r
828 buttons = (dbyte >> 4) & 3;
\r
830 if (!(--DemoBuffer[DemoOffset]))
\r
833 if (DemoOffset >= DemoSize)
\r
834 DemoMode = demo_PlayDone;
\r
839 else if (DemoMode == demo_PlayDone)
\r
840 Quit("Demo playback exceeded");
\r
844 switch (type = player[pn].Controls)
\r
846 case ctrl_Keyboard1:
\r
847 case ctrl_Keyboard2:
\r
848 def = &(inpu.KbdDefs[type - ctrl_Keyboard]);
\r
850 /* if (Keyboard[def->upleft])
\r
851 mx = motion_Left,my = motion_Up;
\r
852 else if (Keyboard[def->upright])
\r
853 mx = motion_Right,my = motion_Up;
\r
854 else if (Keyboard[def->downleft])
\r
855 mx = motion_Left,my = motion_Down;
\r
856 else if (Keyboard[def->downright])
\r
857 mx = motion_Right,my = motion_Down;*/
\r
858 if(DIRECTIONIFELSE)
\r
860 if(!inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]){
\r
861 if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]))
\r
863 if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up]))
\r
865 }else if(!inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]){
\r
866 if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]))
\r
868 if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left]))// || player[pn].pdir != 1)
\r
870 }else{ //2 keys pressed
\r
871 switch (player[pn].pdir)
\r
875 if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])) dir = DirTable[1];
\r
876 else if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])) dir = DirTable[3];
\r
880 if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])) dir = DirTable[0];
\r
881 else if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])) dir = DirTable[4];
\r
886 if(testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c ", dirchar(player[pn].pdir)); }
\r
889 //input from player
\r
890 if (inpu.Keyboard[def->button0])
\r
892 if (inpu.Keyboard[def->button1])
\r
896 case ctrl_Joystick1:
\r
897 case ctrl_Joystick2:
\r
898 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);
\r
899 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
\r
903 INL_GetMouseDelta(&dx,&dy);
\r
904 buttons = INL_GetMouseButtons();
\r
918 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
\r
919 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
\r
927 player[pn].info.x = dx;
\r
928 player[pn].info.xaxis = mx;
\r
929 player[pn].info.y = dy;
\r
930 player[pn].info.yaxis = my;
\r
931 player[pn].info.button0 = buttons & (1 << 0);
\r
932 player[pn].info.button1 = buttons & (1 << 1);
\r
933 player[pn].info.button2 = buttons & (1 << 2);
\r
934 player[pn].info.button3 = buttons & (1 << 3);
\r
935 // player[pn].info.dir = DirTable[((my + 1) * 3) + (mx + 1)];
\r
936 conpee=(((my + 1) * 2) + (mx + 1))-1;
\r
937 player[pn].info.dir = DirTable[conpee];
\r
939 //TODO: overwriting direction must be added
\r
940 if(DirTable[conpee]!=2) player[pn].pdir=DirTable[conpee];
\r
941 if(player[pn].q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None)))
\r
943 if(dir==2) player[pn].d = player[pn].info.dir;
\r
944 else player[pn].d = DirTable[dir];
\r
948 if (DemoMode == demo_Record)
\r
950 // Pack the control info into a byte
\r
951 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);
\r
955 (DemoBuffer[DemoOffset + 1] == dbyte)
\r
956 && (DemoBuffer[DemoOffset] < 255)
\r
958 (DemoBuffer[DemoOffset])++;
\r
961 if (DemoOffset || DemoBuffer[DemoOffset])
\r
964 if (DemoOffset >= DemoSize)
\r
965 Quit("Demo buffer overflow");
\r
967 DemoBuffer[DemoOffset] = 1;
\r
968 DemoBuffer[DemoOffset + 1] = dbyte;
\r
972 //#ifdef TESTCONTROLNOISY
\r
973 if(testcontrolnoisy > 0)
\r
974 if((inpu.Keyboard[def->up] || inpu.Keyboard[def->down] || inpu.Keyboard[def->left] || inpu.Keyboard[def->right]) || player[pn].q>1)
\r
976 printf("q=%d ", player[pn].q);
\r
977 printf("cpee=%c ", dirchar(conpee));
\r
978 //printf("(mx)=%d ", mx);
\r
979 //printf("(my)=%d ", my);
\r
980 printf("pdir=%c d=%c dir=%c ", dirchar(player[pn].pdir), dirchar(player[pn].d), dirchar(player[pn].info.dir));
\r
981 printf("%c%d %c%d %c%d %c%d\n", dirchar(0), inpu.Keyboard[def->up], dirchar(4), inpu.Keyboard[def->down], dirchar(1), inpu.Keyboard[def->left], dirchar(3), inpu.Keyboard[def->right]);
\r
986 ///////////////////////////////////////////////////////////////////////////
\r
988 // IN_SetControlType() - Sets the control type to be used by the specified
\r
991 ///////////////////////////////////////////////////////////////////////////
\r
993 IN_SetControlType(word pn,player_t *player,ControlType type)
\r
995 // DEBUG - check that requested type is present?
\r
996 player[pn].Controls = type;
\r
1000 ///////////////////////////////////////////////////////////////////////////
\r
1002 // IN_StartDemoRecord() - Starts the demo recording, using a buffer the
\r
1003 // size passed. Returns if the buffer allocation was successful
\r
1005 ///////////////////////////////////////////////////////////////////////////
\r
1007 IN_StartDemoRecord(word bufsize)
\r
1012 MM_GetPtr((memptr *)&DemoBuffer,bufsize);
\r
1013 DemoMode = demo_Record;
\r
1014 DemoSize = bufsize & ~1;
\r
1016 DemoBuffer[0] = DemoBuffer[1] = 0;
\r
1021 ///////////////////////////////////////////////////////////////////////////
\r
1023 // IN_StartDemoPlayback() - Plays back the demo pointed to of the given size
\r
1025 ///////////////////////////////////////////////////////////////////////////
\r
1027 IN_StartDemoPlayback(byte /*__segment*/ *buffer,word bufsize)
\r
1029 DemoBuffer = buffer;
\r
1030 DemoMode = demo_Playback;
\r
1031 DemoSize = bufsize & ~1;
\r
1035 ///////////////////////////////////////////////////////////////////////////
\r
1037 // IN_StopDemo() - Turns off demo mode
\r
1039 ///////////////////////////////////////////////////////////////////////////
\r
1043 if ((DemoMode == demo_Record) && DemoOffset)
\r
1046 DemoMode = demo_Off;
\r
1049 ///////////////////////////////////////////////////////////////////////////
\r
1051 // IN_FreeDemoBuffer() - Frees the demo buffer, if it's been allocated
\r
1053 ///////////////////////////////////////////////////////////////////////////
\r
1055 IN_FreeDemoBuffer(void)
\r
1058 MM_FreePtr((memptr *)&DemoBuffer);
\r
1063 ///////////////////////////////////////////////////////////////////////////
\r
1065 // IN_GetScanName() - Returns a string containing the name of the
\r
1066 // specified scan code
\r
1068 ///////////////////////////////////////////////////////////////////////////
\r
1070 IN_GetScanName(ScanCode scan)
\r
1075 for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)
\r
1079 return(ScanNames[scan]);
\r
1082 ///////////////////////////////////////////////////////////////////////////
\r
1084 // IN_WaitForKey() - Waits for a scan code, then clears LastScan and
\r
1085 // returns the scan code
\r
1087 ///////////////////////////////////////////////////////////////////////////
\r
1093 while (!(result = inpu.LastScan))
\r
1095 inpu.LastScan = 0;
\r
1099 ///////////////////////////////////////////////////////////////////////////
\r
1101 // IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and
\r
1102 // returns the ASCII value
\r
1104 ///////////////////////////////////////////////////////////////////////////
\r
1110 while (!(result = inpu.LastASCII))
\r
1112 inpu.LastASCII = '\0';
\r
1116 ///////////////////////////////////////////////////////////////////////////
\r
1118 // IN_AckBack() - Waits for either an ASCII keypress or a button press
\r
1120 ///////////////////////////////////////////////////////////////////////////
\r
1126 while (!inpu.LastScan)
\r
1128 if (inpu.MousePresent)
\r
1130 if (INL_GetMouseButtons())
\r
1132 while (INL_GetMouseButtons())
\r
1138 for (i = 0;i < MaxJoys;i++)
\r
1140 if (inpu.JoysPresent[i])
\r
1142 if (IN_GetJoyButtonsDB(i))
\r
1144 while (IN_GetJoyButtonsDB(i))
\r
1152 IN_ClearKey(inpu.LastScan);
\r
1153 inpu.LastScan = sc_None;
\r
1156 ///////////////////////////////////////////////////////////////////////////
\r
1158 // IN_Ack() - Clears user input & then calls IN_AckBack()
\r
1160 ///////////////////////////////////////////////////////////////////////////
\r
1166 IN_ClearKey(inpu.LastScan);
\r
1167 inpu.LastScan = sc_None;
\r
1169 if (inpu.MousePresent)
\r
1170 while (INL_GetMouseButtons())
\r
1172 for (i = 0;i < MaxJoys;i++)
\r
1173 if (inpu.JoysPresent[i])
\r
1174 while (IN_GetJoyButtonsDB(i))
\r
1180 ///////////////////////////////////////////////////////////////////////////
\r
1182 // IN_IsUserInput() - Returns true if a key has been pressed or a button
\r
1185 ///////////////////////////////////////////////////////////////////////////
\r
1192 result = inpu.LastScan;
\r
1194 if (inpu.MousePresent)
\r
1195 if (INL_GetMouseButtons())
\r
1198 for (i = 0;i < MaxJoys;i++)
\r
1199 if (inpu.JoysPresent[i])
\r
1200 if (INL_GetJoyButtons(i))
\r
1206 ///////////////////////////////////////////////////////////////////////////
\r
1208 // IN_UserInput() - Waits for the specified delay time (in ticks) or the
\r
1209 // user pressing a key or a mouse button. If the clear flag is set, it
\r
1210 // then either clears the key or waits for the user to let the mouse
\r
1213 ///////////////////////////////////////////////////////////////////////////
\r
1215 IN_UserInput(dword delay,boolean clear)
\r
1217 word TimeCount = *clockw;
\r
1220 lasttime = TimeCount;
\r
1223 if (IN_IsUserInput())
\r
1229 } while (TimeCount - lasttime < delay);
\r
1233 boolean IN_KeyDown(byte code)
\r
1235 return inpu.Keyboard[code];
\r
1238 void IN_ClearKey(byte code)
\r
1240 inpu.Keyboard[code] = false;
\r
1241 if(code == inpu.LastScan)
\r
1242 inpu.LastScan = sc_None;
\r
1245 boolean IN_qb(byte kee)
\r
1247 //#ifdef TESTKEYIN
\r
1248 // if(testkeyin > 0) printf("%u\n", inpu.Keyboard[kee]);
\r
1250 if(inpu.Keyboard[kee]==true) return 1;
\r