From c375e43839713daa1e0c09d18bde3ed06469e1d8 Mon Sep 17 00:00:00 2001 From: sonninnos Date: Fri, 26 Jan 2024 05:03:08 +0200 Subject: [PATCH] Input state overflow band-aid --- input/input_driver.c | 49 +++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/input/input_driver.c b/input/input_driver.c index dbae8cc28b30..d112eb9049cf 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -688,7 +688,7 @@ bool input_driver_button_combo( return false; } -static int16_t input_state_wrap( +static int32_t input_state_wrap( input_driver_t *current_input, void *data, const input_device_driver_t *joypad, @@ -701,7 +701,7 @@ static int16_t input_state_wrap( unsigned idx, unsigned id) { - int16_t ret = 0; + int32_t ret = 0; if (!binds) return 0; @@ -780,18 +780,33 @@ static int16_t input_state_wrap( idx, id); - /* No binds, no input. This is for ignoring RETROK_UNKNOWN - * if the driver allows setting the key down somehow. - * Otherwise all hotkeys and inputs with null bind get triggered. */ if (device == RETRO_DEVICE_JOYPAD) { - /* Drivers can also overflow when sending all keys at once, - * resulting in negative values which also need to be ignored.. */ - if ( (id == RETRO_DEVICE_ID_JOYPAD_MASK && ret < 0) - || ( binds[_port][id].key == RETROK_UNKNOWN - && binds[_port][id].mbutton == NO_BTN - && binds[_port][id].joykey == NO_BTN - && binds[_port][id].joyaxis == AXIS_NONE)) + /* Drivers can overflow when sending too many keys at once.. */ + if (id == RETRO_DEVICE_ID_JOYPAD_MASK && ret) + { + /* Deal with menu toggle combo buttons that won't stay inside +32767. */ + if (ret == -0x8000) /* R3 */ + ret = 0x8000; + else if (ret == -0x4000) /* LR+R3 */ + ret = 0x8000 + 0x4000; + else if (ret < 0) + ret = 0; + return ret; + } + + /* No binds, no input. This is for ignoring RETROK_UNKNOWN + * if the driver allows setting the key down somehow. + * Otherwise all hotkeys and inputs with null bind get triggered. */ + if ( id != RETRO_DEVICE_ID_JOYPAD_MASK && ret + && binds[_port][id].key == RETROK_UNKNOWN + && binds[_port][id].mbutton == NO_BTN + && ( ( binds[_port][id].joykey == NO_BTN + && binds[_port][id].joyaxis == AXIS_NONE) + || ( joypad_info->auto_binds[id].joykey == NO_BTN + && joypad_info->auto_binds[id].joyaxis == AXIS_NONE) + ) + ) return 0; } @@ -1213,7 +1228,7 @@ static int16_t input_state_device( settings_t *settings, input_mapper_t *handle, unsigned input_analog_dpad_mode, - int16_t ret, + int32_t ret, unsigned port, unsigned device, unsigned idx, unsigned id, bool button_mask) @@ -1594,8 +1609,8 @@ static int16_t input_state_internal( * 'virtual' port index */ while ((mapped_port = *(input_remap_port_map++)) < MAX_USERS) { - int16_t ret = 0; - int16_t port_result = 0; + int32_t ret = 0; + int32_t port_result = 0; unsigned input_analog_dpad_mode = settings->uints.input_analog_dpad_mode[mapped_port]; joypad_info.joy_idx = settings->uints.input_joypad_index[mapped_port]; @@ -4833,7 +4848,7 @@ static void input_keys_pressed( } { - int16_t ret = 0; + int32_t ret = 0; bool libretro_input_pressed = false; /* Check libretro input if emulated device type is active, @@ -5588,7 +5603,7 @@ void input_driver_poll(void) if (joypad) { unsigned k, j; - int16_t ret = input_state_wrap( + int32_t ret = input_state_wrap( input_st->current_driver, input_st->current_data, input_st->primary_joypad,