2006-04-13 20:47:06 +00:00
|
|
|
/*
|
|
|
|
* control.c
|
|
|
|
* MACT library controller handling
|
2008-06-29 10:41:01 +00:00
|
|
|
*
|
2006-04-13 20:47:06 +00:00
|
|
|
* Derived from MACT386.LIB disassembly by Jonathon Fowler
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-12-21 12:53:11 +00:00
|
|
|
#include "compat.h"
|
2009-04-26 05:57:42 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#include "keyboard.h"
|
|
|
|
#include "mouse.h"
|
|
|
|
#include "control.h"
|
|
|
|
#include "_control.h"
|
|
|
|
#include "util_lib.h"
|
|
|
|
|
|
|
|
#include "baselayer.h"
|
2008-07-12 23:44:07 +00:00
|
|
|
#include "osd.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
#include "pragmas.h"
|
|
|
|
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t CONTROL_JoyPresent = FALSE;
|
|
|
|
int32_t CONTROL_JoystickEnabled = FALSE;
|
|
|
|
int32_t CONTROL_MousePresent = FALSE;
|
|
|
|
int32_t CONTROL_MouseEnabled = FALSE;
|
2009-09-09 07:19:14 +00:00
|
|
|
uint64_t CONTROL_ButtonState = 0;
|
|
|
|
uint64_t CONTROL_ButtonHeldState = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
// static int32_t CONTROL_UserInputDelay = -1;
|
2009-04-29 19:43:51 +00:00
|
|
|
float CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY;
|
2009-04-26 05:57:42 +00:00
|
|
|
static int32_t CONTROL_NumMouseButtons = 0;
|
|
|
|
static int32_t CONTROL_NumMouseAxes = 0;
|
|
|
|
static int32_t CONTROL_NumJoyButtons = 0;
|
|
|
|
static int32_t CONTROL_NumJoyAxes = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
static controlflags CONTROL_Flags[CONTROL_NUM_FLAGS];
|
|
|
|
static controlbuttontype CONTROL_MouseButtonMapping[MAXMOUSEBUTTONS],
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_JoyButtonMapping[MAXJOYBUTTONS];
|
2006-04-13 20:47:06 +00:00
|
|
|
static controlkeymaptype CONTROL_KeyMapping[CONTROL_NUM_FLAGS];
|
|
|
|
static controlaxismaptype CONTROL_MouseAxesMap[MAXMOUSEAXES], // maps physical axes onto virtual ones
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_JoyAxesMap[MAXJOYAXES];
|
2006-04-13 20:47:06 +00:00
|
|
|
static controlaxistype CONTROL_MouseAxes[MAXMOUSEAXES], // physical axes
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_JoyAxes[MAXJOYAXES];
|
2006-04-13 20:47:06 +00:00
|
|
|
static controlaxistype CONTROL_LastMouseAxes[MAXMOUSEAXES],
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_LastJoyAxes[MAXJOYAXES];
|
2009-04-26 05:57:42 +00:00
|
|
|
static int32_t CONTROL_MouseAxesScale[MAXMOUSEAXES], CONTROL_JoyAxesScale[MAXJOYAXES];
|
|
|
|
static int32_t CONTROL_MouseButtonState[MAXMOUSEBUTTONS], CONTROL_JoyButtonState[MAXJOYBUTTONS];
|
|
|
|
static int32_t CONTROL_MouseButtonClickedTime[MAXMOUSEBUTTONS], CONTROL_JoyButtonClickedTime[MAXJOYBUTTONS];
|
|
|
|
static int32_t CONTROL_MouseButtonClickedState[MAXMOUSEBUTTONS], CONTROL_JoyButtonClickedState[MAXJOYBUTTONS];
|
|
|
|
static int32_t CONTROL_MouseButtonClicked[MAXMOUSEBUTTONS], CONTROL_JoyButtonClicked[MAXJOYBUTTONS];
|
|
|
|
static uint8_t CONTROL_MouseButtonClickedCount[MAXMOUSEBUTTONS], CONTROL_JoyButtonClickedCount[MAXJOYBUTTONS];
|
|
|
|
static int32_t CONTROL_UserInputCleared[3];
|
|
|
|
static int32_t(*GetTime)(void);
|
2009-12-05 09:22:43 +00:00
|
|
|
int32_t CONTROL_Started = FALSE;
|
2009-04-26 05:57:42 +00:00
|
|
|
static int32_t ticrate;
|
|
|
|
static int32_t CONTROL_DoubleClickSpeed;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t extinput[CONTROL_NUM_FLAGS];
|
2009-01-10 07:38:50 +00:00
|
|
|
keybind KeyBindings[MAXBOUNDKEYS], MouseBindings[MAXMOUSEBUTTONS];
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t bindsenabled = 0;
|
|
|
|
int32_t control_smoothmouse = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
void CONTROL_GetMouseDelta(void)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t x,y;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
MOUSE_GetDelta(&x, &y);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-10-13 01:16:40 +00:00
|
|
|
if (control_smoothmouse)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
static int32_t lastx = 0, lasty = 0;
|
2008-10-13 01:16:40 +00:00
|
|
|
|
2009-07-09 02:29:48 +00:00
|
|
|
CONTROL_MouseAxes[0].analog = (int32_t)(((x + lastx) / 2.0f) * 4.0f * CONTROL_MouseSensitivity);
|
|
|
|
CONTROL_MouseAxes[1].analog = (int32_t)((((y + lasty) / 2.0f) * 4.0f * CONTROL_MouseSensitivity) * 2.0f);
|
2008-10-13 01:16:40 +00:00
|
|
|
lastx = x;
|
|
|
|
lasty = y;
|
|
|
|
return;
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-07-09 02:29:48 +00:00
|
|
|
CONTROL_MouseAxes[0].analog = (int32_t)(x * 4.0f * CONTROL_MouseSensitivity);
|
|
|
|
CONTROL_MouseAxes[1].analog = (int32_t)((y * 4.0f * CONTROL_MouseSensitivity) * 2.0f);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t CONTROL_StartMouse(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_NumMouseButtons = MAXMOUSEBUTTONS;
|
|
|
|
return MOUSE_Init();
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
void CONTROL_GetJoyAbs(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_FilterJoyDelta(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
void CONTROL_GetJoyDelta(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
|
|
|
for (i=0; i<joynumaxes; i++)
|
|
|
|
CONTROL_JoyAxes[i].analog = joyaxis[i] >> 5;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t CONTROL_StartJoy(int32_t joy)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2008-03-22 10:23:57 +00:00
|
|
|
UNREFERENCED_PARAMETER(joy);
|
2006-09-02 02:34:29 +00:00
|
|
|
return (inputdevices & 4) == 4;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_ShutJoy(int32_t joy)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2008-03-22 10:23:57 +00:00
|
|
|
UNREFERENCED_PARAMETER(joy);
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_JoyPresent = FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t CONTROL_GetTime(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
static int32_t t = 0;
|
2006-09-02 02:34:29 +00:00
|
|
|
t += 5;
|
|
|
|
return t;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
static inline int32_t CONTROL_CheckRange(int32_t which)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
if ((uint32_t)which >= (uint32_t)CONTROL_NUM_FLAGS) return TRUE;
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_CheckRange: Index %d out of valid range for %d control flags.",
|
|
|
|
// which, CONTROL_NUM_FLAGS);
|
2009-04-26 05:57:42 +00:00
|
|
|
return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_SetFlag(int32_t which, int32_t active)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_CheckRange(which)) return;
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (CONTROL_Flags[which].toggle == INSTANT_ONOFF)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_Flags[which].active = active;
|
2008-08-24 09:01:17 +00:00
|
|
|
return;
|
2008-06-29 10:41:01 +00:00
|
|
|
}
|
2008-08-24 09:01:17 +00:00
|
|
|
if (active)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_Flags[which].buttonheld = FALSE;
|
2008-08-24 09:01:17 +00:00
|
|
|
}
|
2009-04-26 05:57:42 +00:00
|
|
|
else if (CONTROL_Flags[which].buttonheld == FALSE)
|
2008-08-24 09:01:17 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_Flags[which].buttonheld = TRUE;
|
|
|
|
CONTROL_Flags[which].active = (CONTROL_Flags[which].active ? FALSE : TRUE);
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t CONTROL_KeyboardFunctionPressed(int32_t which)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t key1 = 0, key2 = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
if (CONTROL_CheckRange(which)) return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
if (!CONTROL_Flags[which].used) return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
if (CONTROL_KeyMapping[which].key1 != KEYUNDEFINED && !KeyBindings[CONTROL_KeyMapping[which].key1].cmd[0])
|
2009-04-26 05:57:42 +00:00
|
|
|
key1 = KB_KeyDown[ CONTROL_KeyMapping[which].key1 ] ? TRUE : FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
if (CONTROL_KeyMapping[which].key2 != KEYUNDEFINED && !KeyBindings[CONTROL_KeyMapping[which].key2].cmd[0])
|
2009-04-26 05:57:42 +00:00
|
|
|
key2 = KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] ? TRUE : FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
return (key1 | key2);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_ClearKeyboardFunction(int32_t which)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_CheckRange(which)) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
if (!CONTROL_Flags[which].used) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_KeyMapping[which].key1 != KEYUNDEFINED)
|
|
|
|
KB_KeyDown[ CONTROL_KeyMapping[which].key1 ] = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_KeyMapping[which].key2 != KEYUNDEFINED)
|
|
|
|
KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_DefineFlag(int32_t which, int32_t toggle)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_CheckRange(which)) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_Flags[which].active = FALSE;
|
|
|
|
CONTROL_Flags[which].used = TRUE;
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_Flags[which].toggle = toggle;
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_Flags[which].buttonheld = FALSE;
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_Flags[which].cleared = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t CONTROL_FlagActive(int32_t which)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
if (CONTROL_CheckRange(which)) return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
return CONTROL_Flags[which].used;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_MapKey(int32_t which, kb_scancode key1, kb_scancode key2)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_CheckRange(which)) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_KeyMapping[which].key1 = key1 ? key1 : KEYUNDEFINED;
|
|
|
|
CONTROL_KeyMapping[which].key2 = key2 ? key2 : KEYUNDEFINED;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_PrintKeyMap(void)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
for (i=0; i<CONTROL_NUM_FLAGS; i++)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
initprintf("function %2ld key1=%3x key2=%3x\n",
|
|
|
|
i, CONTROL_KeyMapping[i].key1, CONTROL_KeyMapping[i].key2);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_PrintControlFlag(int32_t which)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
initprintf("function %2ld active=%d used=%d toggle=%d buttonheld=%d cleared=%d\n",
|
2006-09-02 02:34:29 +00:00
|
|
|
which, CONTROL_Flags[which].active, CONTROL_Flags[which].used,
|
|
|
|
CONTROL_Flags[which].toggle, CONTROL_Flags[which].buttonheld,
|
|
|
|
CONTROL_Flags[which].cleared);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_PrintAxes(void)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
initprintf("nummouseaxes=%d\n", CONTROL_NumMouseAxes);
|
2009-04-26 05:57:42 +00:00
|
|
|
for (i=0; i<CONTROL_NumMouseAxes; i++)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
initprintf("axis=%d analog=%d digital1=%d digital2=%d\n",
|
2006-09-02 02:34:29 +00:00
|
|
|
i, CONTROL_MouseAxesMap[i].analogmap,
|
|
|
|
CONTROL_MouseAxesMap[i].minmap, CONTROL_MouseAxesMap[i].maxmap);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
initprintf("numjoyaxes=%d\n", CONTROL_NumJoyAxes);
|
2009-04-26 05:57:42 +00:00
|
|
|
for (i=0; i<CONTROL_NumJoyAxes; i++)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
initprintf("axis=%d analog=%d digital1=%d digital2=%d\n",
|
2006-09-02 02:34:29 +00:00
|
|
|
i, CONTROL_JoyAxesMap[i].analogmap,
|
|
|
|
CONTROL_JoyAxesMap[i].minmap, CONTROL_JoyAxesMap[i].maxmap);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_MapButton(int32_t whichfunction, int32_t whichbutton, int32_t doubleclicked, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
controlbuttontype *set;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_CheckRange(whichfunction)) whichfunction = BUTTONUNDEFINED;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_mouse:
|
2009-04-26 05:57:42 +00:00
|
|
|
if ((uint32_t)whichbutton >= (uint32_t)MAXMOUSEBUTTONS)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_MapButton: button %d out of valid range for %d mouse buttons.",
|
|
|
|
// whichbutton, CONTROL_NumMouseButtons);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
set = CONTROL_MouseButtonMapping;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_joystick:
|
2009-04-26 05:57:42 +00:00
|
|
|
if ((uint32_t)whichbutton >= (uint32_t)MAXJOYBUTTONS)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_MapButton: button %d out of valid range for %d joystick buttons.",
|
|
|
|
// whichbutton, CONTROL_NumJoyButtons);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
set = CONTROL_JoyButtonMapping;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//Error("CONTROL_MapButton: invalid controller device type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doubleclicked)
|
|
|
|
set[whichbutton].doubleclicked = whichfunction;
|
|
|
|
else
|
|
|
|
set[whichbutton].singleclicked = whichfunction;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_MapAnalogAxis(int32_t whichaxis, int32_t whichanalog, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
controlaxismaptype *set;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
if ((uint32_t)whichanalog >= (uint32_t)analog_maxtype)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_MapAnalogAxis: analog function %d out of valid range for %d analog functions.",
|
|
|
|
// whichanalog, analog_maxtype);
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_mouse:
|
2009-04-26 05:57:42 +00:00
|
|
|
if ((uint32_t)whichaxis >= (uint32_t)MAXMOUSEAXES)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_MapAnalogAxis: axis %d out of valid range for %d mouse axes.",
|
|
|
|
// whichaxis, MAXMOUSEAXES);
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
set = CONTROL_MouseAxesMap;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_joystick:
|
2009-04-26 05:57:42 +00:00
|
|
|
if ((uint32_t)whichaxis >= (uint32_t)MAXJOYAXES)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_MapAnalogAxis: axis %d out of valid range for %d joystick axes.",
|
|
|
|
// whichaxis, MAXJOYAXES);
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
set = CONTROL_JoyAxesMap;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
default:
|
|
|
|
//Error("CONTROL_MapAnalogAxis: invalid controller device type");
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
set[whichaxis].analogmap = whichanalog;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_SetAnalogAxisScale(int32_t whichaxis, int32_t axisscale, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t *set;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_mouse:
|
2009-04-26 05:57:42 +00:00
|
|
|
if ((uint32_t)whichaxis >= (uint32_t)MAXMOUSEAXES)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_SetAnalogAxisScale: axis %d out of valid range for %d mouse axes.",
|
|
|
|
// whichaxis, MAXMOUSEAXES);
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
set = CONTROL_MouseAxesScale;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_joystick:
|
2009-04-26 05:57:42 +00:00
|
|
|
if ((uint32_t)whichaxis >= (uint32_t)MAXJOYAXES)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_SetAnalogAxisScale: axis %d out of valid range for %d joystick axes.",
|
|
|
|
// whichaxis, MAXJOYAXES);
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
set = CONTROL_JoyAxesScale;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
default:
|
|
|
|
//Error("CONTROL_SetAnalogAxisScale: invalid controller device type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
set[whichaxis] = axisscale;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_MapDigitalAxis(int32_t whichaxis, int32_t whichfunction, int32_t direction, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
controlaxismaptype *set;
|
|
|
|
|
|
|
|
if (CONTROL_CheckRange(whichfunction)) whichfunction = AXISUNDEFINED;
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_mouse:
|
2009-04-26 05:57:42 +00:00
|
|
|
if ((uint32_t)whichaxis >= (uint32_t)MAXMOUSEAXES)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_MapDigitalAxis: axis %d out of valid range for %d mouse axes.",
|
|
|
|
// whichaxis, MAXMOUSEAXES);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
set = CONTROL_MouseAxesMap;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case controldevice_joystick:
|
2009-04-26 05:57:42 +00:00
|
|
|
if ((uint32_t)whichaxis >= (uint32_t)MAXJOYAXES)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
//Error("CONTROL_MapDigitalAxis: axis %d out of valid range for %d joystick axes.",
|
|
|
|
// whichaxis, MAXJOYAXES);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
set = CONTROL_JoyAxesMap;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//Error("CONTROL_MapDigitalAxis: invalid controller device type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (direction) // JBF: this is all very much a guess. The ASM puzzles me.
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case axis_up:
|
|
|
|
case axis_left:
|
|
|
|
set[whichaxis].minmap = whichfunction;
|
|
|
|
break;
|
|
|
|
case axis_down:
|
|
|
|
case axis_right:
|
|
|
|
set[whichaxis].maxmap = whichfunction;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
void CONTROL_ClearAssignments(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
memset(CONTROL_MouseButtonMapping, BUTTONUNDEFINED, sizeof(CONTROL_MouseButtonMapping));
|
|
|
|
memset(CONTROL_JoyButtonMapping, BUTTONUNDEFINED, sizeof(CONTROL_JoyButtonMapping));
|
|
|
|
memset(CONTROL_KeyMapping, KEYUNDEFINED, sizeof(CONTROL_KeyMapping));
|
|
|
|
memset(CONTROL_MouseAxesMap, AXISUNDEFINED, sizeof(CONTROL_MouseAxesMap));
|
|
|
|
memset(CONTROL_JoyAxesMap, AXISUNDEFINED, sizeof(CONTROL_JoyAxesMap));
|
|
|
|
memset(CONTROL_MouseAxes, 0, sizeof(CONTROL_MouseAxes));
|
|
|
|
memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes));
|
|
|
|
memset(CONTROL_LastMouseAxes, 0, sizeof(CONTROL_LastMouseAxes));
|
|
|
|
memset(CONTROL_LastJoyAxes, 0, sizeof(CONTROL_LastJoyAxes));
|
2009-04-26 05:57:42 +00:00
|
|
|
for (i=0; i<MAXMOUSEAXES; i++)
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_MouseAxesScale[i] = NORMALAXISSCALE;
|
2009-04-26 05:57:42 +00:00
|
|
|
for (i=0; i<MAXJOYAXES; i++)
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_JoyAxesScale[i] = NORMALAXISSCALE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void DoGetDeviceButtons(
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t buttons, int32_t tm,
|
|
|
|
int32_t NumButtons,
|
|
|
|
int32_t *DeviceButtonState,
|
|
|
|
int32_t *ButtonClickedTime,
|
|
|
|
int32_t *ButtonClickedState,
|
|
|
|
int32_t *ButtonClicked,
|
|
|
|
uint8_t *ButtonClickedCount
|
2008-06-29 10:41:01 +00:00
|
|
|
)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i=NumButtons-1, bs;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
for (; i>=0; i--)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
bs = (buttons >> i) & 1;
|
|
|
|
|
|
|
|
DeviceButtonState[i] = bs;
|
2009-04-26 05:57:42 +00:00
|
|
|
ButtonClickedState[i] = FALSE;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (bs)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
if (ButtonClicked[i] == FALSE)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
ButtonClicked[i] = TRUE;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (ButtonClickedCount[i] == 0 || tm > ButtonClickedTime[i])
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
ButtonClickedTime[i] = tm + CONTROL_DoubleClickSpeed;
|
|
|
|
ButtonClickedCount[i] = 1;
|
|
|
|
}
|
2008-06-29 10:41:01 +00:00
|
|
|
else if (tm < ButtonClickedTime[i])
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
ButtonClickedState[i] = TRUE;
|
2006-09-02 02:34:29 +00:00
|
|
|
ButtonClickedTime[i] = 0;
|
|
|
|
ButtonClickedCount[i] = 2;
|
|
|
|
}
|
|
|
|
}
|
2008-06-29 10:41:01 +00:00
|
|
|
else if (ButtonClickedCount[i] == 2)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
ButtonClickedState[i] = TRUE;
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2008-08-24 05:39:28 +00:00
|
|
|
continue;
|
2008-06-29 10:41:01 +00:00
|
|
|
}
|
2008-08-24 05:39:28 +00:00
|
|
|
if (ButtonClickedCount[i] == 2)
|
|
|
|
ButtonClickedCount[i] = 0;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
ButtonClicked[i] = FALSE;
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_GetDeviceButtons(void)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t t;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
|
|
|
t = GetTime();
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (CONTROL_MouseEnabled)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
DoGetDeviceButtons(
|
|
|
|
MOUSE_GetButtons(), t,
|
|
|
|
CONTROL_NumMouseButtons,
|
|
|
|
CONTROL_MouseButtonState,
|
|
|
|
CONTROL_MouseButtonClickedTime,
|
|
|
|
CONTROL_MouseButtonClickedState,
|
|
|
|
CONTROL_MouseButtonClicked,
|
|
|
|
CONTROL_MouseButtonClickedCount
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (CONTROL_JoystickEnabled)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t buttons = joyb;
|
2008-06-29 10:41:01 +00:00
|
|
|
if (joynumhats > 0 && joyhat[0] != -1)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
static int32_t hatstate[] = { 1, 1|2, 2, 2|4, 4, 4|8, 8, 8|1 };
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t val;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
|
|
|
// thanks SDL for this much more sensible method
|
|
|
|
val = ((joyhat[0] + 4500 / 2) % 36000) / 4500;
|
|
|
|
if (val < 8) buttons |= hatstate[val] << min(MAXJOYBUTTONS,joynumbuttons);
|
|
|
|
}
|
|
|
|
|
|
|
|
DoGetDeviceButtons(
|
|
|
|
buttons, t,
|
|
|
|
CONTROL_NumJoyButtons,
|
|
|
|
CONTROL_JoyButtonState,
|
|
|
|
CONTROL_JoyButtonClickedTime,
|
|
|
|
CONTROL_JoyButtonClickedState,
|
|
|
|
CONTROL_JoyButtonClicked,
|
|
|
|
CONTROL_JoyButtonClickedCount
|
|
|
|
);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_DigitizeAxis(int32_t axis, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
controlaxistype *set, *lastset;
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_mouse:
|
|
|
|
set = CONTROL_MouseAxes;
|
|
|
|
lastset = CONTROL_LastMouseAxes;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case controldevice_joystick:
|
|
|
|
set = CONTROL_JoyAxes;
|
|
|
|
lastset = CONTROL_LastJoyAxes;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (set[axis].analog > 0)
|
|
|
|
{
|
2008-08-24 09:01:17 +00:00
|
|
|
if (set[axis].analog > THRESHOLD || (set[axis].analog > MINTHRESHOLD && lastset[axis].digital == 1))
|
|
|
|
set[axis].digital = 1;
|
2008-06-29 10:41:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-24 09:01:17 +00:00
|
|
|
if (set[axis].analog < -THRESHOLD || (set[axis].analog < -MINTHRESHOLD && lastset[axis].digital == -1))
|
2006-09-02 02:34:29 +00:00
|
|
|
set[axis].digital = -1;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_ScaleAxis(int32_t axis, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
controlaxistype *set;
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t *scale;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_mouse:
|
|
|
|
set = CONTROL_MouseAxes;
|
|
|
|
scale = CONTROL_MouseAxesScale;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_joystick:
|
|
|
|
set = CONTROL_JoyAxes;
|
|
|
|
scale = CONTROL_JoyAxesScale;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
set[axis].analog = mulscale16(set[axis].analog, scale[axis]);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_ApplyAxis(int32_t axis, ControlInfo *info, controldevice device)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
controlaxistype *set;
|
|
|
|
controlaxismaptype *map;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_mouse:
|
|
|
|
set = CONTROL_MouseAxes;
|
|
|
|
map = CONTROL_MouseAxesMap;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
case controldevice_joystick:
|
|
|
|
set = CONTROL_JoyAxes;
|
|
|
|
map = CONTROL_JoyAxesMap;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
switch (map[axis].analogmap)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
case analog_turning: info->dyaw += set[axis].analog; break;
|
|
|
|
case analog_strafing: info->dx += set[axis].analog; break;
|
|
|
|
case analog_lookingupanddown: info->dpitch += set[axis].analog; break;
|
|
|
|
case analog_elevation: info->dy += set[axis].analog; break;
|
|
|
|
case analog_rolling: info->droll += set[axis].analog; break;
|
|
|
|
case analog_moving: info->dz += set[axis].analog; break;
|
|
|
|
default: break;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_PollDevices(ControlInfo *info)
|
|
|
|
{
|
2009-06-09 06:19:58 +00:00
|
|
|
Bmemcpy(CONTROL_LastMouseAxes, CONTROL_MouseAxes, sizeof(CONTROL_MouseAxes));
|
|
|
|
Bmemcpy(CONTROL_LastJoyAxes, CONTROL_JoyAxes, sizeof(CONTROL_JoyAxes));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
memset(CONTROL_MouseAxes, 0, sizeof(CONTROL_MouseAxes));
|
|
|
|
memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes));
|
|
|
|
memset(info, 0, sizeof(ControlInfo));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (CONTROL_MouseEnabled)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i = MAXMOUSEAXES-1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-08-24 09:01:17 +00:00
|
|
|
CONTROL_GetMouseDelta();
|
2008-08-24 04:55:57 +00:00
|
|
|
do
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_DigitizeAxis(i, controldevice_mouse);
|
|
|
|
CONTROL_ScaleAxis(i, controldevice_mouse);
|
|
|
|
LIMITCONTROL(&CONTROL_MouseAxes[i].analog);
|
|
|
|
CONTROL_ApplyAxis(i, info, controldevice_mouse);
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2008-08-24 09:01:17 +00:00
|
|
|
while (--i);
|
|
|
|
|
|
|
|
CONTROL_DigitizeAxis(0, controldevice_mouse);
|
|
|
|
CONTROL_ScaleAxis(0, controldevice_mouse);
|
|
|
|
LIMITCONTROL(&CONTROL_MouseAxes[0].analog);
|
|
|
|
CONTROL_ApplyAxis(0, info, controldevice_mouse);
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2008-08-24 04:55:57 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
if (CONTROL_JoystickEnabled)
|
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i = MAXJOYAXES-1;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2008-08-24 09:01:17 +00:00
|
|
|
CONTROL_GetJoyDelta();
|
2008-08-24 04:55:57 +00:00
|
|
|
do
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_DigitizeAxis(i, controldevice_joystick);
|
|
|
|
CONTROL_ScaleAxis(i, controldevice_joystick);
|
|
|
|
LIMITCONTROL(&CONTROL_JoyAxes[i].analog);
|
|
|
|
CONTROL_ApplyAxis(i, info, controldevice_joystick);
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2008-08-24 09:01:17 +00:00
|
|
|
while (--i);
|
|
|
|
|
|
|
|
CONTROL_DigitizeAxis(0, controldevice_joystick);
|
|
|
|
CONTROL_ScaleAxis(0, controldevice_joystick);
|
|
|
|
LIMITCONTROL(&CONTROL_JoyAxes[0].analog);
|
|
|
|
CONTROL_ApplyAxis(0, info, controldevice_joystick);
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CONTROL_GetDeviceButtons();
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_AxisFunctionState(int32_t *p1)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2008-08-24 06:06:04 +00:00
|
|
|
if (CONTROL_NumMouseAxes)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t j, i = CONTROL_NumMouseAxes-1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-08-24 06:06:04 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!CONTROL_MouseAxes[i].digital) continue;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-08-24 06:06:04 +00:00
|
|
|
if (CONTROL_MouseAxes[i].digital < 0)
|
|
|
|
j = CONTROL_MouseAxesMap[i].minmap;
|
|
|
|
else
|
|
|
|
j = CONTROL_MouseAxesMap[i].maxmap;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-08-24 06:06:04 +00:00
|
|
|
if (j != AXISUNDEFINED)
|
|
|
|
p1[j] = 1;
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2008-08-24 23:24:14 +00:00
|
|
|
while (i--);
|
2008-08-24 06:06:04 +00:00
|
|
|
}
|
2008-08-24 04:55:57 +00:00
|
|
|
|
2008-08-24 06:06:04 +00:00
|
|
|
if (CONTROL_NumJoyAxes)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t j, i = CONTROL_NumJoyAxes-1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-08-24 06:06:04 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!CONTROL_JoyAxes[i].digital) continue;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2008-08-24 06:06:04 +00:00
|
|
|
if (CONTROL_JoyAxes[i].digital < 0)
|
|
|
|
j = CONTROL_JoyAxesMap[i].minmap;
|
|
|
|
else
|
|
|
|
j = CONTROL_JoyAxesMap[i].maxmap;
|
|
|
|
|
|
|
|
if (j != AXISUNDEFINED)
|
|
|
|
p1[j] = 1;
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2008-08-24 23:24:14 +00:00
|
|
|
while (i--);
|
2008-08-24 06:06:04 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_ButtonFunctionState(int32_t *p1)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2008-08-24 09:01:17 +00:00
|
|
|
if (CONTROL_NumMouseButtons)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i = CONTROL_NumMouseButtons-1, j;
|
2008-08-24 09:01:17 +00:00
|
|
|
|
|
|
|
do
|
2008-06-30 19:06:05 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
if (!MouseBindings[i].cmd[0])
|
2008-08-24 09:01:17 +00:00
|
|
|
{
|
|
|
|
j = CONTROL_MouseButtonMapping[i].doubleclicked;
|
|
|
|
if (j != KEYUNDEFINED)
|
|
|
|
p1[j] |= CONTROL_MouseButtonClickedState[i];
|
2008-06-30 19:06:05 +00:00
|
|
|
|
2008-08-24 09:01:17 +00:00
|
|
|
j = CONTROL_MouseButtonMapping[i].singleclicked;
|
|
|
|
if (j != KEYUNDEFINED)
|
|
|
|
p1[j] |= CONTROL_MouseButtonState[i];
|
|
|
|
}
|
2008-08-24 06:17:09 +00:00
|
|
|
|
2008-08-24 09:01:17 +00:00
|
|
|
if (!bindsenabled)
|
|
|
|
continue;
|
2008-08-24 06:17:09 +00:00
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
if (MouseBindings[i].cmd[0] && CONTROL_MouseButtonState[i])
|
2008-08-24 09:01:17 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
if (MouseBindings[i].repeat || (MouseBindings[i].laststate == 0))
|
|
|
|
OSD_Dispatch(MouseBindings[i].cmd);
|
2008-08-24 09:01:17 +00:00
|
|
|
}
|
2009-01-10 07:38:50 +00:00
|
|
|
MouseBindings[i].laststate = CONTROL_MouseButtonState[i];
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2008-08-24 23:24:14 +00:00
|
|
|
while (i--);
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-08-24 09:01:17 +00:00
|
|
|
if (CONTROL_NumJoyButtons)
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i=CONTROL_NumJoyButtons-1, j;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-08-24 09:01:17 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
j = CONTROL_JoyButtonMapping[i].doubleclicked;
|
|
|
|
if (j != KEYUNDEFINED)
|
|
|
|
p1[j] |= CONTROL_JoyButtonClickedState[i];
|
|
|
|
|
|
|
|
j = CONTROL_JoyButtonMapping[i].singleclicked;
|
|
|
|
if (j != KEYUNDEFINED)
|
|
|
|
p1[j] |= CONTROL_JoyButtonState[i];
|
|
|
|
}
|
2008-08-24 23:24:14 +00:00
|
|
|
while (i--);
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2006-04-30 00:40:41 +00:00
|
|
|
/*
|
2006-04-13 20:47:06 +00:00
|
|
|
void CONTROL_GetUserInput( UserInput *info )
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
ControlInfo ci;
|
|
|
|
|
|
|
|
CONTROL_PollDevices( &ci );
|
|
|
|
|
|
|
|
info->dir = dir_None;
|
|
|
|
|
|
|
|
// checks if CONTROL_UserInputDelay is too far in the future due to clock skew?
|
|
|
|
if (GetTime() + ((ticrate * USERINPUTDELAY) / 1000) < CONTROL_UserInputDelay)
|
|
|
|
CONTROL_UserInputDelay = -1;
|
|
|
|
|
|
|
|
if (GetTime() >= CONTROL_UserInputDelay) {
|
|
|
|
if (CONTROL_MouseAxes[1].digital == -1)
|
|
|
|
info->dir = dir_North;
|
|
|
|
else if (CONTROL_MouseAxes[1].digital == 1)
|
|
|
|
info->dir = dir_South;
|
|
|
|
else if (CONTROL_MouseAxes[0].digital == -1)
|
|
|
|
info->dir = dir_West;
|
|
|
|
else if (CONTROL_MouseAxes[0].digital == 1)
|
|
|
|
info->dir = dir_East;
|
|
|
|
|
|
|
|
if (CONTROL_JoyAxes[1].digital == -1)
|
|
|
|
info->dir = dir_North;
|
|
|
|
else if (CONTROL_JoyAxes[1].digital == 1)
|
|
|
|
info->dir = dir_South;
|
|
|
|
else if (CONTROL_JoyAxes[0].digital == -1)
|
|
|
|
info->dir = dir_West;
|
|
|
|
else if (CONTROL_JoyAxes[0].digital == 1)
|
|
|
|
info->dir = dir_East;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->button0 = CONTROL_MouseButtonState[0] | CONTROL_JoyButtonState[0];
|
|
|
|
info->button1 = CONTROL_MouseButtonState[1] | CONTROL_JoyButtonState[1];
|
|
|
|
|
|
|
|
if (KB_KeyDown[sc_kpad_8] || KB_KeyDown[sc_UpArrow])
|
|
|
|
info->dir = dir_North;
|
|
|
|
else if (KB_KeyDown[sc_kpad_2] || KB_KeyDown[sc_DownArrow])
|
|
|
|
info->dir = dir_South;
|
|
|
|
else if (KB_KeyDown[sc_kpad_4] || KB_KeyDown[sc_LeftArrow])
|
|
|
|
info->dir = dir_West;
|
|
|
|
else if (KB_KeyDown[sc_kpad_6] || KB_KeyDown[sc_RightArrow])
|
|
|
|
info->dir = dir_East;
|
|
|
|
|
|
|
|
if (KB_KeyDown[BUTTON0_SCAN_1] || KB_KeyDown[BUTTON0_SCAN_2] || KB_KeyDown[BUTTON0_SCAN_3])
|
|
|
|
info->button0 = 1;
|
|
|
|
if (KB_KeyDown[BUTTON1_SCAN])
|
|
|
|
info->button1 = 1;
|
|
|
|
|
|
|
|
if (CONTROL_UserInputCleared[1]) {
|
|
|
|
if (!info->button0)
|
|
|
|
CONTROL_UserInputCleared[1] = false;
|
|
|
|
else
|
|
|
|
info->button0 = false;
|
|
|
|
}
|
|
|
|
if (CONTROL_UserInputCleared[2]) {
|
|
|
|
if (!info->button1)
|
|
|
|
CONTROL_UserInputCleared[2] = false;
|
|
|
|
else
|
|
|
|
info->button1 = false;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_ClearUserInput( UserInput *info )
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
switch (info->dir) {
|
|
|
|
case dir_North:
|
|
|
|
case dir_South:
|
|
|
|
case dir_East:
|
|
|
|
case dir_West:
|
|
|
|
CONTROL_UserInputCleared[0] = true;
|
|
|
|
CONTROL_UserInputDelay = GetTime() + ((ticrate * USERINPUTDELAY) / 1000);
|
|
|
|
switch (info->dir) {
|
|
|
|
case dir_North: KB_KeyDown[sc_UpArrow] = KB_KeyDown[sc_kpad_8] = 0; break;
|
|
|
|
case dir_South: KB_KeyDown[sc_DownArrow] = KB_KeyDown[sc_kpad_2] = 0; break;
|
|
|
|
case dir_East: KB_KeyDown[sc_LeftArrow] = KB_KeyDown[sc_kpad_4] = 0; break;
|
|
|
|
case dir_West: KB_KeyDown[sc_RightArrow] = KB_KeyDown[sc_kpad_6] = 0; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
if (info->button0) CONTROL_UserInputCleared[1] = true;
|
|
|
|
if (info->button1) CONTROL_UserInputCleared[2] = true;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2006-04-30 00:40:41 +00:00
|
|
|
*/
|
2009-04-26 05:57:42 +00:00
|
|
|
void CONTROL_ClearButton(int32_t whichbutton)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2008-06-29 10:41:01 +00:00
|
|
|
if (CONTROL_CheckRange(whichbutton)) return;
|
|
|
|
BUTTONCLEAR(whichbutton);
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_Flags[whichbutton].cleared = TRUE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
inline void CONTROL_ProcessBinds(void)
|
2008-06-29 10:40:37 +00:00
|
|
|
{
|
2009-06-09 06:19:58 +00:00
|
|
|
if (!bindsenabled)
|
|
|
|
return;
|
2008-08-24 09:01:17 +00:00
|
|
|
|
2008-06-29 10:40:37 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i=MAXBOUNDKEYS-1;
|
2008-08-24 09:01:17 +00:00
|
|
|
|
|
|
|
do
|
2008-06-29 10:40:37 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
if (KeyBindings[i].cmd[0] && KB_KeyPressed(i))
|
2008-08-24 09:01:17 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
if (KeyBindings[i].repeat || (KeyBindings[i].laststate == 0))
|
|
|
|
OSD_Dispatch(KeyBindings[i].cmd);
|
2008-08-24 09:01:17 +00:00
|
|
|
}
|
2009-01-10 07:38:50 +00:00
|
|
|
KeyBindings[i].laststate = KB_KeyPressed(i);
|
2008-06-29 10:40:37 +00:00
|
|
|
}
|
2008-08-24 09:01:17 +00:00
|
|
|
while (--i);
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2008-08-24 04:55:57 +00:00
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
if (KeyBindings[0].cmd[0] && KB_KeyPressed(0))
|
2008-08-24 04:55:57 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
if (KeyBindings[0].repeat || (KeyBindings[0].laststate == 0))
|
|
|
|
OSD_Dispatch(KeyBindings[0].cmd);
|
2008-06-29 10:40:37 +00:00
|
|
|
}
|
2009-01-10 07:38:50 +00:00
|
|
|
KeyBindings[0].laststate = KB_KeyPressed(0);
|
2008-06-29 10:40:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
void CONTROL_GetInput(ControlInfo *info)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t periphs[CONTROL_NUM_FLAGS];
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
CONTROL_PollDevices(info);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
memset(periphs, 0, sizeof(periphs));
|
|
|
|
CONTROL_ButtonFunctionState(periphs);
|
|
|
|
CONTROL_AxisFunctionState(periphs);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
CONTROL_ButtonHeldState = CONTROL_ButtonState;
|
|
|
|
CONTROL_ButtonState = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-29 10:40:37 +00:00
|
|
|
CONTROL_ProcessBinds();
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i = CONTROL_NUM_FLAGS-1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-08-24 04:55:57 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
CONTROL_SetFlag(i, CONTROL_KeyboardFunctionPressed(i) | periphs[i] | extinput[i]);
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
if (CONTROL_Flags[i].cleared == FALSE) BUTTONSET(i, CONTROL_Flags[i].active);
|
|
|
|
else if (CONTROL_Flags[i].active == FALSE) CONTROL_Flags[i].cleared = 0;
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
|
|
|
while (--i);
|
2008-08-24 04:55:57 +00:00
|
|
|
|
|
|
|
CONTROL_SetFlag(0, CONTROL_KeyboardFunctionPressed(0) | periphs[0] | extinput[0]);
|
2009-04-26 05:57:42 +00:00
|
|
|
if (CONTROL_Flags[0].cleared == FALSE) BUTTONSET(0, CONTROL_Flags[0].active);
|
|
|
|
else if (CONTROL_Flags[0].active == FALSE) CONTROL_Flags[0].cleared = 0;
|
2006-09-02 02:34:29 +00:00
|
|
|
}
|
2008-08-24 04:55:57 +00:00
|
|
|
|
2008-06-29 10:40:37 +00:00
|
|
|
memset(extinput, 0, sizeof(extinput));
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
void CONTROL_WaitRelease(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-06-29 10:41:01 +00:00
|
|
|
void CONTROL_Ack(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t CONTROL_Startup(controltype which, int32_t(*TimeFunction)(void), int32_t ticspersecond)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-04-26 05:57:42 +00:00
|
|
|
int32_t i;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2008-03-22 10:23:57 +00:00
|
|
|
UNREFERENCED_PARAMETER(which);
|
2008-03-21 04:01:38 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
if (CONTROL_Started) return FALSE;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
|
|
|
if (TimeFunction) GetTime = TimeFunction;
|
|
|
|
else GetTime = CONTROL_GetTime;
|
|
|
|
|
|
|
|
ticrate = ticspersecond;
|
|
|
|
|
|
|
|
CONTROL_DoubleClickSpeed = (ticspersecond*57)/100;
|
|
|
|
if (CONTROL_DoubleClickSpeed <= 0)
|
|
|
|
CONTROL_DoubleClickSpeed = 1;
|
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
if (initinput()) return TRUE;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_MousePresent = CONTROL_MouseEnabled = FALSE;
|
|
|
|
CONTROL_JoyPresent = CONTROL_JoystickEnabled = FALSE;
|
2006-09-02 02:34:29 +00:00
|
|
|
CONTROL_NumMouseButtons = CONTROL_NumJoyButtons = 0;
|
|
|
|
CONTROL_NumMouseAxes = CONTROL_NumJoyAxes = 0;
|
|
|
|
KB_Startup();
|
|
|
|
|
|
|
|
//switch (which) {
|
|
|
|
// case controltype_keyboard:
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// case controltype_keyboardandmouse:
|
|
|
|
CONTROL_NumMouseAxes = MAXMOUSEAXES;
|
|
|
|
CONTROL_NumMouseButtons = MAXMOUSEBUTTONS;
|
|
|
|
CONTROL_MousePresent = MOUSE_Init();
|
|
|
|
CONTROL_MouseEnabled = CONTROL_MousePresent;
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// case controltype_keyboardandjoystick:
|
|
|
|
CONTROL_NumJoyAxes = min(MAXJOYAXES,joynumaxes);
|
|
|
|
CONTROL_NumJoyButtons = min(MAXJOYBUTTONS,joynumbuttons + 4*(joynumhats>0));
|
|
|
|
CONTROL_JoyPresent = CONTROL_StartJoy(0);;
|
|
|
|
CONTROL_JoystickEnabled = CONTROL_JoyPresent;
|
|
|
|
// break;
|
|
|
|
//}
|
|
|
|
|
2008-07-09 23:25:38 +00:00
|
|
|
/*
|
2006-09-02 02:34:29 +00:00
|
|
|
if (CONTROL_MousePresent)
|
|
|
|
initprintf("CONTROL_Startup: Mouse Present\n");
|
|
|
|
if (CONTROL_JoyPresent)
|
|
|
|
initprintf("CONTROL_Startup: Joystick Present\n");
|
2008-07-09 23:25:38 +00:00
|
|
|
*/
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
CONTROL_ButtonState = 0;
|
|
|
|
CONTROL_ButtonHeldState = 0;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
|
|
|
memset(CONTROL_UserInputCleared, 0, sizeof(CONTROL_UserInputCleared));
|
|
|
|
|
|
|
|
for (i=0; i<CONTROL_NUM_FLAGS; i++)
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_Flags[i].used = FALSE;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_Started = TRUE;
|
2006-09-02 02:34:29 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
return FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_Shutdown(void)
|
|
|
|
{
|
2006-09-02 02:34:29 +00:00
|
|
|
if (!CONTROL_Started) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_JoyPresent = FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-02 02:34:29 +00:00
|
|
|
MOUSE_Shutdown();
|
|
|
|
uninitinput();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-26 05:57:42 +00:00
|
|
|
CONTROL_Started = FALSE;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|