#include "wl_def.h" /* ============================================================================= GLOBAL VARIABLES ============================================================================= */ // // configuration variables // boolean MousePresent; boolean JoysPresent[MaxJoys]; // Global variables boolean Keyboard[NumCodes]; boolean InternalKeyboard[NumCodes]; boolean Paused; char LastASCII; ScanCode LastScan; KeyboardDef KbdDefs = {sc_Control, sc_Alt, sc_Home, sc_UpArrow, sc_PgUp, sc_LeftArrow, sc_RightArrow, sc_End, sc_DownArrow, sc_PgDn}; ControlType Controls[MaxPlayers]; /* ============================================================================= LOCAL VARIABLES ============================================================================= */ static byte ASCIINames[] = // Unshifted ASCII for scan codes { // 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8 ,9 , // 0 'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0 ,'a','s', // 1 'd','f','g','h','j','k','l',';',39 ,'`',0 ,92 ,'z','x','c','v', // 2 'b','n','m',',','.','/',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7 }, ShiftNames[] = // Shifted ASCII for scan codes { // 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8 ,9 , // 0 'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0 ,'A','S', // 1 'D','F','G','H','J','K','L',':',34 ,'~',0 ,'|','Z','X','C','V', // 2 'B','N','M','<','>','?',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3 0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4 '2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7 }; static boolean IN_Started; static boolean CapsLock; static ScanCode CurCode,LastCode; static Direction DirTable[] = // Quick lookup for total direction { dir_NorthWest, dir_North, dir_NorthEast, dir_West, dir_None, dir_East, dir_SouthWest, dir_South, dir_SouthEast }; void keyboard_handler(int code, int press) { byte k, c = 0; k = code; if (k == 0xe1) // Handle Pause key Paused = true; else { if (press == 0) { Keyboard[k] = false; InternalKeyboard[k] = false; } else // Make code { LastCode = CurCode; CurCode = LastScan = k; Keyboard[k] = true; InternalKeyboard[k] = true; if (k == sc_CapsLock) { CapsLock ^= true; } if (Keyboard[sc_LShift] || Keyboard[sc_RShift]) // If shifted { c = ShiftNames[k]; if ((c >= 'A') && (c <= 'Z') && CapsLock) c += 'a' - 'A'; } else { c = ASCIINames[k]; if ((c >= 'a') && (c <= 'z') && CapsLock) c -= 'a' - 'A'; } if (c) LastASCII = c; } } } /////////////////////////////////////////////////////////////////////////// // // 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(longword delay) { longword lasttime; lasttime = get_TimeCount(); IN_StartAck(); do { if (IN_CheckAck()) return true; } while ( (get_TimeCount() - lasttime) < delay ); return false; } //=========================================================================== /* =================== = = IN_JoyButtons = =================== */ byte IN_JoyButtons() { return 0; } /////////////////////////////////////////////////////////////////////////// // // IN_GetJoyAbs() - Reads the absolute position of the specified joystick // /////////////////////////////////////////////////////////////////////////// void IN_GetJoyAbs(word joy,word *xp,word *yp) { *xp = 0; *yp = 0; } /////////////////////////////////////////////////////////////////////////// // // INL_GetJoyDelta() - Returns the relative movement of the specified // joystick (from +/-127) // /////////////////////////////////////////////////////////////////////////// void INL_GetJoyDelta(word joy,int *dx,int *dy) { *dx = 0; *dy = 0; } /////////////////////////////////////////////////////////////////////////// // // INL_GetJoyButtons() - Returns the button status of the specified // joystick // /////////////////////////////////////////////////////////////////////////// static word INL_GetJoyButtons(word joy) { return 0; } /////////////////////////////////////////////////////////////////////////// // // INL_StartKbd() - Sets up my keyboard stuff for use // /////////////////////////////////////////////////////////////////////////// static void INL_StartKbd(void) { IN_ClearKeysDown(); } /////////////////////////////////////////////////////////////////////////// // // INL_ShutKbd() - Restores keyboard control to the BIOS // /////////////////////////////////////////////////////////////////////////// static void INL_ShutKbd(void) { } /////////////////////////////////////////////////////////////////////////// // // INL_ShutMouse() - Cleans up after the mouse // /////////////////////////////////////////////////////////////////////////// static void INL_ShutMouse(void) { } /////////////////////////////////////////////////////////////////////////// // // 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) { } /////////////////////////////////////////////////////////////////////////// // // INL_StartJoy() - Detects & auto-configures the specified joystick // The auto-config assumes the joystick is centered // /////////////////////////////////////////////////////////////////////////// static boolean INL_StartJoy(word joy) { return false; } /////////////////////////////////////////////////////////////////////////// // // INL_ShutJoy() - Cleans up the joystick stuff // /////////////////////////////////////////////////////////////////////////// static void INL_ShutJoy(word joy) { JoysPresent[joy] = false; } /////////////////////////////////////////////////////////////////////////// // // IN_Startup() - Starts up the Input Mgr // /////////////////////////////////////////////////////////////////////////// void IN_Startup(void) { boolean checkjoys; word i; if (IN_Started) return; checkjoys = true; if (MS_CheckParm("nojoy")) checkjoys = false; if (MS_CheckParm("nomouse")) MousePresent = false; else MousePresent = true; INL_StartKbd(); for (i = 0;i < MaxJoys;i++) JoysPresent[i] = checkjoys ? INL_StartJoy(i) : false; IN_Started = true; } /////////////////////////////////////////////////////////////////////////// // // IN_Shutdown() - Shuts down the Input Mgr // /////////////////////////////////////////////////////////////////////////// void IN_Shutdown(void) { word i; if (!IN_Started) return; INL_ShutMouse(); for (i = 0;i < MaxJoys;i++) INL_ShutJoy(i); INL_ShutKbd(); IN_Started = false; } /////////////////////////////////////////////////////////////////////////// // // IN_ClearKeysDown() - Clears the keyboard array // /////////////////////////////////////////////////////////////////////////// void IN_ClearKeysDown(void) { LastScan = sc_None; LastASCII = key_None; memset(Keyboard, 0, sizeof(Keyboard)); } /////////////////////////////////////////////////////////////////////////// // // IN_ReadControl() - Reads the device associated with the specified // player and fills in the control info struct // /////////////////////////////////////////////////////////////////////////// void IN_ReadControl(int player,ControlInfo *info) { boolean realdelta = false; word buttons; int dx,dy; Motion mx,my; ControlType type; KeyboardDef *def; dx = dy = 0; mx = my = motion_None; buttons = 0; IN_CheckAck(); switch (type = Controls[player]) { case ctrl_Keyboard: def = &KbdDefs; 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 (Keyboard[def->up]) my = motion_Up; else if (Keyboard[def->down]) my = motion_Down; if (Keyboard[def->left]) mx = motion_Left; else if (Keyboard[def->right]) mx = motion_Right; if (Keyboard[def->button0]) buttons += 1 << 0; if (Keyboard[def->button1]) buttons += 1 << 1; realdelta = false; break; case ctrl_Joystick1: case ctrl_Joystick2: INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy); buttons = INL_GetJoyButtons(type - ctrl_Joystick); realdelta = true; break; case ctrl_Mouse: IN_GetMouseDelta(&dx,&dy); buttons = IN_MouseButtons(); realdelta = true; break; } 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; } 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)]; } /////////////////////////////////////////////////////////////////////////// // // 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 // /////////////////////////////////////////////////////////////////////////// boolean btnstate[8]; void IN_StartAck(void) { unsigned i,buttons; // // get initial state of everything // IN_ClearKeysDown(); memset (btnstate,0,sizeof(btnstate)); buttons = IN_JoyButtons () << 4; if (MousePresent) buttons |= IN_MouseButtons (); for (i=0;i<8;i++,buttons>>=1) if (buttons&1) btnstate[i] = true; } boolean IN_CheckAck() { unsigned i, buttons; INL_Update(); if (LastScan) return true; buttons = IN_JoyButtons () << 4; if (MousePresent) buttons |= IN_MouseButtons (); 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() { IN_StartAck(); while(!IN_CheckAck()) ; }