]> 4ch.mooo.com Git - 16.git/commitdiff
branch~
authorsparky4 <sparky4@cock.li>
Mon, 29 Jun 2015 07:42:47 +0000 (02:42 -0500)
committersparky4 <sparky4@cock.li>
Mon, 29 Jun 2015 07:42:47 +0000 (02:42 -0500)
new file:   16/16_in.c
new file:   16/16_in.h
new file:   16/inpu.bat
new file:   16/inputest.c

16/16_in.c [new file with mode: 0644]
16/16_in.h [new file with mode: 0644]
16/inpu.bat [new file with mode: 0644]
16/inputest.c [new file with mode: 0644]

diff --git a/16/16_in.c b/16/16_in.c
new file mode 100644 (file)
index 0000000..147f17e
--- /dev/null
@@ -0,0 +1,284 @@
+/* Catacomb Apocalypse Source Code\r
+ * Copyright (C) 1993-2014 Flat Rock Software\r
+ *\r
+ * This program 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
+ * (at your option) any later version.\r
+ *\r
+ * This program 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
+ */\r
+\r
+//\r
+//     ID Engine\r
+//     ID_IN.h - Header file for Input Manager\r
+//     v1.0d1w\r
+//     By Jason Blochowiak
+//     Open Watcom port by sparky4\r
+//\r
+\r
+#ifndef        __16_IN__\r
+#define        __16_IN__\r
+
+#include <string.h>\r
+#include "../src/lib/lib_head.h"\r
+\r
+//++++#ifdef   __DEBUG__\r
+#define        __DEBUG_InputMgr__\r
+//++++#endif\r
+\r
+#define TESTKEYIN
+#define TESTCONTROLNOISY\r
+\r
+#define        KeyInt  9       // The keyboard ISR number\r
+\r
+// Stuff for the joystick\r
+#define        JoyScaleMax             32768\r
+#define        JoyScaleShift   8\r
+#define        MaxJoyValue             5000\r
+\r
+#define        MaxPlayers      4\r
+#define        MaxKbds         2\r
+#define        MaxJoys         2
+#define        MaxPads         2\r
+#define        NumCodes        128\r
+\r
+typedef        byte            ScanCode;\r
+#define        sc_None                 0\r
+#define        sc_Bad                  0xff\r
+#define        sc_Return               0x1c\r
+#define        sc_Enter                sc_Return\r
+#define        sc_Escape               0x01\r
+#define        sc_Space                0x39\r
+#define        sc_BackSpace    0x0e\r
+#define        sc_Tab                  0x0f\r
+#define        sc_Alt                  0x38\r
+#define        sc_Control              0x1d\r
+#define        sc_CapsLock             0x3a\r
+#define        sc_LShift               0x2a\r
+#define        sc_RShift               0x36\r
+#define        sc_UpArrow              0x48\r
+#define        sc_DownArrow    0x50\r
+#define        sc_LeftArrow    0x4b\r
+#define        sc_RightArrow   0x4d\r
+#define        sc_Insert               0x52\r
+#define        sc_Delete               0x53\r
+#define        sc_Home                 0x47\r
+#define        sc_End                  0x4f\r
+#define        sc_PgUp                 0x49\r
+#define        sc_PgDn                 0x51\r
+#define        sc_F1                   0x3b\r
+#define        sc_F2                   0x3c\r
+#define        sc_F3                   0x3d\r
+#define        sc_F4                   0x3e\r
+#define        sc_F5                   0x3f\r
+#define        sc_F6                   0x40\r
+#define        sc_F7                   0x41\r
+#define        sc_F8                   0x42\r
+#define        sc_F9                   0x43\r
+#define        sc_F10                  0x44\r
+#define        sc_F11                  0x57\r
+#define        sc_F12                  0x59\r
+\r
+#define        sc_1                    0x02\r
+#define        sc_2                    0x03\r
+#define        sc_3                    0x04\r
+#define        sc_4                    0x05\r
+#define        sc_5                    0x06\r
+#define        sc_6                    0x07\r
+#define        sc_7                    0x08\r
+#define        sc_8                    0x09\r
+#define        sc_9                    0x0a\r
+#define        sc_0                    0x0b\r
+\r
+#define        sc_A                    0x1e\r
+#define        sc_B                    0x30\r
+#define        sc_C                    0x2e\r
+#define        sc_D                    0x20\r
+#define        sc_E                    0x12\r
+#define        sc_F                    0x21\r
+#define        sc_G                    0x22\r
+#define        sc_H                    0x23\r
+#define        sc_I                    0x17\r
+#define        sc_J                    0x24\r
+#define        sc_K                    0x25\r
+#define        sc_L                    0x26\r
+#define        sc_M                    0x32\r
+#define        sc_N                    0x31\r
+#define        sc_O                    0x18\r
+#define        sc_P                    0x19\r
+#define        sc_Q                    0x10\r
+#define        sc_R                    0x13\r
+#define        sc_S                    0x1f\r
+#define        sc_T                    0x14\r
+#define        sc_U                    0x16\r
+#define        sc_V                    0x2f\r
+#define        sc_W                    0x11\r
+#define        sc_X                    0x2d\r
+#define        sc_Y                    0x15\r
+#define        sc_Z                    0x2c\r
+\r
+#define        key_None                0\r
+#define        key_Return              0x0d\r
+#define        key_Enter               key_Return\r
+#define        key_Escape              0x1b\r
+#define        key_Space               0x20\r
+#define        key_BackSpace   0x08\r
+#define        key_Tab                 0x09\r
+#define        key_Delete              0x7f\r
+
+#define        key_LSuper                      0x5b
+#define        key_RSuper                      0x5c
+#define        key_Menu                        0x5d
+\r
+//     Stuff for the mouse\r
+#define        MReset          0\r
+#define        MButtons        3\r
+#define        MDelta          11\r
+\r
+#define        MouseInt        0x33\r
+#ifdef DEMO0\r
+typedef        enum            {\r
+                                               demo_Off,demo_Record,demo_Playback,demo_PlayDone\r
+                                       } Demo;\r
+#endif\r
+typedef        enum            {\r
+                                               //ctrl_None,                            // MDM (GAMERS EDGE) - added\r
+                                               ctrl_Keyboard,\r
+                                                       ctrl_Keyboard1 = ctrl_Keyboard,ctrl_Keyboard2,\r
+                                               ctrl_Joystick,\r
+                                                       ctrl_Joystick1 = ctrl_Joystick,ctrl_Joystick2,\r
+                                               ctrl_Mouse,
+                                               ctrl_Joypad,
+                                                       ctrl_Joypad1 = ctrl_Joypad,ctrl_Joypad2\r
+                                       } ControlType;\r
+typedef        enum            {\r
+                                               motion_Left = -1,motion_Up = -1,\r
+                                               motion_None = 0,\r
+                                               motion_Right = 1,motion_Down = 1\r
+                                       } Motion;\r
+typedef        enum            {\r
+                                               dir_North,//dir_NorthEast,\r
+                                               dir_East,//dir_SouthEast,\r
+                                               dir_South,//dir_Soutinest,\r
+                                               dir_West,//dir_Nortinest,\r
+                                               dir_None\r
+                                       } Direction;\r
+typedef        struct          {\r
+                                               boolean         button0,button1,button2,button3;\r
+                                               int                     x,y;\r
+                                               Motion          xaxis,yaxis;\r
+                                               Direction       dir;\r
+                                       } CursorInfo;\r
+\r
+typedef        struct          {\r
+                                               ScanCode        button0,button1,\r
+                                                                       //upleft,\r
+                                                                       up,\r
+                                                                       //upright,\r
+                                                                       left,                           right,\r
+                                                                       //downleft,\r
+                                                                       down\r
+                                                                       //,downright\r
+                                                                       ;\r
+                                       } KeyboardDef;\r
+typedef        struct          {\r
+                                               word            joyMinX,joyMinY,\r
+                                                                       threshMinX,threshMinY,\r
+                                                                       threshMaxX,threshMaxY,\r
+                                                                       joyMaxX,joyMaxY,\r
+                                                                       joyMultXL,joyMultYL,\r
+                                                                       joyMultXH,joyMultYH;\r
+                                       } JoystickDef;
+typedef        struct
+{
+       boolean w;\r
+} JoypadDef;
+
+typedef        struct
+{
+       CursorInfo      info;
+       ControlType     Controls;
+} player_t;
+
+/*\r
+=============================================================================\r
+\r
+                                       GLOBAL VARIABLES\r
+\r
+=============================================================================\r
+*/
+/*extern struct inconfig
+{
+       boolean                 MousePresent;\r
+       boolean                 JoysPresent[MaxJoys];\r
+       boolean                 JoyPadPresent[MaxPads];
+       boolean         Keyboard[NumCodes];\r
+       boolean         Paused;\r
+       char            LastASCII;\r
+       ScanCode        LastScan;
+
+       KeyboardDef     KbdDefs[MaxKbds];
+       JoystickDef     JoyDefs[MaxJoys];
+       JoypadDef       JoypadDefs[MaxPads];
+} inpu;*/
+
+#ifdef DEMO0\r
+               static Demo             DemoMode = demo_Off;\r
+               static byte /*_seg*/    *DemoBuffer;\r
+               static word             DemoOffset,DemoSize;\r
+#endif\r
+
+extern dword far* clockdw;\r
+\r
+//     Internal routines
+extern void interrupt INL_KeyService();
+extern void Mouse(int x);
+//static void INL_GetMouseDelta(int *x,int *y);
+//static word INL_GetMouseButtons(void);
+extern void IN_GetJoyAbs(word joy,word *xp,word *yp);
+//static void INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive);
+//static word INL_GetJoyButtons(word joy);
+extern word IN_GetJoyButtonsDB(word joy);
+//static void INL_StartKbd(void);
+//static void INL_ShutKbd(void);
+//static boolean INL_StartMouse(void);
+//static void INL_ShutMouse(void);
+//static void INL_SetJoyScale(word joy);
+extern void IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy);
+//static boolean INL_StartJoy(word joy);
+//static void INL_ShutJoy(word joy);
+extern void IN_Startup();
+extern void IN_Default(boolean gotit,player_t *player,ControlType nt);
+extern void IN_Shutdown();
+extern void IN_SetKeyHook(void (*hook)());
+extern void IN_ClearKeysDown();
+//static void INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy);
+extern void IN_ReadCursor(CursorInfo *info);
+extern void IN_ReadControl(int playnum,player_t *player);
+extern void IN_SetControlType(word playnum,player_t *player,ControlType type);
+#if DEMO0
+extern boolean IN_StartDemoRecord(word bufsize);
+extern void IN_StartDemoPlayback(byte /*__segment*/ *buffer,word bufsize);
+extern void IN_StopDemo(void);
+extern void IN_FreeDemoBuffer(void);
+#endif
+extern byte *IN_GetScanName(ScanCode scan);
+extern ScanCode IN_WaitForKey();
+extern char IN_WaitForASCII();
+extern void IN_AckBack();
+extern void IN_Ack();
+extern boolean IN_IsUserInput();
+extern boolean IN_UserInput(dword delay,boolean clear);
+extern boolean IN_KeyDown(byte code);
+extern void IN_ClearKey(byte code);
+extern boolean IN_qb(byte kee);
+\r
+#endif\r
diff --git a/16/16_in.h b/16/16_in.h
new file mode 100644 (file)
index 0000000..3a36fbb
--- /dev/null
@@ -0,0 +1,1186 @@
+/* Catacomb Apocalypse Source Code\r
+ * Copyright (C) 1993-2014 Flat Rock Software\r
+ *\r
+ * This program 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
+ * (at your option) any later version.\r
+ *\r
+ * This program 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
+ */
+
+//
+//     ID Engine
+//     ID_IN.c - Input Manager
+//     v1.0d1w
+//     By Jason Blochowiak
+//     Open Watcom port by sparky4
+//
+
+//
+//     This module handles dealing with the various input devices
+//
+//     Depends on: Memory Mgr (for demo recording), Sound Mgr (for timing stuff),
+//                             User Mgr (for command line parms)
+//
+//     Globals:
+//             LastScan - The keyboard scan code of the last key pressed
+//             LastASCII - The ASCII value of the last key pressed
+//     DEBUG - there are more globals
+//
+
+#include "16_in.h"
+
+/*\r
+=============================================================================\r
+\r
+                                       GLOBAL VARIABLES\r
+\r
+=============================================================================\r
+*/
+struct inconfig
+{
+       boolean                 MousePresent;\r
+       boolean                 JoysPresent[MaxJoys];\r
+       boolean                 JoyPadPresent[MaxPads];
+       boolean         Keyboard[NumCodes];\r
+       boolean         Paused;\r
+       char            LastASCII;\r
+       ScanCode        LastScan;
+
+       KeyboardDef     KbdDefs[MaxKbds];// = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
+       JoystickDef     JoyDefs[MaxJoys];
+       JoypadDef       JoypadDefs[MaxPads];
+} inpu;
+
+//inpu.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
+
+/*\r
+=============================================================================\r
+\r
+                                       LOCAL VARIABLES\r
+\r
+=============================================================================\r
+*/
+
+#ifdef __cplusplus             /* Function must be declared C style */
+extern "C" {
+#endif
+\r
+static struct instat {
+       boolean         IN_Started;\r
+       boolean         CapsLock;\r
+       ScanCode        CurCode,LastCode;
+} inst;
+\r
+static void                    (*INL_KeyHook)(void);
+static void interrupt  (*OldKeyVect)(void);
+static char                    *ParmStringsIN[] = {"nojoys","nomouse",nil};
+\r
+static byte        far ASCIINames[] =          // Unshifted ASCII for scan codes\r
+                                       {\r
+//      0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F\r
+       0  ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8  ,9  ,        // 0\r
+       'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0  ,'a','s',        // 1\r
+       'd','f','g','h','j','k','l',';',39 ,'`',0  ,92 ,'z','x','c','v',        // 2\r
+       'b','n','m',',','.','/',0  ,'*',0  ,' ',0  ,0  ,0  ,0  ,0  ,0  ,        // 3\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,'7','8','9','-','4','5','6','+','1',        // 4\r
+       '2','3','0',127,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 5\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 6\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0           // 7\r
+                                       },\r
+                                       far ShiftNames[] =              // Shifted ASCII for scan codes\r
+                                       {\r
+//      0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F\r
+       0  ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8  ,9  ,        // 0\r
+       'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0  ,'A','S',        // 1\r
+       'D','F','G','H','J','K','L',':',34 ,'~',0  ,'|','Z','X','C','V',        // 2\r
+       'B','N','M','<','>','?',0  ,'*',0  ,' ',0  ,0  ,0  ,0  ,0  ,0  ,        // 3\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,'7','8','9','-','4','5','6','+','1',        // 4\r
+       '2','3','0',127,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 5\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 6\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0           // 7\r
+                                       },\r
+                                       far SpecialNames[] =    // ASCII for 0xe0 prefixed codes\r
+                                       {\r
+//      0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 0\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,13 ,0  ,0  ,0  ,        // 1\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 2\r
+       0  ,0  ,0  ,0  ,0  ,'/',0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 3\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 4\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 5\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 6\r
+       0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0           // 7\r
+                                       },\r
+                                       *ScanNames[] =          // Scan code names with single chars\r
+                                       {\r
+       "?","?","1","2","3","4","5","6","7","8","9","0","-","+","?","?",\r
+       "Q","W","E","R","T","Y","U","I","O","P","[","]","|","?","A","S",\r
+       "D","F","G","H","J","K","L",";","\"","?","?","?","Z","X","C","V",\r
+       "B","N","M",",",".","/","?","?","?","?","?","?","?","?","?","?",\r
+       "?","?","?","?","?","?","?","?","\xf","?","-","\x15","5","\x11","+","?",\r
+       "\x13","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",\r
+       "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",\r
+       "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"\r
+                                       },      // DEBUG - consolidate these\r
+                                       far ExtScanCodes[] =    // Scan codes with >1 char names\r
+                                       {\r
+       1,0xe,0xf,0x1d,0x2a,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,\r
+       0x3f,0x40,0x41,0x42,0x43,0x44,0x57,0x59,0x46,0x1c,0x36,\r
+       0x37,0x38,0x47,0x49,0x4f,0x51,0x52,0x53,0x45,0x48,\r
+       0x50,0x4b,0x4d,0x00\r
+                                       },\r
+                                       *ExtScanNames[] =       // Names corresponding to ExtScanCodes\r
+                                       {\r
+       "Esc","BkSp","Tab","Ctrl","LShft","Space","CapsLk","F1","F2","F3","F4",\r
+       "F5","F6","F7","F8","F9","F10","F11","F12","ScrlLk","Enter","RShft",\r
+       "PrtSc","Alt","Home","PgUp","End","PgDn","Ins","Del","NumLk","Up",\r
+       "Down","Left","Right",""\r
+                                       };
+\r
+static Direction       DirTable[] =            // Quick lookup for total direction\r
+                                       {\r
+                                               //dir_Nortinest,\r
+                                               dir_North,\r
+                                               //dir_NorthEast,\r
+                                               dir_West,               dir_None,       dir_East,\r
+                                               //dir_Soutinest,\r
+                                               dir_South//,dir_SouthEast\r
+                                       };
+#ifdef __cplusplus
+}
+#endif
+
+//     Internal routines
+///////////////////////////////////////////////////////////////////////////
+//
+//     INL_KeyService() - Handles a keyboard interrupt (key up/down)
+//
+///////////////////////////////////////////////////////////////////////////
+void interrupt
+INL_KeyService()
+{
+static boolean special;
+               byte    k,c;
+               register byte temp;
+
+       k = inp(0x60);  // Get the scan code
+
+       // Tell the XT keyboard controller to clear the key
+       outp(0x61,(temp = inp(0x61)) | 0x80);
+       outp(0x61,temp);
+
+       if (k == 0xe0)          // Special key prefix
+               special = true;
+       else if (k == 0xe1)     // Handle Pause key
+               inpu.Paused = true;
+       else
+       {
+               if (k & 0x80)   // Break code
+               {
+                       k &= 0x7f;
+
+// DEBUG - handle special keys: ctl-alt-delete, print scrn
+
+                       inpu.Keyboard[k] = false;
+               }
+               else                    // Make code
+               {
+                       inst.LastCode = inst.CurCode;
+                       inst.CurCode = inpu.LastScan = k;
+                       inpu.Keyboard[k] = true;
+
+                       if (special)
+                               c = SpecialNames[k];
+                       else
+                       {
+                               if (k == sc_CapsLock)
+                               {
+                                       inst.CapsLock ^= true;
+                                       // DEBUG - make caps lock light work
+                               }
+
+                               if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift])       // If shifted
+                               {
+                                       c = ShiftNames[k];
+                                       if ((c >= 'A') && (c <= 'Z') && inst.CapsLock)
+                                               c += 'a' - 'A';
+                               }
+                               else
+                               {
+                                       c = ASCIINames[k];
+                                       if ((c >= 'a') && (c <= 'z') && inst.CapsLock)
+                                               c -= 'a' - 'A';
+                               }
+                       }
+                       if (c)
+                               inpu.LastASCII = c;
+               }
+
+               special = false;
+       }
+
+       if (INL_KeyHook && !special)
+               INL_KeyHook();
+       #ifdef TESTKEYIN
+       printf("%c %x %u\n", c, k, inpu.Keyboard[k]);
+       #endif
+       outp(0x20,0x20);
+}
+
+void
+Mouse(int x)
+{
+       union REGS CPURegs;
+       x = CPURegs.x.ax;
+       int86(MouseInt,&CPURegs,&CPURegs);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
+//             mouse driver
+//
+///////////////////////////////////////////////////////////////////////////
+static void
+INL_GetMouseDelta(int *x,int *y)
+{
+       union REGS CPURegs;
+       Mouse(MDelta);
+       *x = CPURegs.x.cx;
+       *y = CPURegs.x.dx;
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     INL_GetMouseButtons() - Gets the status of the mouse buttons from the
+//             mouse driver
+//
+///////////////////////////////////////////////////////////////////////////
+static word
+INL_GetMouseButtons(void)
+{
+       union REGS CPURegs;
+       word    buttons;
+
+       Mouse(MButtons);
+       buttons = CPURegs.x.bx;
+       return(buttons);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_GetJoyAbs() - Reads the absolute position of the specified joystick
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_GetJoyAbs(word joy,word *xp,word *yp)
+{
+       byte    xb,yb,
+                       xs,ys;
+       word    x,y;
+
+       x = y = 0;
+       xs = joy? 2 : 0;                // Find shift value for x axis
+       xb = 1 << xs;                   // Use shift value to get x bit mask
+       ys = joy? 3 : 1;                // Do the same for y axis
+       yb = 1 << ys;
+
+// Read the absolute joystick values
+       __asm
+       {
+               pushf                           // Save some registers
+               push    si
+               push    di
+               cli                                     // Make sure an interrupt doesn't screw the timings
+
+
+               mov             dx,0x201
+               in              al,dx
+               out             dx,al           // Clear the resistors
+
+               mov             ah,[xb]         // Get masks into registers
+               mov             ch,[yb]
+
+               xor             si,si           // Clear count registers
+               xor             di,di
+               xor             bh,bh           // Clear high byte of bx for later
+
+               push    bp                      // Don't mess up stack frame
+               mov             bp,MaxJoyValue
+
+loo:
+               in              al,dx           // Get bits indicating whether all are finished
+
+               dec             bp                      // Check bounding register
+               jz              done            // We have a silly value - abort
+
+               mov             bl,al           // Duplicate the bits
+               and             bl,ah           // Mask off useless bits (in [xb])
+               add             si,bx           // Possibly increment count register
+               mov             cl,bl           // Save for testing later
+
+               mov             bl,al
+               and             bl,ch           // [yb]
+               add             di,bx
+
+               add             cl,bl
+               jnz             loo             // If both bits were 0, drop out
+
+done:
+               pop             bp
+
+               mov             cl,[xs]         // Get the number of bits to shift
+               shr             si,cl           //  and shift the count that many times
+
+               mov             cl,[ys]
+               shr             di,cl
+
+               mov             [x],si          // Store the values into the variables
+               mov             [y],di
+
+               pop             di
+               pop             si
+               popf                            // Restore the registers
+       }
+
+       *xp = x;
+       *yp = y;
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     INL_GetJoyDelta() - Returns the relative movement of the specified
+//             joystick (from +/-127, scaled adaptively)
+//
+///////////////////////////////////////////////////////////////////////////
+static void
+INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)
+{
+       word            x,y;
+       dword   time;
+       dword TimeCount = *clockdw;
+       JoystickDef     *def;
+static dword   lasttime;
+
+       IN_GetJoyAbs(joy,&x,&y);
+       def = inpu.JoyDefs + joy;
+
+       if (x < def->threshMinX)
+       {
+               if (x < def->joyMinX)
+                       x = def->joyMinX;
+
+               x = -(x - def->threshMinX);
+               x *= def->joyMultXL;
+               x >>= JoyScaleShift;
+               *dx = (x > 127)? -127 : -x;
+       }
+       else if (x > def->threshMaxX)
+       {
+               if (x > def->joyMaxX)
+                       x = def->joyMaxX;
+
+               x = x - def->threshMaxX;
+               x *= def->joyMultXH;
+               x >>= JoyScaleShift;
+               *dx = (x > 127)? 127 : x;
+       }
+       else
+               *dx = 0;
+
+       if (y < def->threshMinY)
+       {
+               if (y < def->joyMinY)
+                       y = def->joyMinY;
+
+               y = -(y - def->threshMinY);
+               y *= def->joyMultYL;
+               y >>= JoyScaleShift;
+               *dy = (y > 127)? -127 : -y;
+       }
+       else if (y > def->threshMaxY)
+       {
+               if (y > def->joyMaxY)
+                       y = def->joyMaxY;
+
+               y = y - def->threshMaxY;
+               y *= def->joyMultYH;
+               y >>= JoyScaleShift;
+               *dy = (y > 127)? 127 : y;
+       }
+       else
+               *dy = 0;
+
+       if (adaptive)
+       {
+               time = (TimeCount - lasttime) / 2;
+               if (time)
+               {
+                       if (time > 8)
+                               time = 8;
+                       *dx *= time;
+                       *dy *= time;
+               }
+       }
+       lasttime = TimeCount;
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     INL_GetJoyButtons() - Returns the button status of the specified
+//             joystick
+//
+///////////////////////////////////////////////////////////////////////////
+static word
+INL_GetJoyButtons(word joy)
+{
+register       word    result;
+
+       result = inp(0x201);    // Get all the joystick buttons
+       result >>= joy? 6 : 4;  // Shift into bits 0-1
+       result &= 3;                            // Mask off the useless bits
+       result ^= 3;
+       return(result);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_GetJoyButtonsDB() - Returns the de-bounced button status of the
+//             specified joystick
+//
+///////////////////////////////////////////////////////////////////////////
+word
+IN_GetJoyButtonsDB(word joy)
+{
+       dword TimeCount = *clockdw;
+       dword   lasttime;
+       word            result1,result2;
+
+       do
+       {
+               result1 = INL_GetJoyButtons(joy);
+               lasttime = TimeCount;
+               while(TimeCount == lasttime)
+               result2 = INL_GetJoyButtons(joy);
+       } while(result1 != result2);
+       return(result1);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     INL_StartKbd() - Sets up my keyboard stuff for use
+//
+///////////////////////////////////////////////////////////////////////////
+static void
+INL_StartKbd()
+{
+       INL_KeyHook = 0;        // Clear key hook
+
+       IN_ClearKeysDown();
+
+       OldKeyVect = _dos_getvect(KeyInt);
+       _dos_setvect(KeyInt,INL_KeyService);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     INL_ShutKbd() - Restores keyboard control to the BIOS
+//
+///////////////////////////////////////////////////////////////////////////
+static void
+INL_ShutKbd(void)
+{
+       pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0);     // Clear ctrl/alt/shift flags
+
+       _dos_setvect(KeyInt,OldKeyVect);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     INL_StartMouse() - Detects and sets up the mouse
+//
+///////////////////////////////////////////////////////////////////////////
+static boolean
+INL_StartMouse(void)
+{
+       union REGS CPURegs;
+       if(_dos_getvect(MouseInt))
+       {
+               Mouse(MReset);
+               if(CPURegs.x.ax == 0xffff)
+                       return(true);
+       }
+       return(false);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     INL_ShutMouse() - Cleans up after the mouse
+//
+///////////////////////////////////////////////////////////////////////////
+static void
+INL_ShutMouse(void)
+{
+}
+
+//
+//     INL_SetJoyScale() - Sets up scaling values for the specified joystick
+//
+static void
+INL_SetJoyScale(word joy)
+{
+       JoystickDef     *def;
+
+       def = &(inpu.JoyDefs[joy]);
+       def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
+       def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
+       def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
+       def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
+//             to set up scaling values
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
+{
+       word            d,r;
+       JoystickDef     *def;
+
+       def = &(inpu.JoyDefs[joy]);
+
+       def->joyMinX = minx;
+       def->joyMaxX = maxx;
+       r = maxx - minx;
+       d = r / 3;
+       def->threshMinX = ((r / 2) - d) + minx;
+       def->threshMaxX = ((r / 2) + d) + minx;
+
+       def->joyMinY = miny;
+       def->joyMaxY = maxy;
+       r = maxy - miny;
+       d = r / 3;
+       def->threshMinY = ((r / 2) - d) + miny;
+       def->threshMaxY = ((r / 2) + d) + miny;
+
+       INL_SetJoyScale(joy);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     INL_StartJoy() - Detects & auto-configures the specified joystick
+//                                     The auto-config assumes the joystick is centered
+//
+///////////////////////////////////////////////////////////////////////////
+static boolean
+INL_StartJoy(word joy)
+{
+       word            x,y;
+
+       IN_GetJoyAbs(joy,&x,&y);
+
+       if
+       (
+               ((x == 0) || (x > MaxJoyValue - 10))
+       ||      ((y == 0) || (y > MaxJoyValue - 10))
+       )
+               return(false);
+       else
+       {
+               IN_SetupJoy(joy,0,x * 2,0,y * 2);
+               return(true);
+       }
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     INL_ShutJoy() - Cleans up the joystick stuff
+//
+///////////////////////////////////////////////////////////////////////////
+static void
+INL_ShutJoy(word joy)
+{
+       inpu.JoysPresent[joy] = false;
+}
+
+//     Public routines
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_Startup() - Starts up the Input Mgr
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_Startup()
+{
+       boolean checkjoys,checkmouse;
+       word    i;
+
+       if (inst.IN_Started)
+               return;
+
+       checkjoys = true;
+       checkmouse = true;
+       for (i = 1;i < __argc;i++)
+       {
+               switch (US_CheckParm(__argv[i],ParmStringsIN))
+               {
+               case 0:
+                       checkjoys = false;
+                       break;
+               case 1:
+                       checkmouse = false;
+                       break;
+               }
+       }
+
+       INL_StartKbd();
+       inpu.MousePresent = checkmouse? INL_StartMouse() : false;
+
+       for (i = 0;i < MaxJoys;i++)
+               inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
+
+       inst.IN_Started = true;
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_Default() - Sets up default conditions for the Input Mgr
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_Default(boolean gotit,player_t *player,ControlType nt)
+{
+       if
+       (
+               (!gotit)
+       ||      ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0])
+       ||      ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1])
+       ||      ((nt == ctrl_Mouse) && !inpu.MousePresent)
+       ||      ((nt == ctrl_Joypad1) && !inpu.JoyPadPresent[0])
+       ||      ((nt == ctrl_Joypad2) && !inpu.JoyPadPresent[1])
+       )
+               nt = ctrl_Keyboard1;
+       IN_SetControlType(0,player,nt);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_Shutdown() - Shuts down the Input Mgr
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_Shutdown()
+{
+       word    i;
+
+       if (!inst.IN_Started)
+               return;
+
+       INL_ShutMouse();
+       for (i = 0;i < MaxJoys;i++)
+               INL_ShutJoy(i);
+       INL_ShutKbd();
+
+       inst.IN_Started = false;
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_SetKeyHook() - Sets the routine that gets called by INL_KeyService()
+//                     everytime a real make/break code gets hit
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_SetKeyHook(void (*hook)())
+{
+       INL_KeyHook = hook;
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_ClearKeyDown() - Clears the keyboard array
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_ClearKeysDown()
+{
+       int     i;
+
+       inpu.LastScan = sc_None;
+       inpu.LastASCII = key_None;
+       memset (inpu.Keyboard,0,sizeof(inpu.Keyboard));
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     INL_AdjustCursor() - Internal routine of common code from IN_ReadCursor()
+//
+///////////////////////////////////////////////////////////////////////////
+static void
+INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
+{
+       if (buttons & (1 << 0))
+               info->button0 = true;
+       if (buttons & (1 << 1))
+               info->button1 = true;
+
+       info->x += dx;
+       info->y += dy;
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_ReadCursor() - Reads the input devices and fills in the cursor info
+//             struct
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_ReadCursor(CursorInfo *info)
+{
+       word    i,
+                       buttons;
+       int             dx,dy;
+
+       info->x = info->y = 0;
+       info->button0 = info->button1 = false;
+
+       if (inpu.MousePresent)
+       {
+               buttons = INL_GetMouseButtons();
+               INL_GetMouseDelta(&dx,&dy);
+               INL_AdjustCursor(info,buttons,dx,dy);
+       }
+
+       for (i = 0;i < MaxJoys;i++)
+       {
+               if (!inpu.JoysPresent[i])
+                       continue;
+
+               buttons = INL_GetJoyButtons(i);
+               INL_GetJoyDelta(i,&dx,&dy,true);
+               dx /= 64;
+               dy /= 64;
+               INL_AdjustCursor(info,buttons,dx,dy);
+       }
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_ReadControl() - Reads the device associated with the specified
+//             player and fills in the control info struct
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_ReadControl(int playnum,player_t *player)
+{
+                       boolean         realdelta;
+                       byte            dbyte;
+                       word            buttons;
+                       int                     dx,dy;
+                       Motion          mx,my;
+                       ControlType     type;
+register       KeyboardDef     *def;
+
+       dx = dy = 0;
+       mx = my = motion_None;
+       buttons = 0;
+
+#if DEMO0
+       if (DemoMode == demo_Playback)
+       {
+               dbyte = DemoBuffer[DemoOffset + 1];
+               my = (dbyte & 3) - 1;
+               mx = ((dbyte >> 2) & 3) - 1;
+               buttons = (dbyte >> 4) & 3;
+
+               if (!(--DemoBuffer[DemoOffset]))
+               {
+                       DemoOffset += 2;
+                       if (DemoOffset >= DemoSize)
+                               DemoMode = demo_PlayDone;
+               }
+
+               realdelta = false;
+       }
+       else if (DemoMode == demo_PlayDone)
+               Quit("Demo playback exceeded");
+       else
+       {
+#endif
+               switch (type = player[playnum].Controls)
+               {
+               case ctrl_Keyboard1:
+               case ctrl_Keyboard2:
+                       def = &(inpu.KbdDefs[type - ctrl_Keyboard]);
+
+/*                     if (Keyboard[def->upleft])
+                               mx = motion_Left,my = motion_Up;
+                       else if (Keyboard[def->upright])
+                               mx = motion_Right,my = motion_Up;
+                       else if (Keyboard[def->downleft])
+                               mx = motion_Left,my = motion_Down;
+                       else if (Keyboard[def->downright])
+                               mx = motion_Right,my = motion_Down;*/
+
+                       if (inpu.Keyboard[def->up])
+                               my = motion_Up;
+                       else if (inpu.Keyboard[def->down])
+                               my = motion_Down;
+
+                       if (inpu.Keyboard[def->left])
+                               mx = motion_Left;
+                       else if (inpu.Keyboard[def->right])
+                               mx = motion_Right;
+
+                       if (inpu.Keyboard[def->button0])
+                               buttons += 1 << 0;
+                       if (inpu.Keyboard[def->button1])
+                               buttons += 1 << 1;
+                       realdelta = false;
+                       break;
+               case ctrl_Joystick1:
+               case ctrl_Joystick2:
+                       INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);
+                       buttons = INL_GetJoyButtons(type - ctrl_Joystick);
+                       realdelta = true;
+                       break;
+               case ctrl_Mouse:
+                       INL_GetMouseDelta(&dx,&dy);
+                       buttons = INL_GetMouseButtons();
+                       realdelta = true;
+                       break;
+               case ctrl_Joypad1:
+               case ctrl_Joypad2:
+                       printf("wwww");
+                       break;
+               }
+#ifdef DEMO0
+       }
+#endif
+
+       if (realdelta)
+       {
+               mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
+               my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
+       }
+       else
+       {
+               dx = mx * 127;
+               dy = my * 127;
+       }
+
+       player[playnum].info.x = dx;
+       player[playnum].info.xaxis = mx;
+       player[playnum].info.y = dy;
+       player[playnum].info.yaxis = my;
+       player[playnum].info.button0 = buttons & (1 << 0);
+       player[playnum].info.button1 = buttons & (1 << 1);
+       player[playnum].info.button2 = buttons & (1 << 2);
+       player[playnum].info.button3 = buttons & (1 << 3);
+       player[playnum].info.dir = DirTable[((my + 1) * 3) + (mx + 1)];
+
+#if DEMO0
+       if (DemoMode == demo_Record)
+       {
+               // Pack the control info into a byte
+               dbyte = (buttons << 4) | ((mx + 1) << 2) | (my + 1);
+
+               if
+               (
+                       (DemoBuffer[DemoOffset + 1] == dbyte)
+               &&      (DemoBuffer[DemoOffset] < 255)
+               )
+                       (DemoBuffer[DemoOffset])++;
+               else
+               {
+                       if (DemoOffset || DemoBuffer[DemoOffset])
+                               DemoOffset += 2;
+
+                       if (DemoOffset >= DemoSize)
+                               Quit("Demo buffer overflow");
+
+                       DemoBuffer[DemoOffset] = 1;
+                       DemoBuffer[DemoOffset + 1] = dbyte;
+               }
+       }
+#endif
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_SetControlType() - Sets the control type to be used by the specified
+//             player
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_SetControlType(word playnum,player_t *player,ControlType type)
+{
+       // DEBUG - check that requested type is present?
+       player[playnum].Controls = type;
+}
+
+#if DEMO0
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_StartDemoRecord() - Starts the demo recording, using a buffer the
+//             size passed. Returns if the buffer allocation was successful
+//
+///////////////////////////////////////////////////////////////////////////
+boolean
+IN_StartDemoRecord(word bufsize)
+{
+       if (!bufsize)
+               return(false);
+
+       MM_GetPtr((memptr *)&DemoBuffer,bufsize);
+       DemoMode = demo_Record;
+       DemoSize = bufsize & ~1;
+       DemoOffset = 0;
+       DemoBuffer[0] = DemoBuffer[1] = 0;
+
+       return(true);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_StartDemoPlayback() - Plays back the demo pointed to of the given size
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_StartDemoPlayback(byte /*__segment*/ *buffer,word bufsize)
+{
+       DemoBuffer = buffer;
+       DemoMode = demo_Playback;
+       DemoSize = bufsize & ~1;
+       DemoOffset = 0;
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_StopDemo() - Turns off demo mode
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_StopDemo(void)
+{
+       if ((DemoMode == demo_Record) && DemoOffset)
+               DemoOffset += 2;
+
+       DemoMode = demo_Off;
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_FreeDemoBuffer() - Frees the demo buffer, if it's been allocated
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_FreeDemoBuffer(void)
+{
+       if (DemoBuffer)
+               MM_FreePtr((memptr *)&DemoBuffer);
+}
+#endif
+
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_GetScanName() - Returns a string containing the name of the
+//             specified scan code
+//
+///////////////////////////////////////////////////////////////////////////
+byte *
+IN_GetScanName(ScanCode scan)
+{
+       byte            **p;
+       ScanCode        far *s;
+
+       for (s = ExtScanCodes,p = ExtScanNames;*s;p++,s++)
+               if (*s == scan)
+                       return(*p);
+
+       return(ScanNames[scan]);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_WaitForKey() - Waits for a scan code, then clears LastScan and
+//             returns the scan code
+//
+///////////////////////////////////////////////////////////////////////////
+ScanCode
+IN_WaitForKey()
+{
+       ScanCode        result;
+
+       while (!(result = inpu.LastScan))
+               ;
+       inpu.LastScan = 0;
+       return(result);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_WaitForASCII() - Waits for an ASCII char, then clears LastASCII and
+//             returns the ASCII value
+//
+///////////////////////////////////////////////////////////////////////////
+char
+IN_WaitForASCII()
+{
+       char            result;
+
+       while (!(result = inpu.LastASCII))
+               ;
+       inpu.LastASCII = '\0';
+       return(result);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_AckBack() - Waits for either an ASCII keypress or a button press
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_AckBack()
+{
+       word    i;
+
+       while (!inpu.LastScan)
+       {
+               if (inpu.MousePresent)
+               {
+                       if (INL_GetMouseButtons())
+                       {
+                               while (INL_GetMouseButtons())
+                                       ;
+                               return;
+                       }
+               }
+
+               for (i = 0;i < MaxJoys;i++)
+               {
+                       if (inpu.JoysPresent[i])
+                       {
+                               if (IN_GetJoyButtonsDB(i))
+                               {
+                                       while (IN_GetJoyButtonsDB(i))
+                                               ;
+                                       return;
+                               }
+                       }
+               }
+       }
+
+       IN_ClearKey(inpu.LastScan);
+       inpu.LastScan = sc_None;
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_Ack() - Clears user input & then calls IN_AckBack()
+//
+///////////////////////////////////////////////////////////////////////////
+void
+IN_Ack()
+{
+       word    i;
+
+       IN_ClearKey(inpu.LastScan);
+       inpu.LastScan = sc_None;
+
+       if (inpu.MousePresent)
+               while (INL_GetMouseButtons())
+                                       ;
+       for (i = 0;i < MaxJoys;i++)
+               if (inpu.JoysPresent[i])
+                       while (IN_GetJoyButtonsDB(i))
+                               ;
+
+       IN_AckBack();
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_IsUserInput() - Returns true if a key has been pressed or a button
+//             is down
+//
+///////////////////////////////////////////////////////////////////////////
+boolean
+IN_IsUserInput()
+{
+       boolean result;
+       word    i;
+
+       result = inpu.LastScan;
+
+       if (inpu.MousePresent)
+               if (INL_GetMouseButtons())
+                       result = true;
+
+       for (i = 0;i < MaxJoys;i++)
+               if (inpu.JoysPresent[i])
+                       if (INL_GetJoyButtons(i))
+                               result = true;
+
+       return(result);
+}
+
+///////////////////////////////////////////////////////////////////////////
+//
+//     IN_UserInput() - Waits for the specified delay time (in ticks) or the
+//             user pressing a key or a mouse button. If the clear flag is set, it
+//             then either clears the key or waits for the user to let the mouse
+//             button up.
+//
+///////////////////////////////////////////////////////////////////////////
+boolean
+IN_UserInput(dword delay,boolean clear)
+{
+       dword TimeCount = *clockdw;
+       dword   lasttime;
+
+       lasttime = TimeCount;
+       do
+       {
+               if (IN_IsUserInput())
+               {
+                       if (clear)
+                               IN_AckBack();
+                       return(true);
+               }
+       } while (TimeCount - lasttime < delay);
+       return(false);
+}
+
+boolean IN_KeyDown(byte code)
+{
+       return inpu.Keyboard[code];
+}
+\r
+void IN_ClearKey(byte code)
+{
+       inpu.Keyboard[code] = false;
+       if(code == inpu.LastScan)
+               inpu.LastScan = sc_None;
+       }
+
+boolean IN_qb(byte kee)
+{
+       printf("%u\n", inpu.Keyboard[kee]);
+       if(inpu.Keyboard[kee]==true) return 1;
+       else return 0;
+}
diff --git a/16/inpu.bat b/16/inpu.bat
new file mode 100644 (file)
index 0000000..ba1e4ef
--- /dev/null
@@ -0,0 +1,2 @@
+wcc -0 -mc 16_in.c
+wcl -mc -0 inputest.c 16_in.obj
\ No newline at end of file
diff --git a/16/inputest.c b/16/inputest.c
new file mode 100644 (file)
index 0000000..da9a7ee
--- /dev/null
@@ -0,0 +1,44 @@
+/* Project 16 Source Code~\r
+ * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669\r
+ *\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 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\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\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
+       input test\r
+*/\r
+#include "16_in.h"\r
+\r
+void\r
+main(int argc, char *argv[])\r
+{
+       player_t player[MaxPlayers];
+       //extern struct inconfig inpu;
+\r
+       IN_Startup();
+       IN_Default(0,&player,ctrl_Joystick);\r
+       //while(!IN_KeyDown(sc_Escape))
+       while(!IN_KeyDown(sc_Escape))\r
+       {
+               IN_ReadControl(0,&player);
+               //printf("%u\n", IN_KeyDown(sc_Escape));
+               //printf("%u\n", IN_qb(sc_Escape));\r
+       }
+       IN_Shutdown();
+       //printf("%u\n", in.Keyboard[sc_Escape]);\r
+}\r