]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_in.c
major changes~ ^^ it works~
[16.git] / src / lib / 16_in.c
index ea90a7159711e9cb1a047409d740481d89938edd..6d8c1aba9c76e1176e5038574645904547a02653 100644 (file)
                                        GLOBAL VARIABLES\r
 \r
 =============================================================================\r
-*/\r
-//     Global variables
-//             boolean JoystickCalibrated=false;               // MDM (GAMERS EDGE) - added\r
-//             ControlType ControlTypeUsed;                            // MDM (GAMERS EDGE) - added\r
-               boolean         Keyboard[NumCodes];\r
-               boolean         Paused;\r
-               char            LastASCII;\r
-               ScanCode        LastScan;\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;
+
+//struct inconfig in;
+
+//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
-               //KeyboardDef   KbdDefs = {0x1d,0x38,0x47,0x48,0x49,0x4b,0x4d,0x4f,0x50,0x51};\r
-               JoystickDef     JoyDefs[MaxJoys];\r
-               ControlType     Controls[MaxPlayers];\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
-               dword   MouseDownCount;
+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
 ///////////////////////////////////////////////////////////////////////////
 //
 ///////////////////////////////////////////////////////////////////////////
 void interrupt
-INL_KeyService(void)
+INL_KeyService()
 {
 static boolean special;
                byte    k,c;
@@ -81,7 +183,7 @@ static       boolean special;
        if (k == 0xe0)          // Special key prefix
                special = true;
        else if (k == 0xe1)     // Handle Pause key
-               Paused = true;
+               inpu.Paused = true;
        else
        {
                if (k & 0x80)   // Break code
@@ -90,13 +192,13 @@ static     boolean special;
 
 // DEBUG - handle special keys: ctl-alt-delete, print scrn
 
-                       Keyboard[k] = false;
+                       inpu.Keyboard[k] = false;
                }
                else                    // Make code
                {
-                       LastCode = CurCode;
-                       CurCode = LastScan = k;
-                       Keyboard[k] = true;
+                       inst.LastCode = inst.CurCode;
+                       inst.CurCode = inpu.LastScan = k;
+                       inpu.Keyboard[k] = true;
 
                        if (special)
                                c = SpecialNames[k];
@@ -104,25 +206,25 @@ static    boolean special;
                        {
                                if (k == sc_CapsLock)
                                {
-                                       CapsLock ^= true;
+                                       inst.CapsLock ^= true;
                                        // DEBUG - make caps lock light work
                                }
 
-                               if (Keyboard[sc_LShift] || Keyboard[sc_RShift]) // If shifted
+                               if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift])       // If shifted
                                {
                                        c = ShiftNames[k];
-                                       if ((c >= 'A') && (c <= 'Z') && CapsLock)
+                                       if ((c >= 'A') && (c <= 'Z') && inst.CapsLock)
                                                c += 'a' - 'A';
                                }
                                else
                                {
                                        c = ASCIINames[k];
-                                       if ((c >= 'a') && (c <= 'z') && CapsLock)
+                                       if ((c >= 'a') && (c <= 'z') && inst.CapsLock)
                                                c -= 'a' - 'A';
                                }
                        }
                        if (c)
-                               LastASCII = c;
+                               inpu.LastASCII = c;
                }
 
                special = false;
@@ -131,7 +233,7 @@ static      boolean special;
        if (INL_KeyHook && !special)
                INL_KeyHook();
        #ifdef TESTKEYIN
-       printf("%c %x %u\n", c, k, Keyboard[k]);
+       printf("%c %x %u\n", c, k, inpu.Keyboard[k]);
        #endif
        outp(0x20,0x20);
 }
@@ -272,7 +374,7 @@ INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)
 static dword   lasttime;
 
        IN_GetJoyAbs(joy,&x,&y);
