X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_in.c;h=98ecb70d117a330213f9fb00a974dda1463ecbbd;hb=af2715fef8681d909afe82f7baaf5e13baabb76f;hp=0d3b29c79087d7d43aca9339004ca9b1df8b5976;hpb=de41863a916d793f03f7dba0d5a85bb8c325accc;p=16.git diff --git a/src/lib/16_in.c b/src/lib/16_in.c index 0d3b29c7..98ecb70d 100755 --- a/src/lib/16_in.c +++ b/src/lib/16_in.c @@ -1,21 +1,24 @@ -/* Catacomb Apocalypse Source Code - * Copyright (C) 1993-2014 Flat Rock Software +/* Project 16 Source Code~ + * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover * - * This program is free software; you can redistribute it and/or modify + * This file is part of Project 16. + * + * Project 16 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * Project 16 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see , or + * write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301 USA. + * */ - // // ID Engine // ID_IN.c - Input Manager @@ -37,10 +40,7 @@ // #include "src/lib/16_in.h" - -#ifdef __DEBUG_InputMgr__ -boolean dbg_testkeyin=0,dbg_testcontrolnoisy=0; -#endif +#pragma hdrstop static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */ @@ -51,7 +51,7 @@ static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */ ============================================================================= */ -struct inconfig +/*struct inconfig { boolean MousePresent; boolean JoysPresent[MaxJoys]; @@ -62,10 +62,9 @@ struct inconfig KeyboardDef KbdDefs[MaxKbds]; JoystickDef JoyDefs[MaxJoys]; -} inpu; +} inpu;*/ -//extern inconfig inpu; -//inpu.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/}; +//gvar->in.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/}; /* ============================================================================= @@ -80,14 +79,14 @@ extern "C" { #endif static struct instat { - boolean IN_Started; boolean CapsLock; ScanCode CurCode,LastCode; -} inst; -static void (*INL_KeyHook)(void); -static void interrupt (*OldKeyVect)(void); -static char *ParmStringsIN[] = {"nojoys","nomouse",nil}; + boolean Keyboard[NumCodes]; + boolean Paused; + char LastASCII; + ScanCode LastScan; +} inst; static byte far ASCIINames[] = // Unshifted ASCII for scan codes { @@ -153,20 +152,18 @@ static byte far ASCIINames[] = // Unshifted ASCII for scan codes static Direction DirTable[] = // Quick lookup for total direction { - //dir_Nortinest, - dir_North, - dir_West, - dir_None, - dir_East, - dir_South - //dir_NorthEast, - //dir_Soutinest, - //,dir_SouthEast + /*dir_NorthWest, */dir_North,/* dir_NorthEast,*/ + dir_West, dir_None, dir_East, + /*dir_SouthWest, */dir_South/*, dir_SouthEast*/ }; #ifdef __cplusplus } #endif +static void (*INL_KeyHook)(void); +static void interrupt (*OldKeyVect)(void); +static char *ParmStringsIN[] = {"nojoys","nomouse",nil}; + // Internal routines /////////////////////////////////////////////////////////////////////////// @@ -174,23 +171,23 @@ static Direction DirTable[] = // Quick lookup for total direction // INL_KeyService() - Handles a keyboard interrupt (key up/down) // /////////////////////////////////////////////////////////////////////////// -void interrupt -INL_KeyService() +/*static */void interrupt +INL_KeyService(void) { static boolean special; - byte k,c; - register byte temp; + byte k,c, + temp; - k = inp(0x60); // Get the scan code + k = inportb(0x60); // Get the scan code // Tell the XT keyboard controller to clear the key - outp(0x61,(temp = inp(0x61)) | 0x80); - outp(0x61,temp); + outportb(0x61,(temp = inportb(0x61)) | 0x80); + outportb(0x61,temp); if (k == 0xe0) // Special key prefix special = true; else if (k == 0xe1) // Handle Pause key - inpu.Paused = true; + inst.Paused = true; else { if (k & 0x80) // Break code @@ -199,13 +196,13 @@ static boolean special; // DEBUG - handle special keys: ctl-alt-delete, print scrn - inpu.Keyboard[k] = false; + inst.Keyboard[k] = false; } else // Make code { inst.LastCode = inst.CurCode; - inst.CurCode = inpu.LastScan = k; - inpu.Keyboard[k] = true; + inst.CurCode = inst.LastScan = k; + inst.Keyboard[k] = true; if (special) c = SpecialNames[k]; @@ -217,7 +214,7 @@ static boolean special; // DEBUG - make caps lock light work } - if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift]) // If shifted + if (inst.Keyboard[sc_LShift] || inst.Keyboard[sc_RShift]) // If shifted { c = ShiftNames[k]; if ((c >= 'A') && (c <= 'Z') && inst.CapsLock) @@ -231,7 +228,7 @@ static boolean special; } } if (c) - inpu.LastASCII = c; + inst.LastASCII = c; } special = false; @@ -240,13 +237,12 @@ static boolean special; if (INL_KeyHook && !special) INL_KeyHook(); #ifdef __DEBUG_InputMgr__ - if(dbg_testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, inpu.Keyboard[k]); + if(dbg_testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, inst.Keyboard[k]); #endif - outp(0x20,0x20); + outportb(0x20,0x20); } -void -Mouse(int x) +void INL_Mouse(int x) { //union REGS CPURegs; //x = CPURegs.x.ax; @@ -381,20 +377,18 @@ done: /////////////////////////////////////////////////////////////////////////// // // INL_GetJoyDelta() - Returns the relative movement of the specified -// joystick (from +/-127, scaled adaptively) +// joystick (from +/-127) // /////////////////////////////////////////////////////////////////////////// -static void -INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive) +void INL_GetJoyDelta(word joy,int *dx,int *dy/*,boolean adaptive*/, global_game_variables_t *gvar) { word x,y; - word time; word TimeCount = *clockw; JoystickDef *def; static word lasttime; IN_GetJoyAbs(joy,&x,&y); - def = inpu.JoyDefs + joy; + def = gvar->in.JoyDefs + joy; if (x < def->threshMinX) { @@ -441,18 +435,17 @@ static word lasttime; } else *dy = 0; - - if (adaptive) - { - time = (TimeCount - lasttime) / 2; - if (time) - { - if (time > 8) - time = 8; - *dx *= time; - *dy *= time; - } - } +// if (adaptive) +// { +// time = (TimeCount - lasttime) / 2; +// if (time) +// { +// if (time > 8) +// time = 8; +// *dx *= time; +// *dy *= time; +// } +// } lasttime = TimeCount; } @@ -467,7 +460,7 @@ INL_GetJoyButtons(word joy) { register word result; - result = inp(0x201); // Get all the joystick buttons + result = inportb(0x201); // Get all the joystick buttons result >>= joy? 6 : 4; // Shift into bits 0-1 result &= 3; // Mask off the useless bits result ^= 3; @@ -492,6 +485,7 @@ IN_GetJoyButtonsDB(word joy) result1 = INL_GetJoyButtons(joy); lasttime = TimeCount; while(TimeCount == lasttime) + //; result2 = INL_GetJoyButtons(joy); } while(result1 != result2); return(result1); @@ -503,14 +497,14 @@ IN_GetJoyButtonsDB(word joy) // /////////////////////////////////////////////////////////////////////////// static void -INL_StartKbd() +INL_StartKbd(global_game_variables_t *gvar) { - INL_KeyHook = 0; // Clear key hook + INL_KeyHook = NULL; // Clear key hook IN_ClearKeysDown(); - OldKeyVect = _dos_getvect(KeyInt); - //_dos_setvect(KeyInt,INL_KeyService); + OldKeyVect = getvect(KeyInt);//IN_KbdLED(); + setvect(KeyInt,INL_KeyService); } /////////////////////////////////////////////////////////////////////////// @@ -523,7 +517,7 @@ INL_ShutKbd(void) { pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags - _dos_setvect(KeyInt,OldKeyVect); + setvect(KeyInt,OldKeyVect); } /////////////////////////////////////////////////////////////////////////// @@ -534,14 +528,26 @@ INL_ShutKbd(void) static boolean INL_StartMouse(void) { - union REGS CPURegs; - if(_dos_getvect(MouseInt)) +#if 0 + if (getvect(MouseInt)) { Mouse(MReset); - if(CPURegs.x.ax == 0xffff) + if (_AX == 0xffff) return(true); } return(false); +#endif + byte far *vector; + + + if ((vector=MK_FP(peek(0,0x33*4+2),peek(0,0x33*4)))==NULL) + return false; + + if (*vector == 207) + return false; + + Mouse(MReset); + return true; } /////////////////////////////////////////////////////////////////////////// @@ -558,11 +564,11 @@ INL_ShutMouse(void) // INL_SetJoyScale() - Sets up scaling values for the specified joystick // static void -INL_SetJoyScale(word joy) +INL_SetJoyScale(word joy, global_game_variables_t *gvar) { JoystickDef *def; - def = &(inpu.JoyDefs[joy]); + def = &(gvar->in.JoyDefs[joy]); def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX); def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX); def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY); @@ -576,12 +582,12 @@ INL_SetJoyScale(word joy) // /////////////////////////////////////////////////////////////////////////// void -IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy) +IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy, global_game_variables_t *gvar) { word d,r; JoystickDef *def; - def = &(inpu.JoyDefs[joy]); + def = &(gvar->in.JoyDefs[joy]); def->joyMinX = minx; def->joyMaxX = maxx; @@ -597,7 +603,7 @@ IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy) def->threshMinY = ((r / 2) - d) + miny; def->threshMaxY = ((r / 2) + d) + miny; - INL_SetJoyScale(joy); + INL_SetJoyScale(joy, gvar); } /////////////////////////////////////////////////////////////////////////// @@ -607,7 +613,7 @@ IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy) // /////////////////////////////////////////////////////////////////////////// static boolean -INL_StartJoy(word joy) +INL_StartJoy(word joy, global_game_variables_t *gvar) { word x,y; @@ -621,7 +627,7 @@ INL_StartJoy(word joy) return(false); else { - IN_SetupJoy(joy,0,x * 2,0,y * 2); + IN_SetupJoy(joy,0,x * 2,0,y * 2, gvar); return(true); } } @@ -632,9 +638,9 @@ INL_StartJoy(word joy) // /////////////////////////////////////////////////////////////////////////// static void -INL_ShutJoy(word joy) +INL_ShutJoy(word joy, global_game_variables_t *gvar) { - inpu.JoysPresent[joy] = false; + gvar->in.JoysPresent[joy] = false; } // Public routines @@ -645,12 +651,12 @@ INL_ShutJoy(word joy) // /////////////////////////////////////////////////////////////////////////// void -IN_Startup() +IN_Startup(global_game_variables_t *gvar) { boolean checkjoys,checkmouse; word i; - if (inst.IN_Started) + if (gvar->in.IN_Started) return; checkjoys = true; @@ -668,13 +674,15 @@ IN_Startup() } } - INL_StartKbd(); - inpu.MousePresent = checkmouse? INL_StartMouse() : false; + INL_StartKbd(gvar); + gvar->in.MousePresent = checkmouse? INL_StartMouse() : false; for (i = 0;i < MaxJoys;i++) - inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false; + gvar->in.JoysPresent[i] = checkjoys? INL_StartJoy(i, gvar) : false; + + gvar->in.inst = &inst; - inst.IN_Started = true; + gvar->in.IN_Started = true; } @@ -684,29 +692,30 @@ IN_Startup() // /////////////////////////////////////////////////////////////////////////// void -IN_Default(boolean gotit,player_t *player,ControlType nt) +IN_Default(boolean gotit,player_t *player,ControlType nt, global_game_variables_t *gvar) { - //int i; + int i; if ( (!gotit) - || ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0]) - || ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1]) - || ((nt == ctrl_Mouse) && !inpu.MousePresent) + || ((nt == ctrl_Joystick1) && !gvar->in.JoysPresent[0]) + || ((nt == ctrl_Joystick2) && !gvar->in.JoysPresent[1]) + || ((nt == ctrl_Mouse) && !gvar->in.MousePresent) ) nt = ctrl_Keyboard1; - inpu.KbdDefs[0].button0 = 0x1c; - inpu.KbdDefs[0].button1 = 0x38; + gvar->in.KbdDefs[0].button0 = 0x1c; + gvar->in.KbdDefs[0].button1 = 0x38; //in.KbdDefs[0].upleft = 0x47; - inpu.KbdDefs[0].up = 0x48; + gvar->in.KbdDefs[0].up = 0x48; //in.KbdDefs[0].upright = 0x49; - inpu.KbdDefs[0].left = 0x4b; - inpu.KbdDefs[0].right = 0x4d; + gvar->in.KbdDefs[0].left = 0x4b; + gvar->in.KbdDefs[0].right = 0x4d; //in.KbdDefs[0].downleft = 0x4f; - inpu.KbdDefs[0].down = 0x50; + gvar->in.KbdDefs[0].down = 0x50; //in.KbdDefs[0].downright = 0x51; IN_SetControlType(player,nt); - player->d=2; + for(i=0; i>MaxPlayers;i++) + player[i].enti.d =2; } /////////////////////////////////////////////////////////////////////////// @@ -715,19 +724,19 @@ IN_Default(boolean gotit,player_t *player,ControlType nt) // /////////////////////////////////////////////////////////////////////////// void -IN_Shutdown() +IN_Shutdown(global_game_variables_t *gvar) { word i; - if (!inst.IN_Started) + if (!gvar->in.IN_Started) return; INL_ShutMouse(); for (i = 0;i < MaxJoys;i++) - INL_ShutJoy(i); + INL_ShutJoy(i, gvar); INL_ShutKbd(); - inst.IN_Started = false; + gvar->in.IN_Started = false; } /////////////////////////////////////////////////////////////////////////// @@ -744,17 +753,17 @@ IN_SetKeyHook(void (*hook)()) /////////////////////////////////////////////////////////////////////////// // -// IN_ClearKeyDown() - Clears the keyboard array +// IN_ClearKeysDown() - Clears the keyboard array // /////////////////////////////////////////////////////////////////////////// void -IN_ClearKeysDown() +IN_ClearKeysDown(void) { //int i; - inpu.LastScan = sc_None; - inpu.LastASCII = key_None; - memset (inpu.Keyboard,0,sizeof(inpu.Keyboard)); + inst.LastScan = sc_None; + inst.LastASCII = key_None; + memset (inst.Keyboard,0,sizeof(inst.Keyboard)); } /////////////////////////////////////////////////////////////////////////// @@ -781,7 +790,7 @@ INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy) // /////////////////////////////////////////////////////////////////////////// void -IN_ReadCursor(CursorInfo *info) +IN_ReadCursor(CursorInfo *info, global_game_variables_t *gvar) { word i, buttons; @@ -790,7 +799,7 @@ IN_ReadCursor(CursorInfo *info) info->x = info->y = 0; info->button0 = info->button1 = false; - if (inpu.MousePresent) + if (gvar->in.MousePresent) { buttons = INL_GetMouseButtons(); INL_GetMouseDelta(&dx,&dy); @@ -799,25 +808,29 @@ IN_ReadCursor(CursorInfo *info) for (i = 0;i < MaxJoys;i++) { - if (!inpu.JoysPresent[i]) + if (!gvar->in.JoysPresent[i]) continue; buttons = INL_GetJoyButtons(i); - INL_GetJoyDelta(i,&dx,&dy,true); + INL_GetJoyDelta(i,&dx,&dy/*,true*/, gvar); dx /= 64; dy /= 64; INL_AdjustCursor(info,buttons,dx,dy); } } +//if else for gfxtesting and direction +#define DIRECTIONIFELSE (player->info.dir == 2) +//#define NDIRECTIONIFELSE (player->info.dir != 2) + /////////////////////////////////////////////////////////////////////////// // // IN_ReadControl() - Reads the device associated with the specified // player and fills in the control info struct // /////////////////////////////////////////////////////////////////////////// -void near -IN_ReadControl(player_t *player) +void +IN_ReadControl(player_t *player, global_game_variables_t *gvar) { boolean realdelta; #if DEMO0 @@ -853,7 +866,7 @@ register KeyboardDef *def; realdelta = false; } else if (DemoMode == demo_PlayDone) - Quit("Demo playback exceeded"); + Quit ("Demo playback exceeded"); else { #endif @@ -861,7 +874,7 @@ register KeyboardDef *def; { case ctrl_Keyboard1: case ctrl_Keyboard2: - def = &(inpu.KbdDefs[type - ctrl_Keyboard]); + def = &(gvar->in.KbdDefs[type - ctrl_Keyboard]); /* if (Keyboard[def->upleft]) mx = motion_Left,my = motion_Up; @@ -874,28 +887,28 @@ register KeyboardDef *def; //TODO: make this into a function that the joystick AND keyboard can use wwww if(DIRECTIONIFELSE)//(player->info.dir == 2) { - if(!inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]){ - if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])) + if(!inst.Keyboard[def->left] && !inst.Keyboard[def->right]){ + if((inst.Keyboard[def->up] && !inst.Keyboard[def->down])) my = motion_Up; - if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])) + if((inst.Keyboard[def->down] && !inst.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])) + }else if(!inst.Keyboard[def->up] && !inst.Keyboard[def->down]){ + if((inst.Keyboard[def->left] && !inst.Keyboard[def->right])) mx = motion_Left; - if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])) + if((inst.Keyboard[def->right] && !inst.Keyboard[def->left])) mx = motion_Right; }else{ //2 keys pressed switch (player->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; } + if((inst.Keyboard[def->left] && !inst.Keyboard[def->right])){ dir = DirTable[1]; }//mx = motion_Left; } + else if((inst.Keyboard[def->right] && !inst.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; } + if((inst.Keyboard[def->up] && !inst.Keyboard[def->down])){ dir = DirTable[0]; }//my = motion_Up; } + else if((inst.Keyboard[def->down] && !inst.Keyboard[def->up])){ dir = DirTable[4]; }//my = motion_Down; } break; default: break; @@ -906,15 +919,15 @@ register KeyboardDef *def; } } //input from player - if (inpu.Keyboard[def->button0]) + if (inst.Keyboard[def->button0]) buttons += 1 << 0; - if (inpu.Keyboard[def->button1]) + if (inst.Keyboard[def->button1]) buttons += 1 << 1; realdelta = false; break; case ctrl_Joystick1: case ctrl_Joystick2: - INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false); + INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy/*,false*/, gvar); buttons = INL_GetJoyButtons(type - ctrl_Joystick); realdelta = true; break; @@ -952,10 +965,10 @@ register KeyboardDef *def; player->info.dir = DirTable[conpee]; if(DirTable[conpee]!=2) player->pdir=DirTable[conpee]; - if(player->q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None))) + if(player->enti.q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None))) { - if(dir==2) player->d = player->info.dir; - else player->d = DirTable[dir]; + if(dir==2) player->enti.d = player->info.dir; + else player->enti.d = DirTable[dir]; } #if DEMO0 @@ -976,7 +989,7 @@ register KeyboardDef *def; DemoOffset += 2; if (DemoOffset >= DemoSize) - Quit("Demo buffer overflow"); + Quit ("Demo buffer overflow"); DemoBuffer[DemoOffset] = 1; DemoBuffer[DemoOffset + 1] = dbyte; @@ -985,14 +998,14 @@ register KeyboardDef *def; #endif #ifdef __DEBUG_InputMgr__ if(dbg_testcontrolnoisy > 0) -if(player->info.dir!=2/*(inpu.Keyboard[def->up] || inpu.Keyboard[def->down] || inpu.Keyboard[def->left] || inpu.Keyboard[def->right])*/ || player->q>1) +if(player->info.dir!=2/*(inst.Keyboard[def->up] || inst.Keyboard[def->down] || inst.Keyboard[def->left] || inst.Keyboard[def->right])*/ || player->enti.q>1) { //printf("b1=%u b2=%u b3=%u b4=%u ", player->info.button0, player->info.button1, player->info.button2, player->info.button3); - //printf("q=%d ", player->q); + //printf("q=%d ", player->enti.q); //printf("cpee=%c ", dirchar(conpee)); - printf("pdir=%c d=%c dir=%c ", dirchar(player->pdir), dirchar(player->d), dirchar(player->info.dir)); + printf("pdir=%c d=%c dir=%c ", dirchar(player->pdir), dirchar(player->enti.d), dirchar(player->info.dir)); /*if(realdelta) */printf("dx=%d dy=%d mx=%d my=%d", player->info.x, player->info.y, player->info.xaxis, player->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]); + //else if(!realdelta) printf("%c%d %c%d %c%d %c%d", dirchar(0), inst.Keyboard[def->up], dirchar(4), inst.Keyboard[def->down], dirchar(1), inst.Keyboard[def->left], dirchar(3), inst.Keyboard[def->right]); printf("\n"); } #endif @@ -1101,13 +1114,13 @@ IN_GetScanName(ScanCode scan) // /////////////////////////////////////////////////////////////////////////// ScanCode -IN_WaitForKey() +IN_WaitForKey(void) { ScanCode result; - while (!(result = inpu.LastScan)) + while (!(result = inst.LastScan)) ; - inpu.LastScan = 0; + inst.LastScan = 0; return(result); } @@ -1118,81 +1131,78 @@ IN_WaitForKey() // /////////////////////////////////////////////////////////////////////////// char -IN_WaitForASCII() +IN_WaitForASCII(void) { char result; - while (!(result = inpu.LastASCII)) + while (!(result = inst.LastASCII)) ; - inpu.LastASCII = '\0'; + inst.LastASCII = '\0'; return(result); } /////////////////////////////////////////////////////////////////////////// // -// IN_AckBack() - Waits for either an ASCII keypress or a button press +// IN_Ack() - waits for a button or key press. If a button is down, upon +// calling, it must be released for it to be recognized // /////////////////////////////////////////////////////////////////////////// -void -IN_AckBack() + +boolean btnstate[8]; + +void IN_StartAck(global_game_variables_t *gvar) { - word i; + unsigned i,buttons; - while (!inpu.LastScan) - { - if (inpu.MousePresent) - { - if (INL_GetMouseButtons()) - { - while (INL_GetMouseButtons()) - ; - return; - } - } +// +// get initial state of everything +// + IN_ClearKeysDown(); + memset (btnstate,0,sizeof(btnstate)); - for (i = 0;i < MaxJoys;i++) - { - if (inpu.JoysPresent[i]) - { - if (IN_GetJoyButtonsDB(i)) - { - while (IN_GetJoyButtonsDB(i)) - ; - return; - } - } - } - } + buttons = IN_JoyButtons () << 4; + if (gvar->in.MousePresent) + buttons |= IN_MouseButtons (gvar); - IN_ClearKey(inpu.LastScan); - inpu.LastScan = sc_None; + for (i=0;i<8;i++,buttons>>=1) + if (buttons&1) + btnstate[i] = true; } -/////////////////////////////////////////////////////////////////////////// + +boolean IN_CheckAck (global_game_variables_t *gvar) +{ + unsigned i,buttons; + // -// IN_Ack() - Clears user input & then calls IN_AckBack() +// see if something has been pressed // -/////////////////////////////////////////////////////////////////////////// -void -IN_Ack() -{ - word i; + if (inst.LastScan) + return true; - if (!inst.IN_Started) - return; + buttons = IN_JoyButtons () << 4; + if (gvar->in.MousePresent) + buttons |= IN_MouseButtons (gvar); - IN_ClearKey(inpu.LastScan); - inpu.LastScan = sc_None; + for (i=0;i<8;i++,buttons>>=1) + if ( buttons&1 ) + { + if (!btnstate[i]) + return true; + } + else + btnstate[i]=false; - if (inpu.MousePresent) - while (INL_GetMouseButtons()) - ; - for (i = 0;i < MaxJoys;i++) - if (inpu.JoysPresent[i]) - while (IN_GetJoyButtonsDB(i)) - ; + return false; +} - IN_AckBack(); + +void IN_Ack (global_game_variables_t *gvar) +{ + IN_StartAck (gvar); + + while (!IN_CheckAck (gvar)) + ; } /////////////////////////////////////////////////////////////////////////// @@ -1202,19 +1212,19 @@ IN_Ack() // /////////////////////////////////////////////////////////////////////////// boolean -IN_IsUserInput() +IN_IsUserInput(global_game_variables_t *gvar) { boolean result; word i; - result = inpu.LastScan; + result = inst.LastScan; - if (inpu.MousePresent) + if (gvar->in.MousePresent) if (INL_GetMouseButtons()) result = true; for (i = 0;i < MaxJoys;i++) - if (inpu.JoysPresent[i]) + if (gvar->in.JoysPresent[i]) if (INL_GetJoyButtons(i)) result = true; @@ -1229,57 +1239,112 @@ IN_IsUserInput() // button up. // /////////////////////////////////////////////////////////////////////////// -boolean -IN_UserInput(dword delay,boolean clear) +boolean IN_UserInput(word delay, global_game_variables_t *gvar) { word TimeCount = *clockw; word lasttime; lasttime = TimeCount; + IN_StartAck (gvar); do { - if (IN_IsUserInput()) - { - if (clear) - IN_AckBack(); - return(true); - } + if (IN_CheckAck(gvar)) + return true; } while (TimeCount - lasttime < delay); return(false); } +//=========================================================================== + +/* +=================== += += IN_MouseButtons += +=================== +*/ + +byte IN_MouseButtons (global_game_variables_t *gvar) +{ + union REGS CPURegs; + if (gvar->in.MousePresent) + { + Mouse(MButtons); + return CPURegs.x.bx; + } + else + return 0; +} + + +/* +=================== += += IN_JoyButtons += +=================== +*/ + +byte IN_JoyButtons (void) +{ + byte joybits; + + joybits = inportb(0x201); // Get all the joystick buttons + joybits >>= 4; // only the high bits are useful + joybits ^= 15; // return with 1=pressed + + return joybits; +} + boolean IN_KeyDown(byte code) { - return inpu.Keyboard[code]; +#ifdef __DEBUG_InputMgr__ + if(inst.Keyboard[code]) + printf("IN_KeyDown(%c): %u\n", code, inst.Keyboard[code]); + if(!dbg_nointest) +#endif + return inst.Keyboard[code]; +#ifdef __DEBUG_InputMgr__ + else + if(dbg_nointest && kbhit()) + return 1; + else + return 0; +#endif } void IN_ClearKey(byte code) { - inpu.Keyboard[code] = false; - if(code == inpu.LastScan) - inpu.LastScan = sc_None; + inst.Keyboard[code] = false; + if(code == inst.LastScan) + inst.LastScan = sc_None; } boolean IN_qb(byte kee) { #ifdef __DEBUG_InputMgr__ -// if(dbg_testkeyin > 0) printf("%u\n", inpu.Keyboard[kee]); + if(dbg_testkeyin) if(inst.Keyboard[kee]) printf("IN_qb(): %u\n", inst.Keyboard[kee]); #endif - if(inpu.Keyboard[kee]==true) return 1; + if(inst.Keyboard[kee]==true) return 1; else return 0; } -//init player! -void IN_initplayer(player_t *player) +ScanCode IN_GetLastScan() { - player->x = player->tx*TILEWH; - player->y = player->ty*TILEWH; - player->triggerx = player->tx; - player->triggery = player->ty+1; - player->q=1; - player->d=2; - player->hp=4; - player->speed=4; - player->persist_aniframe=0; - player->spt=(TILEWH/(player->speed)); //speed per tile wwww + return inst.LastScan; +} + +ScanCode IN_GetCurCode() +{ + return inst.CurCode; +} + +void IN_KbdLED() +{ + byte far *lock_key; + + // turn off num-lock via BIOS + lock_key = MK_FP(0x040, 0x017); // Pointing to the address of the bios shift state keys + *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 + OldKeyVect(); // call BIOS keyhandler to change keyboard lights }