Rewritten input code, from slayne
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@515 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
0.2:
|
0.2:
|
||||||
|
- Rewritten input code (better and adds joystick/pad support), from slayne
|
||||||
- Biadapt scaling for pure mode, from fOSSiL
|
- Biadapt scaling for pure mode, from fOSSiL
|
||||||
- Saving user data in "%APPDATA%/Application Data" on windows - SvdB
|
- Saving user data in "%APPDATA%/Application Data" on windows - SvdB
|
||||||
- Melnorme comm fix, from TD.
|
- Melnorme comm fix, from TD.
|
||||||
|
|||||||
@@ -117,20 +117,6 @@ TFB_ProcessEvents ()
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Still testing this... Should fix sticky input soon...
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
Uint8* Temp;
|
|
||||||
|
|
||||||
SDL_PumpEvents ();
|
|
||||||
Temp = SDL_GetKeyState (NULL);
|
|
||||||
for(a = 0; a < 512; a++)
|
|
||||||
{
|
|
||||||
KeyboardDown[a] = Temp[a];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,28 +48,23 @@ typedef enum
|
|||||||
|
|
||||||
#define SK_LF_SHIFT ((UNICODE)139)
|
#define SK_LF_SHIFT ((UNICODE)139)
|
||||||
#define SK_RT_SHIFT ((UNICODE)140)
|
#define SK_RT_SHIFT ((UNICODE)140)
|
||||||
#define SK_CTL ((UNICODE)141)
|
#define SK_LF_CTL ((UNICODE)141)
|
||||||
#define SK_ALT ((UNICODE)142)
|
#define SK_RT_CTL ((UNICODE)142)
|
||||||
|
#define SK_LF_ALT ((UNICODE)143)
|
||||||
|
#define SK_RT_ALT ((UNICODE)144)
|
||||||
|
|
||||||
#define KEY_DOWN ((BYTE)(1 << 0))
|
#define SK_F1 ((UNICODE)145)
|
||||||
#define KEY_UP ((BYTE)(1 << 1))
|
#define SK_F2 ((UNICODE)146)
|
||||||
#define LF_SHIFT_DOWN ((BYTE)(1 << 2))
|
#define SK_F3 ((UNICODE)147)
|
||||||
#define RT_SHIFT_DOWN ((BYTE)(1 << 3))
|
#define SK_F4 ((UNICODE)148)
|
||||||
#define CTL_DOWN ((BYTE)(1 << 4))
|
#define SK_F5 ((UNICODE)149)
|
||||||
#define ALT_DOWN ((BYTE)(1 << 5))
|
#define SK_F6 ((UNICODE)150)
|
||||||
|
#define SK_F7 ((UNICODE)151)
|
||||||
#define SK_F1 ((UNICODE)143)
|
#define SK_F8 ((UNICODE)152)
|
||||||
#define SK_F2 ((UNICODE)144)
|
#define SK_F9 ((UNICODE)153)
|
||||||
#define SK_F3 ((UNICODE)145)
|
#define SK_F10 ((UNICODE)154)
|
||||||
#define SK_F4 ((UNICODE)146)
|
#define SK_F11 ((UNICODE)155)
|
||||||
#define SK_F5 ((UNICODE)147)
|
#define SK_F12 ((UNICODE)156)
|
||||||
#define SK_F6 ((UNICODE)148)
|
|
||||||
#define SK_F7 ((UNICODE)149)
|
|
||||||
#define SK_F8 ((UNICODE)150)
|
|
||||||
#define SK_F9 ((UNICODE)151)
|
|
||||||
#define SK_F10 ((UNICODE)152)
|
|
||||||
#define SK_F11 ((UNICODE)153)
|
|
||||||
#define SK_F12 ((UNICODE)154)
|
|
||||||
|
|
||||||
#define DEVTYPE_MASK 0x03
|
#define DEVTYPE_MASK 0x03
|
||||||
#define GetInputUNICODE(is) (LOWORD (is))
|
#define GetInputUNICODE(is) (LOWORD (is))
|
||||||
@@ -92,14 +87,16 @@ typedef enum
|
|||||||
#define DEVICE_LEFTSHIFT ((INPUT_STATE)1 << 24)
|
#define DEVICE_LEFTSHIFT ((INPUT_STATE)1 << 24)
|
||||||
#define DEVICE_RIGHTSHIFT ((INPUT_STATE)1 << 25)
|
#define DEVICE_RIGHTSHIFT ((INPUT_STATE)1 << 25)
|
||||||
|
|
||||||
extern BOOLEAN InitInput (UNICODE PauseKey, UNICODE ExitKey, BOOLEAN
|
extern BOOLEAN InitInput (BOOLEAN (*PauseFunc) (void), UNICODE Pause,
|
||||||
(*PauseFunc) (void));
|
UNICODE Exit, UNICODE Abort);
|
||||||
extern BOOLEAN UninitInput (void);
|
extern BOOLEAN UninitInput (void);
|
||||||
extern INPUT_DEVICE CreateSerialKeyboardDevice (void);
|
extern INPUT_DEVICE CreateSerialKeyboardDevice (void);
|
||||||
extern INPUT_DEVICE CreateJoystickKeyboardDevice (UNICODE lfkey, UNICODE
|
extern INPUT_DEVICE CreateJoystickKeyboardDevice (UWORD lfkey, UWORD
|
||||||
rtkey, UNICODE topkey, UNICODE botkey, UNICODE but1key, UNICODE
|
rtkey, UWORD topkey, UWORD botkey, UWORD but1key, UWORD
|
||||||
but2key, UNICODE but3key, UNICODE shift1key, UNICODE shift2key);
|
but2key, UWORD but3key, UWORD shift1key, UWORD shift2key);
|
||||||
extern INPUT_DEVICE CreateJoystickDevice (COUNT port);
|
extern INPUT_DEVICE CreateJoystickDevice (COUNT port, UWORD threshold,
|
||||||
|
UWORD left, UWORD right, UWORD up, UWORD down,
|
||||||
|
UWORD but1, UWORD but2, UWORD but3, UWORD s1, UWORD s2);
|
||||||
extern INPUT_DEVICE CreateInternalDevice (INPUT_STATE (*input_func)
|
extern INPUT_DEVICE CreateInternalDevice (INPUT_STATE (*input_func)
|
||||||
(INPUT_REF InputRef, INPUT_STATE InputState));
|
(INPUT_REF InputRef, INPUT_STATE InputState));
|
||||||
extern BOOLEAN DestroyInputDevice (INPUT_DEVICE InputDevice);
|
extern BOOLEAN DestroyInputDevice (INPUT_DEVICE InputDevice);
|
||||||
@@ -109,15 +106,43 @@ extern INPUT_STATE GetInputState (INPUT_REF InputRef);
|
|||||||
extern INPUT_STATE AnyButtonPress (BOOLEAN DetectSpecial);
|
extern INPUT_STATE AnyButtonPress (BOOLEAN DetectSpecial);
|
||||||
|
|
||||||
extern void FlushInput (void);
|
extern void FlushInput (void);
|
||||||
extern int KeyDown (UNICODE which_scan);
|
extern BOOLEAN KeyDown (UNICODE which_scan);
|
||||||
extern UNICODE GetUnicodeKey (void);
|
extern UNICODE GetUnicodeKey (void);
|
||||||
extern UNICODE KBDToUNICODE (UNICODE which_key);
|
extern UNICODE KBDToUNICODE (UWORD which_key);
|
||||||
extern UNICODE KeyHit (void);
|
|
||||||
extern BYTE GetKeyState (UNICODE key);
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Not used right now
|
||||||
extern BOOLEAN FindMouse (void);
|
extern BOOLEAN FindMouse (void);
|
||||||
extern void MoveMouse (SWORD x, SWORD y);
|
extern void MoveMouse (SWORD x, SWORD y);
|
||||||
extern BYTE LocateMouse (PSWORD px, PSWORD py);
|
extern BYTE LocateMouse (PSWORD px, PSWORD py);
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* joystick_buttons format
|
||||||
|
* Bit 15 - (0) - Button
|
||||||
|
* (1) - Axis
|
||||||
|
* Bit 14 - (0) - positive (n/a for buttons)
|
||||||
|
* (1) - negative (use chord for buttons)
|
||||||
|
* Bit 0-7 - button / axis number
|
||||||
|
* Bit 8-13 - chorded button
|
||||||
|
*/
|
||||||
|
#define JOYAXISMASK 0x8000
|
||||||
|
/* axis number, sign */
|
||||||
|
#define JOYAXIS(a,s) (0x8000 | (s < 0 ? 0x4000 : 0 ) | (a & 0xFF))
|
||||||
|
#define JOYBUTTON(b) ((UWORD)(b & 0xFF))
|
||||||
|
#define JOYCHORD(b1,b2) ((UWORD)(0x4000 | (b1 & 0xFF) | ((b2 & 0x3F) << 8)))
|
||||||
|
#define JOYISAXIS(v) (v & JOYAXISMASK)
|
||||||
|
#define JOYISCHORD(v) (v & 0x4000)
|
||||||
|
#define JOYGETVALUE(v) (v & 0xFF)
|
||||||
|
#define JOYGETSIGN(v) ((v & 0x4000) ? -1 : 1)
|
||||||
|
#define JOYGETCHORD(v) ((v & 0x3F00) >> 8)
|
||||||
|
|
||||||
|
#define KEYCHORD(k1, k2) ((UWORD) ((k1 & 0xFF) << 8) | (k2 & 0xFF))
|
||||||
|
#define KEYGETCHORD(v) ((v & 0xFF00) >> 8)
|
||||||
|
#define KEYISCHORD(v) (v & 0xFF00)
|
||||||
|
#define KEYGETKEY(v) (v & 0xFF)
|
||||||
|
|
||||||
|
extern UNICODE PauseKey, ExitKey, AbortKey;
|
||||||
|
|
||||||
#endif /* _INPLIB_H */
|
#endif /* _INPLIB_H */
|
||||||
|
|
||||||
|
|||||||
@@ -21,15 +21,33 @@
|
|||||||
|
|
||||||
#include "inplib.h"
|
#include "inplib.h"
|
||||||
|
|
||||||
#define NUM_INPUTS 16
|
#define NUM_INPUTS 9
|
||||||
|
/*
|
||||||
|
* Inputs
|
||||||
|
* 0 - Left
|
||||||
|
* 1 - Right
|
||||||
|
* 2 - Up
|
||||||
|
* 3 - Down
|
||||||
|
* 4 - Button 1
|
||||||
|
* 5 - Button 2
|
||||||
|
* 6 - Button 3
|
||||||
|
* 7 - Left shift
|
||||||
|
* 8 - Right shift
|
||||||
|
*/
|
||||||
|
|
||||||
typedef struct inp_dev
|
typedef struct inp_dev
|
||||||
{
|
{
|
||||||
INPUT_DEVICE ThisDevice;
|
INPUT_DEVICE ThisDevice;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
UNICODE key_equivalent[NUM_INPUTS];
|
UWORD key_equivalent[NUM_INPUTS];
|
||||||
COUNT joystick_port;
|
struct
|
||||||
|
{
|
||||||
|
BYTE joystick_port;
|
||||||
|
UWORD joystick_threshold;
|
||||||
|
/* See inplib.h for description of this field */
|
||||||
|
UWORD joystick_buttons[NUM_INPUTS];
|
||||||
|
} joystick_info;
|
||||||
} device;
|
} device;
|
||||||
INPUT_STATE (*input_func) (INPUT_REF InputRef, INPUT_STATE
|
INPUT_STATE (*input_func) (INPUT_REF InputRef, INPUT_STATE
|
||||||
InputState);
|
InputState);
|
||||||
@@ -51,17 +69,29 @@ typedef PBYTE BYTEPTR;
|
|||||||
#define SetInputDeviceHandle(i,h) \
|
#define SetInputDeviceHandle(i,h) \
|
||||||
((INPUT_DESCPTR)(i))->ThisDevice = (h)
|
((INPUT_DESCPTR)(i))->ThisDevice = (h)
|
||||||
#define SetInputDeviceKeyEquivalents(i,l,r,t,b,b1,b2,b3,s1,s2) \
|
#define SetInputDeviceKeyEquivalents(i,l,r,t,b,b1,b2,b3,s1,s2) \
|
||||||
(((INPUT_DESCPTR)(i))->device.key_equivalent[0] = KBDToUNICODE (l), \
|
(((INPUT_DESCPTR)(i))->device.key_equivalent[0] = (l), \
|
||||||
((INPUT_DESCPTR)(i))->device.key_equivalent[1] = KBDToUNICODE (r), \
|
((INPUT_DESCPTR)(i))->device.key_equivalent[1] = (r), \
|
||||||
((INPUT_DESCPTR)(i))->device.key_equivalent[2] = KBDToUNICODE (t), \
|
((INPUT_DESCPTR)(i))->device.key_equivalent[2] = (t), \
|
||||||
((INPUT_DESCPTR)(i))->device.key_equivalent[3] = KBDToUNICODE (b), \
|
((INPUT_DESCPTR)(i))->device.key_equivalent[3] = (b), \
|
||||||
((INPUT_DESCPTR)(i))->device.key_equivalent[4] = KBDToUNICODE (b1), \
|
((INPUT_DESCPTR)(i))->device.key_equivalent[4] = (b1), \
|
||||||
((INPUT_DESCPTR)(i))->device.key_equivalent[5] = KBDToUNICODE (b2), \
|
((INPUT_DESCPTR)(i))->device.key_equivalent[5] = (b2), \
|
||||||
((INPUT_DESCPTR)(i))->device.key_equivalent[6] = KBDToUNICODE (b3), \
|
((INPUT_DESCPTR)(i))->device.key_equivalent[6] = (b3), \
|
||||||
((INPUT_DESCPTR)(i))->device.key_equivalent[7] = KBDToUNICODE (s1), \
|
((INPUT_DESCPTR)(i))->device.key_equivalent[7] = (s1), \
|
||||||
((INPUT_DESCPTR)(i))->device.key_equivalent[8] = KBDToUNICODE (s2))
|
((INPUT_DESCPTR)(i))->device.key_equivalent[8] = (s2))
|
||||||
|
#define SetInputDeviceJoystickButtons(i,l,r,t,b,b1,b2,b3,s1,s2) \
|
||||||
|
(((INPUT_DESCPTR)(i))->device.joystick_info.joystick_buttons[0] = l, \
|
||||||
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_buttons[1] = r, \
|
||||||
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_buttons[2] = t, \
|
||||||
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_buttons[3] = b, \
|
||||||
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_buttons[4] = b1, \
|
||||||
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_buttons[5] = b2, \
|
||||||
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_buttons[6] = b3, \
|
||||||
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_buttons[7] = s1, \
|
||||||
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_buttons[8] = s2)
|
||||||
#define SetInputDeviceJoystickPort(i,p) \
|
#define SetInputDeviceJoystickPort(i,p) \
|
||||||
((INPUT_DESCPTR)(i))->device.joystick_port = (p)
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_port = (p)
|
||||||
|
#define SetInputDeviceJoystickThreshold(i,t) \
|
||||||
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_threshold = (t)
|
||||||
#define SetInputDeviceInputFunc(i,f) \
|
#define SetInputDeviceInputFunc(i,f) \
|
||||||
((INPUT_DESCPTR)(i))->input_func = (f)
|
((INPUT_DESCPTR)(i))->input_func = (f)
|
||||||
|
|
||||||
@@ -69,8 +99,12 @@ typedef PBYTE BYTEPTR;
|
|||||||
((INPUT_DESCPTR)(i))->ThisDevice
|
((INPUT_DESCPTR)(i))->ThisDevice
|
||||||
#define GetInputDeviceKeyEquivalentPtr(i) \
|
#define GetInputDeviceKeyEquivalentPtr(i) \
|
||||||
((INPUT_DESCPTR)(i))->device.key_equivalent
|
((INPUT_DESCPTR)(i))->device.key_equivalent
|
||||||
|
#define GetInputDeviceJoystickButtonPtr(i) \
|
||||||
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_buttons
|
||||||
#define GetInputDeviceJoystickPort(i) \
|
#define GetInputDeviceJoystickPort(i) \
|
||||||
((INPUT_DESCPTR)(i))->device.joystick_port
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_port
|
||||||
|
#define GetInputDeviceJoystickThreshold(i) \
|
||||||
|
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_threshold
|
||||||
#define GetInputDeviceInputFunc(i) \
|
#define GetInputDeviceInputFunc(i) \
|
||||||
((INPUT_DESCPTR)(i))->input_func
|
((INPUT_DESCPTR)(i))->input_func
|
||||||
|
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ CreateSerialKeyboardDevice (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
INPUT_DEVICE
|
INPUT_DEVICE
|
||||||
CreateJoystickKeyboardDevice (UNICODE lfkey, UNICODE rtkey, UNICODE
|
CreateJoystickKeyboardDevice (UWORD lfkey, UWORD rtkey, UWORD
|
||||||
topkey, UNICODE botkey, UNICODE but1key, UNICODE but2key, UNICODE
|
topkey, UWORD botkey, UWORD but1key, UWORD but2key, UWORD
|
||||||
but3key, UNICODE shift1key, UNICODE shift2key)
|
but3key, UWORD shift1key, UWORD shift2key)
|
||||||
{
|
{
|
||||||
INPUT_DEVICE InputDevice;
|
INPUT_DEVICE InputDevice;
|
||||||
|
|
||||||
@@ -80,7 +80,9 @@ CreateJoystickKeyboardDevice (UNICODE lfkey, UNICODE rtkey, UNICODE
|
|||||||
}
|
}
|
||||||
|
|
||||||
INPUT_DEVICE
|
INPUT_DEVICE
|
||||||
CreateJoystickDevice (COUNT port)
|
CreateJoystickDevice (COUNT port, UWORD threshold, UWORD left, UWORD right,
|
||||||
|
UWORD top, UWORD bottom, UWORD but1, UWORD but2, UWORD but3, UWORD s1,
|
||||||
|
UWORD s2)
|
||||||
{
|
{
|
||||||
INPUT_DEVICE InputDevice;
|
INPUT_DEVICE InputDevice;
|
||||||
|
|
||||||
@@ -101,6 +103,9 @@ CreateJoystickDevice (COUNT port)
|
|||||||
SetInputDeviceHandle (InputPtr, InputDevice);
|
SetInputDeviceHandle (InputPtr, InputDevice);
|
||||||
SetInputDeviceInputFunc (InputPtr, _get_joystick_state);
|
SetInputDeviceInputFunc (InputPtr, _get_joystick_state);
|
||||||
SetInputDeviceJoystickPort (InputPtr, port);
|
SetInputDeviceJoystickPort (InputPtr, port);
|
||||||
|
SetInputDeviceJoystickButtons (InputPtr, left, right, top, bottom,
|
||||||
|
but1, but2, but3, s1, s2);
|
||||||
|
SetInputDeviceJoystickThreshold(InputPtr, threshold);
|
||||||
|
|
||||||
UnlockInputDevice (InputDevice);
|
UnlockInputDevice (InputDevice);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,33 +21,30 @@
|
|||||||
#include "libs/graphics/sdl/sdl_common.h"
|
#include "libs/graphics/sdl/sdl_common.h"
|
||||||
#include "libs/input/input_common.h"
|
#include "libs/input/input_common.h"
|
||||||
|
|
||||||
|
static Uint8 KeyboardDown[SDLK_LAST];
|
||||||
Uint8 KeyboardDown[512];
|
|
||||||
#define KBDBUFSIZE (1 << 8)
|
#define KBDBUFSIZE (1 << 8)
|
||||||
int kbdhead, kbdtail;
|
static int kbdhead=0, kbdtail=0;
|
||||||
Uint16 kbdbuf[KBDBUFSIZE];
|
static SDLKey kbdbuf[KBDBUFSIZE];
|
||||||
|
|
||||||
SDLKey ControlA;
|
static int nJoysticks = 0;
|
||||||
SDLKey ControlB;
|
static SDL_Joystick **Joysticks = 0;
|
||||||
SDLKey ControlC;
|
|
||||||
SDLKey ControlX;
|
|
||||||
SDLKey ControlStart;
|
|
||||||
SDLKey ControlLeftShift;
|
|
||||||
SDLKey ControlRightShift;
|
|
||||||
|
|
||||||
|
static UBYTE **JoybuttonDown = 0;
|
||||||
|
static SWORD **JoyaxisValues = 0;
|
||||||
|
|
||||||
static UNICODE PauseKey;
|
static BOOLEAN (* PauseFunc) (void) = 0;
|
||||||
static UNICODE ExitKey;
|
static BOOLEAN InputInitialized = FALSE;
|
||||||
static UNICODE OtherKey;
|
|
||||||
|
|
||||||
static BOOLEAN (* PauseFunc) (void);
|
|
||||||
|
|
||||||
|
UNICODE PauseKey = 0;
|
||||||
|
UNICODE ExitKey = 0;
|
||||||
|
UNICODE AbortKey = 0;
|
||||||
|
|
||||||
int
|
int
|
||||||
TFB_InitInput (int driver, int flags)
|
TFB_InitInput (int driver, int flags)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
SDL_Joystick *Joystick1;
|
(void)driver;
|
||||||
|
(void)flags;
|
||||||
|
|
||||||
atexit (TFB_UninitInput);
|
atexit (TFB_UninitInput);
|
||||||
|
|
||||||
@@ -59,230 +56,111 @@ TFB_InitInput (int driver, int flags)
|
|||||||
|
|
||||||
fprintf (stderr, "%i joysticks were found.\n", SDL_NumJoysticks ());
|
fprintf (stderr, "%i joysticks were found.\n", SDL_NumJoysticks ());
|
||||||
|
|
||||||
if (SDL_NumJoysticks () > 0)
|
nJoysticks = SDL_NumJoysticks ();
|
||||||
|
if (nJoysticks > 0)
|
||||||
{
|
{
|
||||||
|
Joysticks = HMalloc(sizeof(SDL_Joystick*) * nJoysticks);
|
||||||
|
JoybuttonDown = HMalloc(sizeof(UBYTE*) * nJoysticks);
|
||||||
|
JoyaxisValues = HMalloc(sizeof(SWORD*) * nJoysticks);
|
||||||
fprintf (stderr, "The names of the joysticks are:\n");
|
fprintf (stderr, "The names of the joysticks are:\n");
|
||||||
for(i = 0; i < SDL_NumJoysticks (); i++)
|
for(i = 0; i < nJoysticks; i++)
|
||||||
{
|
{
|
||||||
fprintf (stderr, " %s\n", SDL_JoystickName (i));
|
fprintf (stderr, " %s\n", SDL_JoystickName (i));
|
||||||
|
Joysticks[i] = SDL_JoystickOpen (i);
|
||||||
|
JoybuttonDown[i] = HMalloc(sizeof(UBYTE) *
|
||||||
|
SDL_JoystickNumButtons(Joysticks[i]));
|
||||||
|
memset(JoybuttonDown[i], 0, sizeof(UBYTE) *
|
||||||
|
SDL_JoystickNumButtons(Joysticks[i]));
|
||||||
|
JoyaxisValues[i] = HMalloc(sizeof(SWORD) *
|
||||||
|
SDL_JoystickNumAxes(Joysticks[i]));
|
||||||
|
memset(JoyaxisValues[i], 0, sizeof(SWORD) *
|
||||||
|
SDL_JoystickNumAxes(Joysticks[i]));
|
||||||
|
fprintf (stderr, " %i axes, %i buttons\n",
|
||||||
|
SDL_JoystickNumAxes(Joysticks[i]),
|
||||||
|
SDL_JoystickNumButtons(Joysticks[i]));
|
||||||
}
|
}
|
||||||
SDL_JoystickEventState (SDL_ENABLE);
|
SDL_JoystickEventState (SDL_ENABLE);
|
||||||
Joystick1 = SDL_JoystickOpen (0);
|
|
||||||
if (SDL_NumJoysticks () > 1)
|
|
||||||
SDL_JoystickOpen(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 512; i++)
|
for (i = 0; i < SDLK_LAST; i++)
|
||||||
{
|
{
|
||||||
KeyboardDown[i] = FALSE;
|
KeyboardDown[i] = FALSE;
|
||||||
//KeyboardStroke[i] = FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlA = SDLK_f;
|
|
||||||
ControlB = SDLK_d;
|
|
||||||
ControlC = SDLK_s;
|
|
||||||
ControlX = SDLK_a;
|
|
||||||
ControlStart = SDLK_RETURN;
|
|
||||||
ControlLeftShift = SDLK_LSHIFT;
|
|
||||||
ControlRightShift = SDLK_RSHIFT;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TFB_UninitInput (void)
|
TFB_UninitInput (void)
|
||||||
{
|
{
|
||||||
|
int j;
|
||||||
|
for (j = 0; j < nJoysticks; ++j)
|
||||||
|
{
|
||||||
|
HFree(JoyaxisValues[j]);
|
||||||
|
HFree(JoybuttonDown[j]);
|
||||||
|
SDL_JoystickClose(Joysticks[j]);
|
||||||
|
Joysticks[j] = 0;
|
||||||
|
}
|
||||||
|
HFree(Joysticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ProcessKeyboardEvent(const SDL_Event *Event)
|
ProcessKeyboardEvent(const SDL_Event *Event)
|
||||||
{
|
{
|
||||||
if(Event->key.keysym.sym == SDLK_BACKQUOTE ||
|
SDLKey k = Event->key.keysym.sym;
|
||||||
Event->key.keysym.sym == SDLK_WORLD_7)
|
if (!InputInitialized)
|
||||||
{
|
return;
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Event->type == SDL_KEYDOWN)
|
if (Event->type == SDL_KEYDOWN)
|
||||||
{
|
{
|
||||||
if ((kbdbuf[kbdtail] = Event->key.keysym.unicode)
|
kbdbuf[kbdtail] = k;
|
||||||
|| (kbdbuf[kbdtail] = Event->key.keysym.sym) <= 0x7F)
|
|
||||||
{
|
|
||||||
kbdtail = (kbdtail + 1) & (KBDBUFSIZE - 1);
|
kbdtail = (kbdtail + 1) & (KBDBUFSIZE - 1);
|
||||||
if (kbdtail == kbdhead)
|
if (kbdtail == kbdhead)
|
||||||
kbdhead = (kbdhead + 1) & (KBDBUFSIZE - 1);
|
kbdhead = (kbdhead + 1) & (KBDBUFSIZE - 1);
|
||||||
}
|
if (KBDToUNICODE(k) == AbortKey)
|
||||||
KeyboardDown[Event->key.keysym.sym]=TRUE;
|
exit(0);
|
||||||
|
KeyboardDown[k] |= 0x3;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
KeyboardDown[Event->key.keysym.sym]=FALSE;
|
KeyboardDown[k] &= (~0x1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ProcessJoystickEvent (const SDL_Event* Event)
|
ProcessJoystickEvent (const SDL_Event* Event)
|
||||||
{
|
{
|
||||||
SDL_Event PseudoEvent;
|
if (!InputInitialized)
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Event->type == SDL_JOYAXISMOTION)
|
switch (Event->type)
|
||||||
{
|
{
|
||||||
if (Event->jaxis.axis == 0)
|
case SDL_JOYAXISMOTION:
|
||||||
{
|
JoyaxisValues[Event->jaxis.which][Event->jaxis.axis] = Event->jaxis.value;
|
||||||
//x-axis
|
break;
|
||||||
|
case SDL_JOYBUTTONDOWN:
|
||||||
if (Event->jaxis.value <= -5) //Left
|
JoybuttonDown[Event->jbutton.which][Event->jbutton.button] |= 0x3;
|
||||||
{
|
break;
|
||||||
PseudoEvent.type = SDL_KEYDOWN;
|
case SDL_JOYBUTTONUP:
|
||||||
PseudoEvent.key.keysym.sym = SDLK_LEFT;
|
JoybuttonDown[Event->jbutton.which][Event->jbutton.button] &= (~0x1);
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
break;
|
||||||
|
|
||||||
PseudoEvent.type = SDL_KEYUP;
|
|
||||||
PseudoEvent.key.keysym.sym = SDLK_RIGHT;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
}
|
|
||||||
if (Event->jaxis.value >= 5) //Right
|
|
||||||
{
|
|
||||||
PseudoEvent.type = SDL_KEYUP;
|
|
||||||
PseudoEvent.key.keysym.sym = SDLK_LEFT;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
|
|
||||||
PseudoEvent.type = SDL_KEYDOWN;
|
|
||||||
PseudoEvent.key.keysym.sym = SDLK_RIGHT;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
}
|
|
||||||
if (Event->jaxis.value > -5 && Event->jaxis.value < 5)
|
|
||||||
//Neither Left nor Right
|
|
||||||
{
|
|
||||||
PseudoEvent.type = SDL_KEYUP;
|
|
||||||
PseudoEvent.key.keysym.sym = SDLK_LEFT;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
|
|
||||||
PseudoEvent.type = SDL_KEYUP;
|
|
||||||
PseudoEvent.key.keysym.sym = SDLK_RIGHT;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Event->jaxis.axis == 1)
|
|
||||||
{
|
|
||||||
//y-axis
|
|
||||||
|
|
||||||
if (Event->jaxis.value <= -5) //Down
|
|
||||||
{
|
|
||||||
PseudoEvent.type = SDL_KEYDOWN;
|
|
||||||
PseudoEvent.key.keysym.sym = SDLK_DOWN;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
|
|
||||||
PseudoEvent.type = SDL_KEYUP;
|
|
||||||
PseudoEvent.key.keysym.sym = SDLK_UP;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
}
|
|
||||||
if (Event->jaxis.value >= 5) //Up
|
|
||||||
{
|
|
||||||
PseudoEvent.type = SDL_KEYUP;
|
|
||||||
PseudoEvent.key.keysym.sym = SDLK_DOWN;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
|
|
||||||
PseudoEvent.type = SDL_KEYDOWN;
|
|
||||||
PseudoEvent.key.keysym.sym = SDLK_UP;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
}
|
|
||||||
if (Event->jaxis.value >-5 && Event->jaxis.value < 5)
|
|
||||||
//Neither Down nor Up
|
|
||||||
{
|
|
||||||
PseudoEvent.type = SDL_KEYUP;
|
|
||||||
PseudoEvent.key.keysym.sym = SDLK_DOWN;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
|
|
||||||
PseudoEvent.type = SDL_KEYUP;
|
|
||||||
PseudoEvent.key.keysym.sym = SDLK_UP;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Event->type == SDL_JOYBUTTONDOWN)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "Joystick %i down\n", Event->jbutton.button);
|
|
||||||
|
|
||||||
if (Event->jbutton.button % 3 == 0)
|
|
||||||
{
|
|
||||||
//Mimic the Primary key
|
|
||||||
|
|
||||||
PseudoEvent.type=SDL_KEYDOWN;
|
|
||||||
PseudoEvent.key.keysym.sym = ControlA;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
}
|
|
||||||
if (Event->jbutton.button % 3 == 1)
|
|
||||||
{
|
|
||||||
//Mimic the Secondary key
|
|
||||||
|
|
||||||
PseudoEvent.type = SDL_KEYDOWN;
|
|
||||||
PseudoEvent.key.keysym.sym = ControlB;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
}
|
|
||||||
if (Event->jbutton.button % 3 == 2)
|
|
||||||
{
|
|
||||||
//Mimic the Tertiary key
|
|
||||||
|
|
||||||
PseudoEvent.type = SDL_KEYDOWN;
|
|
||||||
PseudoEvent.key.keysym.sym = ControlC;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Event->type == SDL_JOYBUTTONUP)
|
|
||||||
{
|
|
||||||
if (Event->jbutton.button % 3 == 0)
|
|
||||||
{
|
|
||||||
//Mimic the Primary key
|
|
||||||
|
|
||||||
PseudoEvent.type = SDL_KEYUP;
|
|
||||||
PseudoEvent.key.keysym.sym = ControlA;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
}
|
|
||||||
if (Event->jbutton.button % 3 == 1)
|
|
||||||
{
|
|
||||||
//Mimic the Secondary key
|
|
||||||
|
|
||||||
PseudoEvent.type = SDL_KEYUP;
|
|
||||||
PseudoEvent.key.keysym.sym = ControlB;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
}
|
|
||||||
if (Event->jbutton.button % 3 == 2)
|
|
||||||
{
|
|
||||||
//Mimic the Tertiary key
|
|
||||||
|
|
||||||
PseudoEvent.type = SDL_KEYUP;
|
|
||||||
PseudoEvent.key.keysym.sym = ControlC;
|
|
||||||
ProcessKeyboardEvent (&PseudoEvent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status: Unimplemented
|
|
||||||
extern BOOLEAN
|
extern BOOLEAN
|
||||||
InitInput (UNICODE Pause, UNICODE Exit, BOOLEAN (*PFunc) (void))
|
InitInput (BOOLEAN (*PFunc) (void), UNICODE Pause, UNICODE Exit, UNICODE Abort)
|
||||||
//Be careful with this one.
|
|
||||||
{
|
{
|
||||||
|
PauseFunc = PFunc;
|
||||||
PauseKey = Pause;
|
PauseKey = Pause;
|
||||||
ExitKey = Exit;
|
ExitKey = Exit;
|
||||||
|
AbortKey = Abort;
|
||||||
// Find a unique byte ID not equal to PauseKey, ExitKey, or 0.
|
InputInitialized = TRUE;
|
||||||
OtherKey = 1;
|
|
||||||
while (OtherKey == PauseKey || OtherKey == ExitKey)
|
|
||||||
OtherKey++;
|
|
||||||
|
|
||||||
PauseFunc = PFunc;
|
|
||||||
|
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Status: Ignored
|
//Status: Ignored
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
UninitInput () // Looks like it'll be empty
|
UninitInput (void) // Looks like it'll be empty
|
||||||
{
|
{
|
||||||
BOOLEAN ret;
|
BOOLEAN ret;
|
||||||
|
|
||||||
@@ -292,52 +170,20 @@ UninitInput () // Looks like it'll be empty
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FlushInput ()
|
FlushInput (void)
|
||||||
{
|
{
|
||||||
kbdtail = kbdhead = 0;
|
kbdtail = kbdhead = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Status: Unimplemented
|
// Translates from SDLKeys to values defined in inplib.h
|
||||||
UNICODE
|
UNICODE
|
||||||
KBDToUNICODE (UNICODE SK_in)
|
KBDToUNICODE (UWORD SK_in)
|
||||||
//This one'll probably require a big table. Arg.
|
|
||||||
{
|
{
|
||||||
return (SK_in);
|
switch (SK_in)
|
||||||
}
|
|
||||||
|
|
||||||
Uint16
|
|
||||||
GetUNICODEKey ()
|
|
||||||
{
|
|
||||||
if (kbdtail != kbdhead)
|
|
||||||
{
|
|
||||||
Uint16 ch;
|
|
||||||
|
|
||||||
ch = kbdbuf[kbdhead];
|
|
||||||
kbdhead = (kbdhead + 1) & (KBDBUFSIZE - 1);
|
|
||||||
return (ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Status: Unimplemented
|
|
||||||
UNICODE
|
|
||||||
KeyHit () // Does this clear the top of a queue, or just read it?
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < sizeof (KeyboardDown) / sizeof (KeyboardDown[0]); ++i)
|
|
||||||
{
|
|
||||||
if (KeyboardDown[i])
|
|
||||||
{
|
|
||||||
if (i == SDLK_RETURN)
|
|
||||||
return ('\n');
|
|
||||||
else if (i >= 256)
|
|
||||||
{
|
|
||||||
switch (i)
|
|
||||||
{
|
{
|
||||||
case SDLK_KP_ENTER:
|
case SDLK_KP_ENTER:
|
||||||
return ('\n');
|
case SDLK_RETURN:
|
||||||
|
return '\n';
|
||||||
case SDLK_KP4:
|
case SDLK_KP4:
|
||||||
case SDLK_LEFT:
|
case SDLK_LEFT:
|
||||||
return (SK_LF_ARROW);
|
return (SK_LF_ARROW);
|
||||||
@@ -377,11 +223,13 @@ KeyHit () // Does this clear the top of a queue, or just read it?
|
|||||||
case SDLK_RSHIFT:
|
case SDLK_RSHIFT:
|
||||||
return (SK_RT_SHIFT);
|
return (SK_RT_SHIFT);
|
||||||
case SDLK_LCTRL:
|
case SDLK_LCTRL:
|
||||||
|
return (SK_LF_CTL);
|
||||||
case SDLK_RCTRL:
|
case SDLK_RCTRL:
|
||||||
return (SK_CTL);
|
return (SK_RT_CTL);
|
||||||
case SDLK_LALT:
|
case SDLK_LALT:
|
||||||
|
return (SK_LF_ALT);
|
||||||
case SDLK_RALT:
|
case SDLK_RALT:
|
||||||
return (SK_ALT);
|
return (SK_RT_ALT);
|
||||||
case SDLK_F1:
|
case SDLK_F1:
|
||||||
case SDLK_F2:
|
case SDLK_F2:
|
||||||
case SDLK_F3:
|
case SDLK_F3:
|
||||||
@@ -394,108 +242,57 @@ KeyHit () // Does this clear the top of a queue, or just read it?
|
|||||||
case SDLK_F10:
|
case SDLK_F10:
|
||||||
case SDLK_F11:
|
case SDLK_F11:
|
||||||
case SDLK_F12:
|
case SDLK_F12:
|
||||||
return ((UNICODE) ((i - SDLK_F1) + SK_F1));
|
return ((UNICODE) ((SK_in - SDLK_F1) + SK_F1));
|
||||||
}
|
default:
|
||||||
continue;
|
return (UNICODE)SK_in;
|
||||||
}
|
|
||||||
|
|
||||||
return ((UNICODE) i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
// Translates from values defined in inplib.h to SDLKey values
|
||||||
}
|
UWORD
|
||||||
|
UNICODEToKBD (UNICODE which_key)
|
||||||
//Status: Unimplemented
|
|
||||||
int
|
|
||||||
KeyDown (UNICODE which_scan)
|
|
||||||
// This might use SK_* stuff, of just plain old chars
|
|
||||||
{
|
{
|
||||||
int i;
|
switch (which_key)
|
||||||
|
|
||||||
i = which_scan;
|
|
||||||
if (i == '\n')
|
|
||||||
{
|
|
||||||
if (KeyboardDown[SDLK_KP_ENTER])
|
|
||||||
return (1);
|
|
||||||
i = SDLK_RETURN;
|
|
||||||
}
|
|
||||||
else if (i >= 128)
|
|
||||||
{
|
|
||||||
switch (i)
|
|
||||||
{
|
{
|
||||||
|
case '\r':
|
||||||
|
case '\n':
|
||||||
|
return SDLK_RETURN;
|
||||||
case SK_LF_ARROW:
|
case SK_LF_ARROW:
|
||||||
if (KeyboardDown[SDLK_KP4])
|
return SDLK_LEFT;
|
||||||
return (1);
|
|
||||||
i = SDLK_LEFT;
|
|
||||||
break;
|
|
||||||
case SK_RT_ARROW:
|
case SK_RT_ARROW:
|
||||||
if (KeyboardDown[SDLK_KP6])
|
return SDLK_RIGHT;
|
||||||
return (1);
|
|
||||||
i = SDLK_RIGHT;
|
|
||||||
break;
|
|
||||||
case SK_UP_ARROW:
|
case SK_UP_ARROW:
|
||||||
if (KeyboardDown[SDLK_KP8])
|
return SDLK_UP;
|
||||||
return (1);
|
|
||||||
i = SDLK_UP;
|
|
||||||
break;
|
|
||||||
case SK_DN_ARROW:
|
case SK_DN_ARROW:
|
||||||
if (KeyboardDown[SDLK_KP2])
|
return SDLK_DOWN;
|
||||||
return (1);
|
|
||||||
i = SDLK_DOWN;
|
|
||||||
break;
|
|
||||||
case SK_HOME:
|
case SK_HOME:
|
||||||
if (KeyboardDown[SDLK_KP7])
|
return SDLK_HOME;
|
||||||
return (1);
|
|
||||||
i = SDLK_HOME;
|
|
||||||
break;
|
|
||||||
case SK_PAGE_UP:
|
case SK_PAGE_UP:
|
||||||
if (KeyboardDown[SDLK_KP9])
|
return SDLK_PAGEUP;
|
||||||
return (1);
|
|
||||||
i = SDLK_PAGEUP;
|
|
||||||
break;
|
|
||||||
case SK_END:
|
case SK_END:
|
||||||
if (KeyboardDown[SDLK_KP1])
|
return SDLK_END;
|
||||||
return (1);
|
|
||||||
i = SDLK_END;
|
|
||||||
break;
|
|
||||||
case SK_PAGE_DOWN:
|
case SK_PAGE_DOWN:
|
||||||
if (KeyboardDown[SDLK_KP3])
|
return SDLK_PAGEDOWN;
|
||||||
return (1);
|
|
||||||
i = SDLK_PAGEDOWN;
|
|
||||||
break;
|
|
||||||
case SK_INSERT:
|
case SK_INSERT:
|
||||||
if (KeyboardDown[SDLK_KP0])
|
return SDLK_INSERT;
|
||||||
return (1);
|
|
||||||
i = SDLK_INSERT;
|
|
||||||
break;
|
|
||||||
case SK_DELETE:
|
case SK_DELETE:
|
||||||
if (KeyboardDown[SDLK_KP_PERIOD])
|
return SDLK_DELETE;
|
||||||
return (1);
|
|
||||||
i = SDLK_DELETE;
|
|
||||||
break;
|
|
||||||
case SK_KEYPAD_PLUS:
|
case SK_KEYPAD_PLUS:
|
||||||
i = SDLK_KP_PLUS;
|
return SDLK_KP_PLUS;
|
||||||
break;
|
|
||||||
case SK_KEYPAD_MINUS:
|
case SK_KEYPAD_MINUS:
|
||||||
i = SDLK_KP_MINUS;
|
return SDLK_KP_MINUS;
|
||||||
break;
|
|
||||||
case SK_LF_SHIFT:
|
case SK_LF_SHIFT:
|
||||||
i = SDLK_LSHIFT;
|
return SDLK_LSHIFT;
|
||||||
break;
|
|
||||||
case SK_RT_SHIFT:
|
case SK_RT_SHIFT:
|
||||||
i = SDLK_RSHIFT;
|
return SDLK_RSHIFT;
|
||||||
break;
|
case SK_LF_CTL:
|
||||||
case SK_CTL:
|
return SDLK_LCTRL;
|
||||||
if (KeyboardDown[SDLK_LCTRL])
|
case SK_RT_CTL:
|
||||||
return (1);
|
return SDLK_RCTRL;
|
||||||
i = SDLK_RCTRL;
|
case SK_LF_ALT:
|
||||||
break;
|
return SDLK_LALT;
|
||||||
case SK_ALT:
|
case SK_RT_ALT:
|
||||||
if (KeyboardDown[SDLK_LALT])
|
return SDLK_RALT;
|
||||||
return (1);
|
|
||||||
i = SDLK_RALT;
|
|
||||||
break;
|
|
||||||
case SK_F1:
|
case SK_F1:
|
||||||
case SK_F2:
|
case SK_F2:
|
||||||
case SK_F3:
|
case SK_F3:
|
||||||
@@ -508,44 +305,78 @@ KeyDown (UNICODE which_scan)
|
|||||||
case SK_F10:
|
case SK_F10:
|
||||||
case SK_F11:
|
case SK_F11:
|
||||||
case SK_F12:
|
case SK_F12:
|
||||||
i = (i - SK_F1) + SDLK_F1;
|
return (which_key - SK_F1) + SDLK_F1;
|
||||||
|
default:
|
||||||
|
return which_key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (KeyboardDown[i]);
|
UNICODE
|
||||||
|
GetUNICODEKey (void)
|
||||||
|
{
|
||||||
|
if (kbdtail != kbdhead)
|
||||||
|
{
|
||||||
|
SDLKey ch;
|
||||||
|
|
||||||
|
ch = kbdbuf[kbdhead];
|
||||||
|
kbdhead = (kbdhead + 1) & (KBDBUFSIZE - 1);
|
||||||
|
return KBDToUNICODE(ch);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOLEAN
|
||||||
|
KeyDown (UNICODE which_scan)
|
||||||
|
{
|
||||||
|
UWORD i;
|
||||||
|
|
||||||
|
i = UNICODEToKBD(which_scan);
|
||||||
|
if (KeyboardDown[i] != 0)
|
||||||
|
{
|
||||||
|
KeyboardDown[i] &= (~0x2);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
INPUT_STATE
|
INPUT_STATE
|
||||||
AnyButtonPress (BOOLEAN DetectSpecial)
|
AnyButtonPress (BOOLEAN DetectSpecial)
|
||||||
{
|
{
|
||||||
int i;
|
int i,j;
|
||||||
|
|
||||||
if (DetectSpecial)
|
if (DetectSpecial)
|
||||||
{
|
{
|
||||||
if (KeyDown (PauseKey) && PauseFunc && (*PauseFunc) ())
|
if (KeyDown (PauseKey) && PauseFunc)
|
||||||
;
|
PauseFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < sizeof (KeyboardDown) / sizeof (KeyboardDown[0]); ++i)
|
for (i = 0; i < SDLK_LAST; ++i)
|
||||||
{
|
{
|
||||||
if (KeyboardDown[i])
|
if (KeyboardDown[i])
|
||||||
|
{
|
||||||
|
KeyboardDown[i] &= ~0x2;
|
||||||
return (DEVICE_BUTTON1);
|
return (DEVICE_BUTTON1);
|
||||||
}
|
}
|
||||||
#if 0
|
}
|
||||||
for (i = 0; i < JOYSTICKS_AVAIL; i++)
|
for (j = 0; j < nJoysticks; ++j)
|
||||||
if (read_joystick (i))
|
{
|
||||||
|
for (i = 0; i < SDL_JoystickNumButtons(Joysticks[j]); ++i)
|
||||||
|
{
|
||||||
|
if (JoybuttonDown[j][i])
|
||||||
|
{
|
||||||
|
JoybuttonDown[j][i] &= ~0x2;
|
||||||
return (DEVICE_BUTTON1);
|
return (DEVICE_BUTTON1);
|
||||||
#endif
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status: Ignored - The keyboard will serve as the joystick, thus a port is always open.
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
_joystick_port_active(COUNT port) //SDL handles this nicely.
|
_joystick_port_active(COUNT port) //SDL handles this nicely.
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Unimplemented function activated: _joystick_port_active()\n");
|
return SDL_JoystickOpened(port);
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INPUT_STATE
|
INPUT_STATE
|
||||||
@@ -554,37 +385,14 @@ _get_pause_exit_state (void)
|
|||||||
INPUT_STATE InputState;
|
INPUT_STATE InputState;
|
||||||
|
|
||||||
InputState = 0;
|
InputState = 0;
|
||||||
if (KeyDown (PauseKey))
|
if (KeyDown (PauseKey) && PauseFunc)
|
||||||
{
|
{
|
||||||
if (PauseFunc && (*PauseFunc) ())
|
PauseFunc();
|
||||||
;
|
|
||||||
}
|
}
|
||||||
else if (KeyDown (ExitKey))
|
else if (KeyDown (ExitKey))
|
||||||
{
|
{
|
||||||
InputState = DEVICE_EXIT;
|
InputState = DEVICE_EXIT;
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
for (i = 0; i < JOYSTICKS_AVAIL; i++)
|
|
||||||
{
|
|
||||||
DWORD joy;
|
|
||||||
|
|
||||||
joy = read_joystick (i);
|
|
||||||
if (joy & ControlStart) // pause
|
|
||||||
{
|
|
||||||
if (PauseFunc && (*PauseFunc) ())
|
|
||||||
// while (KeyDown (PauseKey))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
else if (joy & ControlX) // exit
|
|
||||||
{
|
|
||||||
// while (KeyDown (ExitKey))
|
|
||||||
// TaskSwitch ();
|
|
||||||
|
|
||||||
InputState = DEVICE_EXIT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return (InputState);
|
return (InputState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,6 +402,7 @@ _get_serial_keyboard_state (INPUT_REF ref, INPUT_STATE InputState)
|
|||||||
// I hope these are defined somewhere...
|
// I hope these are defined somewhere...
|
||||||
{
|
{
|
||||||
Uint16 key;
|
Uint16 key;
|
||||||
|
(void) ref;
|
||||||
|
|
||||||
if ((key = GetUNICODEKey ()) == '\r')
|
if ((key = GetUNICODEKey ()) == '\r')
|
||||||
key = '\n';
|
key = '\n';
|
||||||
@@ -603,35 +412,52 @@ _get_serial_keyboard_state (INPUT_REF ref, INPUT_STATE InputState)
|
|||||||
return (InputState);
|
return (InputState);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status: Unimplemented
|
static BOOLEAN
|
||||||
|
GetKeyboardDown (UWORD value)
|
||||||
|
{
|
||||||
|
if (KEYISCHORD(value))
|
||||||
|
{
|
||||||
|
int k1, k2;
|
||||||
|
k1 = KeyDown(KEYGETKEY(value));
|
||||||
|
k2 = KeyDown(KEYGETCHORD(value));
|
||||||
|
if (k1 && k2)
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (KeyDown(KEYGETKEY(value)))
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
INPUT_STATE
|
INPUT_STATE
|
||||||
_get_joystick_keyboard_state (INPUT_REF InputRef, INPUT_STATE InputState)
|
_get_joystick_keyboard_state (INPUT_REF InputRef, INPUT_STATE InputState)
|
||||||
// see line above.
|
|
||||||
{
|
{
|
||||||
SBYTE dx, dy;
|
SBYTE dx, dy;
|
||||||
BYTEPTR KeyEquivalentPtr;
|
UWORD* KeyEquivalentPtr;
|
||||||
|
|
||||||
KeyEquivalentPtr = GetInputDeviceKeyEquivalentPtr (InputRef);
|
KeyEquivalentPtr = GetInputDeviceKeyEquivalentPtr (InputRef);
|
||||||
dx = (SBYTE)(KeyDown (KeyEquivalentPtr[1]) -
|
dx = (SBYTE)(GetKeyboardDown (KeyEquivalentPtr[1]) -
|
||||||
KeyDown (KeyEquivalentPtr[0]));
|
GetKeyboardDown (KeyEquivalentPtr[0]));
|
||||||
SetInputXComponent (&InputState, dx);
|
SetInputXComponent (&InputState, dx);
|
||||||
|
|
||||||
KeyEquivalentPtr += 2;
|
KeyEquivalentPtr += 2;
|
||||||
dy = (SBYTE)(KeyDown (KeyEquivalentPtr[1]) -
|
dy = (SBYTE)(GetKeyboardDown (KeyEquivalentPtr[1]) -
|
||||||
KeyDown (KeyEquivalentPtr[0]));
|
GetKeyboardDown (KeyEquivalentPtr[0]));
|
||||||
SetInputYComponent (&InputState, dy);
|
SetInputYComponent (&InputState, dy);
|
||||||
|
|
||||||
KeyEquivalentPtr += 2;
|
KeyEquivalentPtr += 2;
|
||||||
if (KeyDown (*KeyEquivalentPtr++))
|
if (GetKeyboardDown (*KeyEquivalentPtr++))
|
||||||
InputState |= DEVICE_BUTTON1;
|
InputState |= DEVICE_BUTTON1;
|
||||||
if (KeyDown (*KeyEquivalentPtr++))
|
if (GetKeyboardDown (*KeyEquivalentPtr++))
|
||||||
InputState |= DEVICE_BUTTON2;
|
InputState |= DEVICE_BUTTON2;
|
||||||
if (KeyDown (*KeyEquivalentPtr++))
|
if (GetKeyboardDown (*KeyEquivalentPtr++))
|
||||||
InputState |= DEVICE_BUTTON3;
|
InputState |= DEVICE_BUTTON3;
|
||||||
|
|
||||||
if (KeyDown (*KeyEquivalentPtr++))
|
if (GetKeyboardDown (*KeyEquivalentPtr++))
|
||||||
InputState |= DEVICE_LEFTSHIFT;
|
InputState |= DEVICE_LEFTSHIFT;
|
||||||
if (KeyDown (*KeyEquivalentPtr++))
|
if (GetKeyboardDown (*KeyEquivalentPtr++))
|
||||||
InputState |= DEVICE_RIGHTSHIFT;
|
InputState |= DEVICE_RIGHTSHIFT;
|
||||||
|
|
||||||
if (InputState)
|
if (InputState)
|
||||||
@@ -640,161 +466,76 @@ _get_joystick_keyboard_state (INPUT_REF InputRef, INPUT_STATE InputState)
|
|||||||
return (InputState);
|
return (InputState);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static BOOLEAN
|
||||||
// Status: Implemented
|
GetJoystickDown (int port, UWORD map, UWORD threshold)
|
||||||
INPUT_STATE
|
|
||||||
_get_joystick_state (INPUT_REF ref, INPUT_STATE InputState)
|
|
||||||
// consistant, at least.
|
|
||||||
{
|
{
|
||||||
// fprintf (stderr, "Half-implemented function activated: _get_joystick_state()\n");
|
int axis, sign;
|
||||||
|
if (JOYISAXIS(map))
|
||||||
if (KeyboardStroke[SDLK_LEFT])
|
|
||||||
{
|
{
|
||||||
SetInputXComponent (&InputState, -1);
|
axis = JOYGETVALUE(map);
|
||||||
// fprintf (stderr, "LEFT!\n");
|
sign = JOYGETSIGN(map);
|
||||||
KeyboardStroke[SDLK_LEFT] = FALSE;
|
if ((sign * JoyaxisValues[port][axis]) > threshold)
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (KeyboardStroke[SDLK_RIGHT])
|
else
|
||||||
{
|
{
|
||||||
SetInputXComponent (&InputState, 1);
|
if (JOYISCHORD(map))
|
||||||
// fprintf (stderr, "RIGHT!\n");
|
|
||||||
KeyboardStroke[SDLK_RIGHT] = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (KeyboardStroke[SDLK_UP])
|
|
||||||
{
|
{
|
||||||
SetInputYComponent (&InputState, -1);
|
UBYTE b1 = JoybuttonDown[port][JOYGETVALUE(map)];
|
||||||
// fprintf (stderr, "UP!\n");
|
UBYTE b2 = JoybuttonDown[port][JOYGETCHORD(map)];
|
||||||
KeyboardStroke[SDLK_UP] = FALSE;
|
JoybuttonDown[port][JOYGETVALUE(map)] &= (~0x2);
|
||||||
|
JoybuttonDown[port][JOYGETCHORD(map)] &= (~0x2);
|
||||||
|
if (b1 && b2)
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (KeyboardStroke[SDLK_DOWN])
|
else if (JoybuttonDown[port][JOYGETVALUE(map)])
|
||||||
{
|
{
|
||||||
SetInputYComponent (&InputState, 1);
|
JoybuttonDown[port][JOYGETVALUE(map)] &= (~0x2);
|
||||||
// fprintf (stderr, "DOWN!\n");
|
return TRUE;
|
||||||
KeyboardStroke[SDLK_DOWN] = FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (KeyboardStroke[ControlA])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_BUTTON1;
|
|
||||||
// fprintf (stderr, "BUTTON1!\n");
|
|
||||||
KeyboardStroke[ControlA]=FALSE;
|
|
||||||
}
|
}
|
||||||
if (KeyboardStroke[ControlB])
|
return FALSE;
|
||||||
{
|
|
||||||
InputState |= DEVICE_BUTTON2;
|
|
||||||
// fprintf (stderr, "BUTTON2!\n");
|
|
||||||
KeyboardStroke[ControlB] = FALSE;
|
|
||||||
}
|
}
|
||||||
if (KeyboardStroke[ControlC])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_BUTTON3;
|
|
||||||
// fprintf (stderr, "BUTTON3!\n");
|
|
||||||
KeyboardStroke[ControlC] = FALSE;
|
|
||||||
}
|
|
||||||
if (KeyboardStroke[ControlX])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_EXIT;
|
|
||||||
// fprintf (stderr, "BUTTONX!\n");
|
|
||||||
KeyboardStroke[ControlX] = FALSE;
|
|
||||||
}
|
|
||||||
if (KeyboardStroke[ControlStart])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_PAUSE;
|
|
||||||
// fprintf (stderr, "CONTROLSTART!\n");
|
|
||||||
KeyboardStroke[ControlStart] = FALSE;
|
|
||||||
}
|
|
||||||
if (KeyboardStroke[ControlLeftShift])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_LEFTSHIFT;
|
|
||||||
// fprintf (stderr, "LEFTSHIFT!\n");
|
|
||||||
KeyboardStroke[ControlLeftShift] = FALSE;
|
|
||||||
}
|
|
||||||
if (KeyboardStroke[ControlRightShift])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_RIGHTSHIFT;
|
|
||||||
// fprintf (stderr, "RIGHTSHIFT!\n");
|
|
||||||
KeyboardStroke[ControlRightShift] = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (InputState);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
INPUT_STATE
|
INPUT_STATE
|
||||||
_get_joystick_state (INPUT_REF ref, INPUT_STATE InputState)
|
_get_joystick_state (INPUT_REF ref, INPUT_STATE InputState)
|
||||||
// consistant, at least.
|
|
||||||
{
|
{
|
||||||
#if 0
|
SBYTE dx, dy;
|
||||||
if (ref == JoystickInput[1] && 0)
|
UWORD *JoystickButtons = GetInputDeviceJoystickButtonPtr(ref);
|
||||||
{
|
UWORD threshold = GetInputDeviceJoystickThreshold(ref);
|
||||||
//fprintf (stderr, "ref\n");
|
int port = GetInputDeviceJoystickPort(ref);
|
||||||
|
|
||||||
return(0);
|
if (GetJoystickDown(port, JoystickButtons[0], threshold))
|
||||||
}
|
dx = -1;
|
||||||
|
else if (GetJoystickDown(port, JoystickButtons[1], threshold))
|
||||||
|
dx = 1;
|
||||||
|
else
|
||||||
|
dx = 0;
|
||||||
|
|
||||||
// fprintf (stderr, "Half-implemented function activated: _get_joystick_state()\n");
|
if (GetJoystickDown(port, JoystickButtons[2], threshold))
|
||||||
|
dy = -1;
|
||||||
|
else if (GetJoystickDown(port, JoystickButtons[3], threshold))
|
||||||
|
dy = 1;
|
||||||
|
else
|
||||||
|
dy = 0;
|
||||||
|
|
||||||
if (KeyboardDown[SDLK_LEFT])
|
SetInputXComponent(&InputState, dx);
|
||||||
{
|
SetInputYComponent(&InputState, dy);
|
||||||
SetInputXComponent (&InputState, -1);
|
|
||||||
//fprintf (stderr, "LEFT!\n");
|
|
||||||
}
|
|
||||||
if (KeyboardDown[SDLK_RIGHT])
|
|
||||||
{
|
|
||||||
SetInputXComponent (&InputState, 1);
|
|
||||||
//fprintf (stderr, "RIGHT!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (KeyboardDown[SDLK_UP])
|
if (GetJoystickDown(port, JoystickButtons[4], threshold))
|
||||||
{
|
|
||||||
SetInputYComponent (&InputState, -1);
|
|
||||||
//fprintf (stderr, "UP!\n");
|
|
||||||
}
|
|
||||||
if (KeyboardDown[SDLK_DOWN])
|
|
||||||
{
|
|
||||||
SetInputYComponent (&InputState, 1);
|
|
||||||
//fprintf (stderr, "DOWN!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (KeyboardDown[ControlA])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_BUTTON1;
|
InputState |= DEVICE_BUTTON1;
|
||||||
//fprintf (stderr, "BUTTON1!\n");
|
if (GetJoystickDown(port, JoystickButtons[5], threshold))
|
||||||
}
|
|
||||||
if (KeyboardDown[ControlB])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_BUTTON2;
|
InputState |= DEVICE_BUTTON2;
|
||||||
//fprintf (stderr, "BUTTON2!\n");
|
if (GetJoystickDown(port, JoystickButtons[6], threshold))
|
||||||
}
|
|
||||||
if (KeyboardDown[ControlC])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_BUTTON3;
|
InputState |= DEVICE_BUTTON3;
|
||||||
//fprintf (stderr, "BUTTON3!\n");
|
if (GetJoystickDown(port, JoystickButtons[7], threshold))
|
||||||
}
|
|
||||||
if (KeyboardDown[ControlX])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_EXIT;
|
|
||||||
//fprintf (stderr, "BUTTONX!\n");
|
|
||||||
}
|
|
||||||
if (KeyboardDown[ControlStart])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_PAUSE;
|
|
||||||
//fprintf (stderr, "CONTROLSTART!\n");
|
|
||||||
}
|
|
||||||
if (KeyboardDown[ControlLeftShift])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_LEFTSHIFT;
|
InputState |= DEVICE_LEFTSHIFT;
|
||||||
//fprintf (stderr, "LEFTSHIFT!\n");
|
if (GetJoystickDown(port, JoystickButtons[8], threshold))
|
||||||
}
|
|
||||||
if (KeyboardDown[ControlRightShift])
|
|
||||||
{
|
|
||||||
InputState |= DEVICE_RIGHTSHIFT;
|
InputState |= DEVICE_RIGHTSHIFT;
|
||||||
//fprintf (stderr, "RIGHTSHIFT!\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return (InputState);
|
if (InputState)
|
||||||
|
SetInputDevType(&InputState, JOYSTICK_DEVICE);
|
||||||
|
return InputState;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -19,18 +19,8 @@
|
|||||||
#ifndef INPUT_H
|
#ifndef INPUT_H
|
||||||
#define INPUT_H
|
#define INPUT_H
|
||||||
|
|
||||||
extern Uint8 KeyboardDown[512];
|
UNICODE GetUNICODEKey (void);
|
||||||
|
void FlushInput (void);
|
||||||
extern SDLKey ControlA;
|
|
||||||
extern SDLKey ControlB;
|
|
||||||
extern SDLKey ControlC;
|
|
||||||
extern SDLKey ControlX;
|
|
||||||
extern SDLKey ControlStart;
|
|
||||||
extern SDLKey ControlLeftShift;
|
|
||||||
extern SDLKey ControlRightShift;
|
|
||||||
|
|
||||||
Uint16 GetUNICODEKey ();
|
|
||||||
void FlushInput ();
|
|
||||||
void ProcessKeyboardEvent (const SDL_Event *Event);
|
void ProcessKeyboardEvent (const SDL_Event *Event);
|
||||||
void ProcessJoystickEvent (const SDL_Event *Event);
|
void ProcessJoystickEvent (const SDL_Event *Event);
|
||||||
|
|
||||||
|
|||||||
+204
-35
@@ -48,39 +48,218 @@ Semaphore GraphicsSem;
|
|||||||
CondVar RenderingCond;
|
CondVar RenderingCond;
|
||||||
STRING GameStrings;
|
STRING GameStrings;
|
||||||
|
|
||||||
|
static UWORD ParseKeyString(char* line)
|
||||||
|
{
|
||||||
|
char key[16];
|
||||||
|
char* index = strchr(line+1, '"');
|
||||||
|
if (index == NULL)
|
||||||
|
return 0;
|
||||||
|
memset(key, 0, sizeof(key));
|
||||||
|
strncpy(key, line+1, index - (line + 1));
|
||||||
|
if (strchr(key, ',') != NULL && strlen(key) != 1)
|
||||||
|
{
|
||||||
|
// We have a chorded key!
|
||||||
|
UWORD k1, k2;
|
||||||
|
char l[16];
|
||||||
|
char* comma = line;
|
||||||
|
memset(l, 0, sizeof(l));
|
||||||
|
while (strchr(comma + 1, ',') != NULL)
|
||||||
|
comma = strchr(comma + 1, ',');
|
||||||
|
strncpy(l, line, comma - line);
|
||||||
|
strcat(l, "\"");
|
||||||
|
k1 = ParseKeyString(l);
|
||||||
|
memset(l, 0, sizeof(l));
|
||||||
|
l[0] = '"';
|
||||||
|
strncpy(l + 1, comma + 1, index - (comma + 1));
|
||||||
|
strcat(l, "\"");
|
||||||
|
k2 = ParseKeyString(l);
|
||||||
|
return KEYCHORD(k1, k2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(key, "Left"))
|
||||||
|
return SK_LF_ARROW;
|
||||||
|
else if (!strcmp(key, "Right"))
|
||||||
|
return SK_RT_ARROW;
|
||||||
|
else if (!strcmp(key, "Up"))
|
||||||
|
return SK_UP_ARROW;
|
||||||
|
else if (!strcmp(key, "Down"))
|
||||||
|
return SK_DN_ARROW;
|
||||||
|
else if (!strcmp(key, "RCtrl"))
|
||||||
|
return SK_RT_CTL;
|
||||||
|
else if (!strcmp(key, "LCtrl"))
|
||||||
|
return SK_LF_CTL;
|
||||||
|
else if (!strcmp(key, "RAlt"))
|
||||||
|
return SK_RT_ALT;
|
||||||
|
else if (!strcmp(key, "LAlt"))
|
||||||
|
return SK_LF_ALT;
|
||||||
|
else if (!strcmp(key, "LShift"))
|
||||||
|
return SK_LF_SHIFT;
|
||||||
|
else if (!strcmp(key, "RShift"))
|
||||||
|
return SK_RT_SHIFT;
|
||||||
|
else if (!strcmp(key, "Enter"))
|
||||||
|
return '\n';
|
||||||
|
else if (!strcmp(key, "F1"))
|
||||||
|
return SK_F1;
|
||||||
|
else if (!strcmp(key, "F2"))
|
||||||
|
return SK_F2;
|
||||||
|
else if (!strcmp(key, "F3"))
|
||||||
|
return SK_F3;
|
||||||
|
else if (!strcmp(key, "F4"))
|
||||||
|
return SK_F4;
|
||||||
|
else if (!strcmp(key, "F5"))
|
||||||
|
return SK_F5;
|
||||||
|
else if (!strcmp(key, "F6"))
|
||||||
|
return SK_F6;
|
||||||
|
else if (!strcmp(key, "F7"))
|
||||||
|
return SK_F7;
|
||||||
|
else if (!strcmp(key, "F8"))
|
||||||
|
return SK_F8;
|
||||||
|
else if (!strcmp(key, "F9"))
|
||||||
|
return SK_F9;
|
||||||
|
else if (!strcmp(key, "F10"))
|
||||||
|
return SK_F10;
|
||||||
|
else if (!strcmp(key, "F11"))
|
||||||
|
return SK_F11;
|
||||||
|
else if (!strcmp(key, "F12"))
|
||||||
|
return SK_F12;
|
||||||
|
else if (!strcmp(key, "KP+"))
|
||||||
|
return SK_KEYPAD_PLUS;
|
||||||
|
else if (!strcmp(key, "KP-"))
|
||||||
|
return SK_KEYPAD_MINUS;
|
||||||
|
else
|
||||||
|
return key[0];
|
||||||
|
}
|
||||||
|
|
||||||
static MEM_HANDLE
|
static MEM_HANDLE
|
||||||
LoadKeyConfig (FILE *fp, DWORD length)
|
LoadKeyConfig (FILE *fp, DWORD length)
|
||||||
{
|
{
|
||||||
COUNT i;
|
UWORD buf[18];
|
||||||
BYTE buf[38], *pbuf;
|
int p;
|
||||||
|
int i;
|
||||||
|
char line[256];
|
||||||
|
extern BOOLEAN PauseGame (void);
|
||||||
|
|
||||||
ReadResFile (buf, 1, sizeof (buf), fp);
|
UNICODE specialKeys[3];
|
||||||
|
|
||||||
// new temporary melee keys 2002/11/22
|
// Look for pause, exit, abort keys
|
||||||
// mapped as left, right, thrust, ?, ?, fire, special, ?, ?
|
for (i = 0; i < 3; ++i)
|
||||||
KeyboardInput[0] = CaptureInputDevice
|
|
||||||
(
|
|
||||||
CreateJoystickKeyboardDevice (SK_LF_ARROW, SK_RT_ARROW, SK_UP_ARROW, 0, 0, SK_RT_SHIFT, SK_CTL, 0, 0x1b)
|
|
||||||
);
|
|
||||||
KeyboardInput[1] = CaptureInputDevice
|
|
||||||
(
|
|
||||||
CreateJoystickKeyboardDevice ('s', 'f', 'e', 0, 0, 'q', 'a', 0, 0x1b)
|
|
||||||
);
|
|
||||||
|
|
||||||
// old melee key code
|
|
||||||
/*for (i = 0, pbuf = buf; i < NUM_PLAYERS; ++i, pbuf += 10)
|
|
||||||
{
|
{
|
||||||
KeyboardInput[i] = CaptureInputDevice (
|
for (;;)
|
||||||
CreateJoystickKeyboardDevice (
|
{
|
||||||
pbuf[2], pbuf[4], pbuf[6], 0,
|
if (feof(fp) || ferror(fp))
|
||||||
0, pbuf[8], pbuf[0],
|
break;
|
||||||
0, 0x1b
|
fgets(line, 256, fp);
|
||||||
)
|
if (line[0] != '#')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (line[0] == '"')
|
||||||
|
{
|
||||||
|
specialKeys[i] = (UNICODE)(ParseKeyString(line) & 0xFF);
|
||||||
|
fprintf(stderr, "Special %i = %i\n", i, specialKeys[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For each of two players
|
||||||
|
for (p = 0; p < 2; ++p)
|
||||||
|
{
|
||||||
|
int joyN = -1;
|
||||||
|
int joyThresh = 0;
|
||||||
|
memset(buf, 0xFF, sizeof(buf));
|
||||||
|
// Read in 9 inputs
|
||||||
|
for (i = 0; i < 9; ++i)
|
||||||
|
{
|
||||||
|
// Look for valid lines
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
if (feof(fp) || ferror(fp))
|
||||||
|
break;
|
||||||
|
fgets(line, 256, fp);
|
||||||
|
|
||||||
|
if (line[0] != '#')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// line now contains what should be a valid line
|
||||||
|
if (strstr(line, "<Joyport") != NULL)
|
||||||
|
{
|
||||||
|
joyN = atoi(line + 8);
|
||||||
|
joyThresh = atoi(strchr(line, '-') + 10);
|
||||||
|
--i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (line[0] == '"')
|
||||||
|
{
|
||||||
|
char joy[16];
|
||||||
|
char* index;
|
||||||
|
memset(joy, 0, sizeof(joy));
|
||||||
|
index = strchr(line+1, '"');
|
||||||
|
if (index != NULL)
|
||||||
|
index = strchr(index+1, '<');
|
||||||
|
if (index != NULL)
|
||||||
|
{
|
||||||
|
char* index2 = strchr(index+1, '>');
|
||||||
|
if (index2 != NULL)
|
||||||
|
strncpy(joy, index+1, index2 - (index + 1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
joy[0] = 0;
|
||||||
|
}
|
||||||
|
buf[i] = ParseKeyString (line);
|
||||||
|
fprintf(stderr, "Player %i, key %i = %i\n", p, i, buf[i]);
|
||||||
|
if (joy[0] != 0)
|
||||||
|
{
|
||||||
|
char type;
|
||||||
|
if (strchr(joy, '-') != NULL)
|
||||||
|
type = *(strchr(joy, '-') + 1);
|
||||||
|
else
|
||||||
|
type = 0;
|
||||||
|
|
||||||
|
if (type == 'A')
|
||||||
|
{
|
||||||
|
int axis = atoi(strchr(joy, '-') + 2);
|
||||||
|
char sign = joy[strlen(joy)-1];
|
||||||
|
int s;
|
||||||
|
if (sign == '+')
|
||||||
|
s = 1;
|
||||||
|
else if (sign == '-')
|
||||||
|
s = -1;
|
||||||
|
else
|
||||||
|
s = 1;
|
||||||
|
buf[9 + i] = JOYAXIS(axis, s);
|
||||||
|
}
|
||||||
|
else if (type == 'B')
|
||||||
|
{
|
||||||
|
int button = atoi(strchr(joy, '-') + 2);
|
||||||
|
buf[9 + i] = JOYBUTTON(button);
|
||||||
|
}
|
||||||
|
else if (type == 'C')
|
||||||
|
{
|
||||||
|
int b1 = atoi(strchr(joy, '-') + 2);
|
||||||
|
int b2 = atoi(strchr(joy, ',') + 1);
|
||||||
|
buf[9 + i] = JOYCHORD(b1, b2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KeyboardInput[p] = CaptureInputDevice (
|
||||||
|
CreateJoystickKeyboardDevice(buf[0], buf[1], buf[2], buf[3], buf[4],
|
||||||
|
buf[5], buf[6], buf[7], buf[8])
|
||||||
);
|
);
|
||||||
|
if (joyN != -1)
|
||||||
}*/
|
{
|
||||||
|
JoystickInput[p] = CaptureInputDevice (
|
||||||
|
CreateJoystickDevice(joyN, joyThresh, buf[9], buf[10], buf[11],
|
||||||
|
buf[12], buf[13], buf[14], buf[15], buf[16], buf[17])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JoystickInput[p] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ArrowInput = KeyboardInput[0];
|
||||||
(void) length; /* Satisfying compiler (unused parameter) */
|
(void) length; /* Satisfying compiler (unused parameter) */
|
||||||
|
InitInput(PauseGame, specialKeys[0], specialKeys[1], specialKeys[2]);
|
||||||
return (NULL_HANDLE);
|
return (NULL_HANDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,18 +267,8 @@ static void
|
|||||||
InitPlayerInput (void)
|
InitPlayerInput (void)
|
||||||
{
|
{
|
||||||
INPUT_DEVICE InputDevice;
|
INPUT_DEVICE InputDevice;
|
||||||
extern BOOLEAN PauseGame (void);
|
|
||||||
|
|
||||||
InitInput (SK_F1, SK_F10, PauseGame);
|
|
||||||
|
|
||||||
JoystickInput[0] = CaptureInputDevice (CreateJoystickDevice (0));
|
|
||||||
JoystickInput[1] = CaptureInputDevice (CreateJoystickDevice (1));
|
|
||||||
|
|
||||||
SerialInput = CaptureInputDevice (CreateSerialKeyboardDevice ());
|
SerialInput = CaptureInputDevice (CreateSerialKeyboardDevice ());
|
||||||
ArrowInput = CaptureInputDevice (CreateJoystickKeyboardDevice (
|
|
||||||
SK_LF_ARROW, SK_RT_ARROW, SK_UP_ARROW, SK_DN_ARROW,
|
|
||||||
'\n', ' ', 0x1b, SK_KEYPAD_MINUS, SK_KEYPAD_PLUS
|
|
||||||
));
|
|
||||||
|
|
||||||
InputDevice = CreateInternalDevice (game_input);
|
InputDevice = CreateInternalDevice (game_input);
|
||||||
NormalInput = CaptureInputDevice (InputDevice);
|
NormalInput = CaptureInputDevice (InputDevice);
|
||||||
|
|||||||
@@ -181,16 +181,13 @@ PauseGame (void)
|
|||||||
FlushGraphics ();
|
FlushGraphics ();
|
||||||
//SetSemaphore (GraphicsSem);
|
//SetSemaphore (GraphicsSem);
|
||||||
|
|
||||||
{
|
while (KeyDown (PauseKey))
|
||||||
BYTE scan;
|
|
||||||
|
|
||||||
scan = KBDToUNICODE (SK_F1);
|
|
||||||
while (KeyDown (scan))
|
|
||||||
TaskSwitch ();
|
TaskSwitch ();
|
||||||
}
|
|
||||||
|
|
||||||
FlushInput ();
|
FlushInput ();
|
||||||
while (KeyHit () != SK_F1)
|
|
||||||
|
// Wait for the pause key to be pressed again
|
||||||
|
while (!KeyDown (PauseKey))
|
||||||
TaskSwitch ();
|
TaskSwitch ();
|
||||||
|
|
||||||
s.frame = F;
|
s.frame = F;
|
||||||
|
|||||||
Reference in New Issue
Block a user