]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_in.c
[16_ca needs huge amounts of work and I should remember what needs to be done soon...
[16.git] / src / lib / 16_in.c
index 85709c5e00c53fc90dd649a8698984b3741005ba..14086bd8909381c57da08fa8836a4a881efbc708 100755 (executable)
@@ -1,21 +1,24 @@
-/* Catacomb Apocalypse Source Code\r
- * Copyright (C) 1993-2014 Flat Rock Software\r
+/* Project 16 Source Code~\r
+ * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
  *\r
- * This program is free software; you can redistribute it and/or modify\r
+ * This file is part of Project 16.\r
+ *\r
+ * Project 16 is free software; you can redistribute it and/or modify\r
  * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
+ * the Free Software Foundation; either version 3 of the License, or\r
  * (at your option) any later version.\r
  *\r
- * This program is distributed in the hope that it will be useful,\r
+ * Project 16 is distributed in the hope that it will be useful,\r
  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
  * GNU General Public License for more details.\r
  *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
+ * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
+ * Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
  */\r
-\r
 //\r
 //     ID Engine\r
 //     ID_IN.c - Input Manager\r
 //\r
 \r
 #include "src/lib/16_in.h"\r
+#pragma        hdrstop\r
 \r
-#ifdef __DEBUG_InputMgr__\r
-boolean dbg_testkeyin=0,dbg_testcontrolnoisy=0;\r
-#endif\r
+static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */\r
 \r
 /*\r
 =============================================================================\r
@@ -49,10 +51,10 @@ boolean dbg_testkeyin=0,dbg_testcontrolnoisy=0;
 \r
 =============================================================================\r
 */\r
-struct inconfig\r
+/*struct inconfig\r
 {\r
-       boolean                 MousePresent;\r
-       boolean                 JoysPresent[MaxJoys];\r
+       boolean         MousePresent;\r
+       boolean         JoysPresent[MaxJoys];\r
        boolean         Keyboard[NumCodes];\r
        boolean         Paused;\r
        char            LastASCII;\r
@@ -60,10 +62,9 @@ struct inconfig
 \r
        KeyboardDef     KbdDefs[MaxKbds];\r
        JoystickDef     JoyDefs[MaxJoys];\r
-} inpu;\r
+} inpu;*/\r
 \r
-//extern inconfig inpu;\r
-//inpu.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};\r
+//gvar->in.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};\r
 \r
 /*\r
 =============================================================================\r
@@ -77,15 +78,21 @@ struct inconfig
 extern "C" {\r
 #endif\r
 \r
-static struct instat {\r
-       boolean         IN_Started;\r
-       boolean         CapsLock;\r
+/*static struct instat {\r
+       boolean         CapsLock;\r
        ScanCode        CurCode,LastCode;\r
-} inst;\r
 \r
-static void                    (*INL_KeyHook)(void);\r
-static void interrupt  (*OldKeyVect)(void);\r
-static char                    *ParmStringsIN[] = {"nojoys","nomouse",nil};\r
+       boolean         Keyboard[NumCodes];\r
+       boolean         Paused;\r
+       char            LastASCII;\r
+       ScanCode        LastScan;\r
+} inst;*/\r
+\r
+//the def stuff is need fix warnings\r
+#ifndef INSTDEFED\r
+#define INSTDEFED\r
+static inst_t inst;\r
+#endif\r
 \r
 static byte        far ASCIINames[] =          // Unshifted ASCII for scan codes\r
                                        {\r
@@ -151,20 +158,18 @@ static    byte        far ASCIINames[] =          // Unshifted ASCII for scan codes
 \r
 static Direction       DirTable[] =            // Quick lookup for total direction\r
                                        {\r
-                                               //dir_Nortinest,\r
-                                               dir_North,\r
-                                               dir_West,\r
-                                               dir_None,\r
-                                               dir_East,\r
-                                               dir_South\r
-                                               //dir_NorthEast,\r
-                                               //dir_Soutinest,\r
-                                               //,dir_SouthEast\r
+                                               /*dir_NorthWest,        */dir_North,/*  dir_NorthEast,*/\r
+                                               dir_West,               dir_None,       dir_East,\r
+                                               /*dir_SouthWest,        */dir_South/*,  dir_SouthEast*/\r
                                        };\r
 #ifdef __cplusplus\r
 }\r
 #endif\r
 \r
+static void                    (*INL_KeyHook)(void);\r
+static void interrupt  (*OldKeyVect)(void);\r
+static char                    *ParmStringsIN[] = {"nojoys","nomouse",nil};\r
+\r
 //     Internal routines\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
@@ -172,23 +177,23 @@ static    Direction       DirTable[] =            // Quick lookup for total direction
 //     INL_KeyService() - Handles a keyboard interrupt (key up/down)\r
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
-void interrupt\r
-INL_KeyService()\r
+/*static */void interrupt\r
+INL_KeyService(void)\r
 {\r
 static boolean special;\r
-               byte    k,c;\r
-               register byte temp;\r
+               byte    k,c,\r
+                               temp;\r
 \r
-       k = inp(0x60);  // Get the scan code\r
+       k = inportb(0x60);      // Get the scan code\r
 \r
        // Tell the XT keyboard controller to clear the key\r
-       outp(0x61,(temp = inp(0x61)) | 0x80);\r
-       outp(0x61,temp);\r
+       outportb(0x61,(temp = inportb(0x61)) | 0x80);\r
+       outportb(0x61,temp);\r
 \r
        if (k == 0xe0)          // Special key prefix\r
                special = true;\r
        else if (k == 0xe1)     // Handle Pause key\r
-               inpu.Paused = true;\r
+               inst.Paused = true;\r
        else\r
        {\r
                if (k & 0x80)   // Break code\r
@@ -197,13 +202,13 @@ static    boolean special;
 \r
 // DEBUG - handle special keys: ctl-alt-delete, print scrn\r
 \r
-                       inpu.Keyboard[k] = false;\r
+                       inst.Keyboard[k] = false;\r
                }\r
                else                    // Make code\r
                {\r
                        inst.LastCode = inst.CurCode;\r
-                       inst.CurCode = inpu.LastScan = k;\r
-                       inpu.Keyboard[k] = true;\r
+                       inst.CurCode = inst.LastScan = k;\r
+                       inst.Keyboard[k] = true;\r
 \r
                        if (special)\r
                                c = SpecialNames[k];\r
@@ -215,7 +220,7 @@ static      boolean special;
                                        // DEBUG - make caps lock light work\r
                                }\r
 \r
-                               if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift])       // If shifted\r
+                               if (inst.Keyboard[sc_LShift] || inst.Keyboard[sc_RShift])       // If shifted\r
                                {\r
                                        c = ShiftNames[k];\r
                                        if ((c >= 'A') && (c <= 'Z') && inst.CapsLock)\r
@@ -229,7 +234,7 @@ static      boolean special;
                                }\r
                        }\r
                        if (c)\r
