X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_in.c;h=8d17c37ff27d8950ff024fc8f3f306c5fa6f0cc8;hb=d26e0714368d1cfbe4caee5d6309cf97e0af55db;hp=3cceaa4ed60d54dcc8a5177ce5943b00c4bcd47e;hpb=5567269c594169b6651a053e2e34f7e3acc7e3de;p=16.git diff --git a/src/lib/16_in.c b/src/lib/16_in.c index 3cceaa4e..8d17c37f 100755 --- a/src/lib/16_in.c +++ b/src/lib/16_in.c @@ -38,7 +38,7 @@ #include "src/lib/16_in.h" -word testkeyin=1,testcontrolnoisy=0; +static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */ /* ============================================================================= @@ -49,9 +49,8 @@ word testkeyin=1,testcontrolnoisy=0; */ struct inconfig { - boolean MousePresent; - boolean JoysPresent[MaxJoys]; - boolean JoyPadPresent[MaxPads]; + boolean MousePresent; + boolean JoysPresent[MaxJoys]; boolean Keyboard[NumCodes]; boolean Paused; char LastASCII; @@ -59,7 +58,6 @@ struct inconfig KeyboardDef KbdDefs[MaxKbds]; JoystickDef JoyDefs[MaxJoys]; - JoypadDef JoypadDefs[MaxPads]; } inpu; //extern inconfig inpu; @@ -166,6 +164,7 @@ static Direction DirTable[] = // Quick lookup for total direction #endif // Internal routines + /////////////////////////////////////////////////////////////////////////// // // INL_KeyService() - Handles a keyboard interrupt (key up/down) @@ -236,18 +235,22 @@ static boolean special; if (INL_KeyHook && !special) INL_KeyHook(); -//#ifdef TESTKEYIN - if(testkeyin > 0) printf("%c %x %u\n", c, k, inpu.Keyboard[k]); -//endif +#ifdef __DEBUG_InputMgr__ + if(dbg_testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, inpu.Keyboard[k]); +#endif outp(0x20,0x20); } void Mouse(int x) { - union REGS CPURegs; - x = CPURegs.x.ax; - int86(MouseInt,&CPURegs,&CPURegs); + //union REGS CPURegs; + //x = CPURegs.x.ax; + __asm { + mov ax,x + int MouseInt + } + //int86(MouseInt,&CPURegs,&CPURegs); } /////////////////////////////////////////////////////////////////////////// @@ -301,8 +304,7 @@ IN_GetJoyAbs(word joy,word *xp,word *yp) yb = 1 << ys; // Read the absolute joystick values - __asm - { + __asm { pushf // Save some registers push si push di @@ -322,8 +324,13 @@ IN_GetJoyAbs(word joy,word *xp,word *yp) push bp // Don't mess up stack frame mov bp,MaxJoyValue - +#ifdef __BORLANDC__ + } +#endif loo: +#ifdef __BORLANDC__ + __asm { +#endif in al,dx // Get bits indicating whether all are finished dec bp // Check bounding register @@ -340,8 +347,13 @@ loo: add cl,bl jnz loo // If both bits were 0, drop out - +#ifdef __BORLANDC__ + } +#endif done: +#ifdef __BORLANDC__ + __asm { +#endif pop bp mov cl,[xs] // Get the number of bits to shift @@ -639,9 +651,9 @@ IN_Startup() checkjoys = true; checkmouse = true; - for (i = 1;i < __argc;i++) + for (i = 1;i < _argc;i++) { - switch (US_CheckParm(__argv[i],ParmStringsIN)) + switch (US_CheckParm(_argv[i],ParmStringsIN)) { case 0: checkjoys = false; @@ -659,6 +671,7 @@ IN_Startup() inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false; inst.IN_Started = true; + } /////////////////////////////////////////////////////////////////////////// @@ -669,14 +682,13 @@ IN_Startup() void IN_Default(boolean gotit,player_t *player,ControlType nt) { + int i; if ( (!gotit) || ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0]) || ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1]) || ((nt == ctrl_Mouse) && !inpu.MousePresent) - || ((nt == ctrl_Joypad1) && !inpu.JoyPadPresent[0]) - || ((nt == ctrl_Joypad2) && !inpu.JoyPadPresent[1]) ) nt = ctrl_Keyboard1; inpu.KbdDefs[0].button0 = 0x1c; @@ -690,6 +702,8 @@ IN_Default(boolean gotit,player_t *player,ControlType nt) inpu.KbdDefs[0].down = 0x50; //in.KbdDefs[0].downright = 0x51; IN_SetControlType(0,player,nt); + for(i=0; i>MaxPlayers;i++) + player[i].enti.d =2; } /////////////////////////////////////////////////////////////////////////// @@ -733,7 +747,7 @@ IN_SetKeyHook(void (*hook)()) void IN_ClearKeysDown() { - int i; + //int i; inpu.LastScan = sc_None; inpu.LastASCII = key_None; @@ -800,15 +814,18 @@ IN_ReadCursor(CursorInfo *info) // /////////////////////////////////////////////////////////////////////////// void near -IN_ReadControl(int playnum,player_t *player) +IN_ReadControl(word pn, player_t *player) { boolean realdelta; +#if DEMO0 byte dbyte; +#endif word buttons; int dx,dy; Motion mx,my; ControlType type; sword conpee; + byte dir=DirTable[2]; register KeyboardDef *def; dx = dy = 0; @@ -833,11 +850,11 @@ register KeyboardDef *def; realdelta = false; } else if (DemoMode == demo_PlayDone) - Quit("Demo playback exceeded"); + Quit ("Demo playback exceeded"); else { #endif - switch (type = player[playnum].Controls) + switch (type = player[pn].Controls) { case ctrl_Keyboard1: case ctrl_Keyboard2: @@ -851,16 +868,39 @@ register KeyboardDef *def; mx = motion_Left,my = motion_Down; else if (Keyboard[def->downright]) mx = motion_Right,my = motion_Down;*/ +//TODO: make this into a function that the joystick AND keyboard can use wwww + if(DIRECTIONIFELSE)//(player[pn].info.dir == 2) + { if(!inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]){ - if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down] && player[playnum].d == 2))// || player[playnum].info.dir == 0) - my = motion_Up; - if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up] && player[playnum].d == 2))// || player[playnum].info.dir == 4) - my = motion_Down; + if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])) + my = motion_Up; + if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])) + my = motion_Down; }else if(!inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]){ - if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right] && player[playnum].d == 2))// || player[playnum].info.dir == 1) - mx = motion_Left; - if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left] && player[playnum].d == 2))// || player[playnum].info.dir == 3) - mx = motion_Right; + if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])) + mx = motion_Left; + if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])) + mx = motion_Right; + }else{ //2 keys pressed + switch (player[pn].pdir) + { + case 0: + case 4: + if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])){ dir = DirTable[1]; }//mx = motion_Left; } + else if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])){ dir = DirTable[3]; }//mx = motion_Right; } + break; + case 1: + case 3: + if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])){ dir = DirTable[0]; }//my = motion_Up; } + else if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])){ dir = DirTable[4]; }//my = motion_Down; } + break; + default: + break; + } +#ifdef __DEBUG_InputMgr__ + //if(dbg_testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c ", dirchar(player[pn].pdir)); } +#endif + } } //input from player if (inpu.Keyboard[def->button0]) @@ -880,10 +920,6 @@ register KeyboardDef *def; buttons = INL_GetMouseButtons(); realdelta = true; break; - case ctrl_Joypad1: - case ctrl_Joypad2: - printf("wwww"); - break; } #ifdef DEMO0 } @@ -900,21 +936,23 @@ register KeyboardDef *def; dy = my;// * 127; } - player[playnum].info.x = dx; - player[playnum].info.xaxis = mx; - player[playnum].info.y = dy; - player[playnum].info.yaxis = my; - player[playnum].info.button0 = buttons & (1 << 0); - player[playnum].info.button1 = buttons & (1 << 1); - player[playnum].info.button2 = buttons & (1 << 2); - player[playnum].info.button3 = buttons & (1 << 3); -// player[playnum].info.dir = DirTable[((my + 1) * 3) + (mx + 1)]; - conpee=(((my + 1) * 2) + (mx + 1)); - if(conpee) conpee--; - player[playnum].info.dir = DirTable[conpee]; - if(player[playnum].q==1 && (mx!=motion_None || my!=motion_None)) + player[pn].info.x = dx; + player[pn].info.xaxis = mx; + player[pn].info.y = dy; + player[pn].info.yaxis = my; + player[pn].info.button0 = buttons & (1 << 0); + player[pn].info.button1 = buttons & (1 << 1); + player[pn].info.button2 = buttons & (1 << 2); + player[pn].info.button3 = buttons & (1 << 3); +// player[pn].info.dir = DirTable[((my + 1) * 3) + (mx + 1)]; + conpee=(((my + 1) * 2) + (mx + 1))-1; + player[pn].info.dir = DirTable[conpee]; + + if(DirTable[conpee]!=2) player[pn].pdir=DirTable[conpee]; + if(player[pn].enti.q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None))) { - player[playnum].d = player[playnum].info.dir; + if(dir==2) player[pn].enti.d = player[pn].info.dir; + else player[pn].enti.d = DirTable[dir]; } #if DEMO0 @@ -935,22 +973,26 @@ register KeyboardDef *def; DemoOffset += 2; if (DemoOffset >= DemoSize) - Quit("Demo buffer overflow"); + Quit ("Demo buffer overflow"); DemoBuffer[DemoOffset] = 1; DemoBuffer[DemoOffset + 1] = dbyte; } } #endif -//#ifdef TESTCONTROLNOISY -if(testcontrolnoisy > 0) -if((inpu.Keyboard[def->up] || inpu.Keyboard[def->down] || inpu.Keyboard[def->left] || inpu.Keyboard[def->right])&& player[playnum].info.dir!=2) +#ifdef __DEBUG_InputMgr__ +if(dbg_testcontrolnoisy > 0) +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) { - printf("(mx)=%d ", mx); - printf("(my)=%d ", my); - printf("dir=%d\n", player[playnum].info.dir); + //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); + //printf("q=%d ", player[pn].enti.q); + //printf("cpee=%c ", dirchar(conpee)); + printf("pdir=%c d=%c dir=%c ", dirchar(player[pn].pdir), dirchar(player[pn].enti.d), dirchar(player[pn].info.dir)); + /*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); + //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]); + printf("\n"); } -//#endif +#endif } /////////////////////////////////////////////////////////////////////////// @@ -960,10 +1002,10 @@ if((inpu.Keyboard[def->up] || inpu.Keyboard[def->down] || inpu.Keyboard[def->lef // /////////////////////////////////////////////////////////////////////////// void -IN_SetControlType(word playnum,player_t *player,ControlType type) +IN_SetControlType(word pn,player_t *player,ControlType type) { // DEBUG - check that requested type is present? - player[playnum].Controls = type; + player[pn].Controls = type; } #if DEMO0 @@ -1133,6 +1175,9 @@ IN_Ack() { word i; + if (!inst.IN_Started) + return; + IN_ClearKey(inpu.LastScan); inpu.LastScan = sc_None; @@ -1202,7 +1247,17 @@ IN_UserInput(dword delay,boolean clear) boolean IN_KeyDown(byte code) { +#ifdef __DEBUG_InputMgr__ + if(!dbg_nointest) +#endif return inpu.Keyboard[code]; +#ifdef __DEBUG_InputMgr__ + else + if(dbg_nointest && kbhit()) + return 1; + else + return 0; +#endif } void IN_ClearKey(byte code) @@ -1214,9 +1269,9 @@ void IN_ClearKey(byte code) boolean IN_qb(byte kee) { -//#ifdef TESTKEYIN - if(testkeyin > 0) printf("%u\n", inpu.Keyboard[kee]); -//#endif +#ifdef __DEBUG_InputMgr__ + if(dbg_testkeyin) printf("%u\n", inpu.Keyboard[kee]); +#endif if(inpu.Keyboard[kee]==true) return 1; else return 0; }