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(inconfig *in)
+INL_KeyService()
{
static boolean special;
byte k,c;
if (k == 0xe0) // Special key prefix
special = true;
else if (k == 0xe1) // Handle Pause key
- in->Paused = true;
+ inpu.Paused = true;
else
{
if (k & 0x80) // Break code
// DEBUG - handle special keys: ctl-alt-delete, print scrn
- in->Keyboard[k] = false;
+ inpu.Keyboard[k] = false;
}
else // Make code
{
- in->LastCode = in->CurCode;
- in->CurCode = in->LastScan = k;
- in->Keyboard[k] = true;
+ inst.LastCode = inst.CurCode;
+ inst.CurCode = inpu.LastScan = k;
+ inpu.Keyboard[k] = true;
if (special)
c = SpecialNames[k];
{
if (k == sc_CapsLock)
{
- in->CapsLock ^= true;
+ inst.CapsLock ^= true;
// DEBUG - make caps lock light work
}
- if (in->Keyboard[sc_LShift] || in->Keyboard[sc_RShift]) // If shifted
+ if (inpu.Keyboard[sc_LShift] || inpu.Keyboard[sc_RShift]) // If shifted
{
c = ShiftNames[k];
- if ((c >= 'A') && (c <= 'Z') && in->CapsLock)
+ if ((c >= 'A') && (c <= 'Z') && inst.CapsLock)
c += 'a' - 'A';
}
else
{
c = ASCIINames[k];
- if ((c >= 'a') && (c <= 'z') && in->CapsLock)
+ if ((c >= 'a') && (c <= 'z') && inst.CapsLock)
c -= 'a' - 'A';
}
}
if (c)
- in->LastASCII = c;
+ inpu.LastASCII = c;
}
special = false;
if (INL_KeyHook && !special)
INL_KeyHook();
#ifdef TESTKEYIN
- printf("%c %x %u\n", c, k, in->Keyboard[k]);
+ printf("%c %x %u\n", c, k, inpu.Keyboard[k]);
#endif
outp(0x20,0x20);
}
//
///////////////////////////////////////////////////////////////////////////
static void
-INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive, inconfig *in)
+INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive)
{
word x,y;
dword time;
static dword lasttime;
IN_GetJoyAbs(joy,&x,&y);
- def = in->JoyDefs + joy;
+ def = inpu.JoyDefs + joy;
if (x < def->threshMinX)
{
//
///////////////////////////////////////////////////////////////////////////
static void
-INL_StartKbd(inconfig *in)
+INL_StartKbd()
{
INL_KeyHook = 0; // Clear key hook
- IN_ClearKeysDown(in);
+ IN_ClearKeysDown();
OldKeyVect = _dos_getvect(KeyInt);
_dos_setvect(KeyInt,INL_KeyService);
// INL_SetJoyScale() - Sets up scaling values for the specified joystick
//
static void
-INL_SetJoyScale(word joy, inconfig *in)
+INL_SetJoyScale(word joy)
{
JoystickDef *def;
- def = &(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);
//
///////////////////////////////////////////////////////////////////////////
void
-IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy, inconfig *in)
+IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
{
word d,r;
JoystickDef *def;
- def = &(in->JoyDefs[joy]);
+ def = &(inpu.JoyDefs[joy]);
def->joyMinX = minx;
def->joyMaxX = maxx;
def->threshMinY = ((r / 2) - d) + miny;
def->threshMaxY = ((r / 2) + d) + miny;
- INL_SetJoyScale(joy, in);
+ INL_SetJoyScale(joy);
}
///////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////
static boolean
-INL_StartJoy(word joy, inconfig *in)
+INL_StartJoy(word joy)
{
word x,y;
return(false);
else
{
- IN_SetupJoy(joy,0,x * 2,0,y * 2, in);
+ IN_SetupJoy(joy,0,x * 2,0,y * 2);
return(true);
}
}
//
///////////////////////////////////////////////////////////////////////////
static void
-INL_ShutJoy(word joy, inconfig *in)
+INL_ShutJoy(word joy)
{
- in->JoysPresent[joy] = false;
+ inpu.JoysPresent[joy] = false;
}
// Public routines
//
///////////////////////////////////////////////////////////////////////////
void
-IN_Startup(inconfig *in)
+IN_Startup()
{
boolean checkjoys,checkmouse;
word i;
- if (in->IN_Started)
+ if (inst.IN_Started)
return;
checkjoys = true;
}
}
- INL_StartKbd(in);
- in->MousePresent = checkmouse? INL_StartMouse() : false;
+ INL_StartKbd();
+ inpu.MousePresent = checkmouse? INL_StartMouse() : false;
for (i = 0;i < MaxJoys;i++)
- in->JoysPresent[i] = checkjoys? INL_StartJoy(i, in) : false;
+ inpu.JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
- in->IN_Started = true;
+ inst.IN_Started = true;
}
///////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////
void
-IN_Default(boolean gotit,player_t *player,ControlType nt, inconfig *in)
+IN_Default(boolean gotit,player_t *player,ControlType nt)
{
if
(
(!gotit)
- || ((nt == ctrl_Joystick1) && !in->JoysPresent[0])
- || ((nt == ctrl_Joystick2) && !in->JoysPresent[1])
- || ((nt == ctrl_Mouse) && !in->MousePresent)
- || ((nt == ctrl_Joypad1) && !in->JoyPadPresent[0])
- || ((nt == ctrl_Joypad2) && !in->JoyPadPresent[1])
+ || ((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);
//
///////////////////////////////////////////////////////////////////////////
void
-IN_Shutdown(inconfig *in)
+IN_Shutdown()
{
word i;
- if (!in->IN_Started)
+ if (!inst.IN_Started)
return;
INL_ShutMouse();
for (i = 0;i < MaxJoys;i++)
- INL_ShutJoy(i, in);
+ INL_ShutJoy(i);
INL_ShutKbd();
- in->IN_Started = false;
+ inst.IN_Started = false;
}
///////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////
void
-IN_ClearKeysDown(inconfig *in)
+IN_ClearKeysDown()
{
int i;
- in->LastScan = sc_None;
- in->LastASCII = key_None;
- memset (in->Keyboard,0,sizeof(in->Keyboard));
+ inpu.LastScan = sc_None;
+ inpu.LastASCII = key_None;
+ memset (inpu.Keyboard,0,sizeof(inpu.Keyboard));
}
///////////////////////////////////////////////////////////////////////////
info->x = info->y = 0;
info->button0 = info->button1 = false;
- if (MousePresent)
+ if (inpu.MousePresent)
{
buttons = INL_GetMouseButtons();
INL_GetMouseDelta(&dx,&dy);
for (i = 0;i < MaxJoys;i++)
{
- if (!JoysPresent[i])
+ if (!inpu.JoysPresent[i])
continue;
buttons = INL_GetJoyButtons(i);
else
{
#endif
- switch (type = player[playnum]->Controls)
+ switch (type = player[playnum].Controls)
{
case ctrl_Keyboard1:
case ctrl_Keyboard2:
- def = player[playnum]->KbdDefs[type - ctrl_Keyboard];
+ def = &(inpu.KbdDefs[type - ctrl_Keyboard]);
/* if (Keyboard[def->upleft])
mx = motion_Left,my = motion_Up;
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;
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)];
+ 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)
IN_SetControlType(word playnum,player_t *player,ControlType type)
{
// DEBUG - check that requested type is present?
- player[playnum]->Controls = type;
+ player[playnum].Controls = type;
}
#if DEMO0
//
///////////////////////////////////////////////////////////////////////////
ScanCode
-IN_WaitForKey(void)
+IN_WaitForKey()
{
ScanCode result;
- while (!(result = LastScan))
+ while (!(result = inpu.LastScan))
;
- LastScan = 0;
+ inpu.LastScan = 0;
return(result);
}
//
///////////////////////////////////////////////////////////////////////////
char
-IN_WaitForASCII(void)
+IN_WaitForASCII()
{
char result;
- while (!(result = LastASCII))
+ while (!(result = inpu.LastASCII))
;
- LastASCII = '\0';
+ inpu.LastASCII = '\0';
return(result);
}
//
///////////////////////////////////////////////////////////////////////////
void
-IN_AckBack(void)
+IN_AckBack()
{
word i;
- while (!LastScan)
+ while (!inpu.LastScan)
{
- if (MousePresent)
+ if (inpu.MousePresent)
{
if (INL_GetMouseButtons())
{
for (i = 0;i < MaxJoys;i++)
{
- if (JoysPresent[i])
+ if (inpu.JoysPresent[i])
{
if (IN_GetJoyButtonsDB(i))
{
}
}
- IN_ClearKey(LastScan);
- LastScan = sc_None;
+ IN_ClearKey(inpu.LastScan);
+ inpu.LastScan = sc_None;
}
///////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////
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))
;
//
///////////////////////////////////////////////////////////////////////////
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;
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;
}