-                               inpu.LastASCII = c;\r
+                               inst.LastASCII = c;\r
                }\r
 \r
                special = false;\r
@@ -238,13 +243,12 @@ static    boolean special;
        if (INL_KeyHook && !special)\r
                INL_KeyHook();\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
+       if(dbg_testkeyin > 0) printf("%c        %u      [0x%x %u]       %u\n", c, c, k, k, inst.Keyboard[k]);\r
 #endif\r
-       outp(0x20,0x20);\r
+       outportb(0x20,0x20);\r
 }\r
 \r
-void\r
-Mouse(int x)\r
+void INL_Mouse(int x)\r
 {\r
        //union REGS CPURegs;\r
        //x = CPURegs.x.ax;\r
@@ -379,20 +383,18 @@ done:
 ///////////////////////////////////////////////////////////////////////////\r
 //\r
 //     INL_GetJoyDelta() - Returns the relative movement of the specified\r
-//             joystick (from +/-127, scaled adaptively)\r
+//             joystick (from +/-127)\r
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
-static void\r
-INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)\r
+void INL_GetJoyDelta(word joy,int *dx,int *dy/*,boolean adaptive*/, global_game_variables_t *gvar)\r
 {\r
        word            x,y;\r
-       word    time;\r
        word TimeCount = *clockw;\r
        JoystickDef     *def;\r
 static word    lasttime;\r
 \r
        IN_GetJoyAbs(joy,&x,&y);\r
-       def = inpu.JoyDefs + joy;\r
+       def = gvar->in.JoyDefs + joy;\r
 \r
        if (x < def->threshMinX)\r
        {\r
@@ -439,18 +441,17 @@ static    word    lasttime;
        }\r
        else\r
                *dy = 0;\r
-\r
-       if (adaptive)\r
-       {\r
-               time = (TimeCount - lasttime) / 2;\r
-               if (time)\r
-               {\r
-                       if (time > 8)\r
-                               time = 8;\r
-                       *dx *= time;\r
-                       *dy *= time;\r
-               }\r
-       }\r
+//     if (adaptive)\r
+//     {\r
+//             time = (TimeCount - lasttime) / 2;\r
+//             if (time)\r
+//             {\r
+//                     if (time > 8)\r
+//                             time = 8;\r
+//                     *dx *= time;\r
+//                     *dy *= time;\r
+//             }\r
+//     }\r
        lasttime = TimeCount;\r
 }\r
 \r
