mirror of
https://github.com/libretro/RetroArch
synced 2024-12-28 09:29:16 +00:00
Should fix up some flaws with joypad support.
This commit is contained in:
parent
b813518f69
commit
28ae93ed23
56
config.h.def
56
config.h.def
@ -122,6 +122,12 @@ static const bool audio_sync = true;
|
||||
// How far an axis must be tilted to result in a button press
|
||||
#define AXIS_THRESHOLD 0.8
|
||||
|
||||
#define AXIS_NEG(x) ((uint32_t)(x << 16) | 0xFFFF)
|
||||
#define AXIS_POS(x) ((uint32_t)(x) | 0xFFFF0000U)
|
||||
#define AXIS_NEG_GET(x) ((x >> 16) & 0xFFFF)
|
||||
#define AXIS_POS_GET(x) (x & 0xFFFF)
|
||||
#define AXIS_NONE ((uint32_t)0xFFFFFFFFU)
|
||||
|
||||
// To figure out which joypad buttons to use, check jstest or similar.
|
||||
// Axes are configured using the axis number for the positive (up, right)
|
||||
// direction and the number's two's-complement (~) for negative directions.
|
||||
@ -130,37 +136,37 @@ static const bool audio_sync = true;
|
||||
// Player 1
|
||||
static const struct snes_keybind snes_keybinds_1[] = {
|
||||
// SNES button | keyboard key | js btn | js axis |
|
||||
{ SNES_DEVICE_ID_JOYPAD_A, 'X', 1, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_B, 'Z', 0, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_X, 'S', 3, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_Y, 'A', 2, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_L, 'Q', 4, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_R, 'W', 5, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_LEFT, GLFW_KEY_LEFT, 11, ~4 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_RIGHT, GLFW_KEY_RIGHT, 12, 4 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_UP, GLFW_KEY_UP, 13, 5 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_DOWN, GLFW_KEY_DOWN, 14, ~5 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_START, GLFW_KEY_ENTER, 6, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_SELECT, GLFW_KEY_RSHIFT, 7, 0 },
|
||||
{ SNES_FAST_FORWARD_KEY, GLFW_KEY_SPACE, 9, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_A, 'X', 1, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_B, 'Z', 0, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_X, 'S', 3, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_Y, 'A', 2, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_L, 'Q', 4, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_R, 'W', 5, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_LEFT, GLFW_KEY_LEFT, 11, AXIS_NEG(0) },
|
||||
{ SNES_DEVICE_ID_JOYPAD_RIGHT, GLFW_KEY_RIGHT, 12, AXIS_POS(0) },
|
||||
{ SNES_DEVICE_ID_JOYPAD_UP, GLFW_KEY_UP, 13, AXIS_POS(1) },
|
||||
{ SNES_DEVICE_ID_JOYPAD_DOWN, GLFW_KEY_DOWN, 14, AXIS_NEG(1) },
|
||||
{ SNES_DEVICE_ID_JOYPAD_START, GLFW_KEY_ENTER, 7, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_SELECT, GLFW_KEY_RSHIFT, 6, AXIS_NONE },
|
||||
{ SNES_FAST_FORWARD_KEY, GLFW_KEY_SPACE, 10, AXIS_NONE },
|
||||
{ -1 }
|
||||
};
|
||||
|
||||
// Player 2
|
||||
static const struct snes_keybind snes_keybinds_2[] = {
|
||||
// SNES button | keyboard key | js btn | js axis |
|
||||
{ SNES_DEVICE_ID_JOYPAD_A, 'B', 1, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_B, 'V', 0, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_X, 'G', 3, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_Y, 'F', 2, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_L, 'R', 4, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_R, 'T', 5, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_LEFT, 'J', 11, ~4 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_RIGHT, 'L', 12, 4 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_UP, 'I', 13, 5 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_DOWN, 'K', 14, ~5 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_START, 'P', 6, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_SELECT, 'O', 7, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_A, 'B', 1, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_B, 'V', 0, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_X, 'G', 3, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_Y, 'F', 2, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_L, 'R', 4, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_R, 'T', 5, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_LEFT, 'J', 11, AXIS_NEG(0) },
|
||||
{ SNES_DEVICE_ID_JOYPAD_RIGHT, 'L', 12, AXIS_POS(0) },
|
||||
{ SNES_DEVICE_ID_JOYPAD_UP, 'I', 13, AXIS_POS(1) },
|
||||
{ SNES_DEVICE_ID_JOYPAD_DOWN, 'K', 14, AXIS_NEG(1) },
|
||||
{ SNES_DEVICE_ID_JOYPAD_START, 'P', 6, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_SELECT, 'O', 7, AXIS_NONE },
|
||||
{ -1 }
|
||||
};
|
||||
|
||||
|
6
driver.h
6
driver.h
@ -30,9 +30,9 @@ void set_fast_forward_button(bool state);
|
||||
struct snes_keybind
|
||||
{
|
||||
int id;
|
||||
int key;
|
||||
int joykey;
|
||||
int joyaxis;
|
||||
uint16_t key;
|
||||
uint16_t joykey;
|
||||
uint32_t joyaxis;
|
||||
};
|
||||
|
||||
typedef struct video_info
|
||||
|
24
gl.c
24
gl.c
@ -77,11 +77,11 @@ static void glfw_input_poll(void *data)
|
||||
#define BUTTONS_MAX 128
|
||||
#define AXES_MAX 128
|
||||
|
||||
static int joypad_id[2];
|
||||
static int joypad_buttons[2];
|
||||
static int joypad_axes[2];
|
||||
static unsigned joypad_id[2];
|
||||
static unsigned joypad_buttons[2];
|
||||
static unsigned joypad_axes[2];
|
||||
static bool joypad_inited = false;
|
||||
static int joypad_count = 0;
|
||||
static unsigned joypad_count = 0;
|
||||
|
||||
static int init_joypads(int max_pads)
|
||||
{
|
||||
@ -111,11 +111,17 @@ static bool glfw_is_pressed(int port_num, const struct snes_keybind *key, unsign
|
||||
return true;
|
||||
if (port_num >= joypad_count)
|
||||
return false;
|
||||
if (key->joykey >= 0)
|
||||
return (key->joykey < joypad_buttons[port_num] && buttons[key->joykey] == GLFW_PRESS);
|
||||
if (key->joyaxis >= 0)
|
||||
return (key->joyaxis < joypad_axes[port_num] && axes[key->joyaxis] >= AXIS_THRESHOLD);
|
||||
return (~key->joyaxis < joypad_axes[port_num] && axes[~key->joyaxis] <= -AXIS_THRESHOLD);
|
||||
if (key->joykey < joypad_buttons[port_num] && buttons[key->joykey] == GLFW_PRESS)
|
||||
return true;
|
||||
|
||||
if (key->joyaxis != AXIS_NONE)
|
||||
{
|
||||
if (AXIS_NEG_GET(key->joyaxis) < joypad_axes[port_num] && axes[AXIS_NEG_GET(key->joyaxis)] <= -AXIS_THRESHOLD)
|
||||
return true;
|
||||
if (AXIS_POS_GET(key->joyaxis) < joypad_axes[port_num] && axes[AXIS_POS_GET(key->joyaxis)] >= AXIS_THRESHOLD)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int16_t glfw_input_state(void *data, const struct snes_keybind **binds, bool port, unsigned device, unsigned index, unsigned id)
|
||||
|
Loading…
Reference in New Issue
Block a user