3 // ID_IN.c - Input Manager
\r
5 // By Jason Blochowiak
\r
6 // Open Watcom port by sparky4
\r
10 // This module handles dealing with the various input devices
\r
12 // Depends on: Memory Mgr (for demo recording), Sound Mgr (for timing stuff),
\r
13 // User Mgr (for command line parms)
\r
16 // LastScan - The keyboard scan code of the last key pressed
\r
17 // LastASCII - The ASCII value of the last key pressed
\r
18 // DEBUG - there are more globals
\r
21 #include "src/lib/16_in.h"
\r
24 static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */
\r
27 =============================================================================
\r
31 =============================================================================
\r
35 boolean MousePresent;
\r
36 boolean JoysPresent[MaxJoys];
\r
37 boolean Keyboard[NumCodes];
\r
42 KeyboardDef KbdDefs[MaxKbds];
\r
43 JoystickDef JoyDefs[MaxJoys];
\r
46 //inpu.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
\r
49 =============================================================================
\r
53 =============================================================================
\r
56 #ifdef __cplusplus /* Function must be declared C style */
\r
60 static struct instat {
\r
63 ScanCode CurCode,LastCode;
\r
66 static byte far ASCIINames[] = // Unshifted ASCII for scan codes
\r
68 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
69 0 ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8 ,9 , // 0
\r
70 'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0 ,'a','s', // 1
\r
71 'd','f','g','h','j','k','l',';',39 ,'`',0 ,92 ,'z','x','c','v', // 2
\r
72 'b','n','m',',','.','/',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
73 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
74 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
75 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
76 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
78 far ShiftNames[] = // Shifted ASCII for scan codes
\r
80 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
81 0 ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8 ,9 , // 0
\r
82 'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0 ,'A','S', // 1
\r
83 'D','F','G','H','J','K','L',':',34 ,'~',0 ,'|','Z','X','C','V', // 2
\r
84 'B','N','M','<','>','?',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
85 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
\r
86 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
\r
87 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
\r
88 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
\r
90 far SpecialNames[] = // ASCII for 0xe0 prefixed codes
\r
92 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
\r
93 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 0
\r
94 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,13 ,0 ,0 ,0 , // 1
\r
95 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 2
\r
96 0 ,0 ,0 ,0 ,0 ,'/',0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 3
\r
97 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 4
\r
98 0 ,0 ,0 ,0 ,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 *ScanNames[] = // Scan code names with single chars
\r
104 "?","?","1","2","3","4","5","6","7","8","9","0","-","+","?","?",
\r
105 "Q","W","E","R","T","Y","U","I","O","P","[","]","|","?","A","S",
\r
106 "D","F","G","H","J","K","L",";","\"","?","?","?","Z","X","C","V",
\r
107 "B","N","M",",",".","/","?","?","?","?","?","?","?","?","?","?",
\r
108 "?","?","?","?","?","?","?","?","\xf","?","-","\x15","5","\x11","+","?",
\r
109 "\x13","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
110 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",
\r
111 "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"
\r
112 }, // DEBUG - consolidate these
\r
113 far ExtScanCodes[] = // Scan codes with >1 char names
\r
115 1,0xe,0xf,0x1d,0x2a,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,
\r
116 0x3f,0x40,0x41,0x42,0x43,0x44,0x57,0x59,0x46,0x1c,0x36,
\r
117 0x37,0x38,0x47,0x49,0x4f,0x51,0x52,0x53,0x45,0x48,
\r
118 0x50,0x4b,0x4d,0x00
\r
120 *ExtScanNames[] = // Names corresponding to ExtScanCodes
\r
122 "Esc","BkSp","Tab","Ctrl","LShft","Space","CapsLk","F1","F2","F3","F4",
\r
123 "F5","F6","F7","F8","F9","F10","F11","F12","ScrlLk","Enter","RShft",
\r
124 "PrtSc","Alt","Home","PgUp","End","PgDn","Ins","Del","NumLk","Up",
\r
125 "Down","Left","Right",""
\r
128 static Direction DirTable[] = // Quick lookup for total direction
\r
130 /*dir_NorthWest, */dir_North,/* dir_NorthEast,*/
\r
131 dir_West, dir_None, dir_East,
\r
132 /*dir_SouthWest, */dir_South/*, dir_SouthEast*/
\r
138 static void (*INL_KeyHook)(void);
\r
139 static void interrupt (*OldKeyVect)(void);
\r
140 static char *ParmStringsIN[] = {"nojoys","nomouse",nil};
\r
142 // Internal routines
\r
144 ///////////////////////////////////////////////////////////////////////////
\r
146 // INL_KeyService() - Handles a keyboard interrupt (key up/down)
\r
148 ///////////////////////////////////////////////////////////////////////////
\r
149 /*static */void interrupt
\r
150 INL_KeyService(void)
\r
152 static boolean special;
\r
156 k = inportb(0x60); // Get the scan code
\r
158 // Tell the XT keyboard controller to clear the key
\r
159 outportb(0x61,(temp = inportb(0x61)) | 0x80);
\r
160 outportb(0x61,temp);
\r
162 if (k == 0xe0) // Special key prefix
\r
164 else if (k == 0xe1) // Handle Pause key
\r
165 inpu.Paused = true;
\r
168 if (k & 0x80) // Break code
\r
172 // DEBUG - handle special keys: ctl-alt-delete, print scrn
\r
174 inpu.Keyboard[k] = false;
\r
178 inst.LastCode = inst.CurCode;
\r
179 inst.CurCode = inpu.LastScan = k;
\r
180 inpu.Keyboard[k] = true;
\r
183 c = SpecialNames[k];
\r
186 if (k == sc_CapsLock)
\r
188 inst.CapsLock ^= true;
\r
189 // DEBUG - make caps lock light work
\r
192 if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift]) // If shifted
\r
195 if ((c >= 'A') && (c <= 'Z') && inst.CapsLock)
\r
201 if ((c >= 'a') && (c <= 'z') && inst.CapsLock)
\r
206 inpu.LastASCII = c;
\r
212 if (INL_KeyHook && !special)
\r
214 #ifdef __DEBUG_InputMgr__
\r
215 if(dbg_testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, inpu.Keyboard[k]);
\r
217 outportb(0x20,0x20);
\r
220 void INL_Mouse(int x)
\r
222 //union REGS CPURegs;
\r
223 //x = CPURegs.x.ax;
\r
228 //int86(MouseInt,&CPURegs,&CPURegs);
\r
231 ///////////////////////////////////////////////////////////////////////////
\r
233 // INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
\r
236 ///////////////////////////////////////////////////////////////////////////
\r
238 INL_GetMouseDelta(int *x,int *y)
\r
240 union REGS CPURegs;
\r
246 ///////////////////////////////////////////////////////////////////////////
\r
248 // INL_GetMouseButtons() - Gets the status of the mouse buttons from the
\r
251 ///////////////////////////////////////////////////////////////////////////
\r
253 INL_GetMouseButtons(void)
\r
255 union REGS CPURegs;
\r
259 buttons = CPURegs.x.bx;
\r
263 ///////////////////////////////////////////////////////////////////////////
\r
265 // IN_GetJoyAbs() - Reads the absolute position of the specified joystick
\r
267 ///////////////////////////////////////////////////////////////////////////
\r
269 IN_GetJoyAbs(word joy,word *xp,word *yp)
\r
276 xs = joy? 2 : 0; // Find shift value for x axis
\r
277 xb = 1 << xs; // Use shift value to get x bit mask
\r
278 ys = joy? 3 : 1; // Do the same for y axis
\r
281 // Read the absolute joystick values
\r
283 pushf // Save some registers
\r
286 cli // Make sure an interrupt doesn't screw the timings
\r
291 out dx,al // Clear the resistors
\r
293 mov ah,[xb] // Get masks into registers
\r
296 xor si,si // Clear count registers
\r
298 xor bh,bh // Clear high byte of bx for later
\r
300 push bp // Don't mess up stack frame
\r
302 #ifdef __BORLANDC__
\r
306 #ifdef __BORLANDC__
\r
309 in al,dx // Get bits indicating whether all are finished
\r
311 dec bp // Check bounding register
\r
312 jz done // We have a silly value - abort
\r
314 mov bl,al // Duplicate the bits
\r
315 and bl,ah // Mask off useless bits (in [xb])
\r
316 add si,bx // Possibly increment count register
\r
317 mov cl,bl // Save for testing later
\r
324 jnz loo // If both bits were 0, drop out
\r
325 #ifdef __BORLANDC__
\r
329 #ifdef __BORLANDC__
\r
334 mov cl,[xs] // Get the number of bits to shift
\r
335 shr si,cl // and shift the count that many times
\r
340 mov [x],si // Store the values into the variables
\r
345 popf // Restore the registers
\r
352 ///////////////////////////////////////////////////////////////////////////
\r
354 // INL_GetJoyDelta() - Returns the relative movement of the specified
\r
355 // joystick (from +/-127)
\r
357 ///////////////////////////////////////////////////////////////////////////
\r
358 void INL_GetJoyDelta(word joy,int *dx,int *dy/*,boolean adaptive*/)
\r
361 word TimeCount = *clockw;
\r
363 static word lasttime;
\r
365 IN_GetJoyAbs(joy,&x,&y);
\r
366 def = inpu.JoyDefs + joy;
\r
368 if (x < def->threshMinX)
\r
370 if (x < def->joyMinX)
\r
373 x = -(x - def->threshMinX);
\r
374 x *= def->joyMultXL;
\r
375 x >>= JoyScaleShift;
\r
376 *dx = (x > 127)? -127 : -x;
\r
378 else if (x > def->threshMaxX)
\r
380 if (x > def->joyMaxX)
\r
383 x = x - def->threshMaxX;
\r
384 x *= def->joyMultXH;
\r
385 x >>= JoyScaleShift;
\r
386 *dx = (x > 127)? 127 : x;
\r
391 if (y < def->threshMinY)
\r
393 if (y < def->joyMinY)
\r
396 y = -(y - def->threshMinY);
\r
397 y *= def->joyMultYL;
\r
398 y >>= JoyScaleShift;
\r
399 *dy = (y > 127)? -127 : -y;
\r
401 else if (y > def->threshMaxY)
\r
403 if (y > def->joyMaxY)
\r
406 y = y - def->threshMaxY;
\r
407 y *= def->joyMultYH;
\r
408 y >>= JoyScaleShift;
\r
409 *dy = (y > 127)? 127 : y;
\r
415 // time = (TimeCount - lasttime) / 2;
\r
424 lasttime = TimeCount;
\r
427 ///////////////////////////////////////////////////////////////////////////
\r
429 // INL_GetJoyButtons() - Returns the button status of the specified
\r
432 ///////////////////////////////////////////////////////////////////////////
\r
434 INL_GetJoyButtons(word joy)
\r
436 register word result;
\r
438 result = inportb(0x201); // Get all the joystick buttons
\r
439 result >>= joy? 6 : 4; // Shift into bits 0-1
\r
440 result &= 3; // Mask off the useless bits
\r
445 ///////////////////////////////////////////////////////////////////////////
\r
447 // IN_GetJoyButtonsDB() - Returns the de-bounced button status of the
\r
448 // specified joystick
\r
450 ///////////////////////////////////////////////////////////////////////////
\r
452 IN_GetJoyButtonsDB(word joy)
\r
454 word TimeCount = *clockw;
\r
456 word result1,result2;
\r
460 result1 = INL_GetJoyButtons(joy);
\r
461 lasttime = TimeCount;
\r
462 while(TimeCount == lasttime)
\r
464 result2 = INL_GetJoyButtons(joy);
\r
465 } while(result1 != result2);
\r
469 ///////////////////////////////////////////////////////////////////////////
\r
471 // INL_StartKbd() - Sets up my keyboard stuff for use
\r
473 ///////////////////////////////////////////////////////////////////////////
\r
477 INL_KeyHook = NULL; // Clear key hook
\r
479 IN_ClearKeysDown();
\r
481 OldKeyVect = getvect(KeyInt);//IN_KbdLED();
\r
482 setvect(KeyInt,INL_KeyService);
\r
485 ///////////////////////////////////////////////////////////////////////////
\r
487 // INL_ShutKbd() - Restores keyboard control to the BIOS
\r
489 ///////////////////////////////////////////////////////////////////////////
\r
493 pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags
\r
495 setvect(KeyInt,OldKeyVect);
\r
498 ///////////////////////////////////////////////////////////////////////////
\r
500 // INL_StartMouse() - Detects and sets up the mouse
\r
502 ///////////////////////////////////////////////////////////////////////////
\r
504 INL_StartMouse(void)
\r
507 if (getvect(MouseInt))
\r
518 if ((vector=MK_FP(peek(0,0x33*4+2),peek(0,0x33*4)))==NULL)
\r
521 if (*vector == 207)
\r
528 ///////////////////////////////////////////////////////////////////////////
\r
530 // INL_ShutMouse() - Cleans up after the mouse
\r
532 ///////////////////////////////////////////////////////////////////////////
\r
534 INL_ShutMouse(void)
\r
539 // INL_SetJoyScale() - Sets up scaling values for the specified joystick
\r
542 INL_SetJoyScale(word joy)
\r
546 def = &(inpu.JoyDefs[joy]);
\r
547 def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
\r
548 def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
\r
549 def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
\r
550 def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);
\r
553 ///////////////////////////////////////////////////////////////////////////
\r
555 // IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
\r
556 // to set up scaling values
\r
558 ///////////////////////////////////////////////////////////////////////////
\r
560 IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
\r
565 def = &(inpu.JoyDefs[joy]);
\r
567 def->joyMinX = minx;
\r
568 def->joyMaxX = maxx;
\r
571 def->threshMinX = ((r / 2) - d) + minx;
\r
572 def->threshMaxX = ((r / 2) + d) + minx;
\r
574 def->joyMinY = miny;
\r
575 def->joyMaxY = maxy;
\r
578 def->threshMinY = ((r / 2) - d) + miny;
\r
579 def->threshMaxY = ((r / 2) + d) + miny;
\r
581 INL_SetJoyScale(joy);
\r
584 ///////////////////////////////////////////////////////////////////////////
\r
586 // INL_StartJoy() - Detects & auto-configures the specified joystick
\r
587 // The auto-config assumes the joystick is centered
\r
589 ///////////////////////////////////////////////////////////////////////////
\r
591 INL_StartJoy(word joy)
\r
595 IN_GetJoyAbs(joy,&x,&y);
\r
599 ((x == 0) || (x > MaxJoyValue - 10))
\r
600 || ((y == 0) || (y > MaxJoyValue - 10))
\r
605 IN_SetupJoy(joy,0,x * 2,0,y * 2);
\r
610 ///////////////////////////////////////////////////////////////////////////
\r
612 // INL_ShutJoy() - Cleans up the joystick stuff
\r
614 ///////////////////////////////////////////////////////////////////////////
\r
616 INL_ShutJoy(word joy)
\r
618 inpu.JoysPresent[joy] = false;
\r
623 ///////////////////////////////////////////////////////////////////////////
\r
625 // IN_Startup() - Starts up the Input Mgr
\r
627 ///////////////////////////////////////////////////////////////////////////
\r
631 boolean checkjoys,checkmouse;
\r
634 if (inst.IN_Started)
\r
639 for (i = 1;i < _argc;i++)
\r
641 switch (US_CheckParm(_argv[i],ParmStringsIN))
\r
647 checkmouse = false;
\r
653 inpu.MousePresent = checkmouse? INL_StartMouse() : false;
\r
655 for (i = 0;i < MaxJoys;i++)
\r
656 inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
\r
658 inst.IN_Started = true;
\r
662 ///////////////////////////////////////////////////////////////////////////
\r
664 // IN_Default() - Sets up default conditions for the Input Mgr
\r
666 ///////////////////////////////////////////////////////////////////////////
\r
668 IN_Default(boolean gotit,player_t *player,ControlType nt)
\r
674 || ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0])
\r
675 || ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1])
\r
676 || ((nt == ctrl_Mouse) && !inpu.MousePresent)
\r
678 nt = ctrl_Keyboard1;
\r
679 inpu.KbdDefs[0].button0 = 0x1c;
\r
680 inpu.KbdDefs[0].button1 = 0x38;
\r
681 //in.KbdDefs[0].upleft = 0x47;
\r
682 inpu.KbdDefs[0].up = 0x48;
\r
683 //in.KbdDefs[0].upright = 0x49;
\r
684 inpu.KbdDefs[0].left = 0x4b;
\r
685 inpu.KbdDefs[0].right = 0x4d;
\r
686 //in.KbdDefs[0].downleft = 0x4f;
\r
687 inpu.KbdDefs[0].down = 0x50;
\r
688 //in.KbdDefs[0].downright = 0x51;
\r
689 IN_SetControlType(player,nt);
\r
690 for(i=0; i>MaxPlayers;i++)
\r
691 player[i].enti.d =2;
\r
694 ///////////////////////////////////////////////////////////////////////////
\r
696 // IN_Shutdown() - Shuts down the Input Mgr
\r
698 ///////////////////////////////////////////////////////////////////////////
\r
704 if (!inst.IN_Started)
\r
708 for (i = 0;i < MaxJoys;i++)
\r
712 inst.IN_Started = false;
\r
715 ///////////////////////////////////////////////////////////////////////////
\r
717 // IN_SetKeyHook() - Sets the routine that gets called by INL_KeyService()
\r
718 // everytime a real make/break code gets hit
\r
720 ///////////////////////////////////////////////////////////////////////////
\r
722 IN_SetKeyHook(void (*hook)())
\r
724 INL_KeyHook = hook;
\r
727 ///////////////////////////////////////////////////////////////////////////
\r
729 // IN_ClearKeysDown() - Clears the keyboard array
\r
731 ///////////////////////////////////////////////////////////////////////////
\r
733 IN_ClearKeysDown(void)
\r
737 inpu.LastScan = sc_None;
\r
738 inpu.LastASCII = key_None;
\r
739 memset (inpu.Keyboard,0,sizeof(inpu.Keyboard));
\r
742 ///////////////////////////////////////////////////////////////////////////
\r
744 // INL_AdjustCursor() - Internal routine of common code from IN_ReadCursor()
\r
746 ///////////////////////////////////////////////////////////////////////////
\r
748 INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
\r
750 if (buttons & (1 << 0))
\r
751 info->button0 = true;
\r
752 if (buttons & (1 << 1))
\r
753 info->button1 = true;
\r
759 ///////////////////////////////////////////////////////////////////////////
\r
761 // IN_ReadCursor() - Reads the input devices and fills in the cursor info
\r
764 ///////////////////////////////////////////////////////////////////////////
\r
766 IN_ReadCursor(CursorInfo *info)
\r
772 info->x = info->y = 0;
\r
773 info->button0 = info->button1 = false;
\r
775 if (inpu.MousePresent)
\r
777 buttons = INL_GetMouseButtons();
\r
778 INL_GetMouseDelta(&dx,&dy);
\r
779 INL_AdjustCursor(info,buttons,dx,dy);
\r
782 for (i = 0;i < MaxJoys;i++)
\r
784 if (!inpu.JoysPresent[i])
\r
787 buttons = INL_GetJoyButtons(i);
\r
788 INL_GetJoyDelta(i,&dx,&dy/*,true*/);
\r
791 INL_AdjustCursor(info,buttons,dx,dy);
\r
795 //if else for gfxtesting and direction
\r
796 #define DIRECTIONIFELSE (player->info.dir == 2)
\r
797 //#define NDIRECTIONIFELSE (player->info.dir != 2)
\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(player_t *player)
\r
817 byte dir=DirTable[2];
\r
818 register KeyboardDef *def;
\r
821 mx = my = motion_None;
\r
825 if (DemoMode == demo_Playback)
\r
827 dbyte = DemoBuffer[DemoOffset + 1];
\r
828 my = (dbyte & 3) - 1;
\r
829 mx = ((dbyte >> 2) & 3) - 1;
\r
830 buttons = (dbyte >> 4) & 3;
\r
832 if (!(--DemoBuffer[DemoOffset]))
\r
835 if (DemoOffset >= DemoSize)
\r
836 DemoMode = demo_PlayDone;
\r
841 else if (DemoMode == demo_PlayDone)
\r
842 Quit ("Demo playback exceeded");
\r
846 switch (type = player->Controls)
\r
848 case ctrl_Keyboard1:
\r
849 case ctrl_Keyboard2:
\r
850 def = &(inpu.KbdDefs[type - ctrl_Keyboard]);
\r
852 /* if (Keyboard[def->upleft])
\r
853 mx = motion_Left,my = motion_Up;
\r
854 else if (Keyboard[def->upright])
\r
855 mx = motion_Right,my = motion_Up;
\r
856 else if (Keyboard[def->downleft])
\r
857 mx = motion_Left,my = motion_Down;
\r
858 else if (Keyboard[def->downright])
\r
859 mx = motion_Right,my = motion_Down;*/
\r
860 //TODO: make this into a function that the joystick AND keyboard can use wwww
\r
861 if(DIRECTIONIFELSE)//(player->info.dir == 2)
\r
863 if(!inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]){
\r
864 if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]))
\r
866 if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up]))
\r
868 }else if(!inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]){
\r
869 if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]))
\r
871 if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left]))
\r
873 }else{ //2 keys pressed
\r
874 switch (player->pdir)
\r
878 if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])){ dir = DirTable[1]; }//mx = motion_Left; }
\r
879 else if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])){ dir = DirTable[3]; }//mx = motion_Right; }
\r
883 if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])){ dir = DirTable[0]; }//my = motion_Up; }
\r
884 else if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])){ dir = DirTable[4]; }//my = motion_Down; }
\r
889 #ifdef __DEBUG_InputMgr__
\r
890 //if(dbg_testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c ", dirchar(player->pdir)); }
\r
894 //input from player
\r
895 if (inpu.Keyboard[def->button0])
\r
897 if (inpu.Keyboard[def->button1])
\r
901 case ctrl_Joystick1:
\r
902 case ctrl_Joystick2:
\r
903 INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy/*,false*/);
\r
904 buttons = INL_GetJoyButtons(type - ctrl_Joystick);
\r
908 INL_GetMouseDelta(&dx,&dy);
\r
909 buttons = INL_GetMouseButtons();
\r
919 mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
\r
920 my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
\r
928 player->info.x = dx;
\r
929 player->info.xaxis = mx;
\r
930 player->info.y = dy;
\r
931 player->info.yaxis = my;
\r
932 player->info.button0 = buttons & (1 << 0);
\r
933 player->info.button1 = buttons & (1 << 1);
\r
934 player->info.button2 = buttons & (1 << 2);
\r
935 player->info.button3 = buttons & (1 << 3);
\r
936 // player->info.dir = DirTable[((my + 1) * 3) + (mx + 1)];
\r
937 conpee=(((my + 1) * 2) + (mx + 1))-1;
\r
938 player->info.dir = DirTable[conpee];
\r
940 if(DirTable[conpee]!=2) player->pdir=DirTable[conpee];
\r
941 if(player->enti.q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None)))
\r
943 if(dir==2) player->enti.d = player->info.dir;
\r
944 else player->enti.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 __DEBUG_InputMgr__
\r
973 if(dbg_testcontrolnoisy > 0)
\r
974 if(player->info.dir!=2/*(inpu.Keyboard[def->up] || inpu.Keyboard[def->down] || inpu.Keyboard[def->left] || inpu.Keyboard[def->right])*/ || player->enti.q>1)
\r
976 //printf("b1=%u b2=%u b3=%u b4=%u ", player->info.button0, player->info.button1, player->info.button2, player->info.button3);
\r
977 //printf("q=%d ", player->enti.q);
\r
978 //printf("cpee=%c ", dirchar(conpee));
\r
979 printf("pdir=%c d=%c dir=%c ", dirchar(player->pdir), dirchar(player->enti.d), dirchar(player->info.dir));
\r
980 /*if(realdelta) */printf("dx=%d dy=%d mx=%d my=%d", player->info.x, player->info.y, player->info.xaxis, player->info.yaxis);
\r
981 //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
987 ///////////////////////////////////////////////////////////////////////////
\r
989 // IN_SetControlType() - Sets the control type to be used by the specified
\r
992 ///////////////////////////////////////////////////////////////////////////
\r
994 IN_SetControlType(player_t *player,ControlType type)
\r
996 // DEBUG - check that requested type is present?
\r
997 player->Controls = type;
\r
1001 ///////////////////////////////////////////////////////////////////////////
\r
1003 // IN_StartDemoRecord() - Starts the demo recording, using a buffer the
\r
1004 // size passed. Returns if the buffer allocation was successful
\r
1006 ///////////////////////////////////////////////////////////////////////////
\r
1008 IN_StartDemoRecord(word bufsize)
\r
1013 MM_GetPtr((memptr *)&DemoBuffer,bufsize);
\r
1014 DemoMode = demo_Record;
\r
1015 DemoSize = bufsize & ~1;
\r
1017 DemoBuffer[0] = DemoBuffer[1] = 0;
\r
1022 ///////////////////////////////////////////////////////////////////////////
\r
1024 // IN_StartDemoPlayback() - Plays back the demo pointed to of the given size
\r
1026 ///////////////////////////////////////////////////////////////////////////
\r
1028 IN_StartDemoPlayback(byte /*__segment*/ *buffer,word bufsize)
\r
1030 DemoBuffer = buffer;
\r
1031 DemoMode = demo_Playback;
\r
1032 DemoSize = bufsize & ~1;
\r
1036 ///////////////////////////////////////////////////////////////////////////
\r
1038 // IN_StopDemo() - Turns off demo mode
\r
1040 ///////////////////////////////////////////////////////////////////////////
\r
1044 if ((DemoMode == demo_Record) && DemoOffset)
\r
1047 DemoMode = demo_Off;
\r
1050 ///////////////////////////////////////////////////////////////////////////
\r
1052 // IN_FreeDemoBuffer() - Frees the demo buffer, if it's been allocated
\r
1054 ///////////////////////////////////////////////////////////////////////////
\r
1056 IN_FreeDemoBuffer(void)
\r
1059 MM_FreePtr((memptr *)&DemoBuffer);
\r
1064 ///////////////////////////////////////////////////////////////////////////
\r
1066 // IN_GetScanName() - Returns a string containing the name of the
\r
1067 // specified scan code
\r
1069 ///////////////////////////////////////////////////////////////////////////
\r
1071 IN_GetScanName(ScanCode scan)
\r
1076 for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)
\r
1080 return(ScanNames[scan]);
\r
1083 ///////////////////////////////////////////////////////////////////////////
\r
1085 // IN_WaitForKey() - Waits for a scan code, then clears LastScan and
\r
1086 // returns the scan code
\r
1088 ///////////////////////////////////////////////////////////////////////////
\r
1090 IN_WaitForKey(void)
\r
1094 while (!(result = inpu.LastScan))
\r
1096 inpu.LastScan = 0;
\r
1100 ///////////////////////////////////////////////////////////////////////////
\r
1102 // IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and
\r
1103 // returns the ASCII value
\r
1105 ///////////////////////////////////////////////////////////////////////////
\r
1107 IN_WaitForASCII(void)
\r
1111 while (!(result = inpu.LastASCII))
\r
1113 inpu.LastASCII = '\0';
\r
1117 ///////////////////////////////////////////////////////////////////////////
\r
1119 // IN_Ack() - waits for a button or key press. If a button is down, upon
\r
1120 // calling, it must be released for it to be recognized
\r
1122 ///////////////////////////////////////////////////////////////////////////
\r
1124 boolean btnstate[8];
\r
1126 void IN_StartAck(void)
\r
1128 unsigned i,buttons;
\r
1131 // get initial state of everything
\r
1133 IN_ClearKeysDown();
\r
1134 memset (btnstate,0,sizeof(btnstate));
\r
1136 buttons = IN_JoyButtons () << 4;
\r
1137 if (inpu.MousePresent)
\r
1138 buttons |= IN_MouseButtons ();
\r
1140 for (i=0;i<8;i++,buttons>>=1)
\r
1142 btnstate[i] = true;
\r
1146 boolean IN_CheckAck (void)
\r
1148 unsigned i,buttons;
\r
1151 // see if something has been pressed
\r
1153 if (inpu.LastScan)
\r
1156 buttons = IN_JoyButtons () << 4;
\r
1157 if (inpu.MousePresent)
\r
1158 buttons |= IN_MouseButtons ();
\r
1160 for (i=0;i<8;i++,buttons>>=1)
\r
1167 btnstate[i]=false;
\r
1173 void IN_Ack (void)
\r
1177 while (!IN_CheckAck ())
\r
1181 ///////////////////////////////////////////////////////////////////////////
\r
1183 // IN_IsUserInput() - Returns true if a key has been pressed or a button
\r
1186 ///////////////////////////////////////////////////////////////////////////
\r
1193 result = inpu.LastScan;
\r
1195 if (inpu.MousePresent)
\r
1196 if (INL_GetMouseButtons())
\r
1199 for (i = 0;i < MaxJoys;i++)
\r
1200 if (inpu.JoysPresent[i])
\r
1201 if (INL_GetJoyButtons(i))
\r
1207 ///////////////////////////////////////////////////////////////////////////
\r
1209 // IN_UserInput() - Waits for the specified delay time (in ticks) or the
\r
1210 // user pressing a key or a mouse button. If the clear flag is set, it
\r
1211 // then either clears the key or waits for the user to let the mouse
\r
1214 ///////////////////////////////////////////////////////////////////////////
\r
1215 boolean IN_UserInput(word delay)
\r
1217 word TimeCount = *clockw;
\r
1220 lasttime = TimeCount;
\r
1224 if (IN_CheckAck())
\r
1226 } while (TimeCount - lasttime < delay);
\r
1230 //===========================================================================
\r
1233 ===================
\r
1237 ===================
\r
1240 byte IN_MouseButtons (void)
\r
1242 union REGS CPURegs;
\r
1243 if (inpu.MousePresent)
\r
1246 return CPURegs.x.bx;
\r
1254 ===================
\r
1258 ===================
\r
1261 byte IN_JoyButtons (void)
\r
1265 joybits = inportb(0x201); // Get all the joystick buttons
\r
1266 joybits >>= 4; // only the high bits are useful
\r
1267 joybits ^= 15; // return with 1=pressed
\r
1272 boolean IN_KeyDown(byte code)
\r
1274 #ifdef __DEBUG_InputMgr__
\r
1277 return inpu.Keyboard[code];
\r
1278 #ifdef __DEBUG_InputMgr__
\r
1280 if(dbg_nointest && kbhit())
\r
1287 void IN_ClearKey(byte code)
\r
1289 inpu.Keyboard[code] = false;
\r
1290 if(code == inpu.LastScan)
\r
1291 inpu.LastScan = sc_None;
\r
1294 boolean IN_qb(byte kee)
\r
1296 #ifdef __DEBUG_InputMgr__
\r
1297 if(dbg_testkeyin) printf("%u\n", inpu.Keyboard[kee]);
\r
1299 if(inpu.Keyboard[kee]==true) return 1;
\r
1303 ScanCode IN_GetLastScan()
\r
1305 return inpu.LastScan;
\r
1308 ScanCode IN_GetCurCode()
\r
1310 return inst.CurCode;
\r
1315 byte far *lock_key;
\r
1317 // turn off num-lock via BIOS
\r
1318 lock_key = MK_FP(0x040, 0x017); // Pointing to the address of the bios shift state keys
\r
1319 *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
1320 OldKeyVect(); // call BIOS keyhandler to change keyboard lights
\r