@@ -465,7 +466,7 @@ INL_GetJoyButtons(word joy)
 {\r
 register       word    result;\r
 \r
-       result = inp(0x201);    // Get all the joystick buttons\r
+       result = inportb(0x201);        // Get all the joystick buttons\r
        result >>= joy? 6 : 4;  // Shift into bits 0-1\r
        result &= 3;                            // Mask off the useless bits\r
        result ^= 3;\r
@@ -490,6 +491,7 @@ IN_GetJoyButtonsDB(word joy)
                result1 = INL_GetJoyButtons(joy);\r
                lasttime = TimeCount;\r
                while(TimeCount == lasttime)\r
+                       //;\r
                result2 = INL_GetJoyButtons(joy);\r
        } while(result1 != result2);\r
        return(result1);\r
@@ -501,14 +503,14 @@ IN_GetJoyButtonsDB(word joy)
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 static void\r
-INL_StartKbd()\r
+INL_StartKbd(global_game_variables_t *gvar)\r
 {\r
-       INL_KeyHook = 0;        // Clear key hook\r
+       INL_KeyHook = NULL;     // Clear key hook\r
 \r
        IN_ClearKeysDown();\r
 \r
-       OldKeyVect = _dos_getvect(KeyInt);\r
-       _dos_setvect(KeyInt,INL_KeyService);\r
+       OldKeyVect = getvect(KeyInt);//IN_KbdLED();\r
+       setvect(KeyInt,INL_KeyService);\r
 }\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
@@ -521,7 +523,7 @@ INL_ShutKbd(void)
 {\r
        pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0);     // Clear ctrl/alt/shift flags\r
 \r
-       _dos_setvect(KeyInt,OldKeyVect);\r
+       setvect(KeyInt,OldKeyVect);\r
 }\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
@@ -532,14 +534,26 @@ INL_ShutKbd(void)
 static boolean\r
 INL_StartMouse(void)\r
 {\r
-       union REGS CPURegs;\r
-       if(_dos_getvect(MouseInt))\r
+#if 0\r
+       if (getvect(MouseInt))\r
        {\r
                Mouse(MReset);\r
-               if(CPURegs.x.ax == 0xffff)\r
+               if (_AX == 0xffff)\r
                        return(true);\r
        }\r
        return(false);\r
+#endif\r
+       byte far *vector;\r
+\r
+\r
+       if ((vector=MK_FP(peek(0,0x33*4+2),peek(0,0x33*4)))==NULL)\r
+       return false;\r
+\r
+       if (*vector == 207)\r
+               return false;\r
+\r
+       Mouse(MReset);\r
+       return true;\r
 }\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
@@ -556,11 +570,11 @@ INL_ShutMouse(void)
 //     INL_SetJoyScale() - Sets up scaling values for the specified joystick\r
 //\r
 static void\r
-INL_SetJoyScale(word joy)\r
+INL_SetJoyScale(word joy, global_game_variables_t *gvar)\r
 {\r
        JoystickDef     *def;\r
 \r
-       def = &(inpu.JoyDefs[joy]);\r
+       def = &(gvar->in.JoyDefs[joy]);\r
        def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);\r
        def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);\r
        def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);\r
@@ -574,12 +588,12 @@ INL_SetJoyScale(word joy)
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 void\r
-IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)\r
+IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy, global_game_variables_t *gvar)\r
 {\r
        word            d,r;\r
        JoystickDef     *def;\r
 \r
-       def = &(inpu.JoyDefs[joy]);\r
+       def = &(gvar->in.JoyDefs[joy]);\r
 \r
        def->joyMinX = minx;\r
        def->joyMaxX = maxx;\r
@@ -595,7 +609,7 @@ IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
        def->threshMinY = ((r / 2) - d) + miny;\r
        def->threshMaxY = ((r / 2) + d) + miny;\r
 \r
-       INL_SetJoyScale(joy);\r
+       INL_SetJoyScale(joy, gvar);\r
 }\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
@@ -605,7 +619,7 @@ IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 static boolean\r
-INL_StartJoy(word joy)\r
+INL_StartJoy(word joy, global_game_variables_t *gvar)\r
 {\r
        word            x,y;\r
 \r
@@ -619,7 +633,7 @@ INL_StartJoy(word joy)
                return(false);\r
        else\r
        {\r
-               IN_SetupJoy(joy,0,x * 2,0,y * 2);\r
+               IN_SetupJoy(joy,0,x * 2,0,y * 2, gvar);\r
                return(true);\r
        }\r
 }\r
