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:
|
||||
- Rewritten input code (better and adds joystick/pad support), from slayne
|
||||
- Biadapt scaling for pure mode, from fOSSiL
|
||||
- Saving user data in "%APPDATA%/Application Data" on windows - SvdB
|
||||
- Melnorme comm fix, from TD.
|
||||
|
||||
@@ -117,20 +117,6 @@ TFB_ProcessEvents ()
|
||||
default:
|
||||
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_RT_SHIFT ((UNICODE)140)
|
||||
#define SK_CTL ((UNICODE)141)
|
||||
#define SK_ALT ((UNICODE)142)
|
||||
#define SK_LF_CTL ((UNICODE)141)
|
||||
#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 KEY_UP ((BYTE)(1 << 1))
|
||||
#define LF_SHIFT_DOWN ((BYTE)(1 << 2))
|
||||
#define RT_SHIFT_DOWN ((BYTE)(1 << 3))
|
||||
#define CTL_DOWN ((BYTE)(1 << 4))
|
||||
#define ALT_DOWN ((BYTE)(1 << 5))
|
||||
|
||||
#define SK_F1 ((UNICODE)143)
|
||||
#define SK_F2 ((UNICODE)144)
|
||||
#define SK_F3 ((UNICODE)145)
|
||||
#define SK_F4 ((UNICODE)146)
|
||||
#define SK_F5 ((UNICODE)147)
|
||||
#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 SK_F1 ((UNICODE)145)
|
||||
#define SK_F2 ((UNICODE)146)
|
||||
#define SK_F3 ((UNICODE)147)
|
||||
#define SK_F4 ((UNICODE)148)
|
||||
#define SK_F5 ((UNICODE)149)
|
||||
#define SK_F6 ((UNICODE)150)
|
||||
#define SK_F7 ((UNICODE)151)
|
||||
#define SK_F8 ((UNICODE)152)
|
||||
#define SK_F9 ((UNICODE)153)
|
||||
#define SK_F10 ((UNICODE)154)
|
||||
#define SK_F11 ((UNICODE)155)
|
||||
#define SK_F12 ((UNICODE)156)
|
||||
|
||||
#define DEVTYPE_MASK 0x03
|
||||
#define GetInputUNICODE(is) (LOWORD (is))
|
||||
@@ -92,14 +87,16 @@ typedef enum
|
||||
#define DEVICE_LEFTSHIFT ((INPUT_STATE)1 << 24)
|
||||
#define DEVICE_RIGHTSHIFT ((INPUT_STATE)1 << 25)
|
||||
|
||||
extern BOOLEAN InitInput (UNICODE PauseKey, UNICODE ExitKey, BOOLEAN
|
||||
(*PauseFunc) (void));
|
||||
extern BOOLEAN InitInput (BOOLEAN (*PauseFunc) (void), UNICODE Pause,
|
||||
UNICODE Exit, UNICODE Abort);
|
||||
extern BOOLEAN UninitInput (void);
|
||||
extern INPUT_DEVICE CreateSerialKeyboardDevice (void);
|
||||
extern INPUT_DEVICE CreateJoystickKeyboardDevice (UNICODE lfkey, UNICODE
|
||||
rtkey, UNICODE topkey, UNICODE botkey, UNICODE but1key, UNICODE
|
||||
but2key, UNICODE but3key, UNICODE shift1key, UNICODE shift2key);
|
||||
extern INPUT_DEVICE CreateJoystickDevice (COUNT port);
|
||||
extern INPUT_DEVICE CreateJoystickKeyboardDevice (UWORD lfkey, UWORD
|
||||
rtkey, UWORD topkey, UWORD botkey, UWORD but1key, UWORD
|
||||
but2key, UWORD but3key, UWORD shift1key, UWORD shift2key);
|
||||
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)
|
||||
(INPUT_REF InputRef, INPUT_STATE InputState));
|
||||
extern BOOLEAN DestroyInputDevice (INPUT_DEVICE InputDevice);
|
||||
@@ -109,15 +106,43 @@ extern INPUT_STATE GetInputState (INPUT_REF InputRef);
|
||||
extern INPUT_STATE AnyButtonPress (BOOLEAN DetectSpecial);
|
||||
|
||||
extern void FlushInput (void);
|
||||
extern int KeyDown (UNICODE which_scan);
|
||||
extern BOOLEAN KeyDown (UNICODE which_scan);
|
||||
extern UNICODE GetUnicodeKey (void);
|
||||
extern UNICODE KBDToUNICODE (UNICODE which_key);
|
||||
extern UNICODE KeyHit (void);
|
||||
extern BYTE GetKeyState (UNICODE key);
|
||||
extern UNICODE KBDToUNICODE (UWORD which_key);
|
||||
|
||||
/*
|
||||
* Not used right now
|
||||
extern BOOLEAN FindMouse (void);
|
||||
extern void MoveMouse (SWORD x, SWORD y);
|
||||
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 */
|
||||
|
||||
|
||||
@@ -21,15 +21,33 @@
|
||||
|
||||
#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
|
||||
{
|
||||
INPUT_DEVICE ThisDevice;
|
||||
union
|
||||
{
|
||||
UNICODE key_equivalent[NUM_INPUTS];
|
||||
COUNT joystick_port;
|
||||
UWORD key_equivalent[NUM_INPUTS];
|
||||
struct
|
||||
{
|
||||
BYTE joystick_port;
|
||||
UWORD joystick_threshold;
|
||||
/* See inplib.h for description of this field */
|
||||
UWORD joystick_buttons[NUM_INPUTS];
|
||||
} joystick_info;
|
||||
} device;
|
||||
INPUT_STATE (*input_func) (INPUT_REF InputRef, INPUT_STATE
|
||||
InputState);
|
||||
@@ -51,17 +69,29 @@ typedef PBYTE BYTEPTR;
|
||||
#define SetInputDeviceHandle(i,h) \
|
||||
((INPUT_DESCPTR)(i))->ThisDevice = (h)
|
||||
#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[1] = KBDToUNICODE (r), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[2] = KBDToUNICODE (t), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[3] = KBDToUNICODE (b), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[4] = KBDToUNICODE (b1), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[5] = KBDToUNICODE (b2), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[6] = KBDToUNICODE (b3), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[7] = KBDToUNICODE (s1), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[8] = KBDToUNICODE (s2))
|
||||
(((INPUT_DESCPTR)(i))->device.key_equivalent[0] = (l), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[1] = (r), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[2] = (t), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[3] = (b), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[4] = (b1), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[5] = (b2), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[6] = (b3), \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent[7] = (s1), \
|
||||
((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) \
|
||||
((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) \
|
||||
((INPUT_DESCPTR)(i))->input_func = (f)
|
||||
|
||||
@@ -69,8 +99,12 @@ typedef PBYTE BYTEPTR;
|
||||
((INPUT_DESCPTR)(i))->ThisDevice
|
||||
#define GetInputDeviceKeyEquivalentPtr(i) \
|
||||
((INPUT_DESCPTR)(i))->device.key_equivalent
|
||||
#define GetInputDeviceJoystickButtonPtr(i) \
|
||||
((INPUT_DESCPTR)(i))->device.joystick_info.joystick_buttons
|
||||
#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) \
|
||||
((INPUT_DESCPTR)(i))->input_func
|
||||
|
||||
|
||||
@@ -47,9 +47,9 @@ CreateSerialKeyboardDevice (void)
|
||||
}
|
||||
|
||||
INPUT_DEVICE
|
||||
CreateJoystickKeyboardDevice (UNICODE lfkey, UNICODE rtkey, UNICODE
|
||||
topkey, UNICODE botkey, UNICODE but1key, UNICODE but2key, UNICODE
|
||||
but3key, UNICODE shift1key, UNICODE shift2key)
|
||||
CreateJoystickKeyboardDevice (UWORD lfkey, UWORD rtkey, UWORD
|
||||
topkey, UWORD botkey, UWORD but1key, UWORD but2key, UWORD
|
||||
but3key, UWORD shift1key, UWORD shift2key)
|
||||
{
|
||||
INPUT_DEVICE InputDevice;
|
||||
|
||||
@@ -80,7 +80,9 @@ CreateJoystickKeyboardDevice (UNICODE lfkey, UNICODE rtkey, UNICODE
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -101,6 +103,9 @@ CreateJoystickDevice (COUNT port)
|
||||
SetInputDeviceHandle (InputPtr, InputDevice);
|
||||
SetInputDeviceInputFunc (InputPtr, _get_joystick_state);
|
||||
SetInputDeviceJoystickPort (InputPtr, port);
|
||||
SetInputDeviceJoystickButtons (InputPtr, left, right, top, bottom,
|
||||
but1, but2, but3, s1, s2);
|
||||
SetInputDeviceJoystickThreshold(InputPtr, threshold);
|
||||
|
||||
UnlockInputDevice (InputDevice);
|
||||
}
|
||||
|
||||
@@ -21,33 +21,30 @@
|
||||
#include "libs/graphics/sdl/sdl_common.h"
|
||||
#include "libs/input/input_common.h"
|
||||
|
||||
|
||||
Uint8 KeyboardDown[512];
|
||||
static Uint8 KeyboardDown[SDLK_LAST];
|
||||
#define KBDBUFSIZE (1 << 8)
|
||||
int kbdhead, kbdtail;
|
||||
Uint16 kbdbuf[KBDBUFSIZE];
|
||||
static int kbdhead=0, kbdtail=0;
|
||||
static SDLKey kbdbuf[KBDBUFSIZE];
|
||||
|
||||
SDLKey ControlA;
|
||||
SDLKey ControlB;
|
||||
SDLKey ControlC;
|
||||
SDLKey ControlX;
|
||||
SDLKey ControlStart;
|
||||
SDLKey ControlLeftShift;
|
||||
SDLKey ControlRightShift;
|
||||
static int nJoysticks = 0;
|
||||
static SDL_Joystick **Joysticks = 0;
|
||||
|
||||
static UBYTE **JoybuttonDown = 0;
|
||||
static SWORD **JoyaxisValues = 0;
|
||||
|
||||
static UNICODE PauseKey;
|
||||
static UNICODE ExitKey;
|
||||
static UNICODE OtherKey;
|
||||
|
||||
static BOOLEAN (* PauseFunc) (void);
|
||||
static BOOLEAN (* PauseFunc) (void) = 0;
|
||||
static BOOLEAN InputInitialized = FALSE;
|
||||
|
||||
UNICODE PauseKey = 0;
|
||||
UNICODE ExitKey = 0;
|
||||
UNICODE AbortKey = 0;
|
||||
|
||||
int
|
||||
TFB_InitInput (int driver, int flags)
|
||||
{
|
||||
int i;
|
||||
SDL_Joystick *Joystick1;
|
||||
(void)driver;
|
||||
(void)flags;
|
||||
|
||||
atexit (TFB_UninitInput);
|
||||
|
||||
@@ -59,230 +56,111 @@ TFB_InitInput (int driver, int flags)
|
||||
|
||||
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");
|
||||
for(i = 0; i < SDL_NumJoysticks (); i++)
|
||||
for(i = 0; i < nJoysticks; 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);
|
||||
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;
|
||||
//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;
|
||||
}
|
||||
|
||||
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
|
||||
ProcessKeyboardEvent(const SDL_Event *Event)
|
||||
{
|
||||
if(Event->key.keysym.sym == SDLK_BACKQUOTE ||
|
||||
Event->key.keysym.sym == SDLK_WORLD_7)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDLKey k = Event->key.keysym.sym;
|
||||
if (!InputInitialized)
|
||||
return;
|
||||
|
||||
if (Event->type == SDL_KEYDOWN)
|
||||
{
|
||||
if ((kbdbuf[kbdtail] = Event->key.keysym.unicode)
|
||||
|| (kbdbuf[kbdtail] = Event->key.keysym.sym) <= 0x7F)
|
||||
{
|
||||
kbdbuf[kbdtail] = k;
|
||||
kbdtail = (kbdtail + 1) & (KBDBUFSIZE - 1);
|
||||
if (kbdtail == kbdhead)
|
||||
kbdhead = (kbdhead + 1) & (KBDBUFSIZE - 1);
|
||||
}
|
||||
KeyboardDown[Event->key.keysym.sym]=TRUE;
|
||||
if (KBDToUNICODE(k) == AbortKey)
|
||||
exit(0);
|
||||
KeyboardDown[k] |= 0x3;
|
||||
}
|
||||
else
|
||||
{
|
||||
KeyboardDown[Event->key.keysym.sym]=FALSE;
|
||||
}
|
||||
KeyboardDown[k] &= (~0x1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ProcessJoystickEvent (const SDL_Event* Event)
|
||||
{
|
||||
SDL_Event PseudoEvent;
|
||||
|
||||
if (!InputInitialized)
|
||||
return;
|
||||
|
||||
if (Event->type == SDL_JOYAXISMOTION)
|
||||
switch (Event->type)
|
||||
{
|
||||
if (Event->jaxis.axis == 0)
|
||||
{
|
||||
//x-axis
|
||||
|
||||
if (Event->jaxis.value <= -5) //Left
|
||||
{
|
||||
PseudoEvent.type = SDL_KEYDOWN;
|
||||
PseudoEvent.key.keysym.sym = SDLK_LEFT;
|
||||
ProcessKeyboardEvent (&PseudoEvent);
|
||||
|
||||
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);
|
||||
}
|
||||
case SDL_JOYAXISMOTION:
|
||||
JoyaxisValues[Event->jaxis.which][Event->jaxis.axis] = Event->jaxis.value;
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
JoybuttonDown[Event->jbutton.which][Event->jbutton.button] |= 0x3;
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
JoybuttonDown[Event->jbutton.which][Event->jbutton.button] &= (~0x1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Status: Unimplemented
|
||||
extern BOOLEAN
|
||||
InitInput (UNICODE Pause, UNICODE Exit, BOOLEAN (*PFunc) (void))
|
||||
//Be careful with this one.
|
||||
InitInput (BOOLEAN (*PFunc) (void), UNICODE Pause, UNICODE Exit, UNICODE Abort)
|
||||
{
|
||||
PauseFunc = PFunc;
|
||||
PauseKey = Pause;
|
||||
ExitKey = Exit;
|
||||
|
||||
// Find a unique byte ID not equal to PauseKey, ExitKey, or 0.
|
||||
OtherKey = 1;
|
||||
while (OtherKey == PauseKey || OtherKey == ExitKey)
|
||||
OtherKey++;
|
||||
|
||||
PauseFunc = PFunc;
|
||||
|
||||
AbortKey = Abort;
|
||||
InputInitialized = TRUE;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
//Status: Ignored
|
||||
BOOLEAN
|
||||
UninitInput () // Looks like it'll be empty
|
||||
UninitInput (void) // Looks like it'll be empty
|
||||
{
|
||||
BOOLEAN ret;
|
||||
|
||||
@@ -292,52 +170,20 @@ UninitInput () // Looks like it'll be empty
|
||||
}
|
||||
|
||||
void
|
||||
FlushInput ()
|
||||
FlushInput (void)
|
||||
{
|
||||
kbdtail = kbdhead = 0;
|
||||
}
|
||||
|
||||
//Status: Unimplemented
|
||||
// Translates from SDLKeys to values defined in inplib.h
|
||||
UNICODE
|
||||
KBDToUNICODE (UNICODE SK_in)
|
||||
//This one'll probably require a big table. Arg.
|
||||
KBDToUNICODE (UWORD SK_in)
|
||||
{
|
||||
return (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)
|
||||
switch (SK_in)
|
||||
{
|
||||
case SDLK_KP_ENTER:
|
||||
return ('\n');
|
||||
case SDLK_RETURN:
|
||||
return '\n';
|
||||
case SDLK_KP4:
|
||||
case SDLK_LEFT:
|
||||
return (SK_LF_ARROW);
|
||||
@@ -377,11 +223,13 @@ KeyHit () // Does this clear the top of a queue, or just read it?
|
||||
case SDLK_RSHIFT:
|
||||
return (SK_RT_SHIFT);
|
||||
case SDLK_LCTRL:
|
||||
return (SK_LF_CTL);
|
||||
case SDLK_RCTRL:
|
||||
return (SK_CTL);
|
||||
return (SK_RT_CTL);
|
||||
case SDLK_LALT:
|
||||
return (SK_LF_ALT);
|
||||
case SDLK_RALT:
|
||||
return (SK_ALT);
|
||||
return (SK_RT_ALT);
|
||||
case SDLK_F1:
|
||||
case SDLK_F2:
|
||||
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_F11:
|
||||
case SDLK_F12:
|
||||
return ((UNICODE) ((i - SDLK_F1) + SK_F1));
|
||||
return ((UNICODE) ((SK_in - SDLK_F1) + SK_F1));
|
||||
default:
|
||||
return (UNICODE)SK_in;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
return ((UNICODE) i);
|
||||
}
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
//Status: Unimplemented
|
||||
int
|
||||
KeyDown (UNICODE which_scan)
|
||||
// This might use SK_* stuff, of just plain old chars
|
||||
// Translates from values defined in inplib.h to SDLKey values
|
||||
UWORD
|
||||
UNICODEToKBD (UNICODE which_key)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = which_scan;
|
||||
if (i == '\n')
|
||||
{
|
||||
if (KeyboardDown[SDLK_KP_ENTER])
|
||||
return (1);
|
||||
i = SDLK_RETURN;
|
||||
}
|
||||
else if (i >= 128)
|
||||
{
|
||||
switch (i)
|
||||
switch (which_key)
|
||||
{
|
||||
case '\r':
|
||||
case '\n':
|
||||
return SDLK_RETURN;
|
||||
case SK_LF_ARROW:
|
||||
if (KeyboardDown[SDLK_KP4])
|
||||
return (1);
|
||||
i = SDLK_LEFT;
|
||||
break;
|
||||
return SDLK_LEFT;
|
||||
case SK_RT_ARROW:
|
||||
if (KeyboardDown[SDLK_KP6])
|
||||
return (1);
|
||||
i = SDLK_RIGHT;
|
||||
break;
|
||||
return SDLK_RIGHT;
|
||||
case SK_UP_ARROW:
|
||||
if (KeyboardDown[SDLK_KP8])
|
||||
return (1);
|
||||
i = SDLK_UP;
|
||||
break;
|
||||
return SDLK_UP;
|
||||
case SK_DN_ARROW:
|
||||
if (KeyboardDown[SDLK_KP2])
|
||||
return (1);
|
||||
i = SDLK_DOWN;
|
||||
break;
|
||||
return SDLK_DOWN;
|
||||
case SK_HOME:
|
||||
if (KeyboardDown[SDLK_KP7])
|
||||
return (1);
|
||||
i = SDLK_HOME;
|
||||
break;
|
||||
return SDLK_HOME;
|
||||
case SK_PAGE_UP:
|
||||
if (KeyboardDown[SDLK_KP9])
|
||||
return (1);
|
||||
i = SDLK_PAGEUP;
|
||||
break;
|
||||
return SDLK_PAGEUP;
|
||||
case SK_END:
|
||||
if (KeyboardDown[SDLK_KP1])
|
||||
return (1);
|
||||
i = SDLK_END;
|
||||
break;
|
||||
return SDLK_END;
|
||||
case SK_PAGE_DOWN:
|
||||
if (KeyboardDown[SDLK_KP3])
|
||||
return (1);
|
||||
i = SDLK_PAGEDOWN;
|
||||
break;
|
||||
return SDLK_PAGEDOWN;
|
||||
case SK_INSERT:
|
||||
if (KeyboardDown[SDLK_KP0])
|
||||
return (1);
|
||||
i = SDLK_INSERT;
|
||||
break;
|
||||
return SDLK_INSERT;
|
||||
case SK_DELETE:
|
||||
if (KeyboardDown[SDLK_KP_PERIOD])
|
||||
return (1);
|
||||
i = SDLK_DELETE;
|
||||
break;
|
||||
return SDLK_DELETE;
|
||||
case SK_KEYPAD_PLUS:
|
||||
i = SDLK_KP_PLUS;
|
||||
break;
|
||||
return SDLK_KP_PLUS;
|
||||
case SK_KEYPAD_MINUS:
|
||||
i = SDLK_KP_MINUS;
|
||||
break;
|
||||
return SDLK_KP_MINUS;
|
||||
case SK_LF_SHIFT:
|
||||
i = SDLK_LSHIFT;
|
||||
break;
|
||||
return SDLK_LSHIFT;
|
||||
case SK_RT_SHIFT:
|
||||
i = SDLK_RSHIFT;
|
||||
break;
|
||||
case SK_CTL:
|
||||
if (KeyboardDown[SDLK_LCTRL])
|
||||
return (1);
|
||||
i = SDLK_RCTRL;
|
||||
break;
|
||||
case SK_ALT:
|
||||
if (KeyboardDown[SDLK_LALT])
|
||||
return (1);
|
||||
i = SDLK_RALT;
|
||||
break;
|
||||
return SDLK_RSHIFT;
|
||||
case SK_LF_CTL:
|
||||
return SDLK_LCTRL;
|
||||
case SK_RT_CTL:
|
||||
return SDLK_RCTRL;
|
||||
case SK_LF_ALT:
|
||||
return SDLK_LALT;
|
||||
case SK_RT_ALT:
|
||||
return SDLK_RALT;
|
||||
case SK_F1:
|
||||
case SK_F2:
|
||||
case SK_F3:
|
||||
@@ -508,44 +305,78 @@ KeyDown (UNICODE which_scan)
|
||||
case SK_F10:
|
||||
case SK_F11:
|
||||
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
|
||||
AnyButtonPress (BOOLEAN DetectSpecial)
|
||||
{
|
||||
int i;
|
||||
int i,j;
|
||||
|
||||
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])
|
||||
{
|
||||
KeyboardDown[i] &= ~0x2;
|
||||
return (DEVICE_BUTTON1);
|
||||
}
|
||||
#if 0
|
||||
for (i = 0; i < JOYSTICKS_AVAIL; i++)
|
||||
if (read_joystick (i))
|
||||
}
|
||||
for (j = 0; j < nJoysticks; ++j)
|
||||
{
|
||||
for (i = 0; i < SDL_JoystickNumButtons(Joysticks[j]); ++i)
|
||||
{
|
||||
if (JoybuttonDown[j][i])
|
||||
{
|
||||
JoybuttonDown[j][i] &= ~0x2;
|
||||
return (DEVICE_BUTTON1);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
// Status: Ignored - The keyboard will serve as the joystick, thus a port is always open.
|
||||
BOOLEAN
|
||||
_joystick_port_active(COUNT port) //SDL handles this nicely.
|
||||
{
|
||||
fprintf (stderr, "Unimplemented function activated: _joystick_port_active()\n");
|
||||
return (0);
|
||||
return SDL_JoystickOpened(port);
|
||||
}
|
||||
|
||||
INPUT_STATE
|
||||
@@ -554,37 +385,14 @@ _get_pause_exit_state (void)
|
||||
INPUT_STATE InputState;
|
||||
|
||||
InputState = 0;
|
||||
if (KeyDown (PauseKey))
|
||||
if (KeyDown (PauseKey) && PauseFunc)
|
||||
{
|
||||
if (PauseFunc && (*PauseFunc) ())
|
||||
;
|
||||
PauseFunc();
|
||||
}
|
||||
else if (KeyDown (ExitKey))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -594,6 +402,7 @@ _get_serial_keyboard_state (INPUT_REF ref, INPUT_STATE InputState)
|
||||
// I hope these are defined somewhere...
|
||||
{
|
||||
Uint16 key;
|
||||
(void) ref;
|
||||
|
||||
if ((key = GetUNICODEKey ()) == '\r')
|
||||
key = '\n';
|
||||
@@ -603,35 +412,52 @@ _get_serial_keyboard_state (INPUT_REF ref, INPUT_STATE 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
|
||||
_get_joystick_keyboard_state (INPUT_REF InputRef, INPUT_STATE InputState)
|
||||
// see line above.
|
||||
{
|
||||
SBYTE dx, dy;
|
||||
BYTEPTR KeyEquivalentPtr;
|
||||
UWORD* KeyEquivalentPtr;
|
||||
|
||||
KeyEquivalentPtr = GetInputDeviceKeyEquivalentPtr (InputRef);
|
||||
dx = (SBYTE)(KeyDown (KeyEquivalentPtr[1]) -
|
||||
KeyDown (KeyEquivalentPtr[0]));
|
||||
dx = (SBYTE)(GetKeyboardDown (KeyEquivalentPtr[1]) -
|
||||
GetKeyboardDown (KeyEquivalentPtr[0]));
|
||||
SetInputXComponent (&InputState, dx);
|
||||
|
||||
KeyEquivalentPtr += 2;
|
||||
dy = (SBYTE)(KeyDown (KeyEquivalentPtr[1]) -
|
||||
KeyDown (KeyEquivalentPtr[0]));
|
||||
dy = (SBYTE)(GetKeyboardDown (KeyEquivalentPtr[1]) -
|
||||
GetKeyboardDown (KeyEquivalentPtr[0]));
|
||||
SetInputYComponent (&InputState, dy);
|
||||
|
||||
KeyEquivalentPtr += 2;
|
||||
if (KeyDown (*KeyEquivalentPtr++))
|
||||
if (GetKeyboardDown (*KeyEquivalentPtr++))
|
||||
InputState |= DEVICE_BUTTON1;
|
||||
if (KeyDown (*KeyEquivalentPtr++))
|
||||
if (GetKeyboardDown (*KeyEquivalentPtr++))
|
||||
InputState |= DEVICE_BUTTON2;
|
||||
if (KeyDown (*KeyEquivalentPtr++))
|
||||
if (GetKeyboardDown (*KeyEquivalentPtr++))
|
||||
InputState |= DEVICE_BUTTON3;
|
||||
|
||||
if (KeyDown (*KeyEquivalentPtr++))
|
||||
if (GetKeyboardDown (*KeyEquivalentPtr++))
|
||||
InputState |= DEVICE_LEFTSHIFT;
|
||||
if (KeyDown (*KeyEquivalentPtr++))
|
||||
if (GetKeyboardDown (*KeyEquivalentPtr++))
|
||||
InputState |= DEVICE_RIGHTSHIFT;
|
||||
|
||||
if (InputState)
|
||||
@@ -640,161 +466,76 @@ _get_joystick_keyboard_state (INPUT_REF InputRef, INPUT_STATE InputState)
|
||||
return (InputState);
|
||||
}
|
||||
|
||||
/*
|
||||
// Status: Implemented
|
||||
INPUT_STATE
|
||||
_get_joystick_state (INPUT_REF ref, INPUT_STATE InputState)
|
||||
// consistant, at least.
|
||||
static BOOLEAN
|
||||
GetJoystickDown (int port, UWORD map, UWORD threshold)
|
||||
{
|
||||
// fprintf (stderr, "Half-implemented function activated: _get_joystick_state()\n");
|
||||
|
||||
if (KeyboardStroke[SDLK_LEFT])
|
||||
int axis, sign;
|
||||
if (JOYISAXIS(map))
|
||||
{
|
||||
SetInputXComponent (&InputState, -1);
|
||||
// fprintf (stderr, "LEFT!\n");
|
||||
KeyboardStroke[SDLK_LEFT] = FALSE;
|
||||
axis = JOYGETVALUE(map);
|
||||
sign = JOYGETSIGN(map);
|
||||
if ((sign * JoyaxisValues[port][axis]) > threshold)
|
||||
return TRUE;
|
||||
}
|
||||
if (KeyboardStroke[SDLK_RIGHT])
|
||||
else
|
||||
{
|
||||
SetInputXComponent (&InputState, 1);
|
||||
// fprintf (stderr, "RIGHT!\n");
|
||||
KeyboardStroke[SDLK_RIGHT] = FALSE;
|
||||
}
|
||||
|
||||
if (KeyboardStroke[SDLK_UP])
|
||||
if (JOYISCHORD(map))
|
||||
{
|
||||
SetInputYComponent (&InputState, -1);
|
||||
// fprintf (stderr, "UP!\n");
|
||||
KeyboardStroke[SDLK_UP] = FALSE;
|
||||
UBYTE b1 = JoybuttonDown[port][JOYGETVALUE(map)];
|
||||
UBYTE b2 = JoybuttonDown[port][JOYGETCHORD(map)];
|
||||
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);
|
||||
// fprintf (stderr, "DOWN!\n");
|
||||
KeyboardStroke[SDLK_DOWN] = FALSE;
|
||||
JoybuttonDown[port][JOYGETVALUE(map)] &= (~0x2);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (KeyboardStroke[ControlA])
|
||||
{
|
||||
InputState |= DEVICE_BUTTON1;
|
||||
// fprintf (stderr, "BUTTON1!\n");
|
||||
KeyboardStroke[ControlA]=FALSE;
|
||||
}
|
||||
if (KeyboardStroke[ControlB])
|
||||
{
|
||||
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);
|
||||
return FALSE;
|
||||
}
|
||||
*/
|
||||
|
||||
INPUT_STATE
|
||||
_get_joystick_state (INPUT_REF ref, INPUT_STATE InputState)
|
||||
// consistant, at least.
|
||||
{
|
||||
#if 0
|
||||
if (ref == JoystickInput[1] && 0)
|
||||
{
|
||||
//fprintf (stderr, "ref\n");
|
||||
SBYTE dx, dy;
|
||||
UWORD *JoystickButtons = GetInputDeviceJoystickButtonPtr(ref);
|
||||
UWORD threshold = GetInputDeviceJoystickThreshold(ref);
|
||||
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, -1);
|
||||
//fprintf (stderr, "LEFT!\n");
|
||||
}
|
||||
if (KeyboardDown[SDLK_RIGHT])
|
||||
{
|
||||
SetInputXComponent (&InputState, 1);
|
||||
//fprintf (stderr, "RIGHT!\n");
|
||||
}
|
||||
SetInputXComponent(&InputState, dx);
|
||||
SetInputYComponent(&InputState, dy);
|
||||
|
||||
if (KeyboardDown[SDLK_UP])
|
||||
{
|
||||
SetInputYComponent (&InputState, -1);
|
||||
//fprintf (stderr, "UP!\n");
|
||||
}
|
||||
if (KeyboardDown[SDLK_DOWN])
|
||||
{
|
||||
SetInputYComponent (&InputState, 1);
|
||||
//fprintf (stderr, "DOWN!\n");
|
||||
}
|
||||
|
||||
if (KeyboardDown[ControlA])
|
||||
{
|
||||
if (GetJoystickDown(port, JoystickButtons[4], threshold))
|
||||
InputState |= DEVICE_BUTTON1;
|
||||
//fprintf (stderr, "BUTTON1!\n");
|
||||
}
|
||||
if (KeyboardDown[ControlB])
|
||||
{
|
||||
if (GetJoystickDown(port, JoystickButtons[5], threshold))
|
||||
InputState |= DEVICE_BUTTON2;
|
||||
//fprintf (stderr, "BUTTON2!\n");
|
||||
}
|
||||
if (KeyboardDown[ControlC])
|
||||
{
|
||||
if (GetJoystickDown(port, JoystickButtons[6], threshold))
|
||||
InputState |= DEVICE_BUTTON3;
|
||||
//fprintf (stderr, "BUTTON3!\n");
|
||||
}
|
||||
if (KeyboardDown[ControlX])
|
||||
{
|
||||
InputState |= DEVICE_EXIT;
|
||||
//fprintf (stderr, "BUTTONX!\n");
|
||||
}
|
||||
if (KeyboardDown[ControlStart])
|
||||
{
|
||||
InputState |= DEVICE_PAUSE;
|
||||
//fprintf (stderr, "CONTROLSTART!\n");
|
||||
}
|
||||
if (KeyboardDown[ControlLeftShift])
|
||||
{
|
||||
if (GetJoystickDown(port, JoystickButtons[7], threshold))
|
||||
InputState |= DEVICE_LEFTSHIFT;
|
||||
//fprintf (stderr, "LEFTSHIFT!\n");
|
||||
}
|
||||
if (KeyboardDown[ControlRightShift])
|
||||
{
|
||||
if (GetJoystickDown(port, JoystickButtons[8], threshold))
|
||||
InputState |= DEVICE_RIGHTSHIFT;
|
||||
//fprintf (stderr, "RIGHTSHIFT!\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return (InputState);
|
||||
if (InputState)
|
||||
SetInputDevType(&InputState, JOYSTICK_DEVICE);
|
||||
return InputState;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -19,18 +19,8 @@
|
||||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
extern Uint8 KeyboardDown[512];
|
||||
|
||||
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 ();
|
||||
UNICODE GetUNICODEKey (void);
|
||||
void FlushInput (void);
|
||||
void ProcessKeyboardEvent (const SDL_Event *Event);
|
||||
void ProcessJoystickEvent (const SDL_Event *Event);
|
||||
|
||||
|
||||
+204
-35
@@ -48,39 +48,218 @@ Semaphore GraphicsSem;
|
||||
CondVar RenderingCond;
|
||||
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
|
||||
LoadKeyConfig (FILE *fp, DWORD length)
|
||||
{
|
||||
COUNT i;
|
||||
BYTE buf[38], *pbuf;
|
||||
UWORD buf[18];
|
||||
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
|
||||
// mapped as left, right, thrust, ?, ?, fire, special, ?, ?
|
||||
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)
|
||||
// Look for pause, exit, abort keys
|
||||
for (i = 0; i < 3; ++i)
|
||||
{
|
||||
KeyboardInput[i] = CaptureInputDevice (
|
||||
CreateJoystickKeyboardDevice (
|
||||
pbuf[2], pbuf[4], pbuf[6], 0,
|
||||
0, pbuf[8], pbuf[0],
|
||||
0, 0x1b
|
||||
)
|
||||
for (;;)
|
||||
{
|
||||
if (feof(fp) || ferror(fp))
|
||||
break;
|
||||
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) */
|
||||
InitInput(PauseGame, specialKeys[0], specialKeys[1], specialKeys[2]);
|
||||
return (NULL_HANDLE);
|
||||
}
|
||||
|
||||
@@ -88,18 +267,8 @@ static void
|
||||
InitPlayerInput (void)
|
||||
{
|
||||
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 ());
|
||||
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);
|
||||
NormalInput = CaptureInputDevice (InputDevice);
|
||||
|
||||
@@ -181,16 +181,13 @@ PauseGame (void)
|
||||
FlushGraphics ();
|
||||
//SetSemaphore (GraphicsSem);
|
||||
|
||||
{
|
||||
BYTE scan;
|
||||
|
||||
scan = KBDToUNICODE (SK_F1);
|
||||
while (KeyDown (scan))
|
||||
while (KeyDown (PauseKey))
|
||||
TaskSwitch ();
|
||||
}
|
||||
|
||||
FlushInput ();
|
||||
while (KeyHit () != SK_F1)
|
||||
|
||||
// Wait for the pause key to be pressed again
|
||||
while (!KeyDown (PauseKey))
|
||||
TaskSwitch ();
|
||||
|
||||
s.frame = F;
|
||||
|
||||
Reference in New Issue
Block a user