\r
#include "src/lib/16_in.h"\r
\r
-byte testkeyin=0,testcontrolnoisy=0,gfxtest=0;\r
+static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */\r
\r
/*\r
=============================================================================\r
*/\r
struct inconfig\r
{\r
- boolean MousePresent;\r
- boolean JoysPresent[MaxJoys];\r
- boolean JoyPadPresent[MaxPads];\r
+ boolean MousePresent;\r
+ boolean JoysPresent[MaxJoys];\r
boolean Keyboard[NumCodes];\r
boolean Paused;\r
char LastASCII;\r
\r
KeyboardDef KbdDefs[MaxKbds];\r
JoystickDef JoyDefs[MaxJoys];\r
- JoypadDef JoypadDefs[MaxPads];\r
} inpu;\r
\r
//extern inconfig inpu;\r
#endif\r
\r
// Internal routines\r
+\r
///////////////////////////////////////////////////////////////////////////\r
//\r
// INL_KeyService() - Handles a keyboard interrupt (key up/down)\r
\r
if (INL_KeyHook && !special)\r
INL_KeyHook();\r
-//#ifdef TESTKEYIN\r
- if(testkeyin > 0) printf("%c [0x%x %u] %u\n", c, k, k, inpu.Keyboard[k]);\r
-//endif\r
+#ifdef __DEBUG_InputMgr__\r
+ if(dbg_testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, inpu.Keyboard[k]);\r
+#endif\r
outp(0x20,0x20);\r
}\r
\r
void\r
Mouse(int x)\r
{\r
- union REGS CPURegs;\r
- x = CPURegs.x.ax;\r
- int86(MouseInt,&CPURegs,&CPURegs);\r
+ //union REGS CPURegs;\r
+ //x = CPURegs.x.ax;\r
+ __asm {\r
+ mov ax,x\r
+ int MouseInt\r
+ }\r
+ //int86(MouseInt,&CPURegs,&CPURegs);\r
}\r
\r
///////////////////////////////////////////////////////////////////////////\r
yb = 1 << ys;\r
\r
// Read the absolute joystick values\r
- __asm\r
- {\r
+ __asm {\r
pushf // Save some registers\r
push si\r
push di\r
\r
push bp // Don't mess up stack frame\r
mov bp,MaxJoyValue\r
-\r
+#ifdef __BORLANDC__\r
+ }\r
+#endif\r
loo:\r
+#ifdef __BORLANDC__\r
+ __asm {\r
+#endif\r
in al,dx // Get bits indicating whether all are finished\r
\r
dec bp // Check bounding register\r
\r
add cl,bl\r
jnz loo // If both bits were 0, drop out\r
-\r
+#ifdef __BORLANDC__\r
+ }\r
+#endif\r
done:\r
+#ifdef __BORLANDC__\r
+ __asm {\r
+#endif\r
pop bp\r
\r
mov cl,[xs] // Get the number of bits to shift\r
static void\r
INL_StartKbd()\r
{\r
+ byte far *lock_key;\r
INL_KeyHook = 0; // Clear key hook\r
\r
IN_ClearKeysDown();\r
\r
OldKeyVect = _dos_getvect(KeyInt);\r
+\r
+ // turn off num-lock via BIOS\r
+ lock_key = MK_FP(0x040, 0x017); // Pointing to the address of the bios shift state keys\r
+ *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
+ OldKeyVect(); // call BIOS keyhandler to change keyboard lights\r
_dos_setvect(KeyInt,INL_KeyService);\r
}\r
\r
\r
checkjoys = true;\r
checkmouse = true;\r
- for (i = 1;i < __argc;i++)\r
+ for (i = 1;i < _argc;i++)\r
{\r
- switch (US_CheckParm(__argv[i],ParmStringsIN))\r
+ switch (US_CheckParm(_argv[i],ParmStringsIN))\r
{\r
case 0:\r
checkjoys = false;\r
inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;\r
\r
inst.IN_Started = true;\r
+\r
}\r
\r
///////////////////////////////////////////////////////////////////////////\r
|| ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0])\r
|| ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1])\r
|| ((nt == ctrl_Mouse) && !inpu.MousePresent)\r
- || ((nt == ctrl_Joypad1) && !inpu.JoyPadPresent[0])\r
- || ((nt == ctrl_Joypad2) && !inpu.JoyPadPresent[1])\r
)\r
nt = ctrl_Keyboard1;\r
inpu.KbdDefs[0].button0 = 0x1c;\r
//in.KbdDefs[0].downright = 0x51;\r
IN_SetControlType(0,player,nt);\r
for(i=0; i>MaxPlayers;i++)\r
- player[i].d=2;\r
+ player[i].enti.d =2;\r
}\r
\r
///////////////////////////////////////////////////////////////////////////\r
void\r
IN_ClearKeysDown()\r
{\r
- int i;\r
+ //int i;\r
\r
inpu.LastScan = sc_None;\r
inpu.LastASCII = key_None;\r
//\r
///////////////////////////////////////////////////////////////////////////\r
void near\r
-IN_ReadControl(int pn,player_t *player)\r
+IN_ReadControl(word pn, player_t *player)\r
{\r
boolean realdelta;\r
+#if DEMO0\r
byte dbyte;\r
+#endif\r
word buttons;\r
int dx,dy;\r
Motion mx,my;\r
ControlType type;\r
sword conpee;\r
+ byte dir=DirTable[2];\r
register KeyboardDef *def;\r
\r
dx = dy = 0;\r
realdelta = false;\r
}\r
else if (DemoMode == demo_PlayDone)\r
- Quit("Demo playback exceeded");\r
+ Quit ("Demo playback exceeded");\r
else\r
{\r
#endif\r
mx = motion_Left,my = motion_Down;\r
else if (Keyboard[def->downright])\r
mx = motion_Right,my = motion_Down;*/\r
- if(DIRECTIONIFELSEGFXTEST)\r
+//TODO: make this into a function that the joystick AND keyboard can use wwww\r
+ if(DIRECTIONIFELSE)//(player[pn].info.dir == 2)\r
{\r
- if(!inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]){// && (inpu.Keyboard[def->up] || inpu.Keyboard[def->down])){\r
-// if(testcontrolnoisy > 0){ printf("ud "); printf("%u ", inpu.Keyboard[def->up]); printf("%u ", inpu.Keyboard[def->down]);}\r
- if(inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])// || player[pn].info.pdir == 0)\r
+ if(!inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]){\r
+ if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]))\r
my = motion_Up;\r
- if(inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])// || player[pn].info.pdir == 4)\r
+ if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up]))\r
my = motion_Down;\r
- }else if(!inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]){// && (inpu.Keyboard[def->left] || inpu.Keyboard[def->right])){\r
-// if(testcontrolnoisy > 0){ printf("lr "); printf("%u ", inpu.Keyboard[def->left]); printf("%u ", inpu.Keyboard[def->right]); }\r
- if(inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])// || player[pn].info.pdir == 1)\r
+ }else if(!inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]){\r
+ if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]))\r
mx = motion_Left;\r
- if(inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])// || player[pn].info.pdir == 3)\r
+ if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left]))\r
mx = motion_Right;\r
+ }else{ //2 keys pressed\r
+ switch (player[pn].pdir)\r
+ {\r
+ case 0:\r
+ case 4:\r
+ if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])){ dir = DirTable[1]; }//mx = motion_Left; }\r
+ else if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])){ dir = DirTable[3]; }//mx = motion_Right; }\r
+ break;\r
+ case 1:\r
+ case 3:\r
+ if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])){ dir = DirTable[0]; }//my = motion_Up; }\r
+ else if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])){ dir = DirTable[4]; }//my = motion_Down; }\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+#ifdef __DEBUG_InputMgr__\r
+ //if(dbg_testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c ", dirchar(player[pn].pdir)); }\r
+#endif\r
}\r
}\r
//input from player\r
buttons = INL_GetMouseButtons();\r
realdelta = true;\r
break;\r
- case ctrl_Joypad1:\r
- case ctrl_Joypad2:\r
- printf("wwww");\r
- break;\r
}\r
#ifdef DEMO0\r
}\r
player[pn].info.button2 = buttons & (1 << 2);\r
player[pn].info.button3 = buttons & (1 << 3);\r
// player[pn].info.dir = DirTable[((my + 1) * 3) + (mx + 1)];\r
- conpee=(((my + 1) * 2) + (mx + 1))-1; //if(conpee) conpee--;\r
+ conpee=(((my + 1) * 2) + (mx + 1))-1;\r
player[pn].info.dir = DirTable[conpee];\r
- if(DIRECTIONIFELSEGFXTEST && player[pn].d != player[pn].info.dir) player[pn].pdir=DirTable[conpee];\r
- if(player[pn].q==1 && (mx!=motion_None || my!=motion_None))\r
+\r
+ if(DirTable[conpee]!=2) player[pn].pdir=DirTable[conpee];\r
+ if(player[pn].enti.q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None)))\r
{\r
- player[pn].d = player[pn].info.dir;\r
- //printf("q =%d ", player[pn].q);\r
- //if(testcontrolnoisy > 0)\r
- //if(testcontrolnoisy > 0)\r
- //printf("cpee=%d ", conpee);\r
+ if(dir==2) player[pn].enti.d = player[pn].info.dir;\r
+ else player[pn].enti.d = DirTable[dir];\r
}\r
- if(testcontrolnoisy > 0)\r
\r
#if DEMO0\r
if (DemoMode == demo_Record)\r
DemoOffset += 2;\r
\r
if (DemoOffset >= DemoSize)\r
- Quit("Demo buffer overflow");\r
+ Quit ("Demo buffer overflow");\r
\r
DemoBuffer[DemoOffset] = 1;\r
DemoBuffer[DemoOffset + 1] = dbyte;\r
}\r
}\r
#endif\r
-//#ifdef TESTCONTROLNOISY\r
-if(testcontrolnoisy > 0)\r
-if((inpu.Keyboard[def->up] || inpu.Keyboard[def->down] || inpu.Keyboard[def->left] || inpu.Keyboard[def->right]) && NDIRECTIONIFELSEGFXTEST)\r
+#ifdef __DEBUG_InputMgr__\r
+if(dbg_testcontrolnoisy > 0)\r
+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
{\r
- printf("q=%d ", player[pn].q);\r
- printf("cpee=%d ", conpee);\r
- printf("(mx)=%d ", mx);\r
- printf("(my)=%d ", my);\r
- printf("pdir=%d d=%d dir=%d\n", player[pn].pdir, player[pn].d, player[pn].info.dir);\r
+ //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
+ //printf("q=%d ", player[pn].enti.q);\r
+ //printf("cpee=%c ", dirchar(conpee));\r
+ printf("pdir=%c d=%c dir=%c ", dirchar(player[pn].pdir), dirchar(player[pn].enti.d), dirchar(player[pn].info.dir));\r
+ /*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
+ //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
+ printf("\n");\r
}\r
-//#endif\r
+#endif\r
}\r
\r
///////////////////////////////////////////////////////////////////////////\r
{\r
word i;\r
\r
+ if (!inst.IN_Started)\r
+ return;\r
+\r
IN_ClearKey(inpu.LastScan);\r
inpu.LastScan = sc_None;\r
\r
return(false);\r
}\r
\r
+//===========================================================================\r
+\r
+/*\r
+===================\r
+=\r
+= IN_MouseButtons\r
+=\r
+===================\r
+*/\r
+\r
+byte IN_MouseButtons (void)\r
+{\r
+ union REGS CPURegs;\r
+ if (inpu.MousePresent)\r
+ {\r
+ Mouse(MButtons);\r
+ return CPURegs.x.bx;\r
+ }\r
+ else\r
+ return 0;\r
+}\r
+\r
+\r
+/*\r
+===================\r
+=\r
+= IN_JoyButtons\r
+=\r
+===================\r
+*/\r
+\r
+byte IN_JoyButtons (void)\r
+{\r
+ byte joybits;\r
+\r
+ joybits = inp(0x201); // Get all the joystick buttons\r
+ joybits >>= 4; // only the high bits are useful\r
+ joybits ^= 15; // return with 1=pressed\r
+\r
+ return joybits;\r
+}\r
+\r
boolean IN_KeyDown(byte code)\r
{\r
+#ifdef __DEBUG_InputMgr__\r
+ if(!dbg_nointest)\r
+#endif\r
return inpu.Keyboard[code];\r
+#ifdef __DEBUG_InputMgr__\r
+ else\r
+ if(dbg_nointest && kbhit())\r
+ return 1;\r
+ else\r
+ return 0;\r
+#endif\r
}\r
\r
void IN_ClearKey(byte code)\r
\r
boolean IN_qb(byte kee)\r
{\r
-//#ifdef TESTKEYIN\r
-// if(testkeyin > 0) printf("%u\n", inpu.Keyboard[kee]);\r
-//#endif\r
+#ifdef __DEBUG_InputMgr__\r
+ if(dbg_testkeyin) printf("%u\n", inpu.Keyboard[kee]);\r
+#endif\r
if(inpu.Keyboard[kee]==true) return 1;\r
else return 0;\r
}\r
+\r
+ScanCode IN_GetLastScan()\r
+{\r
+ return inpu.LastScan;\r
+}\r
+\r
+ScanCode IN_GetCurCode()\r
+{\r
+ return inst.CurCode;\r
+}\r