@@ -630,9 +644,9 @@ INL_StartJoy(word joy)
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 static void\r
-INL_ShutJoy(word joy)\r
+INL_ShutJoy(word joy, global_game_variables_t *gvar)\r
 {\r
-       inpu.JoysPresent[joy] = false;\r
+       gvar->in.JoysPresent[joy] = false;\r
 }\r
 \r
 //     Public routines\r
@@ -643,12 +657,12 @@ INL_ShutJoy(word joy)
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 void\r
-IN_Startup()\r
+IN_Startup(global_game_variables_t *gvar)\r
 {\r
        boolean checkjoys,checkmouse;\r
        word    i;\r
 \r
-       if (inst.IN_Started)\r
+       if (gvar->in.IN_Started)\r
                return;\r
 \r
        checkjoys = true;\r
@@ -666,13 +680,15 @@ IN_Startup()
                }\r
        }\r
 \r
-       INL_StartKbd();\r
-       inpu.MousePresent = checkmouse? INL_StartMouse() : false;\r
+       INL_StartKbd(gvar);\r
+       gvar->in.MousePresent = checkmouse? INL_StartMouse() : false;\r
 \r
        for (i = 0;i < MaxJoys;i++)\r
-               inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;\r
+               gvar->in.JoysPresent[i] = checkjoys? INL_StartJoy(i, gvar) : false;\r
+\r
+       gvar->in.inst = &inst;\r
 \r
-       inst.IN_Started = true;\r
+       gvar->in.IN_Started = true;\r
 \r
 }\r
 \r
@@ -682,30 +698,30 @@ IN_Startup()
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 void\r
-IN_Default(boolean gotit,player_t *player,ControlType nt)\r
+IN_Default(boolean gotit,player_t *player,ControlType nt, global_game_variables_t *gvar)\r
 {\r
        int i;\r
        if\r
        (\r
                (!gotit)\r
-       ||      ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0])\r
-       ||      ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1])\r
-       ||      ((nt == ctrl_Mouse) && !inpu.MousePresent)\r
+       ||      ((nt == ctrl_Joystick1) && !gvar->in.JoysPresent[0])\r
+       ||      ((nt == ctrl_Joystick2) && !gvar->in.JoysPresent[1])\r
+       ||      ((nt == ctrl_Mouse) && !gvar->in.MousePresent)\r
        )\r
                nt = ctrl_Keyboard1;\r
-       inpu.KbdDefs[0].button0 = 0x1c;\r
-       inpu.KbdDefs[0].button1 = 0x38;\r
+       gvar->in.KbdDefs[0].button0 = 0x1c;\r
+       gvar->in.KbdDefs[0].button1 = 0x38;\r
        //in.KbdDefs[0].upleft = 0x47;\r
-       inpu.KbdDefs[0].up = 0x48;\r
+       gvar->in.KbdDefs[0].up = 0x48;\r
        //in.KbdDefs[0].upright = 0x49;\r
-       inpu.KbdDefs[0].left = 0x4b;\r
-       inpu.KbdDefs[0].right = 0x4d;\r
+       gvar->in.KbdDefs[0].left = 0x4b;\r
+       gvar->in.KbdDefs[0].right = 0x4d;\r
        //in.KbdDefs[0].downleft = 0x4f;\r
-       inpu.KbdDefs[0].down = 0x50;\r
+       gvar->in.KbdDefs[0].down = 0x50;\r
        //in.KbdDefs[0].downright = 0x51;\r
-       IN_SetControlType(0,player,nt);\r
+       IN_SetControlType(player,nt);\r
        for(i=0; i>MaxPlayers;i++)\r
-               player[i].d=2;\r
+               player[i].enti.d =2;\r
 }\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
@@ -714,19 +730,19 @@ IN_Default(boolean gotit,player_t *player,ControlType nt)
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 void\r
-IN_Shutdown()\r
+IN_Shutdown(global_game_variables_t *gvar)\r
 {\r
        word    i;\r
 \r
-       if (!inst.IN_Started)\r
+       if (!gvar->in.IN_Started)\r
                return;\r
 \r
        INL_ShutMouse();\r
        for (i = 0;i < MaxJoys;i++)\r
-               INL_ShutJoy(i);\r
+               INL_ShutJoy(i, gvar);\r
        INL_ShutKbd();\r
 \r
-       inst.IN_Started = false;\r
+       gvar->in.IN_Started = false;\r
 }\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
