X-Git-Url: http://4ch.mooo.com/gitweb/?p=16.git;a=blobdiff_plain;f=src%2Flib%2F16_in_o.c;fp=src%2Flib%2F16_in_1.c;h=e7ed19edafbe81620eadfbd47dac839280a916a9;hp=3eb669d344bcd749916bf76042f7784613383211;hb=af2715fef8681d909afe82f7baaf5e13baabb76f;hpb=9fa80a8cf5bd43862ef829bf16bb6cd80ed7062f diff --git a/src/lib/16_in_1.c b/src/lib/16_in_o.c similarity index 83% rename from src/lib/16_in_1.c rename to src/lib/16_in_o.c index 3eb669d3..e7ed19ed 100755 --- a/src/lib/16_in_1.c +++ b/src/lib/16_in_o.c @@ -39,7 +39,7 @@ // DEBUG - there are more globals // -#include "src/lib/16_in_1.h" +#include "src/lib/16_in.h" #pragma hdrstop static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */ @@ -51,7 +51,7 @@ static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */ ============================================================================= */ -/*struct inconfig +struct inconfig { boolean MousePresent; boolean JoysPresent[MaxJoys]; @@ -62,9 +62,9 @@ static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */ KeyboardDef KbdDefs[MaxKbds]; JoystickDef JoyDefs[MaxJoys]; -} inpu;*/ +} inpu; -//gvar->in.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/}; +//inpu.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/}; /* ============================================================================= @@ -79,13 +79,9 @@ extern "C" { #endif static struct instat { + boolean IN_Started; boolean CapsLock; ScanCode CurCode,LastCode; - - boolean Keyboard[NumCodes]; - boolean Paused; - char LastASCII; - ScanCode LastScan; } inst; static byte far ASCIINames[] = // Unshifted ASCII for scan codes @@ -187,7 +183,7 @@ static boolean special; if (k == 0xe0) // Special key prefix special = true; else if (k == 0xe1) // Handle Pause key - inst.Paused = true; + inpu.Paused = true; else { if (k & 0x80) // Break code @@ -196,13 +192,13 @@ static boolean special; // DEBUG - handle special keys: ctl-alt-delete, print scrn - inst.Keyboard[k] = false; + inpu.Keyboard[k] = false; } else // Make code { inst.LastCode = inst.CurCode; - inst.CurCode = inst.LastScan = k; - inst.Keyboard[k] = true; + inst.CurCode = inpu.LastScan = k; + inpu.Keyboard[k] = true; if (special) c = SpecialNames[k]; @@ -214,7 +210,7 @@ static boolean special; // DEBUG - make caps lock light work } - if (inst.Keyboard[sc_LShift] || inst.Keyboard[sc_RShift]) // If shifted + if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift]) // If shifted { c = ShiftNames[k]; if ((c >= 'A') && (c <= 'Z') && inst.CapsLock) @@ -228,7 +224,7 @@ static boolean special; } } if (c) - inst.LastASCII = c; + inpu.LastASCII = c; } special = false; @@ -237,7 +233,7 @@ static boolean special; if (INL_KeyHook && !special) INL_KeyHook(); #ifdef __DEBUG_InputMgr__ - if(dbg_testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, inst.Keyboard[k]); + if(dbg_testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, inpu.Keyboard[k]); #endif outportb(0x20,0x20); } @@ -380,7 +376,7 @@ done: // joystick (from +/-127) // /////////////////////////////////////////////////////////////////////////// -void INL_GetJoyDelta(word joy,int *dx,int *dy/*,boolean adaptive*/, global_game_variables_t *gvar) +void INL_GetJoyDelta(word joy,int *dx,int *dy/*,boolean adaptive*/) { word x,y; word TimeCount = *clockw; @@ -388,7 +384,7 @@ void INL_GetJoyDelta(word joy,int *dx,int *dy/*,boolean adaptive*/, global_game_ static word lasttime; IN_GetJoyAbs(joy,&x,&y); - def = gvar->in.JoyDefs + joy; + def = inpu.JoyDefs + joy; if (x < def->threshMinX) { @@ -497,7 +493,7 @@ IN_GetJoyButtonsDB(word joy) // /////////////////////////////////////////////////////////////////////////// static void -INL_StartKbd(global_game_variables_t *gvar) +INL_StartKbd(void) { INL_KeyHook = NULL; // Clear key hook @@ -564,11 +560,11 @@ INL_ShutMouse(void) // INL_SetJoyScale() - Sets up scaling values for the specified joystick // static void -INL_SetJoyScale(word joy, global_game_variables_t *gvar) +INL_SetJoyScale(word joy) { JoystickDef *def; - def = &(gvar->in.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); @@ -582,12 +578,12 @@ INL_SetJoyScale(word joy, global_game_variables_t *gvar) // /////////////////////////////////////////////////////////////////////////// void -IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy, global_game_variables_t *gvar) +IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy) { word d,r; JoystickDef *def; - def = &(gvar->in.JoyDefs[joy]); + def = &(inpu.JoyDefs[joy]); def->joyMinX = minx; def->joyMaxX = maxx; @@ -603,7 +599,7 @@ IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy, global_game_variab def->threshMinY = ((r / 2) - d) + miny; def->threshMaxY = ((r / 2) + d) + miny; - INL_SetJoyScale(joy, gvar); + INL_SetJoyScale(joy); } /////////////////////////////////////////////////////////////////////////// @@ -613,7 +609,7 @@ IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy, global_game_variab // /////////////////////////////////////////////////////////////////////////// static boolean -INL_StartJoy(word joy, global_game_variables_t *gvar) +INL_StartJoy(word joy) { word x,y; @@ -627,7 +623,7 @@ INL_StartJoy(word joy, global_game_variables_t *gvar) return(false); else { - IN_SetupJoy(joy,0,x * 2,0,y * 2, gvar); + IN_SetupJoy(joy,0,x * 2,0,y * 2); return(true); } } @@ -638,9 +634,9 @@ INL_StartJoy(word joy, global_game_variables_t *gvar) // /////////////////////////////////////////////////////////////////////////// static void -INL_ShutJoy(word joy, global_game_variables_t *gvar) +INL_ShutJoy(word joy) { - gvar->in.JoysPresent[joy] = false; + inpu.JoysPresent[joy] = false; } // Public routines @@ -651,12 +647,12 @@ INL_ShutJoy(word joy, global_game_variables_t *gvar) // /////////////////////////////////////////////////////////////////////////// void -IN_Startup(global_game_variables_t *gvar) +IN_Startup() { boolean checkjoys,checkmouse; word i; - if (gvar->in.IN_Started) + if (inst.IN_Started) return; checkjoys = true; @@ -674,15 +670,13 @@ IN_Startup(global_game_variables_t *gvar) } } - INL_StartKbd(gvar); - gvar->in.MousePresent = checkmouse? INL_StartMouse() : false; + INL_StartKbd(); + inpu.MousePresent = checkmouse? INL_StartMouse() : false; for (i = 0;i < MaxJoys;i++) - gvar->in.JoysPresent[i] = checkjoys? INL_StartJoy(i, gvar) : false; - - gvar->in.inst = &inst; + inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false; - gvar->in.IN_Started = true; + inst.IN_Started = true; } @@ -692,26 +686,26 @@ IN_Startup(global_game_variables_t *gvar) // /////////////////////////////////////////////////////////////////////////// void -IN_Default(boolean gotit,player_t *player,ControlType nt, global_game_variables_t *gvar) +IN_Default(boolean gotit,player_t *player,ControlType nt) { int i; if ( (!gotit) - || ((nt == ctrl_Joystick1) && !gvar->in.JoysPresent[0]) - || ((nt == ctrl_Joystick2) && !gvar->in.JoysPresent[1]) - || ((nt == ctrl_Mouse) && !gvar->in.MousePresent) + || ((nt == ctrl_Joystick1) && !inpu.JoysPresent[0]) + || ((nt == ctrl_Joystick2) && !inpu.JoysPresent[1]) + || ((nt == ctrl_Mouse) && !inpu.MousePresent) ) nt = ctrl_Keyboard1; - gvar->in.KbdDefs[0].button0 = 0x1c; - gvar->in.KbdDefs[0].button1 = 0x38; + inpu.KbdDefs[0].button0 = 0x1c; + inpu.KbdDefs[0].button1 = 0x38; //in.KbdDefs[0].upleft = 0x47; - gvar->in.KbdDefs[0].up = 0x48; + inpu.KbdDefs[0].up = 0x48; //in.KbdDefs[0].upright = 0x49; - gvar->in.KbdDefs[0].left = 0x4b; - gvar->in.KbdDefs[0].right = 0x4d; + inpu.KbdDefs[0].left = 0x4b; + inpu.KbdDefs[0].right = 0x4d; //in.KbdDefs[0].downleft = 0x4f; - gvar->in.KbdDefs[0].down = 0x50; + inpu.KbdDefs[0].down = 0x50; //in.KbdDefs[0].downright = 0x51; IN_SetControlType(player,nt); for(i=0; i>MaxPlayers;i++) @@ -724,19 +718,19 @@ IN_Default(boolean gotit,player_t *player,ControlType nt, global_game_variables_ // /////////////////////////////////////////////////////////////////////////// void -IN_Shutdown(global_game_variables_t *gvar) +IN_Shutdown(void) { word i; - if (!gvar->in.IN_Started) + if (!inst.IN_Started) return; INL_ShutMouse(); for (i = 0;i < MaxJoys;i++) - INL_ShutJoy(i, gvar); + INL_ShutJoy(i); INL_ShutKbd(); - gvar->in.IN_Started = false; + inst.IN_Started = false; } /////////////////////////////////////////////////////////////////////////// @@ -761,9 +755,9 @@ IN_ClearKeysDown(void) { //int i; - inst.LastScan = sc_None; - inst.LastASCII = key_None; - memset (inst.Keyboard,0,sizeof(inst.Keyboard)); + inpu.LastScan = sc_None; + inpu.LastASCII = key_None; + memset (inpu.Keyboard,0,sizeof(inpu.Keyboard)); } /////////////////////////////////////////////////////////////////////////// @@ -790,7 +784,7 @@ INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy) // /////////////////////////////////////////////////////////////////////////// void -IN_ReadCursor(CursorInfo *info, global_game_variables_t *gvar) +IN_ReadCursor(CursorInfo *info) { word i, buttons; @@ -799,7 +793,7 @@ IN_ReadCursor(CursorInfo *info, global_game_variables_t *gvar) info->x = info->y = 0; info->button0 = info->button1 = false; - if (gvar->in.MousePresent) + if (inpu.MousePresent) { buttons = INL_GetMouseButtons(); INL_GetMouseDelta(&dx,&dy); @@ -808,11 +802,11 @@ IN_ReadCursor(CursorInfo *info, global_game_variables_t *gvar) for (i = 0;i < MaxJoys;i++) { - if (!gvar->in.JoysPresent[i]) + if (!inpu.JoysPresent[i]) continue; buttons = INL_GetJoyButtons(i); - INL_GetJoyDelta(i,&dx,&dy/*,true*/, gvar); + INL_GetJoyDelta(i,&dx,&dy/*,true*/); dx /= 64; dy /= 64; INL_AdjustCursor(info,buttons,dx,dy); @@ -830,7 +824,7 @@ IN_ReadCursor(CursorInfo *info, global_game_variables_t *gvar) // /////////////////////////////////////////////////////////////////////////// void -IN_ReadControl(player_t *player, global_game_variables_t *gvar) +IN_ReadControl(player_t *player) { boolean realdelta; #if DEMO0 @@ -874,7 +868,7 @@ register KeyboardDef *def; { case ctrl_Keyboard1: case ctrl_Keyboard2: - def = &(gvar->in.KbdDefs[type - ctrl_Keyboard]); + def = &(inpu.KbdDefs[type - ctrl_Keyboard]); /* if (Keyboard[def->upleft]) mx = motion_Left,my = motion_Up; @@ -887,28 +881,28 @@ register KeyboardDef *def; //TODO: make this into a function that the joystick AND keyboard can use wwww if(DIRECTIONIFELSE)//(player->info.dir == 2) { - if(!inst.Keyboard[def->left] && !inst.Keyboard[def->right]){ - if((inst.Keyboard[def->up] && !inst.Keyboard[def->down])) + if(!inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]){ + if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])) my = motion_Up; - if((inst.Keyboard[def->down] && !inst.Keyboard[def->up])) + if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])) my = motion_Down; - }else if(!inst.Keyboard[def->up] && !inst.Keyboard[def->down]){ - if((inst.Keyboard[def->left] && !inst.Keyboard[def->right])) + }else if(!inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]){ + if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])) mx = motion_Left; - if((inst.Keyboard[def->right] && !inst.Keyboard[def->left])) + if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])) mx = motion_Right; }else{ //2 keys pressed switch (player->pdir) { case 0: case 4: - if((inst.Keyboard[def->left] && !inst.Keyboard[def->right])){ dir = DirTable[1]; }//mx = motion_Left; } - else if((inst.Keyboard[def->right] && !inst.Keyboard[def->left])){ dir = DirTable[3]; }//mx = motion_Right; } + if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])){ dir = DirTable[1]; }//mx = motion_Left; } + else if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])){ dir = DirTable[3]; }//mx = motion_Right; } break; case 1: case 3: - if((inst.Keyboard[def->up] && !inst.Keyboard[def->down])){ dir = DirTable[0]; }//my = motion_Up; } - else if((inst.Keyboard[def->down] && !inst.Keyboard[def->up])){ dir = DirTable[4]; }//my = motion_Down; } + if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])){ dir = DirTable[0]; }//my = motion_Up; } + else if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])){ dir = DirTable[4]; }//my = motion_Down; } break; default: break; @@ -919,15 +913,15 @@ register KeyboardDef *def; } } //input from player - if (inst.Keyboard[def->button0]) + if (inpu.Keyboard[def->button0]) buttons += 1 << 0; - if (inst.Keyboard[def->button1]) + 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*/, gvar); + INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy/*,false*/); buttons = INL_GetJoyButtons(type - ctrl_Joystick); realdelta = true; break; @@ -998,14 +992,14 @@ register KeyboardDef *def; #endif #ifdef __DEBUG_InputMgr__ if(dbg_testcontrolnoisy > 0) -if(player->info.dir!=2/*(inst.Keyboard[def->up] || inst.Keyboard[def->down] || inst.Keyboard[def->left] || inst.Keyboard[def->right])*/ || player->enti.q>1) +if(player->info.dir!=2/*(inpu.Keyboard[def->up] || inpu.Keyboard[def->down] || inpu.Keyboard[def->left] || inpu.Keyboard[def->right])*/ || player->enti.q>1) { //printf("b1=%u b2=%u b3=%u b4=%u ", player->info.button0, player->info.button1, player->info.button2, player->info.button3); //printf("q=%d ", player->enti.q); //printf("cpee=%c ", dirchar(conpee)); printf("pdir=%c d=%c dir=%c ", dirchar(player->pdir), dirchar(player->enti.d), dirchar(player->info.dir)); /*if(realdelta) */printf("dx=%d dy=%d mx=%d my=%d", player->info.x, player->info.y, player->info.xaxis, player->info.yaxis); - //else if(!realdelta) printf("%c%d %c%d %c%d %c%d", dirchar(0), inst.Keyboard[def->up], dirchar(4), inst.Keyboard[def->down], dirchar(1), inst.Keyboard[def->left], dirchar(3), inst.Keyboard[def->right]); + //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]); printf("\n"); } #endif @@ -1118,9 +1112,9 @@ IN_WaitForKey(void) { ScanCode result; - while (!(result = inst.LastScan)) + while (!(result = inpu.LastScan)) ; - inst.LastScan = 0; + inpu.LastScan = 0; return(result); } @@ -1135,9 +1129,9 @@ IN_WaitForASCII(void) { char result; - while (!(result = inst.LastASCII)) + while (!(result = inpu.LastASCII)) ; - inst.LastASCII = '\0'; + inpu.LastASCII = '\0'; return(result); } @@ -1150,7 +1144,7 @@ IN_WaitForASCII(void) boolean btnstate[8]; -void IN_StartAck(global_game_variables_t *gvar) +void IN_StartAck(void) { unsigned i,buttons; @@ -1161,8 +1155,8 @@ void IN_StartAck(global_game_variables_t *gvar) memset (btnstate,0,sizeof(btnstate)); buttons = IN_JoyButtons () << 4; - if (gvar->in.MousePresent) - buttons |= IN_MouseButtons (gvar); + if (inpu.MousePresent) + buttons |= IN_MouseButtons (); for (i=0;i<8;i++,buttons>>=1) if (buttons&1) @@ -1170,19 +1164,19 @@ void IN_StartAck(global_game_variables_t *gvar) } -boolean IN_CheckAck (global_game_variables_t *gvar) +boolean IN_CheckAck (void) { unsigned i,buttons; // // see if something has been pressed // - if (inst.LastScan) + if (inpu.LastScan) return true; buttons = IN_JoyButtons () << 4; - if (gvar->in.MousePresent) - buttons |= IN_MouseButtons (gvar); + if (inpu.MousePresent) + buttons |= IN_MouseButtons (); for (i=0;i<8;i++,buttons>>=1) if ( buttons&1 ) @@ -1197,11 +1191,11 @@ boolean IN_CheckAck (global_game_variables_t *gvar) } -void IN_Ack (global_game_variables_t *gvar) +void IN_Ack (void) { - IN_StartAck (gvar); + IN_StartAck (); - while (!IN_CheckAck (gvar)) + while (!IN_CheckAck ()) ; } @@ -1212,19 +1206,19 @@ void IN_Ack (global_game_variables_t *gvar) // /////////////////////////////////////////////////////////////////////////// boolean -IN_IsUserInput(global_game_variables_t *gvar) +IN_IsUserInput() { boolean result; word i; - result = inst.LastScan; + result = inpu.LastScan; - if (gvar->in.MousePresent) + if (inpu.MousePresent) if (INL_GetMouseButtons()) result = true; for (i = 0;i < MaxJoys;i++) - if (gvar->in.JoysPresent[i]) + if (inpu.JoysPresent[i]) if (INL_GetJoyButtons(i)) result = true; @@ -1239,16 +1233,16 @@ IN_IsUserInput(global_game_variables_t *gvar) // button up. // /////////////////////////////////////////////////////////////////////////// -boolean IN_UserInput(word delay, global_game_variables_t *gvar) +boolean IN_UserInput(word delay) { word TimeCount = *clockw; word lasttime; lasttime = TimeCount; - IN_StartAck (gvar); + IN_StartAck (); do { - if (IN_CheckAck(gvar)) + if (IN_CheckAck()) return true; } while (TimeCount - lasttime < delay); return(false); @@ -1264,10 +1258,10 @@ boolean IN_UserInput(word delay, global_game_variables_t *gvar) =================== */ -byte IN_MouseButtons (global_game_variables_t *gvar) +byte IN_MouseButtons (void) { union REGS CPURegs; - if (gvar->in.MousePresent) + if (inpu.MousePresent) { Mouse(MButtons); return CPURegs.x.bx; @@ -1299,11 +1293,9 @@ byte IN_JoyButtons (void) boolean IN_KeyDown(byte code) { #ifdef __DEBUG_InputMgr__ - if(inst.Keyboard[code]) - printf("IN_KeyDown(%c): %u\n", code, inst.Keyboard[code]); if(!dbg_nointest) #endif - return inst.Keyboard[code]; + return inpu.Keyboard[code]; #ifdef __DEBUG_InputMgr__ else if(dbg_nointest && kbhit()) @@ -1315,23 +1307,23 @@ boolean IN_KeyDown(byte code) void IN_ClearKey(byte code) { - inst.Keyboard[code] = false; - if(code == inst.LastScan) - inst.LastScan = sc_None; + inpu.Keyboard[code] = false; + if(code == inpu.LastScan) + inpu.LastScan = sc_None; } boolean IN_qb(byte kee) { #ifdef __DEBUG_InputMgr__ - if(dbg_testkeyin) if(inst.Keyboard[kee]) printf("IN_qb(): %u\n", inst.Keyboard[kee]); + if(dbg_testkeyin) printf("%u\n", inpu.Keyboard[kee]); #endif - if(inst.Keyboard[kee]==true) return 1; + if(inpu.Keyboard[kee]==true) return 1; else return 0; } ScanCode IN_GetLastScan() { - return inst.LastScan; + return inpu.LastScan; } ScanCode IN_GetCurCode()