mirror of
https://github.com/libretro/RetroArch
synced 2025-02-13 03:40:33 +00:00
Add mapping support for joypads.
This commit is contained in:
parent
b24bb82d0c
commit
a7e35571cd
@ -71,6 +71,7 @@ struct settings
|
||||
char driver[32];
|
||||
struct snes_keybind binds[MAX_PLAYERS][MAX_BINDS];
|
||||
float axis_threshold;
|
||||
unsigned joypad_map[2];
|
||||
} input;
|
||||
|
||||
char libsnes[256];
|
||||
|
49
input/sdl.c
49
input/sdl.c
@ -36,23 +36,31 @@ static void* sdl_input_init(void)
|
||||
|
||||
SDL_JoystickEventState(SDL_IGNORE);
|
||||
sdl->num_joysticks = SDL_NumJoysticks();
|
||||
if (sdl->num_joysticks > 2)
|
||||
sdl->num_joysticks = 2;
|
||||
for (unsigned i = 0; i < sdl->num_joysticks; i++)
|
||||
{
|
||||
sdl->joysticks[i] = SDL_JoystickOpen(i);
|
||||
if (!sdl->joysticks[i])
|
||||
{
|
||||
SSNES_ERR("Couldn't open SDL joystick %d\n", i);
|
||||
free(sdl);
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSNES_LOG("Opened Joystick: %s\n", SDL_JoystickName(i));
|
||||
sdl->num_axes[i] = SDL_JoystickNumAxes(sdl->joysticks[i]);
|
||||
sdl->num_buttons[i] = SDL_JoystickNumButtons(sdl->joysticks[i]);
|
||||
sdl->num_hats[i] = SDL_JoystickNumHats(sdl->joysticks[i]);
|
||||
for (unsigned i = 0; i < 2; i++)
|
||||
{
|
||||
if (sdl->num_joysticks > g_settings.input.joypad_map[i])
|
||||
{
|
||||
sdl->joysticks[i] = SDL_JoystickOpen(g_settings.input.joypad_map[i]);
|
||||
if (!sdl->joysticks[i])
|
||||
{
|
||||
SSNES_ERR("Couldn't open SDL joystick #%u on SNES port %u\n", g_settings.input.joypad_map[i], i + 1);
|
||||
free(sdl);
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSNES_LOG("Opened Joystick: %s #%u on port %u\n",
|
||||
SDL_JoystickName(g_settings.input.joypad_map[i]), g_settings.input.joypad_map[i], i + 1);
|
||||
sdl->num_axes[i] = SDL_JoystickNumAxes(sdl->joysticks[i]);
|
||||
sdl->num_buttons[i] = SDL_JoystickNumButtons(sdl->joysticks[i]);
|
||||
sdl->num_hats[i] = SDL_JoystickNumHats(sdl->joysticks[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
SSNES_WARN("Desired SDL joystick #%u on port %u, but SDL can only detect %u joysticks ...\n",
|
||||
g_settings.input.joypad_map[i], i + 1, sdl->num_joysticks);
|
||||
}
|
||||
}
|
||||
|
||||
return sdl;
|
||||
@ -137,7 +145,7 @@ static bool sdl_is_pressed(sdl_input_t *sdl, int port_num, const struct snes_key
|
||||
{
|
||||
if (sdl_key_pressed(key->key))
|
||||
return true;
|
||||
if (port_num >= sdl->num_joysticks)
|
||||
if (sdl->joysticks[port_num] == NULL)
|
||||
return false;
|
||||
if (sdl_joykey_pressed(sdl, port_num, key->joykey))
|
||||
return true;
|
||||
@ -187,8 +195,11 @@ static void sdl_input_free(void *data)
|
||||
while (SDL_PollEvent(&event));
|
||||
|
||||
sdl_input_t *sdl = data;
|
||||
for (int i = 0; i < sdl->num_joysticks; i++)
|
||||
SDL_JoystickClose(sdl->joysticks[i]);
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (sdl->joysticks[i])
|
||||
SDL_JoystickClose(sdl->joysticks[i]);
|
||||
}
|
||||
|
||||
free(data);
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||
|
@ -112,6 +112,8 @@ static void set_defaults(void)
|
||||
memcpy(g_settings.input.binds[1], snes_keybinds_2, sizeof(snes_keybinds_2));
|
||||
|
||||
g_settings.input.axis_threshold = AXIS_THRESHOLD;
|
||||
g_settings.input.joypad_map[0] = 0;
|
||||
g_settings.input.joypad_map[1] = 1;
|
||||
}
|
||||
|
||||
void parse_config(void)
|
||||
@ -245,6 +247,12 @@ void parse_config(void)
|
||||
if (config_get_double(conf, "input_axis_threshold", &tmp_double))
|
||||
g_settings.input.axis_threshold = tmp_double;
|
||||
|
||||
if (config_get_int(conf, "input_player1_joypad_index", &tmp_int))
|
||||
g_settings.input.joypad_map[0] = tmp_int;
|
||||
|
||||
if (config_get_int(conf, "input_player2_joypad_index", &tmp_int))
|
||||
g_settings.input.joypad_map[1] = tmp_int;
|
||||
|
||||
// Audio settings.
|
||||
if (config_get_bool(conf, "audio_enable", &tmp_bool))
|
||||
g_settings.audio.enable = tmp_bool;
|
||||
|
@ -88,6 +88,10 @@
|
||||
# input_player1_up = up
|
||||
# input_player1_down = down
|
||||
|
||||
# If desired, it is possible to override which joypads are being used for player 1 and 2. First joypad available is 0.
|
||||
# input_player1_joypad_index = 0
|
||||
# input_player2_joypad_index = 1
|
||||
|
||||
# Joypad buttons. Figure these out by looking at jstest /dev/input/js0 output.
|
||||
# You can use joypad hats with hnxx, where n is the hat, and xx is a string representing direction.
|
||||
# E.g. "h0up"
|
||||
|
Loading…
x
Reference in New Issue
Block a user