@@ -743,17 +759,17 @@ IN_SetKeyHook(void (*hook)())
 \r
 ///////////////////////////////////////////////////////////////////////////\r
 //\r
-//     IN_ClearKeyDown() - Clears the keyboard array\r
+//     IN_ClearKeysDown() - Clears the keyboard array\r
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 void\r
-IN_ClearKeysDown()\r
+IN_ClearKeysDown(void)\r
 {\r
-       int     i;\r
+       //int   i;\r
 \r
-       inpu.LastScan = sc_None;\r
-       inpu.LastASCII = key_None;\r
-       memset (inpu.Keyboard,0,sizeof(inpu.Keyboard));\r
+       inst.LastScan = sc_None;\r
+       inst.LastASCII = key_None;\r
+       memset (inst.Keyboard,0,sizeof(inst.Keyboard));\r
 }\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
@@ -780,7 +796,7 @@ INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 void\r
-IN_ReadCursor(CursorInfo *info)\r
+IN_ReadCursor(CursorInfo *info, global_game_variables_t *gvar)\r
 {\r
        word    i,\r
                        buttons;\r
@@ -789,7 +805,7 @@ IN_ReadCursor(CursorInfo *info)
        info->x = info->y = 0;\r
        info->button0 = info->button1 = false;\r
 \r
-       if (inpu.MousePresent)\r
+       if (gvar->in.MousePresent)\r
        {\r
                buttons = INL_GetMouseButtons();\r
                INL_GetMouseDelta(&dx,&dy);\r
@@ -798,28 +814,34 @@ IN_ReadCursor(CursorInfo *info)
 \r
        for (i = 0;i < MaxJoys;i++)\r
        {\r
-               if (!inpu.JoysPresent[i])\r
+               if (!gvar->in.JoysPresent[i])\r
                        continue;\r
 \r
                buttons = INL_GetJoyButtons(i);\r
-               INL_GetJoyDelta(i,&dx,&dy,true);\r
+               INL_GetJoyDelta(i,&dx,&dy/*,true*/, gvar);\r
                dx /= 64;\r
                dy /= 64;\r
                INL_AdjustCursor(info,buttons,dx,dy);\r
        }\r
 }\r
 \r
+//if else for gfxtesting and direction\r
+#define DIRECTIONIFELSE        (player->info.dir == 2)\r
+//#define NDIRECTIONIFELSE     (player->info.dir != 2)\r
+\r
 ///////////////////////////////////////////////////////////////////////////\r
 //\r
 //     IN_ReadControl() - Reads the device associated with the specified\r
 //             player and fills in the control info struct\r
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
-void near\r
-IN_ReadControl(int pn,player_t *player)\r
+void\r
+IN_ReadControl(player_t *player, global_game_variables_t *gvar)\r
 {\r
                        boolean         realdelta;\r
+#if DEMO0\r
                        byte            dbyte;\r
+#endif\r
                        word            buttons;\r
                        int                     dx,dy;\r
                        Motion          mx,my;\r
@@ -850,15 +872,15 @@ register  KeyboardDef     *def;
                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
-               switch (type = player[pn].Controls)\r
+               switch (type = player->Controls)\r
                {\r
                case ctrl_Keyboard1:\r
                case ctrl_Keyboard2:\r
-                       def = &(inpu.KbdDefs[type - ctrl_Keyboard]);\r
+                       def = &(gvar->in.KbdDefs[type - ctrl_Keyboard]);\r
 \r
 /*                     if (Keyboard[def->upleft])\r
                                mx = motion_Left,my = motion_Up;\r
@@ -869,49 +891,49 @@ register  KeyboardDef     *def;
                        else if (Keyboard[def->downright])\r
                                mx = motion_Right,my = motion_Down;*/\r
 //TODO: make this into a function that the joystick AND keyboard can use wwww\r
-                       if(DIRECTIONIFELSE)//(player[pn].info.dir == 2)\r
+                       if(DIRECTIONIFELSE)//(player->info.dir == 2)\r
                        {\r
-                       if(!inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]){\r
-                               if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]))\r
+                       if(!inst.Keyboard[def->left] && !inst.Keyboard[def->right]){\r
+                               if((inst.Keyboard[def->up] && !inst.Keyboard[def->down]))\r
                                        my = motion_Up;\r
-                               if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up]))\r
+                               if((inst.Keyboard[def->down] && !inst.Keyboard[def->up]))\r
                                        my = motion_Down;\r
