X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_in.c;h=c543caf99a958a7d4a484c5c0444ce67bfb16954;hb=ded380e7aab3ba7460e1f756b576722e996d939a;hp=7f467cce073ab6425d015ca18446d59700bcb24c;hpb=dbcc7e74e91c799c406dd6eded9a4b71f3e3da32;p=16.git
diff --git a/src/lib/16_in.c b/src/lib/16_in.c
index 7f467cce..c543caf9 100755
--- a/src/lib/16_in.c
+++ b/src/lib/16_in.c
@@ -1,21 +1,24 @@
-/* Catacomb Apocalypse Source Code
- * Copyright (C) 1993-2014 Flat Rock Software
+/* Project 16 Source Code~
+ * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
*
- * This program is free software; you can redistribute it and/or modify
+ * This file is part of Project 16.
+ *
+ * Project 16 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * Project 16 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see , or
+ * write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301 USA.
+ *
*/
-
//
// ID Engine
// ID_IN.c - Input Manager
@@ -37,8 +40,9 @@
//
#include "src/lib/16_in.h"
+#pragma hdrstop
-byte testkeyin=0,testcontrolnoisy=0;
+static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */
/*
=============================================================================
@@ -47,11 +51,10 @@ byte testkeyin=0,testcontrolnoisy=0;
=============================================================================
*/
-struct inconfig
+/*struct inconfig
{
- boolean MousePresent;
- boolean JoysPresent[MaxJoys];
- boolean JoyPadPresent[MaxPads];
+ boolean MousePresent;
+ boolean JoysPresent[MaxJoys];
boolean Keyboard[NumCodes];
boolean Paused;
char LastASCII;
@@ -59,11 +62,9 @@ struct inconfig
KeyboardDef KbdDefs[MaxKbds];
JoystickDef JoyDefs[MaxJoys];
- JoypadDef JoypadDefs[MaxPads];
-} inpu;
+} inpu;*/
-//extern inconfig inpu;
-//inpu.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
+//gvar->in.KbdDefs = {0x1d,0x38,/*0x47,*/0x48,/*0x49,*/0x4b,0x4d,/*0x4f,*/0x50/*,0x51*/};
/*
=============================================================================
@@ -77,15 +78,21 @@ struct inconfig
extern "C" {
#endif
-static struct instat {
- boolean IN_Started;
- boolean CapsLock;
+/*static struct instat {
+ boolean CapsLock;
ScanCode CurCode,LastCode;
-} inst;
-static void (*INL_KeyHook)(void);
-static void interrupt (*OldKeyVect)(void);
-static char *ParmStringsIN[] = {"nojoys","nomouse",nil};
+ boolean Keyboard[NumCodes];
+ boolean Paused;
+ char LastASCII;
+ ScanCode LastScan;
+} inst;*/
+
+//the def stuff is need fix warnings
+#ifndef INSTDEFED
+#define INSTDEFED
+static inst_t inst;
+#endif
static byte far ASCIINames[] = // Unshifted ASCII for scan codes
{
@@ -151,43 +158,43 @@ static byte far ASCIINames[] = // Unshifted ASCII for scan codes
static Direction DirTable[] = // Quick lookup for total direction
{
- //dir_Nortinest,
- dir_North,
- dir_West,
- dir_None,
- dir_East,
- dir_South
- //dir_NorthEast,
- //dir_Soutinest,
- //,dir_SouthEast
+ /*dir_NorthWest, */dir_North,/* dir_NorthEast,*/
+ dir_West, dir_None, dir_East,
+ /*dir_SouthWest, */dir_South/*, dir_SouthEast*/
};
#ifdef __cplusplus
}
#endif
+static void (*INL_KeyHook)(void);
+static void interrupt (*OldKeyVect)(void);
+static char *ParmStringsIN[] = {"nojoys","nomouse",nil};
+static void INL_StartKbd(void);
+
// Internal routines
+
///////////////////////////////////////////////////////////////////////////
//
// INL_KeyService() - Handles a keyboard interrupt (key up/down)
//
///////////////////////////////////////////////////////////////////////////
-void interrupt
-INL_KeyService()
+/*static */void interrupt
+INL_KeyService(void)
{
static boolean special;
- byte k,c;
- register byte temp;
+ byte k,c,
+ temp;
- k = inp(0x60); // Get the scan code
+ k = inportb(0x60); // Get the scan code
// Tell the XT keyboard controller to clear the key
- outp(0x61,(temp = inp(0x61)) | 0x80);
- outp(0x61,temp);
+ outportb(0x61,(temp = inportb(0x61)) | 0x80);
+ outportb(0x61,temp);
if (k == 0xe0) // Special key prefix
special = true;
else if (k == 0xe1) // Handle Pause key
- inpu.Paused = true;
+ inst.Paused = true;
else
{
if (k & 0x80) // Break code
@@ -196,13 +203,13 @@ static boolean special;
// DEBUG - handle special keys: ctl-alt-delete, print scrn
- inpu.Keyboard[k] = false;
+ inst.Keyboard[k] = false;
}
else // Make code
{
inst.LastCode = inst.CurCode;
- inst.CurCode = inpu.LastScan = k;
- inpu.Keyboard[k] = true;
+ inst.CurCode = inst.LastScan = k;
+ inst.Keyboard[k] = true;
if (special)
c = SpecialNames[k];
@@ -214,7 +221,7 @@ static boolean special;
// DEBUG - make caps lock light work
}
- if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift]) // If shifted
+ if (inst.Keyboard[sc_LShift] || inst.Keyboard[sc_RShift]) // If shifted
{
c = ShiftNames[k];
if ((c >= 'A') && (c <= 'Z') && inst.CapsLock)
@@ -228,7 +235,7 @@ static boolean special;
}
}
if (c)
- inpu.LastASCII = c;
+ inst.LastASCII = c;
}
special = false;
@@ -236,18 +243,21 @@ static boolean special;
if (INL_KeyHook && !special)
INL_KeyHook();
-//#ifdef TESTKEYIN
- if(testkeyin > 0) printf("%c [0x%x %u] %u\n", c, k, k, inpu.Keyboard[k]);
-//endif
- outp(0x20,0x20);
+#ifdef __DEBUG_InputMgr__
+ if(dbg_testkeyin > 0) printf("%c %u [0x%x %u] %u\n", c, c, k, k, inst.Keyboard[k]);
+#endif
+ outportb(0x20,0x20);
}
-void
-Mouse(int x)
+void INL_Mouse(int x)
{
- union REGS CPURegs;
- x = CPURegs.x.ax;
- int86(MouseInt,&CPURegs,&CPURegs);
+ //union REGS CPURegs;
+ //x = CPURegs.x.ax;
+ __asm {
+ mov ax,x
+ int MouseInt
+ }
+ //int86(MouseInt,&CPURegs,&CPURegs);
}
///////////////////////////////////////////////////////////////////////////
@@ -301,8 +311,7 @@ IN_GetJoyAbs(word joy,word *xp,word *yp)
yb = 1 << ys;
// Read the absolute joystick values
- __asm
- {
+ __asm {
pushf // Save some registers
push si
push di
@@ -322,8 +331,13 @@ IN_GetJoyAbs(word joy,word *xp,word *yp)
push bp // Don't mess up stack frame
mov bp,MaxJoyValue
-
+#ifdef __BORLANDC__
+ }
+#endif
loo:
+#ifdef __BORLANDC__
+ __asm {
+#endif
in al,dx // Get bits indicating whether all are finished
dec bp // Check bounding register
@@ -340,8 +354,13 @@ loo:
add cl,bl
jnz loo // If both bits were 0, drop out
-
+#ifdef __BORLANDC__
+ }
+#endif
done:
+#ifdef __BORLANDC__
+ __asm {
+#endif
pop bp
mov cl,[xs] // Get the number of bits to shift
@@ -365,20 +384,18 @@ done:
///////////////////////////////////////////////////////////////////////////
//
// INL_GetJoyDelta() - Returns the relative movement of the specified
-// joystick (from +/-127, scaled adaptively)
+// joystick (from +/-127)
//
///////////////////////////////////////////////////////////////////////////
-static void
-INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)
+void INL_GetJoyDelta(word joy,int *dx,int *dy/*,boolean adaptive*/, global_game_variables_t *gvar)
{
word x,y;
- word time;
word TimeCount = *clockw;
JoystickDef *def;
static word lasttime;
IN_GetJoyAbs(joy,&x,&y);
- def = inpu.JoyDefs + joy;
+ def = gvar->in.JoyDefs + joy;
if (x < def->threshMinX)
{
@@ -425,18 +442,17 @@ static word lasttime;
}
else
*dy = 0;
-
- if (adaptive)
- {
- time = (TimeCount - lasttime) / 2;
- if (time)
- {
- if (time > 8)
- time = 8;
- *dx *= time;
- *dy *= time;
- }
- }
+// if (adaptive)
+// {
+// time = (TimeCount - lasttime) / 2;
+// if (time)
+// {
+// if (time > 8)
+// time = 8;
+// *dx *= time;
+// *dy *= time;
+// }
+// }
lasttime = TimeCount;
}
@@ -451,7 +467,7 @@ INL_GetJoyButtons(word joy)
{
register word result;
- result = inp(0x201); // Get all the joystick buttons
+ result = inportb(0x201); // Get all the joystick buttons
result >>= joy? 6 : 4; // Shift into bits 0-1
result &= 3; // Mask off the useless bits
result ^= 3;
@@ -476,6 +492,7 @@ IN_GetJoyButtonsDB(word joy)
result1 = INL_GetJoyButtons(joy);
lasttime = TimeCount;
while(TimeCount == lasttime)
+ //;
result2 = INL_GetJoyButtons(joy);
} while(result1 != result2);
return(result1);
@@ -489,12 +506,12 @@ IN_GetJoyButtonsDB(word joy)
static void
INL_StartKbd()
{
- INL_KeyHook = 0; // Clear key hook
+ INL_KeyHook = NULL; // Clear key hook
IN_ClearKeysDown();
- OldKeyVect = _dos_getvect(KeyInt);
- _dos_setvect(KeyInt,INL_KeyService);
+ OldKeyVect = getvect(KeyInt);//IN_KbdLED();
+ setvect(KeyInt,INL_KeyService);
}
///////////////////////////////////////////////////////////////////////////
@@ -507,7 +524,7 @@ INL_ShutKbd(void)
{
pokeb(0x40,0x17,peekb(0x40,0x17) & 0xfaf0); // Clear ctrl/alt/shift flags
- _dos_setvect(KeyInt,OldKeyVect);
+ setvect(KeyInt,OldKeyVect);
}
///////////////////////////////////////////////////////////////////////////
@@ -518,14 +535,26 @@ INL_ShutKbd(void)
static boolean
INL_StartMouse(void)
{
- union REGS CPURegs;
- if(_dos_getvect(MouseInt))
+#if 0
+ if (getvect(MouseInt))
{
Mouse(MReset);
- if(CPURegs.x.ax == 0xffff)
+ if (_AX == 0xffff)
return(true);
}
return(false);
+#endif
+ byte far *vector;
+
+
+ if ((vector=MK_FP(peek(0,0x33*4+2),peek(0,0x33*4)))==NULL)
+ return false;
+
+ if (*vector == 207)
+ return false;
+
+ Mouse(MReset);
+ return true;
}
///////////////////////////////////////////////////////////////////////////
@@ -542,11 +571,11 @@ INL_ShutMouse(void)
// INL_SetJoyScale() - Sets up scaling values for the specified joystick
//
static void
-INL_SetJoyScale(word joy)
+INL_SetJoyScale(word joy, global_game_variables_t *gvar)
{
JoystickDef *def;
- def = &(inpu.JoyDefs[joy]);
+ def = &(gvar->in.JoyDefs[joy]);
def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
@@ -560,12 +589,12 @@ INL_SetJoyScale(word joy)
//
///////////////////////////////////////////////////////////////////////////
void
-IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
+IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy, global_game_variables_t *gvar)
{
word d,r;
JoystickDef *def;
- def = &(inpu.JoyDefs[joy]);
+ def = &(gvar->in.JoyDefs[joy]);
def->joyMinX = minx;
def->joyMaxX = maxx;
@@ -581,7 +610,7 @@ IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
def->threshMinY = ((r / 2) - d) + miny;
def->threshMaxY = ((r / 2) + d) + miny;
- INL_SetJoyScale(joy);
+ INL_SetJoyScale(joy, gvar);
}
///////////////////////////////////////////////////////////////////////////
@@ -591,7 +620,7 @@ IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
//
///////////////////////////////////////////////////////////////////////////
static boolean
-INL_StartJoy(word joy)
+INL_StartJoy(word joy, global_game_variables_t *gvar)
{
word x,y;
@@ -605,7 +634,7 @@ INL_StartJoy(word joy)
return(false);
else
{
- IN_SetupJoy(joy,0,x * 2,0,y * 2);
+ IN_SetupJoy(joy,0,x * 2,0,y * 2, gvar);
return(true);
}
}
@@ -616,9 +645,9 @@ INL_StartJoy(word joy)
//
///////////////////////////////////////////////////////////////////////////
static void
-INL_ShutJoy(word joy)
+INL_ShutJoy(word joy, global_game_variables_t *gvar)
{
- inpu.JoysPresent[joy] = false;
+ gvar->in.JoysPresent[joy] = false;
}
// Public routines
@@ -629,19 +658,19 @@ INL_ShutJoy(word joy)
//
///////////////////////////////////////////////////////////////////////////
void
-IN_Startup()
+IN_Startup(global_game_variables_t *gvar)
{
boolean checkjoys,checkmouse;
word i;
- if (inst.IN_Started)
+ if (gvar->in.IN_Started)
return;
checkjoys = true;
checkmouse = true;
- for (i = 1;i < __argc;i++)
+ for (i = 1;i < _argc;i++)
{
- switch (US_CheckParm(__argv[i],ParmStringsIN))
+ switch (US_CheckParm(_argv[i],ParmStringsIN))
{
case 0:
checkjoys = false;
@@ -653,12 +682,15 @@ IN_Startup()
}
INL_StartKbd();
- inpu.MousePresent = checkmouse? INL_StartMouse() : false;
+ gvar->in.MousePresent = checkmouse? INL_StartMouse() : false;
for (i = 0;i < MaxJoys;i++)
- inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
+ gvar->in.JoysPresent[i] = checkjoys? INL_StartJoy(i, gvar) : false;
+
+ gvar->in.inst = &inst;
+
+ gvar->in.IN_Started = true;
- inst.IN_Started = true;
}
///////////////////////////////////////////////////////////////////////////
@@ -667,32 +699,30 @@ IN_Startup()
//
///////////////////////////////////////////////////////////////////////////
void
-IN_Default(boolean gotit,player_t *player,ControlType nt)
+IN_Default(boolean gotit,player_t *player,ControlType nt, global_game_variables_t *gvar)
{
int i;
if
(
(!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_Joystick1) && !gvar->in.JoysPresent[0])
+ || ((nt == ctrl_Joystick2) && !gvar->in.JoysPresent[1])
+ || ((nt == ctrl_Mouse) && !gvar->in.MousePresent)
)
nt = ctrl_Keyboard1;
- inpu.KbdDefs[0].button0 = 0x1c;
- inpu.KbdDefs[0].button1 = 0x38;
+ gvar->in.KbdDefs[0].button0 = 0x1c;
+ gvar->in.KbdDefs[0].button1 = 0x38;
//in.KbdDefs[0].upleft = 0x47;
- inpu.KbdDefs[0].up = 0x48;
+ gvar->in.KbdDefs[0].up = 0x48;
//in.KbdDefs[0].upright = 0x49;
- inpu.KbdDefs[0].left = 0x4b;
- inpu.KbdDefs[0].right = 0x4d;
+ gvar->in.KbdDefs[0].left = 0x4b;
+ gvar->in.KbdDefs[0].right = 0x4d;
//in.KbdDefs[0].downleft = 0x4f;
- inpu.KbdDefs[0].down = 0x50;
+ gvar->in.KbdDefs[0].down = 0x50;
//in.KbdDefs[0].downright = 0x51;
- IN_SetControlType(0,player,nt);
+ IN_SetControlType(player,nt);
for(i=0; i>MaxPlayers;i++)
- player[i].d=2;
+ player[i].enti.d =2;
}
///////////////////////////////////////////////////////////////////////////
@@ -701,19 +731,19 @@ IN_Default(boolean gotit,player_t *player,ControlType nt)
//
///////////////////////////////////////////////////////////////////////////
void
-IN_Shutdown()
+IN_Shutdown(global_game_variables_t *gvar)
{
word i;
- if (!inst.IN_Started)
+ if (!gvar->in.IN_Started)
return;
INL_ShutMouse();
for (i = 0;i < MaxJoys;i++)
- INL_ShutJoy(i);
+ INL_ShutJoy(i, gvar);
INL_ShutKbd();
- inst.IN_Started = false;
+ gvar->in.IN_Started = false;
}
///////////////////////////////////////////////////////////////////////////
@@ -730,17 +760,17 @@ IN_SetKeyHook(void (*hook)())
///////////////////////////////////////////////////////////////////////////
//
-// IN_ClearKeyDown() - Clears the keyboard array
+// IN_ClearKeysDown() - Clears the keyboard array
//
///////////////////////////////////////////////////////////////////////////
void
-IN_ClearKeysDown()
+IN_ClearKeysDown(void)
{
- int i;
+ //int i;
- inpu.LastScan = sc_None;
- inpu.LastASCII = key_None;
- memset (inpu.Keyboard,0,sizeof(inpu.Keyboard));
+ inst.LastScan = sc_None;
+ inst.LastASCII = key_None;
+ memset (inst.Keyboard,0,sizeof(inst.Keyboard));
}
///////////////////////////////////////////////////////////////////////////
@@ -767,7 +797,7 @@ INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy)
//
///////////////////////////////////////////////////////////////////////////
void
-IN_ReadCursor(CursorInfo *info)
+IN_ReadCursor(CursorInfo *info, global_game_variables_t *gvar)
{
word i,
buttons;
@@ -776,7 +806,7 @@ IN_ReadCursor(CursorInfo *info)
info->x = info->y = 0;
info->button0 = info->button1 = false;
- if (inpu.MousePresent)
+ if (gvar->in.MousePresent)
{
buttons = INL_GetMouseButtons();
INL_GetMouseDelta(&dx,&dy);
@@ -785,28 +815,34 @@ IN_ReadCursor(CursorInfo *info)
for (i = 0;i < MaxJoys;i++)
{
- if (!inpu.JoysPresent[i])
+ if (!gvar->in.JoysPresent[i])
continue;
buttons = INL_GetJoyButtons(i);
- INL_GetJoyDelta(i,&dx,&dy,true);
+ INL_GetJoyDelta(i,&dx,&dy/*,true*/, gvar);
dx /= 64;
dy /= 64;
INL_AdjustCursor(info,buttons,dx,dy);
}
}
+//if else for gfxtesting and direction
+#define DIRECTIONIFELSE (player->info.dir == 2)
+//#define NDIRECTIONIFELSE (player->info.dir != 2)
+
///////////////////////////////////////////////////////////////////////////
//
// IN_ReadControl() - Reads the device associated with the specified
// player and fills in the control info struct
//
///////////////////////////////////////////////////////////////////////////
-void near
-IN_ReadControl(int pn,player_t *player)
+void
+IN_ReadControl(player_t *player, global_game_variables_t *gvar)
{
boolean realdelta;
+#if DEMO0
byte dbyte;
+#endif
word buttons;
int dx,dy;
Motion mx,my;
@@ -837,15 +873,15 @@ register KeyboardDef *def;
realdelta = false;
}
else if (DemoMode == demo_PlayDone)
- Quit("Demo playback exceeded");
+ Quit ("Demo playback exceeded");
else
{
#endif
- switch (type = player[pn].Controls)
+ switch (type = player->Controls)
{
case ctrl_Keyboard1:
case ctrl_Keyboard2:
- def = &(inpu.KbdDefs[type - ctrl_Keyboard]);
+ def = &(gvar->in.KbdDefs[type - ctrl_Keyboard]);
/* if (Keyboard[def->upleft])
mx = motion_Left,my = motion_Up;
@@ -855,50 +891,50 @@ register KeyboardDef *def;
mx = motion_Left,my = motion_Down;
else if (Keyboard[def->downright])
mx = motion_Right,my = motion_Down;*/
- if(DIRECTIONIFELSE)
+//TODO: make this into a function that the joystick AND keyboard can use wwww
+ if(DIRECTIONIFELSE)//(player->info.dir == 2)
{
- //if(!inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]){
- if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]))
+ if(!inst.Keyboard[def->left] && !inst.Keyboard[def->right]){
+ if((inst.Keyboard[def->up] && !inst.Keyboard[def->down]))
my = motion_Up;
- if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up]))
+ if((inst.Keyboard[def->down] && !inst.Keyboard[def->up]))
my = motion_Down;
- //}else if(!inpu.Keyboard[def->up] && !inpu.Keyboard[def->down]){
- if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right]))
+ }else if(!inst.Keyboard[def->up] && !inst.Keyboard[def->down]){
+ if((inst.Keyboard[def->left] && !inst.Keyboard[def->right]))
mx = motion_Left;
- if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left]))// || player[pn].pdir != 1)
+ if((inst.Keyboard[def->right] && !inst.Keyboard[def->left]))
mx = motion_Right;
-
- //}else
- if(mx+my>1pdir)
{
case 0:
case 4:
- if((inpu.Keyboard[def->left] && !inpu.Keyboard[def->right])) dir = DirTable[1];
- else if((inpu.Keyboard[def->right] && !inpu.Keyboard[def->left])) dir = DirTable[3];
+ if((inst.Keyboard[def->left] && !inst.Keyboard[def->right])){ dir = DirTable[1]; }//mx = motion_Left; }
+ else if((inst.Keyboard[def->right] && !inst.Keyboard[def->left])){ dir = DirTable[3]; }//mx = motion_Right; }
break;
case 1:
case 3:
- if((inpu.Keyboard[def->up] && !inpu.Keyboard[def->down])) dir = DirTable[0];
- else if((inpu.Keyboard[def->down] && !inpu.Keyboard[def->up])) dir = DirTable[4];
+ if((inst.Keyboard[def->up] && !inst.Keyboard[def->down])){ dir = DirTable[0]; }//my = motion_Up; }
+ else if((inst.Keyboard[def->down] && !inst.Keyboard[def->up])){ dir = DirTable[4]; }//my = motion_Down; }
break;
default:
break;
}
- if(testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c ", dirchar(player[pn].pdir)); }
+#ifdef __DEBUG_InputMgr__
+ //if(dbg_testcontrolnoisy > 0){ printf("dir=%c ", dirchar(dir)); printf("pdir=%c ", dirchar(player->pdir)); }
+#endif
}
}
//input from player
- if (inpu.Keyboard[def->button0])
+ if (inst.Keyboard[def->button0])
buttons += 1 << 0;
- if (inpu.Keyboard[def->button1])
+ if (inst.Keyboard[def->button1])
buttons += 1 << 1;
realdelta = false;
break;
case ctrl_Joystick1:
case ctrl_Joystick2:
- INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy,false);
+ INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy/*,false*/, gvar);
buttons = INL_GetJoyButtons(type - ctrl_Joystick);
realdelta = true;
break;
@@ -907,10 +943,6 @@ register KeyboardDef *def;
buttons = INL_GetMouseButtons();
realdelta = true;
break;
- case ctrl_Joypad1:
- case ctrl_Joypad2:
- printf("wwww");
- break;
}
#ifdef DEMO0
}
@@ -927,24 +959,23 @@ register KeyboardDef *def;
dy = my;// * 127;
}
- player[pn].info.x = dx;
- player[pn].info.xaxis = mx;
- player[pn].info.y = dy;
- player[pn].info.yaxis = my;
- player[pn].info.button0 = buttons & (1 << 0);
- player[pn].info.button1 = buttons & (1 << 1);
- player[pn].info.button2 = buttons & (1 << 2);
- player[pn].info.button3 = buttons & (1 << 3);
-// player[pn].info.dir = DirTable[((my + 1) * 3) + (mx + 1)];
+ player->info.x = dx;
+ player->info.xaxis = mx;
+ player->info.y = dy;
+ player->info.yaxis = my;
+ player->info.button0 = buttons & (1 << 0);
+ player->info.button1 = buttons & (1 << 1);
+ player->info.button2 = buttons & (1 << 2);
+ player->info.button3 = buttons & (1 << 3);
+// player->info.dir = DirTable[((my + 1) * 3) + (mx + 1)];
conpee=(((my + 1) * 2) + (mx + 1))-1;
- player[pn].info.dir = DirTable[conpee];
+ player->info.dir = DirTable[conpee];
- //TODO: overwriting direction must be added
- if(DirTable[conpee]!=2) player[pn].pdir=DirTable[conpee];
- if(player[pn].q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None)))
+ if(DirTable[conpee]!=2) player->pdir=DirTable[conpee];
+ if(player->enti.q==1 &&( dir!=2 || (mx!=motion_None || my!=motion_None)))
{
- if(dir==2) player[pn].d = player[pn].info.dir;
- else player[pn].d = DirTable[dir];
+ if(dir==2) player->enti.d = player->info.dir;
+ else player->enti.d = DirTable[dir];
}
#if DEMO0
@@ -965,25 +996,26 @@ register KeyboardDef *def;
DemoOffset += 2;
if (DemoOffset >= DemoSize)
- Quit("Demo buffer overflow");
+ Quit ("Demo buffer overflow");
DemoBuffer[DemoOffset] = 1;
DemoBuffer[DemoOffset + 1] = dbyte;
}
}
#endif
-//#ifdef TESTCONTROLNOISY
-if(testcontrolnoisy > 0)
-if((inpu.Keyboard[def->up] || inpu.Keyboard[def->down] || inpu.Keyboard[def->left] || inpu.Keyboard[def->right]) || player[pn].q>1)
+#ifdef __DEBUG_InputMgr__
+if(dbg_testcontrolnoisy > 0)
+if(player->info.dir!=2/*(inst.Keyboard[def->up] || inst.Keyboard[def->down] || inst.Keyboard[def->left] || inst.Keyboard[def->right])*/ || player->enti.q>1)
{
- printf("q=%d ", player[pn].q);
- printf("cpee=%c ", dirchar(conpee));
- //printf("(mx)=%d ", mx);
- //printf("(my)=%d ", my);
- printf("pdir=%c d=%c dir=%c ", dirchar(player[pn].pdir), dirchar(player[pn].d), dirchar(player[pn].info.dir));
- printf("%c%d %c%d %c%d %c%d\n", dirchar(0), inpu.Keyboard[def->up], dirchar(4), inpu.Keyboard[def->down], dirchar(1), inpu.Keyboard[def->left], dirchar(3), inpu.Keyboard[def->right]);
+ //printf("b1=%u b2=%u b3=%u b4=%u ", player->info.button0, player->info.button1, player->info.button2, player->info.button3);
+ //printf("q=%d ", player->enti.q);
+ //printf("cpee=%c ", dirchar(conpee));
+ printf("pdir=%c d=%c dir=%c ", dirchar(player->pdir), dirchar(player->enti.d), dirchar(player->info.dir));
+ /*if(realdelta) */printf("dx=%d dy=%d mx=%d my=%d", player->info.x, player->info.y, player->info.xaxis, player->info.yaxis);
+ //else if(!realdelta) printf("%c%d %c%d %c%d %c%d", dirchar(0), inst.Keyboard[def->up], dirchar(4), inst.Keyboard[def->down], dirchar(1), inst.Keyboard[def->left], dirchar(3), inst.Keyboard[def->right]);
+ printf("\n");
}
-//#endif
+#endif
}
///////////////////////////////////////////////////////////////////////////
@@ -993,10 +1025,10 @@ if((inpu.Keyboard[def->up] || inpu.Keyboard[def->down] || inpu.Keyboard[def->lef
//
///////////////////////////////////////////////////////////////////////////
void
-IN_SetControlType(word pn,player_t *player,ControlType type)
+IN_SetControlType(player_t *player,ControlType type)
{
// DEBUG - check that requested type is present?
- player[pn].Controls = type;
+ player->Controls = type;
}
#if DEMO0
@@ -1089,13 +1121,13 @@ IN_GetScanName(ScanCode scan)
//
///////////////////////////////////////////////////////////////////////////
ScanCode
-IN_WaitForKey()
+IN_WaitForKey(void)
{
ScanCode result;
- while (!(result = inpu.LastScan))
+ while (!(result = inst.LastScan))
;
- inpu.LastScan = 0;
+ inst.LastScan = 0;
return(result);
}
@@ -1106,78 +1138,83 @@ IN_WaitForKey()
//
///////////////////////////////////////////////////////////////////////////
char
-IN_WaitForASCII()
+IN_WaitForASCII(void)
{
char result;
- while (!(result = inpu.LastASCII))
+ while (!(result = inst.LastASCII))
;
- inpu.LastASCII = '\0';
+ inst.LastASCII = '\0';
return(result);
}
///////////////////////////////////////////////////////////////////////////
//
-// IN_AckBack() - Waits for either an ASCII keypress or a button press
+// IN_Ack() - waits for a button or key press. If a button is down, upon
+// calling, it must be released for it to be recognized
//
///////////////////////////////////////////////////////////////////////////
-void
-IN_AckBack()
+
+boolean btnstate[8];
+
+void IN_StartAck(global_game_variables_t *gvar)
{
- word i;
+ unsigned i,buttons;
- while (!inpu.LastScan)
- {
- if (inpu.MousePresent)
- {
- if (INL_GetMouseButtons())
- {
- while (INL_GetMouseButtons())
- ;
- return;
- }
- }
+//
+// get initial state of everything
+//
+ IN_ClearKeysDown();
+ memset (btnstate,0,sizeof(btnstate));
- for (i = 0;i < MaxJoys;i++)
- {
- if (inpu.JoysPresent[i])
- {
- if (IN_GetJoyButtonsDB(i))
- {
- while (IN_GetJoyButtonsDB(i))
- ;
- return;
- }
- }
- }
- }
+ buttons = IN_JoyButtons () << 4;
+ if (gvar->in.MousePresent)
+ buttons |= IN_MouseButtons (gvar);
- IN_ClearKey(inpu.LastScan);
- inpu.LastScan = sc_None;
+ for (i=0;i<8;i++,buttons>>=1)
+ if (buttons&1)
+ btnstate[i] = true;
}
-///////////////////////////////////////////////////////////////////////////
+
+boolean IN_CheckAck (global_game_variables_t *gvar)
+{
+ unsigned i,buttons;
+
//
-// IN_Ack() - Clears user input & then calls IN_AckBack()
+// see if something has been pressed
//
-///////////////////////////////////////////////////////////////////////////
-void
-IN_Ack()
-{
- word i;
+ if(!gvar->in.IN_Started)
+ getch();
+ else
+ {
+ if (inst.LastScan)
+ return true;
+ }
- IN_ClearKey(inpu.LastScan);
- inpu.LastScan = sc_None;
+ buttons = IN_JoyButtons () << 4;
+ if (gvar->in.MousePresent)
+ buttons |= IN_MouseButtons (gvar);
- if (inpu.MousePresent)
- while (INL_GetMouseButtons())
- ;
- for (i = 0;i < MaxJoys;i++)
- if (inpu.JoysPresent[i])
- while (IN_GetJoyButtonsDB(i))
- ;
+ for (i=0;i<8;i++,buttons>>=1)
+ if ( buttons&1 )
+ {
+ if (!btnstate[i])
+ return true;
+ }
+ else
+ btnstate[i]=false;
+
+ return false;
+}
+
+
+void IN_Ack (global_game_variables_t *gvar)
+{
+ IN_StartAck (gvar);
- IN_AckBack();
+ while (!IN_CheckAck (gvar))
+ ;
}
///////////////////////////////////////////////////////////////////////////
@@ -1187,19 +1224,19 @@ IN_Ack()
//
///////////////////////////////////////////////////////////////////////////
boolean
-IN_IsUserInput()
+IN_IsUserInput(global_game_variables_t *gvar)
{
boolean result;
word i;
- result = inpu.LastScan;
+ result = inst.LastScan;
- if (inpu.MousePresent)
+ if (gvar->in.MousePresent)
if (INL_GetMouseButtons())
result = true;
for (i = 0;i < MaxJoys;i++)
- if (inpu.JoysPresent[i])
+ if (gvar->in.JoysPresent[i])
if (INL_GetJoyButtons(i))
result = true;
@@ -1214,42 +1251,112 @@ IN_IsUserInput()
// button up.
//
///////////////////////////////////////////////////////////////////////////
-boolean
-IN_UserInput(dword delay,boolean clear)
+boolean IN_UserInput(word delay, global_game_variables_t *gvar)
{
word TimeCount = *clockw;
word lasttime;
lasttime = TimeCount;
+ IN_StartAck (gvar);
do
{
- if (IN_IsUserInput())
- {
- if (clear)
- IN_AckBack();
- return(true);
- }
+ if (IN_CheckAck(gvar))
+ return true;
} while (TimeCount - lasttime < delay);
return(false);
}
+//===========================================================================
+
+/*
+===================
+=
+= IN_MouseButtons
+=
+===================
+*/
+
+byte IN_MouseButtons (global_game_variables_t *gvar)
+{
+ union REGS CPURegs;
+ if (gvar->in.MousePresent)
+ {
+ Mouse(MButtons);
+ return CPURegs.x.bx;
+ }
+ else
+ return 0;
+}
+
+
+/*
+===================
+=
+= IN_JoyButtons
+=
+===================
+*/
+
+byte IN_JoyButtons (void)
+{
+ byte joybits;
+
+ joybits = inportb(0x201); // Get all the joystick buttons
+ joybits >>= 4; // only the high bits are useful
+ joybits ^= 15; // return with 1=pressed
+
+ return joybits;
+}
+
boolean IN_KeyDown(byte code)
{
- return inpu.Keyboard[code];
+#ifdef __DEBUG_InputMgr__
+// if(inst.Keyboard[code])
+// printf("IN_KeyDown(%c): %u\n", code, inst.Keyboard[code]);
+ if(!dbg_nointest)
+#endif
+ return inst.Keyboard[code];
+#ifdef __DEBUG_InputMgr__
+ else
+ if(dbg_nointest && kbhit())
+ return 1;
+ else
+ return 0;
+#endif
}
void IN_ClearKey(byte code)
{
- inpu.Keyboard[code] = false;
- if(code == inpu.LastScan)
- inpu.LastScan = sc_None;
+ inst.Keyboard[code] = false;
+ if(code == inst.LastScan)
+ inst.LastScan = sc_None;
}
boolean IN_qb(byte kee)
{
-//#ifdef TESTKEYIN
-// if(testkeyin > 0) printf("%u\n", inpu.Keyboard[kee]);
-//#endif
- if(inpu.Keyboard[kee]==true) return 1;
+#ifdef __DEBUG_InputMgr__
+ if(dbg_testkeyin) if(inst.Keyboard[kee]) printf("IN_qb(): %u\n", inst.Keyboard[kee]);
+#endif
+ if(inst.Keyboard[kee]==true) return 1;
else return 0;
}
+
+ScanCode IN_GetLastScan()
+{
+ return inst.LastScan;
+}
+
+ScanCode IN_GetCurCode()
+{
+ return inst.CurCode;
+}
+
+void IN_KbdLED()
+{
+ byte far *lock_key;
+
+ // turn off num-lock via BIOS
+ lock_key = MK_FP(0x040, 0x017); // Pointing to the address of the bios shift state keys
+ *lock_key&=(~(16 | 32 | 64)); // toggle off the locks by changing the values of the 4th, 5th, and 6th bits of the address byte of 0040:0017
+ OldKeyVect(); // call BIOS keyhandler to change keyboard lights
+}