-       def = JoyDefs + joy;
+       def = inpu.JoyDefs + joy;
 
        if (x < def->threshMinX)
        {
@@ -381,7 +483,7 @@ IN_GetJoyButtonsDB(word joy)
 //
 ///////////////////////////////////////////////////////////////////////////
 static void
-INL_StartKbd(void)
+INL_StartKbd()
 {
        INL_KeyHook = 0;        // Clear key hook
 
@@ -440,7 +542,7 @@ INL_SetJoyScale(word joy)
 {
        JoystickDef     *def;
 
-       def = &JoyDefs[joy];
+       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);
@@ -459,7 +561,7 @@ IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
        word            d,r;
        JoystickDef     *def;
 
-       def = &JoyDefs[joy];
+       def = &(inpu.JoyDefs[joy]);
 
        def->joyMinX = minx;
        def->joyMaxX = maxx;
@@ -512,7 +614,7 @@ INL_StartJoy(word joy)
 static void
 INL_ShutJoy(word joy)
 {
-       JoysPresent[joy] = false;
+       inpu.JoysPresent[joy] = false;
 }
 
 //     Public routines
@@ -523,12 +625,12 @@ INL_ShutJoy(word joy)
 //
 ///////////////////////////////////////////////////////////////////////////
 void
-IN_Startup(void)
+IN_Startup()
 {
        boolean checkjoys,checkmouse;
        word    i;
 
-       if (IN_Started)
+       if (inst.IN_Started)
                return;
 
        checkjoys = true;
@@ -547,12 +649,12 @@ IN_Startup(void)
        }
 
        INL_StartKbd();
-       MousePresent = checkmouse? INL_StartMouse() : false;
+       inpu.MousePresent = checkmouse? INL_StartMouse() : false;
 
        for (i = 0;i < MaxJoys;i++)
-               JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
+               inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
 
-       IN_Started = true;
+       inst.IN_Started = true;
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -561,17 +663,19 @@ IN_Startup(void)
 //
 ///////////////////////////////////////////////////////////////////////////
 void
-IN_Default(boolean gotit,ControlType in)
+IN_Default(boolean gotit,player_t *player,ControlType nt)
 {
        if
        (
                (!gotit)
-       ||      ((in == ctrl_Joystick1) && !JoysPresent[0])
-       ||      ((in == ctrl_Joystick2) && !JoysPresent[1])
-       ||      ((in == ctrl_Mouse) && !MousePresent)
+       ||      ((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])
        )
-               in = ctrl_Keyboard1;
-       IN_SetControlType(0,in);
+               nt = ctrl_Keyboard1;
+       IN_SetControlType(0,player,nt);
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -580,11 +684,11 @@ IN_Default(boolean gotit,ControlType in)
 //
 ///////////////////////////////////////////////////////////////////////////
 void
-IN_Shutdown(void)
+IN_Shutdown()
 {
        word    i;
 
-       if (!IN_Started)
+       if (!inst.IN_Started)
                return;
 
        INL_ShutMouse();
@@ -592,7 +696,7 @@ IN_Shutdown(void)
                INL_ShutJoy(i);
        INL_ShutKbd();
 
-       IN_Started = false;
+       inst.IN_Started = false;
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -613,13 +717,13 @@ IN_SetKeyHook(void (*hook)())
 //
 ///////////////////////////////////////////////////////////////////////////
 void
-IN_ClearKeysDown(void)
+IN_ClearKeysDown()
 {
        int     i;
 
-       LastScan = sc_None;
-       LastASCII = key_None;
-       memset (Keyboard,0,sizeof(Keyboard));
+       inpu.LastScan = sc_None;
+       inpu.LastASCII = key_None;
+       memset (inpu.Keyboard,0,sizeof(inpu.Keyboard));
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -655,7 +759,7 @@ IN_ReadCursor(CursorInfo *info)
        info->x = info->y = 0;
        info->button0 = info->button1 = false;
 
-       if (MousePresent)
+       if (inpu.MousePresent)
        {
                buttons = INL_GetMouseButtons();
                INL_GetMouseDelta(&dx,&dy);
@@ -664,7 +768,7 @@ IN_ReadCursor(CursorInfo *info)
 
        for (i = 0;i < MaxJoys;i++)
        {
-               if (!JoysPresent[i])
+               if (!inpu.JoysPresent[i])
                        continue;
 
                buttons = INL_GetJoyButtons(i);
@@ -682,7 +786,7 @@ IN_ReadCursor(CursorInfo *info)
 //
 ///////////////////////////////////////////////////////////////////////////
 void
-IN_ReadControl(int player,CursorInfo *info)
+IN_ReadControl(int playnum,player_t *player)
 {
                        boolean         realdelta;
                        byte            dbyte;
@@ -718,11 +822,11 @@ register  KeyboardDef     *def;
        else
        {
 #endif
-               switch (type = Controls[player])
+               switch (type = player[playnum].Controls)
                {
                case ctrl_Keyboard1:
                case ctrl_Keyboard2:
-                       def = &KbdDefs[type - ctrl_Keyboard];
+                       def = &(inpu.KbdDefs[type - ctrl_Keyboard]);
 
 /*                     if (Keyboard[def->upleft])
                                mx = motion_Left,my = motion_Up;
@@ -733,19 +837,19 @@ register  KeyboardDef     *def;
                        else if (Keyboard[def->downright])
                                mx = motion_Right,my = motion_Down;*/
 
-                       if (Keyboard[def->up])
+                       if (inpu.Keyboard[def->up])
                                my = motion_Up;
-                       else if (Keyboard[def->down])
+                       else if (inpu.Keyboard[def->down])
                                my = motion_Down;
 
-                       if (Keyboard[def->left])
+                       if (inpu.Keyboard[def->left])
                                mx = motion_Left;
-                       else if (Keyboard[def->right])
+                       else if (inpu.Keyboard[def->right])
                                mx = motion_Right;
 
-                       if (Keyboard[def->button0])
+                       if (inpu.Keyboard[def->button0])
                                buttons += 1 << 0;
-                       if (Keyboard[def->button1])
+                       if (inpu.Keyboard[def->button1])
                                buttons += 1 << 1;
                        realdelta = false;
                        break;
@@ -780,15 +884,15 @@ register  KeyboardDef     *def;
                dy = my * 127;
        }
 
-       info->x = dx;
-       info->xaxis = mx;
-       info->y = dy;
-       info->yaxis = my;
-       info->button0 = buttons & (1 << 0);
-       info->button1 = buttons & (1 << 1);
-       info->button2 = buttons & (1 << 2);
-       info->button3 = buttons & (1 << 3);
-       info->dir = DirTable[((my + 1) * 3) + (mx + 1)];
+       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)
@@ -824,10 +928,10 @@ register  KeyboardDef     *def;
 //
 ///////////////////////////////////////////////////////////////////////////
 void
-IN_SetControlType(int player,ControlType type)
+IN_SetControlType(word playnum,player_t *player,ControlType type)
 {
        // DEBUG - check that requested type is present?
-       Controls[player] = type;
+       player[playnum].Controls = type;
 }
 
 #if DEMO0
@@ -920,13 +1024,13 @@ IN_GetScanName(ScanCode scan)
 //
 ///////////////////////////////////////////////////////////////////////////
 ScanCode
-IN_WaitForKey(void)
+IN_WaitForKey()
 {
        ScanCode        result;
 
-       while (!(result = LastScan))
+       while (!(result = inpu.LastScan))
                ;
-       LastScan = 0;
+       inpu.LastScan = 0;
        return(result);
 }
 
@@ -937,13 +1041,13 @@ IN_WaitForKey(void)
 //
 ///////////////////////////////////////////////////////////////////////////
 char
-IN_WaitForASCII(void)
+IN_WaitForASCII()
 {
        char            result;
 
-       while (!(result = LastASCII))
+       while (!(result = inpu.LastASCII))
                ;
-       LastASCII = '\0';
+       inpu.LastASCII = '\0';
        return(result);
 }
 
@@ -953,13 +1057,13 @@ IN_WaitForASCII(void)
 //
 ///////////////////////////////////////////////////////////////////////////
 void
-IN_AckBack(void)
+IN_AckBack()
 {
        word    i;
 
-       while (!LastScan)
+       while (!inpu.LastScan)
        {
-               if (MousePresent)
+               if (inpu.MousePresent)
                {
                        if (INL_GetMouseButtons())
                        {
@@ -971,7 +1075,7 @@ IN_AckBack(void)
 
                for (i = 0;i < MaxJoys;i++)
                {
-                       if (JoysPresent[i])
+                       if (inpu.JoysPresent[i])
                        {
                                if (IN_GetJoyButtonsDB(i))
                                {
@@ -983,8 +1087,8 @@ IN_AckBack(void)
                }
        }
 
-       IN_ClearKey(LastScan);
-       LastScan = sc_None;
+       IN_ClearKey(inpu.LastScan);
+       inpu.LastScan = sc_None;
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -993,18 +1097,18 @@ IN_AckBack(void)
 //
 ///////////////////////////////////////////////////////////////////////////
 void
-IN_Ack(void)
+IN_Ack()
 {
        word    i;
 
-       IN_ClearKey(LastScan);
-       LastScan = sc_None;
+       IN_ClearKey(inpu.LastScan);
+       inpu.LastScan = sc_None;
 
-       if (MousePresent)
+       if (inpu.MousePresent)
                while (INL_GetMouseButtons())
                                        ;
        for (i = 0;i < MaxJoys;i++)
-               if (JoysPresent[i])
+               if (inpu.JoysPresent[i])
                        while (IN_GetJoyButtonsDB(i))
                                ;
 
@@ -1018,19 +1122,19 @@ IN_Ack(void)
 //
 ///////////////////////////////////////////////////////////////////////////
 boolean
-IN_IsUserInput(void)
+IN_IsUserInput()
 {
        boolean result;
        word    i;
 
-       result = LastScan;
+       result = inpu.LastScan;
 
-       if (MousePresent)
+       if (inpu.MousePresent)
                if (INL_GetMouseButtons())
                        result = true;
 
        for (i = 0;i < MaxJoys;i++)
-               if (JoysPresent[i])
+               if (inpu.JoysPresent[i])
                        if (INL_GetJoyButtons(i))
                                result = true;
 
@@ -1064,8 +1168,21 @@ IN_UserInput(dword delay,boolean clear)
        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)
 {
-       if(Keyboard[kee]==true) return 1;
+       printf("%u\n", inpu.Keyboard[kee]);
+       if(inpu.Keyboard[kee]==true) return 1;
        else return 0;
 }