-                       }else if(!inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]){\r
-                               if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]))\r
+                       }else if(!inst.Keyboard[def->up] && !inst.Keyboard[def->down]){\r
+                               if((inst.Keyboard[def->left] && !inst.Keyboard[def->right]))\r
                                        mx = motion_Left;\r
-                               if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left]))\r
+                               if((inst.Keyboard[def->right] && !inst.Keyboard[def->left]))\r
                                        mx = motion_Right;\r
                        }else{  //2 keys pressed\r
-                                       switch (player[pn].pdir)\r
+                                       switch (player->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
+                                                       if((inst.Keyboard[def->left] && !inst.Keyboard[def->right])){ dir = DirTable[1]; }//mx = motion_Left; }\r
+                                                       else if((inst.Keyboard[def->right] && !inst.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
+                                                       if((inst.Keyboard[def->up] && !inst.Keyboard[def->down])){ dir = DirTable[0]; }//my = motion_Up; }\r
+                                                       else if((inst.Keyboard[def->down] && !inst.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
+                                       //if(dbg_testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c        ", dirchar(player->pdir)); }\r
 #endif\r
                                }\r
                        }\r
                        //input from player\r
-                       if (inpu.Keyboard[def->button0])\r
+                       if (inst.Keyboard[def->button0])\r
                                buttons += 1 << 0;\r
-                       if (inpu.Keyboard[def->button1])\r
+                       if (inst.Keyboard[def->button1])\r
                                buttons += 1 << 1;\r
                        realdelta = false;\r
                        break;\r
                case ctrl_Joystick1:\r
                case ctrl_Joystick2:\r
-                       INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);\r
+                       INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy/*,false*/, gvar);\r
                        buttons = INL_GetJoyButtons(type - ctrl_Joystick);\r
                        realdelta = true;\r
                        break;\r
@@ -936,23 +958,23 @@ register  KeyboardDef     *def;
                dy = my;// * 127;\r
        }\r
 \r
-       player[pn].info.x = dx;\r
-       player[pn].info.xaxis = mx;\r
-       player[pn].info.y = dy;\r
-       player[pn].info.yaxis = my;\r
-       player[pn].info.button0 = buttons & (1 << 0);\r
-       player[pn].info.button1 = buttons & (1 << 1);\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
+       player->info.x = dx;\r
+       player->info.xaxis = mx;\r
+       player->info.y = dy;\r
+       player->info.yaxis = my;\r
+       player->info.button0 = buttons & (1 << 0);\r
+       player->info.button1 = buttons & (1 << 1);\r
+       player->info.button2 = buttons & (1 << 2);\r
+       player->info.button3 = buttons & (1 << 3);\r
+//     player->info.dir = DirTable[((my + 1) * 3) + (mx + 1)];\r
        conpee=(((my + 1) * 2) + (mx + 1))-1;\r
-       player[pn].info.dir = DirTable[conpee];\r
+       player->info.dir = DirTable[conpee];\r
 \r
-       if(DirTable[conpee]!=2) player[pn].pdir=DirTable[conpee];\r
-       if(player[pn].q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None)))\r
+       if(DirTable[conpee]!=2) player->pdir=DirTable[conpee];\r
+       if(player->enti.q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None)))\r
        {\r
-               if(dir==2) player[pn].d = player[pn].info.dir;\r
-               else player[pn].d = DirTable[dir];\r
+               if(dir==2) player->enti.d = player->info.dir;\r
+               else player->enti.d = DirTable[dir];\r
        }\r
 \r
 #if DEMO0\r
@@ -973,7 +995,7 @@ register    KeyboardDef     *def;
                                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
@@ -982,14 +1004,14 @@ register KeyboardDef     *def;
 #endif\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].q>1)\r
+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)\r
 {\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].q);\r
+       //printf("b1=%u b2=%u b3=%u b4=%u       ", player->info.button0, player->info.button1, player->info.button2, player->info.button3);\r
+       //printf("q=%d ", player->enti.q);\r
        //printf("cpee=%c ", dirchar(conpee));\r
