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
43 =============================================================================
\r
47 =============================================================================
\r
49 // moved to 16_tdef.h
\r
52 =============================================================================
\r
56 =============================================================================
\r
59 #ifdef __cplusplus /* Function must be declared C style */
\r
63 static byte far ASCIINames[] = // Unshifted ASCII for scan codes
\r
65 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
66 0 ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8 ,9 , // 0
\r
67 'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0 ,'a','s', // 1
\r
68 'd','f','g','h','j','k','l',';',39 ,'`',0 ,92 ,'z','x','c','v', // 2
\r
69 'b','n','m',',','.','/',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
70 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
71 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
72 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
73 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
75 far ShiftNames[] = // Shifted ASCII for scan codes
\r
77 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
78 0 ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8 ,9 , // 0
\r
79 'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0 ,'A','S', // 1
\r
80 'D','F','G','H','J','K','L',':',34 ,'~',0 ,'|','Z','X','C','V', // 2
\r
81 'B','N','M','<','>','?',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
82 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
83 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
84 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
85 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
87 far SpecialNames[] = // ASCII for 0xe0 prefixed codes
\r
89 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
90 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 0
\r
91 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,13 ,0 ,0 ,0 , // 1
\r
92 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 2
\r
93 0 ,0 ,0 ,0 ,0 ,'/',0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
94 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 4
\r
95 0 ,0 ,0 ,0 ,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
101 *ScanNames[] = // Scan code names with single chars
\r
103 "?","?","1","2","3","4","5","6","7","8","9","0","-","+","?","?",
\r
104 "Q","W","E","R","T","Y","U","I","O","P","[","]","|","?","A","S",
\r
105 "D","F","G","H","J","K","L",";","\"","?","?","?","Z","X","C","V",
\r
106 "B","N","M",",",".","/","?","?","?","?","?","?","?","?","?","?",
\r
107 "?","?","?","?","?","?","?","?","\xf","?","-","\x15","5","\x11","+","?",
\r
108 "\x13","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
109 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
110 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"
\r
111 }, // DEBUG - consolidate these
\r
114 far ExtScanCodes[] = // Scan codes with >1 char names
\r
116 1,0xe,0xf,0x1d,0x2a,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,
\r
117 0x3f,0x40,0x41,0x42,0x43,0x44,0x57,0x59,0x46,0x1c,0x36,
\r
118 0x37,0x38,0x47,0x49,0x4f,0x51,0x52,0x53,0x45,0x48,
\r
119 0x50,0x4b,0x4d,0x00
\r
121 *ExtScanNames[] = // Names corresponding to ExtScanCodes
\r
123 "Esc","BkSp","Tab","Ctrl","LShft","Space","CapsLk","F1","F2","F3","F4",
\r
124 "F5","F6","F7","F8","F9","F10","F11","F12","ScrlLk","Enter","RShft",
\r
125 "PrtSc","Alt","Home","PgUp","End","PgDn","Ins","Del","NumLk","Up",
\r
126 "Down","Left","Right",""
\r
129 static Direction DirTable[] = // Quick lookup for total direction
\r
142 static void (*INL_KeyHook)(void);
\r
143 static void interrupt (*OldKeyVect)(void);
\r
145 static char *ParmStringsIN[] = {"nojoys","nomouse",nil};
\r
151 // Internal routines
\r
153 ///////////////////////////////////////////////////////////////////////////
\r
155 // INL_KeyService() - Handles a keyboard interrupt (key up/down)
\r
157 ///////////////////////////////////////////////////////////////////////////
\r
161 static boolean special;
\r
163 register byte temp;
\r
165 k = inp(0x60); // Get the scan code
\r
167 // Tell the XT keyboard controller to clear the key
\r
168 outp(0x61,(temp = inp(0x61)) | 0x80);
\r
171 if (k == 0xe0) // Special key prefix
\r
173 else if (k == 0xe1) // Handle Pause key
\r
174 inpu.Paused = true;
\r
177 if (k & 0x80) // Break code
\r
181 // DEBUG - handle special keys: ctl-alt-delete, print scrn
\r
183 inpu.Keyboard[k] = false;
\r
187 inst.LastCode = inst.CurCode;
\r
188 inst.CurCode = inpu.LastScan = k;
\r
189 inpu.Keyboard[k] = true;
\r
192 c = SpecialNames[k];
\r
195 if (k == sc_CapsLock)
\r
197 inst.CapsLock ^= true;
\r
198 // DEBUG - make caps lock light work
\r
201 if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift]) // If shifted
\r
204 if ((c >= 'A') && (c <= 'Z') && inst.CapsLock)
\r
210 if ((c >= 'a') && (c <= 'z') && inst.CapsLock)
\r
215 inpu.LastASCII = c;
\r
221 if (INL_KeyHook && !special)
\r
223 #ifdef __DEBUG_InputMgr__
\r
224 if(dbg_testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, inpu.Keyboard[k]);
\r
232 //union REGS CPURegs;
\r
233 //x = CPURegs.x.ax;
\r
238 //int86(MouseInt,&CPURegs,&CPURegs);
\r
241 ///////////////////////////////////////////////////////////////////////////
\r
243 // INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
\r
246 ///////////////////////////////////////////////////////////////////////////
\r
248 INL_GetMouseDelta(int *x,int *y)
\r
250 union REGS CPURegs;
\r
256 ///////////////////////////////////////////////////////////////////////////
\r
258 // INL_GetMouseButtons() - Gets the status of the mouse buttons from the
\r
261 ///////////////////////////////////////////////////////////////////////////
\r
263 INL_GetMouseButtons(void)
\r
265 union REGS CPURegs;
\r
269 buttons = CPURegs.x.bx;
\r
273 ///////////////////////////////////////////////////////////////////////////
\r
275 // IN_GetJoyAbs() - Reads the absolute position of the specified joystick
\r
277 ///////////////////////////////////////////////////////////////////////////
\r
279 IN_GetJoyAbs(word joy,word *xp,word *yp)
\r
286 xs = joy? 2 : 0; // Find shift value for x axis
\r
287 xb = 1 << xs; // Use shift value to get x bit mask
\r
288 ys = joy? 3 : 1; // Do the same for y axis
\r
291 // Read the absolute joystick values
\r
293 pushf // Save some registers
\r
296 cli // Make sure an interrupt doesn't screw the timings
\r
301 out dx,al // Clear the resistors
\r
303 mov ah,[xb] // Get masks into registers
\r
306 xor si,si // Clear count registers
\r
308 xor bh,bh // Clear high byte of bx for later
\r
310 push bp // Don't mess up stack frame
\r
312 #ifdef __BORLANDC__
\r
316 #ifdef __BORLANDC__
\r
319 in al,dx // Get bits indicating whether all are finished
\r
321 dec bp // Check bounding register
\r
322 jz done // We have a silly value - abort
\r
324 mov bl,al // Duplicate the bits
\r
325 and bl,ah // Mask off useless bits (in [xb])
\r
326 add si,bx // Possibly increment count register
\r
327 mov cl,bl // Save for testing later
\r
334 jnz loo // If both bits were 0, drop out
\r
335 #ifdef __BORLANDC__
\r
339 #ifdef __BORLANDC__
\r
344 mov cl,[xs] // Get the number of bits to shift
\r
345 shr si,cl // and shift the count that many times
\r
350 mov [x],si // Store the values into the variables
\r
355 popf // Restore the registers
\r
362 ///////////////////////////////////////////////////////////////////////////
\r
364 // INL_GetJoyDelta() - Returns the relative movement of the specified
\r
365 // joystick (from +/-127, scaled adaptively)
\r
367 ///////////////////////////////////////////////////////////////////////////
\r
369 INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)
\r
373 word TimeCount = *clockw;
\r
375 static word lasttime;
\r
377 IN_GetJoyAbs(joy,&x,&y);
\r
378 def = inpu.JoyDefs + joy;
\r
380 if (x < def->threshMinX)
\r
382 if (x < def->joyMinX)
\r
385 x = -(x - def->threshMinX);
\r
386 x *= def->joyMultXL;
\r
387 x >>= JoyScaleShift;
\r
388 *dx = (x > 127)? -127 : -x;
\r
390 else if (x > def->threshMaxX)
\r
392 if (x > def->joyMaxX)
\r
395 x = x - def->threshMaxX;
\r
396 x *= def->joyMultXH;
\r
397 x >>= JoyScaleShift;
\r
398 *dx = (x > 127)? 127 : x;
\r
403 if (y < def->threshMinY)
\r
405 if (y < def->joyMinY)
\r
408 y = -(y - def->threshMinY);
\r
409 y *= def->joyMultYL;
\r
410 y >>= JoyScaleShift;
\r
411 *dy = (y > 127)? -127 : -y;
\r
413 else if (y > def->threshMaxY)
\r
415 if (y > def->joyMaxY)
\r
418 y = y - def->threshMaxY;
\r
419 y *= def->joyMultYH;
\r
420 y >>= JoyScaleShift;
\r
421 *dy = (y > 127)? 127 : y;
\r
428 time = (TimeCount - lasttime) / 2;
\r
437 lasttime = TimeCount;
\r
440 ///////////////////////////////////////////////////////////////////////////
\r
442 // INL_GetJoyButtons() - Returns the button status of the specified
\r
445 ///////////////////////////////////////////////////////////////////////////
\r
447 INL_GetJoyButtons(word joy)
\r
449 register word result;
\r
451 result = inp(0x201); // Get all the joystick buttons
\r
452 result >>= joy? 6 : 4; // Shift into bits 0-1
\r
453 result &= 3; // Mask off the useless bits
\r
458 ///////////////////////////////////////////////////////////////////////////
\r
460 // IN_GetJoyButtonsDB() - Returns the de-bounced button status of the
\r
461 // specified joystick
\r
463 ///////////////////////////////////////////////////////////////////////////
\r
465 IN_GetJoyButtonsDB(word joy)
\r
467 word TimeCount = *clockw;
\r
469 word result1,result2;
\r
473 result1 = INL_GetJoyButtons(joy);
\r
474 lasttime = TimeCount;
\r
475 while(TimeCount == lasttime)
\r
476 result2 = INL_GetJoyButtons(joy);
\r
477 } while(result1 != result2);
\r
481 ///////////////////////////////////////////////////////////////////////////
\r
483 // INL_StartKbd() - Sets up my keyboard stuff for use
\r
485 ///////////////////////////////////////////////////////////////////////////
\r
489 byte far *lock_key;
\r
490 INL_KeyHook = 0; // Clear key hook
\r
492 IN_ClearKeysDown();
\r
494 OldKeyVect = _dos_getvect(KeyInt);
\r
496 // turn off num-lock via BIOS
\r
497 lock_key = MK_FP(0x040, 0x017); // Pointing to the address of the bios shift state keys
\r
498 *lock_key&=(~(16 | 32 | 64)); // toggle off the locks by changing the values of the 4th, 5th, and 6th bits of the address byte of 0040:0017
\r
499 OldKeyVect(); // call BIOS keyhandler to change keyboard lights
\r
500 _dos_setvect(KeyInt,INL_KeyService);
\r
503 ///////////////////////////////////////////////////////////////////////////
\r
505 // INL_ShutKbd() - Restores keyboard control to the BIOS
\r
507 ///////////////////////////////////////////////////////////////////////////
\r
511 pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags
\r
513 _dos_setvect(KeyInt,OldKeyVect);
\r
516 ///////////////////////////////////////////////////////////////////////////
\r
518 // INL_StartMouse() - Detects and sets up the mouse
\r
520 ///////////////////////////////////////////////////////////////////////////
\r
522 INL_StartMouse(void)
\r
524 union REGS CPURegs;
\r
525 if(_dos_getvect(MouseInt))
\r
528 if(CPURegs.x.ax == 0xffff)
\r
534 ///////////////////////////////////////////////////////////////////////////
\r
536 // INL_ShutMouse() - Cleans up after the mouse
\r
538 ///////////////////////////////////////////////////////////////////////////
\r
540 INL_ShutMouse(void)
\r
545 // INL_SetJoyScale() - Sets up scaling values for the specified joystick
\r
548 INL_SetJoyScale(word joy)
\r
552 def = &(inpu.JoyDefs[joy]);
\r
553 def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
\r
554 def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
\r
555 def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
\r
556 def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);
\r
559 ///////////////////////////////////////////////////////////////////////////
\r
561 // IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
\r
562 // to set up scaling values
\r
564 ///////////////////////////////////////////////////////////////////////////
\r
566 IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
\r
571 def = &(inpu.JoyDefs[joy]);
\r
573 def->joyMinX = minx;
\r
574 def->joyMaxX = maxx;
\r
577 def->threshMinX = ((r / 2) - d) + minx;
\r
578 def->threshMaxX = ((r / 2) + d) + minx;
\r
580 def->joyMinY = miny;
\r
581 def->joyMaxY = maxy;
\r
584 def->threshMinY = ((r / 2) - d) + miny;
\r
585 def->threshMaxY = ((r / 2) + d) + miny;
\r
587 INL_SetJoyScale(joy);
\r
590 ///////////////////////////////////////////////////////////////////////////
\r
592 // INL_StartJoy() - Detects & auto-configures the specified joystick
\r
593 // The auto-config assumes the joystick is centered
\r
595 ///////////////////////////////////////////////////////////////////////////
\r
597 INL_StartJoy(word joy)
\r
601 IN_GetJoyAbs(joy,&x,&y);
\r
605 ((x == 0) || (x > MaxJoyValue - 10))
\r
606 || ((y == 0) || (y > MaxJoyValue - 10))
\r
611 IN_SetupJoy(joy,0,x * 2,0,y * 2);
\r
616 ///////////////////////////////////////////////////////////////////////////
\r
618 // INL_ShutJoy() - Cleans up the joystick stuff
\r
620 ///////////////////////////////////////////////////////////////////////////
\r
622 INL_ShutJoy(word joy)
\r
624 inpu.JoysPresent[joy] = false;
\r
629 ///////////////////////////////////////////////////////////////////////////
\r
631 // IN_Startup() - Starts up the Input Mgr
\r
633 ///////////////////////////////////////////////////////////////////////////
\r
637 boolean checkjoys,checkmouse;
\r
640 if (inst.IN_Started)
\r
645 for (i = 1;i < _argc;i++)
\r
647 switch (US_CheckParm(_argv[i],ParmStringsIN))
\r
653 checkmouse = false;
\r
659 inpu.MousePresent = checkmouse? INL_StartMouse() : false;
\r
661 for (i = 0;i < MaxJoys;i++)
\r
662 ININFO_JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
\r
664 for (i = 0;i < MaxKbds;i++)
\r
665 ININFO_KbdDefs[i] = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
\r
667 inst.IN_Started = true;
\r
671 ///////////////////////////////////////////////////////////////////////////
\r
673 // IN_Default() - Sets up default conditions for the Input Mgr
\r
675 ///////////////////////////////////////////////////////////////////////////
\r
677 IN_Default(boolean gotit,player_t *player,ControlType nt)
\r
683 || ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0])
\r
684 || ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1])
\r
685 || ((nt == ctrl_Mouse) && !inpu.MousePresent)
\r
687 nt = ctrl_Keyboard1;
\r
688 ININFO_KbdDefs[0].button0 = 0x1c;
\r
689 ININFO_KbdDefs[0].button1 = 0x38;
\r
690 //in.KbdDefs[0].upleft = 0x47;
\r
691 ININFO_KbdDefs[0].up = 0x48;
\r
692 //in.KbdDefs[0].upright = 0x49;
\r
693 ININFO_KbdDefs[0].left = 0x4b;
\r
694 ININFO_KbdDefs[0].right = 0x4d;
\r
695 //in.KbdDefs[0].downleft = 0x4f;
\r
696 ININFO_KbdDefs[0].down = 0x50;
\r
697 //in.KbdDefs[0].downright = 0x51;
\r
698 IN_SetControlType(0,player,nt);
\r
699 for(i=0; i>MaxPlayers;i++)
\r
700 player[i].enti.d =2;
\r
703 ///////////////////////////////////////////////////////////////////////////
\r
705 // IN_Shutdown() - Shuts down the Input Mgr
\r
707 ///////////////////////////////////////////////////////////////////////////
\r
713 if (!inst.IN_Started)
\r
717 for (i = 0;i < MaxJoys;i++)
\r
721 inst.IN_Started = false;
\r
724 ///////////////////////////////////////////////////////////////////////////
\r
726 // IN_SetKeyHook() - Sets the routine that gets called by INL_KeyService()
\r
727 // everytime a real make/break code gets hit
\r
729 ///////////////////////////////////////////////////////////////////////////
\r
731 IN_SetKeyHook(void (*hook)())
\r
733 INL_KeyHook = hook;
\r
736 ///////////////////////////////////////////////////////////////////////////
\r
738 // IN_ClearKeyDown() - Clears the keyboard array
\r
740 ///////////////////////////////////////////////////////////////////////////
\r
746 inpu.LastScan = sc_None;
\r
747 inpu.LastASCII = key_None;
\r
748 memset (inpu.Keyboard,0,sizeof(inpu.Keyboard));
\r
751 ///////////////////////////////////////////////////////////////////////////
\r
753 // INL_AdjustCursor() - Internal routine of common code from IN_ReadCursor()
\r
755 ///////////////////////////////////////////////////////////////////////////
\r
757 INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
\r
759 if (buttons & (1 << 0))
\r
760 info->button0 = true;
\r
761 if (buttons & (1 << 1))
\r
762 info->button1 = true;
\r
768 ///////////////////////////////////////////////////////////////////////////
\r
770 // IN_ReadCursor() - Reads the input devices and fills in the cursor info
\r
773 ///////////////////////////////////////////////////////////////////////////
\r
775 IN_ReadCursor(CursorInfo *info)
\r
781 info->x = info->y = 0;
\r
782 info->button0 = info->button1 = false;
\r
784 if (inpu.MousePresent)
\r
786 buttons = INL_GetMouseButtons();
\r
787 INL_GetMouseDelta(&dx,&dy);
\r
788 INL_AdjustCursor(info,buttons,dx,dy);
\r
791 for (i = 0;i < MaxJoys;i++)
\r
793 if (!inpu.JoysPresent[i])
\r
796 buttons = INL_GetJoyButtons(i);
\r
797 INL_GetJoyDelta(i,&dx,&dy,true);
\r
800 INL_AdjustCursor(info,buttons,dx,dy);
\r
804 ///////////////////////////////////////////////////////////////////////////
\r
806 // IN_ReadControl() - Reads the device associated with the specified
\r
807 // player and fills in the control info struct
\r
809 ///////////////////////////////////////////////////////////////////////////
\r
811 IN_ReadControl(word pn, player_t *player)
\r
822 byte dir=DirTable[2];
\r
823 register KeyboardDef *def;
\r
826 mx = my = motion_None;
\r
830 if (DemoMode == demo_Playback)
\r
832 dbyte = DemoBuffer[DemoOffset + 1];
\r
833 my = (dbyte & 3) - 1;
\r
834 mx = ((dbyte >> 2) & 3) - 1;
\r
835 buttons = (dbyte >> 4) & 3;
\r
837 if (!(--DemoBuffer[DemoOffset]))
\r
840 if (DemoOffset >= DemoSize)
\r
841 DemoMode = demo_PlayDone;
\r
846 else if (DemoMode == demo_PlayDone)
\r
847 Quit ("Demo playback exceeded");
\r
851 switch (type = player[pn].Controls)
\r
853 case ctrl_Keyboard1:
\r
854 case ctrl_Keyboard2:
\r
855 def = &(ININFO_KbdDefs[type - ctrl_Keyboard]);
\r
857 /* if (Keyboard[def->upleft])
\r
858 mx = motion_Left,my = motion_Up;
\r
859 else if (Keyboard[def->upright])
\r
860 mx = motion_Right,my = motion_Up;
\r
861 else if (Keyboard[def->downleft])
\r
862 mx = motion_Left,my = motion_Down;
\r
863 else if (Keyboard[def->downright])
\r
864 mx = motion_Right,my = motion_Down;*/
\r
865 //TODO: make this into a function that the joystick AND keyboard can use wwww
\r
866 if(DIRECTIONIFELSE)//(player[pn].info.dir == 2)
\r
868 if(!inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]){
\r
869 if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]))
\r
871 if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up]))
\r
873 }else if(!inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]){
\r
874 if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]))
\r
876 if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left]))
\r
878 }else{ //2 keys pressed
\r
879 switch (player[pn].pdir)
\r
883 if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])){ dir = DirTable[1]; }//mx = motion_Left; }
\r
884 else if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])){ dir = DirTable[3]; }//mx = motion_Right; }
\r
888 if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])){ dir = DirTable[0]; }//my = motion_Up; }
\r
889 else if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])){ dir = DirTable[4]; }//my = motion_Down; }
\r
894 #ifdef __DEBUG_InputMgr__
\r
895 //if(dbg_testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c ", dirchar(player[pn].pdir)); }
\r
899 //input from player
\r
900 if (inpu.Keyboard[def->button0])
\r
902 if (inpu.Keyboard[def->button1])
\r
906 case ctrl_Joystick1:
\r
907 case ctrl_Joystick2:
\r
908 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);
\r
909 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
\r
913 INL_GetMouseDelta(&dx,&dy);
\r
914 buttons = INL_GetMouseButtons();
\r
924 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
\r
925 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
\r
933 player[pn].info.x = dx;
\r
934 player[pn].info.xaxis = mx;
\r
935 player[pn].info.y = dy;
\r
936 player[pn].info.yaxis = my;
\r
937 player[pn].info.button0 = buttons & (1 << 0);
\r
938 player[pn].info.button1 = buttons & (1 << 1);
\r
939 player[pn].info.button2 = buttons & (1 << 2);
\r
940 player[pn].info.button3 = buttons & (1 << 3);
\r
941 // player[pn].info.dir = DirTable[((my + 1) * 3) + (mx + 1)];
\r
942 conpee=(((my + 1) * 2) + (mx + 1))-1;
\r
943 player[pn].info.dir = DirTable[conpee];
\r
945 if(DirTable[conpee]!=2) player[pn].pdir=DirTable[conpee];
\r
946 if(player[pn].enti.q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None)))
\r
948 if(dir==2) player[pn].enti.d = player[pn].info.dir;
\r
949 else player[pn].enti.d = DirTable[dir];
\r
953 if (DemoMode == demo_Record)
\r
955 // Pack the control info into a byte
\r
956 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);
\r
960 (DemoBuffer[DemoOffset + 1] == dbyte)
\r
961 && (DemoBuffer[DemoOffset] < 255)
\r
963 (DemoBuffer[DemoOffset])++;
\r
966 if (DemoOffset || DemoBuffer[DemoOffset])
\r
969 if (DemoOffset >= DemoSize)
\r
970 Quit ("Demo buffer overflow");
\r
972 DemoBuffer[DemoOffset] = 1;
\r
973 DemoBuffer[DemoOffset + 1] = dbyte;
\r
977 #ifdef __DEBUG_InputMgr__
\r
978 if(dbg_testcontrolnoisy > 0)
\r
979 if(player[pn].info.dir!=2/*(inpu.Keyboard[def->up] || inpu.Keyboard[def->down] || inpu.Keyboard[def->left] || inpu.Keyboard[def->right])*/ || player[pn].enti.q>1)
\r
981 //printf("b1=%u b2=%u b3=%u b4=%u ", player[pn].info.button0, player[pn].info.button1, player[pn].info.button2, player[pn].info.button3);
\r
982 //printf("q=%d ", player[pn].enti.q);
\r
983 //printf("cpee=%c ", dirchar(conpee));
\r
984 printf("pdir=%c d=%c dir=%c ", dirchar(player[pn].pdir), dirchar(player[pn].enti.d), dirchar(player[pn].info.dir));
\r
985 /*if(realdelta) */printf("dx=%d dy=%d mx=%d my=%d", player[pn].info.x, player[pn].info.y, player[pn].info.xaxis, player[pn].info.yaxis);
\r
986 //else if(!realdelta) printf("%c%d %c%d %c%d %c%d", 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
992 ///////////////////////////////////////////////////////////////////////////
\r
994 // IN_SetControlType() - Sets the control type to be used by the specified
\r
997 ///////////////////////////////////////////////////////////////////////////
\r
999 IN_SetControlType(word pn,player_t *player,ControlType type)
\r
1001 // DEBUG - check that requested type is present?
\r
1002 player[pn].Controls = type;
\r
1006 ///////////////////////////////////////////////////////////////////////////
\r
1008 // IN_StartDemoRecord() - Starts the demo recording, using a buffer the
\r
1009 // size passed. Returns if the buffer allocation was successful
\r
1011 ///////////////////////////////////////////////////////////////////////////
\r
1013 IN_StartDemoRecord(word bufsize)
\r
1018 MM_GetPtr((memptr *)&DemoBuffer,bufsize);
\r
1019 DemoMode = demo_Record;
\r
1020 DemoSize = bufsize & ~1;
\r
1022 DemoBuffer[0] = DemoBuffer[1] = 0;
\r
1027 ///////////////////////////////////////////////////////////////////////////
\r
1029 // IN_StartDemoPlayback() - Plays back the demo pointed to of the given size
\r
1031 ///////////////////////////////////////////////////////////////////////////
\r
1033 IN_StartDemoPlayback(byte /*__segment*/ *buffer,word bufsize)
\r
1035 DemoBuffer = buffer;
\r
1036 DemoMode = demo_Playback;
\r
1037 DemoSize = bufsize & ~1;
\r
1041 ///////////////////////////////////////////////////////////////////////////
\r
1043 // IN_StopDemo() - Turns off demo mode
\r
1045 ///////////////////////////////////////////////////////////////////////////
\r
1049 if ((DemoMode == demo_Record) && DemoOffset)
\r
1052 DemoMode = demo_Off;
\r
1055 ///////////////////////////////////////////////////////////////////////////
\r
1057 // IN_FreeDemoBuffer() - Frees the demo buffer, if it's been allocated
\r
1059 ///////////////////////////////////////////////////////////////////////////
\r
1061 IN_FreeDemoBuffer(void)
\r
1064 MM_FreePtr((memptr *)&DemoBuffer);
\r
1069 ///////////////////////////////////////////////////////////////////////////
\r
1071 // IN_GetScanName() - Returns a string containing the name of the
\r
1072 // specified scan code
\r
1074 ///////////////////////////////////////////////////////////////////////////
\r
1076 IN_GetScanName(ScanCode scan)
\r
1081 for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)
\r
1085 return(ScanNames[scan]);
\r
1088 ///////////////////////////////////////////////////////////////////////////
\r
1090 // IN_WaitForKey() - Waits for a scan code, then clears LastScan and
\r
1091 // returns the scan code
\r
1093 ///////////////////////////////////////////////////////////////////////////
\r
1099 while (!(result = inpu.LastScan))
\r
1101 inpu.LastScan = 0;
\r
1105 ///////////////////////////////////////////////////////////////////////////
\r
1107 // IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and
\r
1108 // returns the ASCII value
\r
1110 ///////////////////////////////////////////////////////////////////////////
\r
1116 while (!(result = inpu.LastASCII))
\r
1118 inpu.LastASCII = '\0';
\r
1122 ///////////////////////////////////////////////////////////////////////////
\r
1124 // IN_AckBack() - Waits for either an ASCII keypress or a button press
\r
1126 ///////////////////////////////////////////////////////////////////////////
\r
1132 while (!inpu.LastScan)
\r
1134 if (inpu.MousePresent)
\r
1136 if (INL_GetMouseButtons())
\r
1138 while (INL_GetMouseButtons())
\r
1144 for (i = 0;i < MaxJoys;i++)
\r
1146 if (inpu.JoysPresent[i])
\r
1148 if (IN_GetJoyButtonsDB(i))
\r
1150 while (IN_GetJoyButtonsDB(i))
\r
1158 IN_ClearKey(inpu.LastScan);
\r
1159 inpu.LastScan = sc_None;
\r
1162 ///////////////////////////////////////////////////////////////////////////
\r
1164 // IN_Ack() - Clears user input & then calls IN_AckBack()
\r
1166 ///////////////////////////////////////////////////////////////////////////
\r
1172 if (!inst.IN_Started)
\r
1175 IN_ClearKey(inpu.LastScan);
\r
1176 inpu.LastScan = sc_None;
\r
1178 if (inpu.MousePresent)
\r
1179 while (INL_GetMouseButtons())
\r
1181 for (i = 0;i < MaxJoys;i++)
\r
1182 if (inpu.JoysPresent[i])
\r
1183 while (IN_GetJoyButtonsDB(i))
\r
1189 ///////////////////////////////////////////////////////////////////////////
\r
1191 // IN_IsUserInput() - Returns true if a key has been pressed or a button
\r
1194 ///////////////////////////////////////////////////////////////////////////
\r
1201 result = inpu.LastScan;
\r
1203 if (inpu.MousePresent)
\r
1204 if (INL_GetMouseButtons())
\r
1207 for (i = 0;i < MaxJoys;i++)
\r
1208 if (inpu.JoysPresent[i])
\r
1209 if (INL_GetJoyButtons(i))
\r
1215 ///////////////////////////////////////////////////////////////////////////
\r
1217 // IN_UserInput() - Waits for the specified delay time (in ticks) or the
\r
1218 // user pressing a key or a mouse button. If the clear flag is set, it
\r
1219 // then either clears the key or waits for the user to let the mouse
\r
1222 ///////////////////////////////////////////////////////////////////////////
\r
1224 IN_UserInput(dword delay,boolean clear)
\r
1226 word TimeCount = *clockw;
\r
1229 lasttime = TimeCount;
\r
1232 if (IN_IsUserInput())
\r
1238 } while (TimeCount - lasttime < delay);
\r
1242 //===========================================================================
\r
1245 ===================
\r
1249 ===================
\r
1252 byte IN_MouseButtons (void)
\r
1254 union REGS CPURegs;
\r
1255 if (inpu.MousePresent)
\r
1258 return CPURegs.x.bx;
\r
1266 ===================
\r
1270 ===================
\r
1273 byte IN_JoyButtons (void)
\r
1277 joybits = inp(0x201); // Get all the joystick buttons
\r
1278 joybits >>= 4; // only the high bits are useful
\r
1279 joybits ^= 15; // return with 1=pressed
\r
1284 boolean IN_KeyDown(byte code)
\r
1286 #ifdef __DEBUG_InputMgr__
\r
1289 return inpu.Keyboard[code];
\r
1290 #ifdef __DEBUG_InputMgr__
\r
1292 if(dbg_nointest && kbhit())
\r
1299 void IN_ClearKey(byte code)
\r
1301 inpu.Keyboard[code] = false;
\r
1302 if(code == inpu.LastScan)
\r
1303 inpu.LastScan = sc_None;
\r
1306 boolean IN_qb(byte kee)
\r
1308 #ifdef __DEBUG_InputMgr__
\r
1309 if(dbg_testkeyin) printf("%u\n", inpu.Keyboard[kee]);
\r
1311 if(inpu.Keyboard[kee]==true) return 1;
\r
1315 ScanCode IN_GetLastScan()
\r
1317 return inpu.LastScan;
\r
1320 ScanCode IN_GetCurCode()
\r
1322 return inst.CurCode;
\r