diff --git a/input/input_defines.h b/input/input_defines.h index b005e90f58..3255a85180 100644 --- a/input/input_defines.h +++ b/input/input_defines.h @@ -26,6 +26,8 @@ RETRO_BEGIN_DECLS #define MAX_USERS 16 +#define MAX_INPUT_DEVICES 16 + #define RARCH_FIRST_CUSTOM_BIND 16 #define RARCH_FIRST_LIGHTGUN_BIND RARCH_ANALOG_BIND_LIST_END #define RARCH_FIRST_MISC_CUSTOM_BIND RARCH_LIGHTGUN_BIND_LIST_END diff --git a/input/input_driver.c b/input/input_driver.c index d17fb5fc61..59ca11e205 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -233,7 +233,7 @@ static const uint8_t buttons[] = { static uint16_t input_config_vid[MAX_USERS]; static uint16_t input_config_pid[MAX_USERS]; -char input_device_names[MAX_USERS][64]; +char input_device_names[MAX_INPUT_DEVICES][64]; struct retro_keybind input_config_binds[MAX_USERS][RARCH_BIND_LIST_END]; struct retro_keybind input_autoconf_binds[MAX_USERS][RARCH_BIND_LIST_END]; const struct retro_keybind *libretro_input_binds[MAX_USERS]; @@ -2691,6 +2691,18 @@ void input_config_get_bind_string(char *buf, const struct retro_keybind *bind, strlcat(buf, "---", size); } +unsigned input_config_get_device_count() +{ + unsigned num_devices; + for ( num_devices = 0; num_devices < MAX_INPUT_DEVICES; ++num_devices ) + { + const char *device_name = input_config_get_device_name(num_devices); + if ( string_is_empty(device_name) ) + break; + } + return num_devices; +} + const char *input_config_get_device_name(unsigned port) { if (string_is_empty(input_device_names[port])) diff --git a/input/input_driver.h b/input/input_driver.h index 3222237a41..1f7b711917 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -761,6 +761,8 @@ void input_config_set_device_name(unsigned port, const char *name); void input_config_clear_device_name(unsigned port); +unsigned input_config_get_device_count(); + unsigned *input_config_get_device_ptr(unsigned port); unsigned input_config_get_device(unsigned port); diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 86cca1a42a..112ce021f5 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -1305,7 +1305,7 @@ static int setting_action_left_bind_device(void *data, bool wraparound) { unsigned index_offset; unsigned *p = NULL; - unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS)); + unsigned max_devices = input_config_get_device_count(); rarch_setting_t *setting = (rarch_setting_t*)data; settings_t *settings = config_get_ptr(); @@ -1316,8 +1316,8 @@ static int setting_action_left_bind_device(void *data, bool wraparound) p = &settings->uints.input_joypad_map[index_offset]; - if ((*p) >= max_users) - *p = max_users - 1; + if ((*p) >= max_devices) + *p = max_devices - 1; else if ((*p) > 0) (*p)--; @@ -1328,7 +1328,7 @@ static int setting_action_right_bind_device(void *data, bool wraparound) { unsigned index_offset; unsigned *p = NULL; - unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS)); + unsigned max_devices = input_config_get_device_count(); rarch_setting_t *setting = (rarch_setting_t*)data; settings_t *settings = config_get_ptr(); @@ -1339,7 +1339,7 @@ static int setting_action_right_bind_device(void *data, bool wraparound) p = &settings->uints.input_joypad_map[index_offset]; - if (*p < max_users) + if (*p < max_devices) (*p)++; return 0; @@ -1497,7 +1497,7 @@ static void get_string_representation_bind_device(void * data, char *s, size_t len) { unsigned index_offset, map = 0; - unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS)); + unsigned max_devices = input_config_get_device_count(); rarch_setting_t *setting = (rarch_setting_t*)data; settings_t *settings = config_get_ptr(); @@ -1507,7 +1507,7 @@ static void get_string_representation_bind_device(void * data, char *s, index_offset = setting->index_offset; map = settings->uints.input_joypad_map[index_offset]; - if (map < max_users) + if (map < max_devices) { const char *device_name = input_config_get_device_name(map);