-       printf("pdir=%c d=%c dir=%c ", dirchar(player[pn].pdir), dirchar(player[pn].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("pdir=%c d=%c dir=%c ", dirchar(player->pdir), dirchar(player->enti.d), dirchar(player->info.dir));\r
+       /*if(realdelta) */printf("dx=%d dy=%d   mx=%d   my=%d", player->info.x, player->info.y, player->info.xaxis, player->info.yaxis);\r
+       //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]);\r
        printf("\n");\r
 }\r
 #endif\r
@@ -1002,10 +1024,10 @@ if(player[pn].info.dir!=2/*(inpu.Keyboard[def->up] || inpu.Keyboard[def->down] |
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 void\r
-IN_SetControlType(word pn,player_t *player,ControlType type)\r
+IN_SetControlType(player_t *player,ControlType type)\r
 {\r
        // DEBUG - check that requested type is present?\r
-       player[pn].Controls = type;\r
+       player->Controls = type;\r
 }\r
 \r
 #if DEMO0\r
@@ -1098,13 +1120,13 @@ IN_GetScanName(ScanCode scan)
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 ScanCode\r
-IN_WaitForKey()\r
+IN_WaitForKey(void)\r
 {\r
        ScanCode        result;\r
 \r
-       while (!(result = inpu.LastScan))\r
+       while (!(result = inst.LastScan))\r
                ;\r
-       inpu.LastScan = 0;\r
+       inst.LastScan = 0;\r
        return(result);\r
 }\r
 \r
@@ -1115,81 +1137,78 @@ IN_WaitForKey()
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 char\r
-IN_WaitForASCII()\r
+IN_WaitForASCII(void)\r
 {\r
        char            result;\r
 \r
-       while (!(result = inpu.LastASCII))\r
+       while (!(result = inst.LastASCII))\r
                ;\r
-       inpu.LastASCII = '\0';\r
+       inst.LastASCII = '\0';\r
        return(result);\r
 }\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
 //\r
-//     IN_AckBack() - Waits for either an ASCII keypress or a button press\r
+//     IN_Ack() - waits for a button or key press.  If a button is down, upon\r
+// calling, it must be released for it to be recognized\r
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
-void\r
-IN_AckBack()\r
+\r
+boolean        btnstate[8];\r
+\r
+void IN_StartAck(global_game_variables_t *gvar)\r
 {\r
-       word    i;\r
+       unsigned        i,buttons;\r
 \r
-       while (!inpu.LastScan)\r
-       {\r
-               if (inpu.MousePresent)\r
-               {\r
-                       if (INL_GetMouseButtons())\r
-                       {\r
-                               while (INL_GetMouseButtons())\r
-                                       ;\r
-                               return;\r
-                       }\r
-               }\r
+//\r
+// get initial state of everything\r
+//\r
+       IN_ClearKeysDown();\r
+       memset (btnstate,0,sizeof(btnstate));\r
 \r
-               for (i = 0;i < MaxJoys;i++)\r
-               {\r
-                       if (inpu.JoysPresent[i])\r
-                       {\r
-                               if (IN_GetJoyButtonsDB(i))\r
-                               {\r
-                                       while (IN_GetJoyButtonsDB(i))\r
-                                               ;\r
-                                       return;\r
-                               }\r
-                       }\r
-               }\r
-       }\r
+       buttons = IN_JoyButtons () << 4;\r
+       if (gvar->in.MousePresent)\r
+               buttons |= IN_MouseButtons (gvar);\r
 \r
-       IN_ClearKey(inpu.LastScan);\r
-       inpu.LastScan = sc_None;\r
+       for (i=0;i<8;i++,buttons>>=1)\r
+               if (buttons&1)\r
+                       btnstate[i] = true;\r
 }\r
 \r
-///////////////////////////////////////////////////////////////////////////\r
+\r
+boolean IN_CheckAck (global_game_variables_t *gvar)\r
+{\r
+       unsigned        i,buttons;\r
+\r
 //\r
-//     IN_Ack() - Clears user input & then calls IN_AckBack()\r
+// see if something has been pressed\r
 //\r
-///////////////////////////////////////////////////////////////////////////\r
-void\r
-IN_Ack()\r
-{\r
-       word    i;\r
+       if (inst.LastScan)\r
+               return true;\r
 \r
-       if (!inst.IN_Started)\r
-               return;\r
+       buttons = IN_JoyButtons () << 4;\r
+       if (gvar->in.MousePresent)\r
+               buttons |= IN_MouseButtons (gvar);\r
 \r
-       IN_ClearKey(inpu.LastScan);\r
-       inpu.LastScan = sc_None;\r
+       for (i=0;i<8;i++,buttons>>=1)\r
+               if ( buttons&1 )\r
+               {\r
+                       if (!btnstate[i])\r
+                               return true;\r
+               }\r
+               else\r
+                       btnstate[i]=false;\r
 \r
-       if (inpu.MousePresent)\r
-               while (INL_GetMouseButtons())\r
-                                       ;\r
-       for (i = 0;i < MaxJoys;i++)\r
-               if (inpu.JoysPresent[i])\r
-                       while (IN_GetJoyButtonsDB(i))\r
-                               ;\r
+       return false;\r
+}\r
 \r
-       IN_AckBack();\r
+\r
+void IN_Ack (global_game_variables_t *gvar)\r
+{\r
+       IN_StartAck (gvar);\r
+\r
+       while (!IN_CheckAck (gvar))\r
+       ;\r
 }\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
@@ -1199,19 +1218,19 @@ IN_Ack()
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 boolean\r
-IN_IsUserInput()\r
+IN_IsUserInput(global_game_variables_t *gvar)\r
 {\r
        boolean result;\r
        word    i;\r
 \r
-       result = inpu.LastScan;\r
+       result = inst.LastScan;\r
 \r
-       if (inpu.MousePresent)\r
+       if (gvar->in.MousePresent)\r
                if (INL_GetMouseButtons())\r
                        result = true;\r
 \r
        for (i = 0;i < MaxJoys;i++)\r
-               if (inpu.JoysPresent[i])\r
+               if (gvar->in.JoysPresent[i])\r
                        if (INL_GetJoyButtons(i))\r
                                result = true;\r
 \r
@@ -1226,61 +1245,112 @@ IN_IsUserInput()
 //             button up.\r
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
-boolean\r
-IN_UserInput(dword delay,boolean clear)\r
+boolean IN_UserInput(word delay, global_game_variables_t *gvar)\r
 {\r
        word TimeCount = *clockw;\r
        word    lasttime;\r
 \r
        lasttime = TimeCount;\r
+       IN_StartAck (gvar);\r
        do\r
        {\r
-               if (IN_IsUserInput())\r
-               {\r
-                       if (clear)\r
-                               IN_AckBack();\r
-                       return(true);\r
-               }\r
+               if (IN_CheckAck(gvar))\r
+                       return true;\r
        } while (TimeCount - lasttime < delay);\r
        return(false);\r
 }\r
 \r
+//===========================================================================\r
+\r
+/*\r
+===================\r
+=\r
+= IN_MouseButtons\r
+=\r
+===================\r
+*/\r
+\r
+byte   IN_MouseButtons (global_game_variables_t *gvar)\r
+{\r
+       union REGS CPURegs;\r
+       if (gvar->in.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 = inportb(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
-       return inpu.Keyboard[code];\r
+#ifdef __DEBUG_InputMgr__\r
+       if(inst.Keyboard[code])\r
+               printf("IN_KeyDown(%c): %u\n", code, inst.Keyboard[code]);\r
+       if(!dbg_nointest)\r
+#endif\r
+       return inst.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
-       inpu.Keyboard[code] = false;\r
-       if(code == inpu.LastScan)\r
-               inpu.LastScan = sc_None;\r
+       inst.Keyboard[code] = false;\r
+       if(code == inst.LastScan)\r
+               inst.LastScan = sc_None;\r
        }\r
 \r
 boolean IN_qb(byte kee)\r
 {\r
 #ifdef __DEBUG_InputMgr__\r
-//     if(dbg_testkeyin > 0) printf("%u\n", inpu.Keyboard[kee]);\r
+       if(dbg_testkeyin) if(inst.Keyboard[kee]) printf("IN_qb():       %u\n", inst.Keyboard[kee]);\r
 #endif\r
-       if(inpu.Keyboard[kee]==true) return 1;\r
+       if(inst.Keyboard[kee]==true) return 1;\r
        else return 0;\r
 }\r
 \r
-//init player!\r
-void IN_initplayer(player_t *player, word pn)\r
+ScanCode IN_GetLastScan()\r
 {\r
-       player[pn].x = player[pn].tx*TILEWH;\r
-       player[pn].y = player[pn].ty*TILEWH;\r
-       player[pn].triggerx = player[pn].tx;\r
-       player[pn].triggery = player[pn].ty+1;\r
-/*     player[0].info.x = player[0].tx;\r
-       player[0].info.xaxis = player[0].tx*TILEWH;\r
-       player[0].info.y = player[0].ty;\r
-       player[0].info.yaxis = player[0].ty*TILEWH;*/\r
-       player[pn].q=1;\r
-       player[pn].d=2;\r
-       player[pn].hp=4;\r
-       player[pn].speed=4;\r
-       player[pn].persist_aniframe=0;\r
-       player[pn].spt=(TILEWH/(player[pn].speed));     //speed per tile wwww\r
+       return inst.LastScan;\r
+}\r
+\r
+ScanCode IN_GetCurCode()\r
+{\r
+       return inst.CurCode;\r
+}\r
+\r
+void IN_KbdLED()\r
+{\r
+       byte far *lock_key;\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
 }\r