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 boolean testkeyin=0,testcontrolnoisy=0;
\r
44 =============================================================================
\r
48 =============================================================================
\r
52 boolean MousePresent;
\r
53 boolean JoysPresent[MaxJoys];
\r
54 boolean Keyboard[NumCodes];
\r
59 KeyboardDef KbdDefs[MaxKbds];
\r
60 JoystickDef JoyDefs[MaxJoys];
\r
63 //extern inconfig inpu;
\r
64 //inpu.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
\r
67 =============================================================================
\r
71 =============================================================================
\r
74 #ifdef __cplusplus /* Function must be declared C style */
\r
78 static struct instat {
\r
81 ScanCode CurCode,LastCode;
\r
84 static void (*INL_KeyHook)(void);
\r
85 static void interrupt (*OldKeyVect)(void);
\r
86 static char *ParmStringsIN[] = {"nojoys","nomouse",nil};
\r
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
166 // Internal routines
\r
167 ///////////////////////////////////////////////////////////////////////////
\r
169 // INL_KeyService() - Handles a keyboard interrupt (key up/down)
\r
171 ///////////////////////////////////////////////////////////////////////////
\r
175 static boolean special;
\r
177 register byte temp;
\r
179 k = inp(0x60); // Get the scan code
\r
181 // Tell the XT keyboard controller to clear the key
\r
182 outp(0x61,(temp = inp(0x61)) | 0x80);
\r
185 if (k == 0xe0) // Special key prefix
\r
187 else if (k == 0xe1) // Handle Pause key
\r
188 inpu.Paused = true;
\r
191 if (k & 0x80) // Break code
\r
195 // DEBUG - handle special keys: ctl-alt-delete, print scrn
\r
197 inpu.Keyboard[k] = false;
\r
201 inst.LastCode = inst.CurCode;
\r
202 inst.CurCode = inpu.LastScan = k;
\r
203 inpu.Keyboard[k] = true;
\r
206 c = SpecialNames[k];
\r
209 if (k == sc_CapsLock)
\r
211 inst.CapsLock ^= true;
\r
212 // DEBUG - make caps lock light work
\r
215 if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift]) // If shifted
\r
218 if ((c >= 'A') && (c <= 'Z') && inst.CapsLock)
\r
224 if ((c >= 'a') && (c <= 'z') && inst.CapsLock)
\r
229 inpu.LastASCII = c;
\r
235 if (INL_KeyHook && !special)
\r
238 if(testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, inpu.Keyboard[k]);
\r
246 union REGS CPURegs;
\r
248 int86(MouseInt,&CPURegs,&CPURegs);
\r
251 ///////////////////////////////////////////////////////////////////////////
\r
253 // INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
\r
256 ///////////////////////////////////////////////////////////////////////////
\r
258 INL_GetMouseDelta(int *x,int *y)
\r
260 union REGS CPURegs;
\r
266 ///////////////////////////////////////////////////////////////////////////
\r
268 // INL_GetMouseButtons() - Gets the status of the mouse buttons from the
\r
271 ///////////////////////////////////////////////////////////////////////////
\r
273 INL_GetMouseButtons(void)
\r
275 union REGS CPURegs;
\r
279 buttons = CPURegs.x.bx;
\r
283 ///////////////////////////////////////////////////////////////////////////
\r
285 // IN_GetJoyAbs() - Reads the absolute position of the specified joystick
\r
287 ///////////////////////////////////////////////////////////////////////////
\r
289 IN_GetJoyAbs(word joy,word *xp,word *yp)
\r
296 xs = joy? 2 : 0; // Find shift value for x axis
\r
297 xb = 1 << xs; // Use shift value to get x bit mask
\r
298 ys = joy? 3 : 1; // Do the same for y axis
\r
301 // Read the absolute joystick values
\r
304 pushf // Save some registers
\r
307 cli // Make sure an interrupt doesn't screw the timings
\r
312 out dx,al // Clear the resistors
\r
314 mov ah,[xb] // Get masks into registers
\r
317 xor si,si // Clear count registers
\r
319 xor bh,bh // Clear high byte of bx for later
\r
321 push bp // Don't mess up stack frame
\r
325 in al,dx // Get bits indicating whether all are finished
\r
327 dec bp // Check bounding register
\r
328 jz done // We have a silly value - abort
\r
330 mov bl,al // Duplicate the bits
\r
331 and bl,ah // Mask off useless bits (in [xb])
\r
332 add si,bx // Possibly increment count register
\r
333 mov cl,bl // Save for testing later
\r
340 jnz loo // If both bits were 0, drop out
\r
345 mov cl,[xs] // Get the number of bits to shift
\r
346 shr si,cl // and shift the count that many times
\r
351 mov [x],si // Store the values into the variables
\r
356 popf // Restore the registers
\r
363 ///////////////////////////////////////////////////////////////////////////
\r
365 // INL_GetJoyDelta() - Returns the relative movement of the specified
\r
366 // joystick (from +/-127, scaled adaptively)
\r
368 ///////////////////////////////////////////////////////////////////////////
\r
370 INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)
\r
374 word TimeCount = *clockw;
\r
376 static word lasttime;
\r
378 IN_GetJoyAbs(joy,&x,&y);
\r
379 def = inpu.JoyDefs + joy;
\r
381 if (x < def->threshMinX)
\r
383 if (x < def->joyMinX)
\r
386 x = -(x - def->threshMinX);
\r
387 x *= def->joyMultXL;
\r
388 x >>= JoyScaleShift;
\r
389 *dx = (x > 127)? -127 : -x;
\r
391 else if (x > def->threshMaxX)
\r
393 if (x > def->joyMaxX)
\r
396 x = x - def->threshMaxX;
\r
397 x *= def->joyMultXH;
\r
398 x >>= JoyScaleShift;
\r
399 *dx = (x > 127)? 127 : x;
\r
404 if (y < def->threshMinY)
\r
406 if (y < def->joyMinY)
\r
409 y = -(y - def->threshMinY);
\r
410 y *= def->joyMultYL;
\r
411 y >>= JoyScaleShift;
\r
412 *dy = (y > 127)? -127 : -y;
\r
414 else if (y > def->threshMaxY)
\r
416 if (y > def->joyMaxY)
\r
419 y = y - def->threshMaxY;
\r
420 y *= def->joyMultYH;
\r
421 y >>= JoyScaleShift;
\r
422 *dy = (y > 127)? 127 : y;
\r
429 time = (TimeCount - lasttime) / 2;
\r
438 lasttime = TimeCount;
\r
441 ///////////////////////////////////////////////////////////////////////////
\r
443 // INL_GetJoyButtons() - Returns the button status of the specified
\r
446 ///////////////////////////////////////////////////////////////////////////
\r
448 INL_GetJoyButtons(word joy)
\r
450 register word result;
\r
452 result = inp(0x201); // Get all the joystick buttons
\r
453 result >>= joy? 6 : 4; // Shift into bits 0-1
\r
454 result &= 3; // Mask off the useless bits
\r
459 ///////////////////////////////////////////////////////////////////////////
\r
461 // IN_GetJoyButtonsDB() - Returns the de-bounced button status of the
\r
462 // specified joystick
\r
464 ///////////////////////////////////////////////////////////////////////////
\r
466 IN_GetJoyButtonsDB(word joy)
\r
468 word TimeCount = *clockw;
\r
470 word result1,result2;
\r
474 result1 = INL_GetJoyButtons(joy);
\r
475 lasttime = TimeCount;
\r
476 while(TimeCount == lasttime)
\r
477 result2 = INL_GetJoyButtons(joy);
\r
478 } while(result1 != result2);
\r
482 ///////////////////////////////////////////////////////////////////////////
\r
484 // INL_StartKbd() - Sets up my keyboard stuff for use
\r
486 ///////////////////////////////////////////////////////////////////////////
\r
490 INL_KeyHook = 0; // Clear key hook
\r
492 IN_ClearKeysDown();
\r
494 OldKeyVect = _dos_getvect(KeyInt);
\r
495 _dos_setvect(KeyInt,INL_KeyService);
\r
498 ///////////////////////////////////////////////////////////////////////////
\r
500 // INL_ShutKbd() - Restores keyboard control to the BIOS
\r
502 ///////////////////////////////////////////////////////////////////////////
\r
506 pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags
\r
508 _dos_setvect(KeyInt,OldKeyVect);
\r
511 ///////////////////////////////////////////////////////////////////////////
\r
513 // INL_StartMouse() - Detects and sets up the mouse
\r
515 ///////////////////////////////////////////////////////////////////////////
\r
517 INL_StartMouse(void)
\r
519 union REGS CPURegs;
\r
520 if(_dos_getvect(MouseInt))
\r
523 if(CPURegs.x.ax == 0xffff)
\r
529 ///////////////////////////////////////////////////////////////////////////
\r
531 // INL_ShutMouse() - Cleans up after the mouse
\r
533 ///////////////////////////////////////////////////////////////////////////
\r
535 INL_ShutMouse(void)
\r
540 // INL_SetJoyScale() - Sets up scaling values for the specified joystick
\r
543 INL_SetJoyScale(word joy)
\r
547 def = &(inpu.JoyDefs[joy]);
\r
548 def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
\r
549 def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
\r
550 def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
\r
551 def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);
\r
554 ///////////////////////////////////////////////////////////////////////////
\r
556 // IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
\r
557 // to set up scaling values
\r
559 ///////////////////////////////////////////////////////////////////////////
\r
561 IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
\r
566 def = &(inpu.JoyDefs[joy]);
\r
568 def->joyMinX = minx;
\r
569 def->joyMaxX = maxx;
\r
572 def->threshMinX = ((r / 2) - d) + minx;
\r
573 def->threshMaxX = ((r / 2) + d) + minx;
\r
575 def->joyMinY = miny;
\r
576 def->joyMaxY = maxy;
\r
579 def->threshMinY = ((r / 2) - d) + miny;
\r
580 def->threshMaxY = ((r / 2) + d) + miny;
\r
582 INL_SetJoyScale(joy);
\r
585 ///////////////////////////////////////////////////////////////////////////
\r
587 // INL_StartJoy() - Detects & auto-configures the specified joystick
\r
588 // The auto-config assumes the joystick is centered
\r
590 ///////////////////////////////////////////////////////////////////////////
\r
592 INL_StartJoy(word joy)
\r
596 IN_GetJoyAbs(joy,&x,&y);
\r
600 ((x == 0) || (x > MaxJoyValue - 10))
\r
601 || ((y == 0) || (y > MaxJoyValue - 10))
\r
606 IN_SetupJoy(joy,0,x * 2,0,y * 2);
\r
611 ///////////////////////////////////////////////////////////////////////////
\r
613 // INL_ShutJoy() - Cleans up the joystick stuff
\r
615 ///////////////////////////////////////////////////////////////////////////
\r
617 INL_ShutJoy(word joy)
\r
619 inpu.JoysPresent[joy] = false;
\r
624 ///////////////////////////////////////////////////////////////////////////
\r
626 // IN_Startup() - Starts up the Input Mgr
\r
628 ///////////////////////////////////////////////////////////////////////////
\r
632 boolean checkjoys,checkmouse;
\r
635 if (inst.IN_Started)
\r
640 for (i = 1;i < __argc;i++)
\r
642 switch (US_CheckParm(__argv[i],ParmStringsIN))
\r
648 checkmouse = false;
\r
654 inpu.MousePresent = checkmouse? INL_StartMouse() : false;
\r
656 for (i = 0;i < MaxJoys;i++)
\r
657 inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
\r
659 inst.IN_Started = true;
\r
663 ///////////////////////////////////////////////////////////////////////////
\r
665 // IN_Default() - Sets up default conditions for the Input Mgr
\r
667 ///////////////////////////////////////////////////////////////////////////
\r
669 IN_Default(boolean gotit,player_t *player,ControlType nt)
\r
675 || ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0])
\r
676 || ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1])
\r
677 || ((nt == ctrl_Mouse) && !inpu.MousePresent)
\r
679 nt = ctrl_Keyboard1;
\r
680 inpu.KbdDefs[0].button0 = 0x1c;
\r
681 inpu.KbdDefs[0].button1 = 0x38;
\r
682 //in.KbdDefs[0].upleft = 0x47;
\r
683 inpu.KbdDefs[0].up = 0x48;
\r
684 //in.KbdDefs[0].upright = 0x49;
\r
685 inpu.KbdDefs[0].left = 0x4b;
\r
686 inpu.KbdDefs[0].right = 0x4d;
\r
687 //in.KbdDefs[0].downleft = 0x4f;
\r
688 inpu.KbdDefs[0].down = 0x50;
\r
689 //in.KbdDefs[0].downright = 0x51;
\r
690 IN_SetControlType(0,player,nt);
\r
691 for(i=0; i>MaxPlayers;i++)
\r
695 ///////////////////////////////////////////////////////////////////////////
\r
697 // IN_Shutdown() - Shuts down the Input Mgr
\r
699 ///////////////////////////////////////////////////////////////////////////
\r
705 if (!inst.IN_Started)
\r
709 for (i = 0;i < MaxJoys;i++)
\r
713 inst.IN_Started = false;
\r
716 ///////////////////////////////////////////////////////////////////////////
\r
718 // IN_SetKeyHook() - Sets the routine that gets called by INL_KeyService()
\r
719 // everytime a real make/break code gets hit
\r
721 ///////////////////////////////////////////////////////////////////////////
\r
723 IN_SetKeyHook(void (*hook)())
\r
725 INL_KeyHook = hook;
\r
728 ///////////////////////////////////////////////////////////////////////////
\r
730 // IN_ClearKeyDown() - Clears the keyboard array
\r
732 ///////////////////////////////////////////////////////////////////////////
\r
738 inpu.LastScan = sc_None;
\r
739 inpu.LastASCII = key_None;
\r
740 memset (inpu.Keyboard,0,sizeof(inpu.Keyboard));
\r
743 ///////////////////////////////////////////////////////////////////////////
\r
745 // INL_AdjustCursor() - Internal routine of common code from IN_ReadCursor()
\r
747 ///////////////////////////////////////////////////////////////////////////
\r
749 INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
\r
751 if (buttons & (1 << 0))
\r
752 info->button0 = true;
\r
753 if (buttons & (1 << 1))
\r
754 info->button1 = true;
\r
760 ///////////////////////////////////////////////////////////////////////////
\r
762 // IN_ReadCursor() - Reads the input devices and fills in the cursor info
\r
765 ///////////////////////////////////////////////////////////////////////////
\r
767 IN_ReadCursor(CursorInfo *info)
\r
773 info->x = info->y = 0;
\r
774 info->button0 = info->button1 = false;
\r
776 if (inpu.MousePresent)
\r
778 buttons = INL_GetMouseButtons();
\r
779 INL_GetMouseDelta(&dx,&dy);
\r
780 INL_AdjustCursor(info,buttons,dx,dy);
\r
783 for (i = 0;i < MaxJoys;i++)
\r
785 if (!inpu.JoysPresent[i])
\r
788 buttons = INL_GetJoyButtons(i);
\r
789 INL_GetJoyDelta(i,&dx,&dy,true);
\r
792 INL_AdjustCursor(info,buttons,dx,dy);
\r
796 ///////////////////////////////////////////////////////////////////////////
\r
798 // IN_ReadControl() - Reads the device associated with the specified
\r
799 // player and fills in the control info struct
\r
801 ///////////////////////////////////////////////////////////////////////////
\r
803 IN_ReadControl(int pn,player_t *player)
\r
812 byte dir=DirTable[2];
\r
813 register KeyboardDef *def;
\r
816 mx = my = motion_None;
\r
820 if (DemoMode == demo_Playback)
\r
822 dbyte = DemoBuffer[DemoOffset + 1];
\r
823 my = (dbyte & 3) - 1;
\r
824 mx = ((dbyte >> 2) & 3) - 1;
\r
825 buttons = (dbyte >> 4) & 3;
\r
827 if (!(--DemoBuffer[DemoOffset]))
\r
830 if (DemoOffset >= DemoSize)
\r
831 DemoMode = demo_PlayDone;
\r
836 else if (DemoMode == demo_PlayDone)
\r
837 Quit("Demo playback exceeded");
\r
841 switch (type = player[pn].Controls)
\r
843 case ctrl_Keyboard1:
\r
844 case ctrl_Keyboard2:
\r
845 def = &(inpu.KbdDefs[type - ctrl_Keyboard]);
\r
847 /* if (Keyboard[def->upleft])
\r
848 mx = motion_Left,my = motion_Up;
\r
849 else if (Keyboard[def->upright])
\r
850 mx = motion_Right,my = motion_Up;
\r
851 else if (Keyboard[def->downleft])
\r
852 mx = motion_Left,my = motion_Down;
\r
853 else if (Keyboard[def->downright])
\r
854 mx = motion_Right,my = motion_Down;*/
\r
855 //TODO: make this into a function that the joystick AND keyboard can use wwww
\r
856 if(DIRECTIONIFELSE)//(player[pn].info.dir == 2)
\r
858 if(!inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]){
\r
859 if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]))
\r
861 if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up]))
\r
863 }else if(!inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]){
\r
864 if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]))
\r
866 if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left]))
\r
868 }else{ //2 keys pressed
\r
869 switch (player[pn].pdir)
\r
873 if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])){ dir = DirTable[1]; }//mx = motion_Left; }
\r
874 else if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])){ dir = DirTable[3]; }//mx = motion_Right; }
\r
878 if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])){ dir = DirTable[0]; }//my = motion_Up; }
\r
879 else if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])){ dir = DirTable[4]; }//my = motion_Down; }
\r
884 //if(testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c ", dirchar(player[pn].pdir)); }
\r
887 //input from player
\r
888 if (inpu.Keyboard[def->button0])
\r
890 if (inpu.Keyboard[def->button1])
\r
894 case ctrl_Joystick1:
\r
895 case ctrl_Joystick2:
\r
896 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);
\r
897 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
\r
901 INL_GetMouseDelta(&dx,&dy);
\r
902 buttons = INL_GetMouseButtons();
\r
912 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
\r
913 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
\r
921 player[pn].info.x = dx;
\r
922 player[pn].info.xaxis = mx;
\r
923 player[pn].info.y = dy;
\r
924 player[pn].info.yaxis = my;
\r
925 player[pn].info.button0 = buttons & (1 << 0);
\r
926 player[pn].info.button1 = buttons & (1 << 1);
\r
927 player[pn].info.button2 = buttons & (1 << 2);
\r
928 player[pn].info.button3 = buttons & (1 << 3);
\r
929 // player[pn].info.dir = DirTable[((my + 1) * 3) + (mx + 1)];
\r
930 conpee=(((my + 1) * 2) + (mx + 1))-1;
\r
931 player[pn].info.dir = DirTable[conpee];
\r
933 if(DirTable[conpee]!=2) player[pn].pdir=DirTable[conpee];
\r
934 if(player[pn].q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None)))
\r
936 if(dir==2) player[pn].d = player[pn].info.dir;
\r
937 else player[pn].d = DirTable[dir];
\r
941 if (DemoMode == demo_Record)
\r
943 // Pack the control info into a byte
\r
944 dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);
\r
948 (DemoBuffer[DemoOffset + 1] == dbyte)
\r
949 && (DemoBuffer[DemoOffset] < 255)
\r
951 (DemoBuffer[DemoOffset])++;
\r
954 if (DemoOffset || DemoBuffer[DemoOffset])
\r
957 if (DemoOffset >= DemoSize)
\r
958 Quit("Demo buffer overflow");
\r
960 DemoBuffer[DemoOffset] = 1;
\r
961 DemoBuffer[DemoOffset + 1] = dbyte;
\r
965 if(testcontrolnoisy > 0)
\r
966 if(player[pn].info.dir!=2/*(inpu.Keyboard[def->up] || inpu.Keyboard[def->down] || inpu.Keyboard[def->left] || inpu.Keyboard[def->right])*/ || player[pn].q>1)
\r
968 //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
969 //printf("q=%d ", player[pn].q);
\r
970 //printf("cpee=%c ", dirchar(conpee));
\r
971 printf("pdir=%c d=%c dir=%c ", dirchar(player[pn].pdir), dirchar(player[pn].d), dirchar(player[pn].info.dir));
\r
972 /*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
973 //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
978 ///////////////////////////////////////////////////////////////////////////
\r
980 // IN_SetControlType() - Sets the control type to be used by the specified
\r
983 ///////////////////////////////////////////////////////////////////////////
\r
985 IN_SetControlType(word pn,player_t *player,ControlType type)
\r
987 // DEBUG - check that requested type is present?
\r
988 player[pn].Controls = type;
\r
992 ///////////////////////////////////////////////////////////////////////////
\r
994 // IN_StartDemoRecord() - Starts the demo recording, using a buffer the
\r
995 // size passed. Returns if the buffer allocation was successful
\r
997 ///////////////////////////////////////////////////////////////////////////
\r
999 IN_StartDemoRecord(word bufsize)
\r
1004 MM_GetPtr((memptr *)&DemoBuffer,bufsize);
\r
1005 DemoMode = demo_Record;
\r
1006 DemoSize = bufsize & ~1;
\r
1008 DemoBuffer[0] = DemoBuffer[1] = 0;
\r
1013 ///////////////////////////////////////////////////////////////////////////
\r
1015 // IN_StartDemoPlayback() - Plays back the demo pointed to of the given size
\r
1017 ///////////////////////////////////////////////////////////////////////////
\r
1019 IN_StartDemoPlayback(byte /*__segment*/ *buffer,word bufsize)
\r
1021 DemoBuffer = buffer;
\r
1022 DemoMode = demo_Playback;
\r
1023 DemoSize = bufsize & ~1;
\r
1027 ///////////////////////////////////////////////////////////////////////////
\r
1029 // IN_StopDemo() - Turns off demo mode
\r
1031 ///////////////////////////////////////////////////////////////////////////
\r
1035 if ((DemoMode == demo_Record) && DemoOffset)
\r
1038 DemoMode = demo_Off;
\r
1041 ///////////////////////////////////////////////////////////////////////////
\r
1043 // IN_FreeDemoBuffer() - Frees the demo buffer, if it's been allocated
\r
1045 ///////////////////////////////////////////////////////////////////////////
\r
1047 IN_FreeDemoBuffer(void)
\r
1050 MM_FreePtr((memptr *)&DemoBuffer);
\r
1055 ///////////////////////////////////////////////////////////////////////////
\r
1057 // IN_GetScanName() - Returns a string containing the name of the
\r
1058 // specified scan code
\r
1060 ///////////////////////////////////////////////////////////////////////////
\r
1062 IN_GetScanName(ScanCode scan)
\r
1067 for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)
\r
1071 return(ScanNames[scan]);
\r
1074 ///////////////////////////////////////////////////////////////////////////
\r
1076 // IN_WaitForKey() - Waits for a scan code, then clears LastScan and
\r
1077 // returns the scan code
\r
1079 ///////////////////////////////////////////////////////////////////////////
\r
1085 while (!(result = inpu.LastScan))
\r
1087 inpu.LastScan = 0;
\r
1091 ///////////////////////////////////////////////////////////////////////////
\r
1093 // IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and
\r
1094 // returns the ASCII value
\r
1096 ///////////////////////////////////////////////////////////////////////////
\r
1102 while (!(result = inpu.LastASCII))
\r
1104 inpu.LastASCII = '\0';
\r
1108 ///////////////////////////////////////////////////////////////////////////
\r
1110 // IN_AckBack() - Waits for either an ASCII keypress or a button press
\r
1112 ///////////////////////////////////////////////////////////////////////////
\r
1118 while (!inpu.LastScan)
\r
1120 if (inpu.MousePresent)
\r
1122 if (INL_GetMouseButtons())
\r
1124 while (INL_GetMouseButtons())
\r
1130 for (i = 0;i < MaxJoys;i++)
\r
1132 if (inpu.JoysPresent[i])
\r
1134 if (IN_GetJoyButtonsDB(i))
\r
1136 while (IN_GetJoyButtonsDB(i))
\r
1144 IN_ClearKey(inpu.LastScan);
\r
1145 inpu.LastScan = sc_None;
\r
1148 ///////////////////////////////////////////////////////////////////////////
\r
1150 // IN_Ack() - Clears user input & then calls IN_AckBack()
\r
1152 ///////////////////////////////////////////////////////////////////////////
\r
1158 IN_ClearKey(inpu.LastScan);
\r
1159 inpu.LastScan = sc_None;
\r
1161 if (inpu.MousePresent)
\r
1162 while (INL_GetMouseButtons())
\r
1164 for (i = 0;i < MaxJoys;i++)
\r
1165 if (inpu.JoysPresent[i])
\r
1166 while (IN_GetJoyButtonsDB(i))
\r
1172 ///////////////////////////////////////////////////////////////////////////
\r
1174 // IN_IsUserInput() - Returns true if a key has been pressed or a button
\r
1177 ///////////////////////////////////////////////////////////////////////////
\r
1184 result = inpu.LastScan;
\r
1186 if (inpu.MousePresent)
\r
1187 if (INL_GetMouseButtons())
\r
1190 for (i = 0;i < MaxJoys;i++)
\r
1191 if (inpu.JoysPresent[i])
\r
1192 if (INL_GetJoyButtons(i))
\r
1198 ///////////////////////////////////////////////////////////////////////////
\r
1200 // IN_UserInput() - Waits for the specified delay time (in ticks) or the
\r
1201 // user pressing a key or a mouse button. If the clear flag is set, it
\r
1202 // then either clears the key or waits for the user to let the mouse
\r
1205 ///////////////////////////////////////////////////////////////////////////
\r
1207 IN_UserInput(dword delay,boolean clear)
\r
1209 word TimeCount = *clockw;
\r
1212 lasttime = TimeCount;
\r
1215 if (IN_IsUserInput())
\r
1221 } while (TimeCount - lasttime < delay);
\r
1225 boolean IN_KeyDown(byte code)
\r
1227 return inpu.Keyboard[code];
\r
1230 void IN_ClearKey(byte code)
\r
1232 inpu.Keyboard[code] = false;
\r
1233 if(code == inpu.LastScan)
\r
1234 inpu.LastScan = sc_None;
\r
1237 boolean IN_qb(byte kee)
\r
1239 //#ifdef TESTKEYIN
\r
1240 // if(testkeyin > 0) printf("%u\n", inpu.Keyboard[kee]);
\r
1242 if(inpu.Keyboard[kee]==true) return 1;
\r
1247 void IN_initplayer(player_t *player, word pn)
\r
1249 player[pn].x = player[pn].tx*TILEWH;
\r
1250 player[pn].y = player[pn].ty*TILEWH;
\r
1251 player[pn].triggerx = player[pn].tx;
\r
1252 player[pn].triggery = player[pn].ty+1;
\r
1253 /* player[0].info.x = player[0].tx;
\r
1254 player[0].info.xaxis = player[0].tx*TILEWH;
\r
1255 player[0].info.y = player[0].ty;
\r
1256 player[0].info.yaxis = player[0].ty*TILEWH;*/
\r
1260 player[pn].speed=4;
\r
1261 player[pn].persist_aniframe=0;
\r
1262 player[pn].spt=(TILEWH/(player[pn].speed)); //speed per tile wwww
\r