X-Git-Url: http://4ch.mooo.com/gitweb/?p=16.git;a=blobdiff_plain;f=src%2Flib%2F16_in.c;h=14086bd8909381c57da08fa8836a4a881efbc708;hp=5bccecafde8529eb59983c6a1674d35a2a92f877;hb=c8d0f894b450f6dc3b80fbe28fedff4d424ce294;hpb=7cbfb3d1f53e33107205d1d8a5ed215898246504 diff --git a/src/lib/16_in.c b/src/lib/16_in.c index 5bccecaf..14086bd8 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,8 +40,9 @@ // #include "src/lib/16_in.h" +#pragma hdrstop -boolean testkeyin=0,testcontrolnoisy=0,testctrltype=0; +static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */ /* ============================================================================= @@ -47,10 +51,10 @@ boolean testkeyin=0,testcontrolnoisy=0,testctrltype=0; ============================================================================= */ -struct inconfig +/*struct inconfig { - boolean MousePresent; - boolean JoysPresent[MaxJoys]; + boolean MousePresent; + boolean JoysPresent[MaxJoys]; boolean Keyboard[NumCodes]; boolean Paused; char LastASCII; @@ -58,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*/}; /* ============================================================================= @@ -75,15 +78,21 @@ struct inconfig extern "C" { #endif -static struct instat { - boolean IN_Started; - boolean CapsLock; +/*static struct instat { + 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;*/ + +//the def stuff is need fix warnings +#ifndef INSTDEFED +#define INSTDEFED +static inst_t inst; +#endif static byte far ASCIINames[] = // Unshifted ASCII for scan codes { @@ -149,43 +158,42 @@ 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 + /////////////////////////////////////////////////////////////////////////// // // 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 @@ -194,13 +202,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]; @@ -212,7 +220,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) @@ -226,7 +234,7 @@ static boolean special; } } if (c) - inpu.LastASCII = c; + inst.LastASCII = c; } special = false; @@ -234,18 +242,21 @@ static boolean special; if (INL_KeyHook && !special) INL_KeyHook(); -//#ifdef TESTKEYIN - if(testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, inpu.Keyboard[k]); -//endif - outp(0x20,0x20); +#ifdef __DEBUG_InputMgr__ + if(dbg_testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, inst.Keyboard[k]); +#endif + outportb(0x20,0x20); } -void -Mouse(int x) +void INL_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); } /////////////////////////////////////////////////////////////////////////// @@ -299,8 +310,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 @@ -320,8 +330,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 @@ -338,8 +353,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 @@ -363,56 +383,19 @@ 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; - //TODO: inject p16 input controls! - //which is this - /* if(DIRECTIONIFELSE) - { - if(!inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]){ - 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])) - mx = motion_Left; - if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left]))// || player[pn].pdir != 1) - mx = motion_Right; - }else - //if(mx+my!=1 && mx+my!=-1 && mx!=my!=0) - { //2 keys pressed - switch (player[pn].pdir) - { - case 0: - case 4: - if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])) dir = DirTable[1]; - else if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])) dir = DirTable[3]; - break; - case 1: - case 3: - if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])) dir = DirTable[0]; - else if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])) dir = DirTable[4]; - break; - default: - break; - } - if(testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c ", dirchar(player[pn].pdir)); } - }//else printf(" "); - }*/ if (x < def->threshMinX) { if (x < def->joyMinX) @@ -458,18 +441,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; } @@ -484,7 +466,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; @@ -509,6 +491,7 @@ IN_GetJoyButtonsDB(word joy) result1 = INL_GetJoyButtons(joy); lasttime = TimeCount; while(TimeCount == lasttime) + //; result2 = INL_GetJoyButtons(joy); } while(result1 != result2); return(result1); @@ -520,14 +503,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); } /////////////////////////////////////////////////////////////////////////// @@ -540,7 +523,7 @@ INL_ShutKbd(void) { pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags - _dos_setvect(KeyInt,OldKeyVect); + setvect(KeyInt,OldKeyVect); } /////////////////////////////////////////////////////////////////////////// @@ -551,14 +534,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; } /////////////////////////////////////////////////////////////////////////// @@ -575,11 +570,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); @@ -593,12 +588,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; @@ -614,7 +609,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); } /////////////////////////////////////////////////////////////////////////// @@ -624,7 +619,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; @@ -638,7 +633,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); } } @@ -649,9 +644,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 @@ -662,19 +657,19 @@ 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; 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; @@ -685,13 +680,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; - inst.IN_Started = true; + gvar->in.inst = &inst; + + gvar->in.IN_Started = true; } @@ -701,31 +698,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; - if(testctrltype==0) 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(0,player,nt); + IN_SetControlType(player,nt); for(i=0; i>MaxPlayers;i++) - player[i].d=2; + player[i].enti.d =2; } /////////////////////////////////////////////////////////////////////////// @@ -734,19 +730,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; } /////////////////////////////////////////////////////////////////////////// @@ -763,17 +759,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; + //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)); } /////////////////////////////////////////////////////////////////////////// @@ -800,7 +796,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; @@ -809,7 +805,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); @@ -818,28 +814,34 @@ 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(int pn,player_t *player) +void +IN_ReadControl(player_t *player, global_game_variables_t *gvar) { boolean realdelta; +#if DEMO0 byte dbyte; +#endif word buttons; int dx,dy; Motion mx,my; @@ -870,16 +872,15 @@ register KeyboardDef *def; realdelta = false; } else if (DemoMode == demo_PlayDone) - Quit("Demo playback exceeded"); + Quit ("Demo playback exceeded"); else { #endif - if(testctrltype>0) printf("player[pn].Controls=%c\n", player[pn].Controls); - switch (type = player[pn].Controls) + switch (type = player->Controls) { 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; @@ -889,49 +890,50 @@ register KeyboardDef *def; mx = motion_Left,my = motion_Down; else if (Keyboard[def->downright]) mx = motion_Right,my = motion_Down;*/ - if(DIRECTIONIFELSE) +//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]))// || player[pn].pdir != 1) + if((inst.Keyboard[def->right] && !inst.Keyboard[def->left])) mx = motion_Right; - }else - //if(mx+my!=1 && mx+my!=-1 && mx!=my!=0) - { //2 keys pressed - switch (player[pn].pdir) + }else{ //2 keys pressed + switch (player->pdir) { case 0: case 4: - if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])) dir = DirTable[1]; - else if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])) dir = DirTable[3]; + 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]; - else if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])) dir = DirTable[4]; + 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; } - if(testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c ", dirchar(player[pn].pdir)); } - }//else printf(" "); +#ifdef __DEBUG_InputMgr__ + //if(dbg_testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c ", dirchar(player->pdir)); } +#endif + } } //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; @@ -956,23 +958,23 @@ register KeyboardDef *def; dy = my;// * 127; } - 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)]; + player->info.x = dx; + player->info.xaxis = mx; + player->info.y = dy; + player->info.yaxis = my; + player->info.button0 = buttons & (1 << 0); + player->info.button1 = buttons & (1 << 1); + player->info.button2 = buttons & (1 << 2); + player->info.button3 = buttons & (1 << 3); +// player->info.dir = DirTable[((my + 1) * 3) + (mx + 1)]; conpee=(((my + 1) * 2) + (mx + 1))-1; - player[pn].info.dir = DirTable[conpee]; + player->info.dir = DirTable[conpee]; - if(DirTable[conpee]!=2) player[pn].pdir=DirTable[conpee]; - if(player[pn].q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None))) + if(DirTable[conpee]!=2) player->pdir=DirTable[conpee]; + if(player->enti.q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None))) { - if(dir==2) player[pn].d = player[pn].info.dir; - else player[pn].d = DirTable[dir]; + if(dir==2) player->enti.d = player->info.dir; + else player->enti.d = DirTable[dir]; } #if DEMO0 @@ -993,26 +995,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[pn].q>1) +#ifdef __DEBUG_InputMgr__ +if(dbg_testcontrolnoisy > 0) +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("q=%d ", player[pn].q); - printf("cpee=%c ", dirchar(conpee)); - //printf("(mx)=%d ", mx); - //printf("(my)=%d ", my); - //printf("[%d] ", mx+my); - printf("pdir=%c d=%c dir=%c ", dirchar(player[pn].pdir), dirchar(player[pn].d), dirchar(player[pn].info.dir)); - printf("%c%d %c%d %c%d %c%d\n", 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("b1=%u b2=%u b3=%u b4=%u ", player->info.button0, player->info.button1, player->info.button2, player->info.button3); + //printf("q=%d ", player->enti.q); + //printf("cpee=%c ", dirchar(conpee)); + 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), 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 +#endif } /////////////////////////////////////////////////////////////////////////// @@ -1022,10 +1024,10 @@ if((inpu.Keyboard[def->up] || inpu.Keyboard[def->down] || inpu.Keyboard[def->lef // /////////////////////////////////////////////////////////////////////////// void -IN_SetControlType(word pn,player_t *player,ControlType type) +IN_SetControlType(player_t *player,ControlType type) { // DEBUG - check that requested type is present? - player[pn].Controls = type; + player->Controls = type; } #if DEMO0 @@ -1118,13 +1120,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); } @@ -1135,78 +1137,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; - IN_ClearKey(inpu.LastScan); - inpu.LastScan = sc_None; + buttons = IN_JoyButtons () << 4; + if (gvar->in.MousePresent) + buttons |= IN_MouseButtons (gvar); + + for (i=0;i<8;i++,buttons>>=1) + if ( buttons&1 ) + { + if (!btnstate[i]) + return true; + } + else + btnstate[i]=false; + + return false; +} - if (inpu.MousePresent) - while (INL_GetMouseButtons()) - ; - for (i = 0;i < MaxJoys;i++) - if (inpu.JoysPresent[i]) - while (IN_GetJoyButtonsDB(i)) - ; - IN_AckBack(); +void IN_Ack (global_game_variables_t *gvar) +{ + IN_StartAck (gvar); + + while (!IN_CheckAck (gvar)) + ; } /////////////////////////////////////////////////////////////////////////// @@ -1216,19 +1218,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; @@ -1243,58 +1245,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 TESTKEYIN -// if(testkeyin > 0) printf("%u\n", inpu.Keyboard[kee]); -//#endif - if(inpu.Keyboard[kee]==true) return 1; +#ifdef __DEBUG_InputMgr__ + if(dbg_testkeyin) if(inst.Keyboard[kee]) printf("IN_qb(): %u\n", inst.Keyboard[kee]); +#endif + if(inst.Keyboard[kee]==true) return 1; else return 0; } -//init player! -void IN_initplayer(player_t *player, word pn) +ScanCode IN_GetLastScan() +{ + return inst.LastScan; +} + +ScanCode IN_GetCurCode() { - player[pn].x = player[pn].tx*TILEWH; - player[pn].y = player[pn].ty*TILEWH; - player[pn].triggerx = player[pn].tx; - player[pn].triggery = player[pn].ty+1; -/* player[0].info.x = player[0].tx; - player[0].info.xaxis = player[0].tx*TILEWH; - player[0].info.y = player[0].ty; - player[0].info.yaxis = player[0].ty*TILEWH;*/ - player[pn].q=1; - player[pn].d=2; - player[pn].hp=4; + 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 }