From ecfdc867f856edc43beddf9bc6a2844e6131e94d Mon Sep 17 00:00:00 2001 From: twinaphex <libretro@gmail.com> Date: Fri, 12 Jun 2020 00:16:31 +0200 Subject: [PATCH] Cleanups --- input/drivers/dos_input.c | 64 +++++++++++++++----------------- input/drivers/gx_input.c | 55 +++++++++++++-------------- input/drivers/ps2_input.c | 54 +++++++++++++-------------- input/drivers/ps3_input.c | 59 +++++++++++++++-------------- input/drivers/ps4_input.c | 54 ++++++++++++++------------- input/drivers/psl1ght_input.c | 59 ++++++++++++++--------------- input/drivers/psp_input.c | 51 +++++++++++++------------ input/drivers/switch_input.c | 51 +++++++++++++------------ input/drivers/xdk_xinput_input.c | 52 ++++++++++++++------------ 9 files changed, 254 insertions(+), 245 deletions(-) diff --git a/input/drivers/dos_input.c b/input/drivers/dos_input.c index 3828cb4315..701ce085fe 100644 --- a/input/drivers/dos_input.c +++ b/input/drivers/dos_input.c @@ -69,6 +69,28 @@ static void dos_input_poll(void *data) dos->joypad->poll(); } +static int16_t dos_is_pressed( + const input_device_driver_t *joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind *binds, + unsigned port, unsigned id) +{ + const struct retro_keybind *bind = &binds[id]; + /* Auto-binds are per joypad, not per user. */ + const uint64_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info->auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis; + if ((uint16_t)joykey != NO_BTN + && joypad->button( + joypad_info->joy_idx, (uint16_t)joykey)) + return 1; + if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis)) + / 0x8000) > joypad_info->axis_threshold) + return 1; + return 0; +} + static int16_t dos_input_state(void *data, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, @@ -89,47 +111,21 @@ static int16_t dos_input_state(void *data, int16_t ret = 0; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][i].joykey != NO_BTN) - ? binds[port][i].joykey : joypad_info->auto_binds[i].joykey; - const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) - ? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis; - - if ((uint16_t)joykey != NO_BTN && dos->joypad->button(joypad_info->joy_idx, (uint16_t)joykey)) - { + if ( + dos_keyboard_port_input_pressed(binds[port], i) + || dos_is_pressed(dos->joypad, joypad_info, binds[port], + port, i)) ret |= (1 << i); - continue; - } - if (((float)abs(dos->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) - { - ret |= (1 << i); - continue; - } - if (dos_keyboard_port_input_pressed(binds[port], i)) - { - ret |= (1 << i); - continue; - } } return ret; } else { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][id].joykey != NO_BTN) - ? binds[port][id].joykey : joypad_info->auto_binds[id].joykey; - const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) - ? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis; - - if ((uint16_t)joykey != NO_BTN && dos->joypad->button( - joypad_info->joy_idx, (uint16_t)joykey)) - return 1; - if (((float)abs(dos->joypad->axis( - joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) - return 1; - - if (dos_keyboard_port_input_pressed(binds[port], id)) + if ( + dos_keyboard_port_input_pressed(binds[port], id) + || dos_is_pressed(dos->joypad, joypad_info, binds[port], + port, id)) return 1; } break; diff --git a/input/drivers/gx_input.c b/input/drivers/gx_input.c index 464e843993..fdf0c9f11f 100644 --- a/input/drivers/gx_input.c +++ b/input/drivers/gx_input.c @@ -134,6 +134,28 @@ static int16_t gx_mouse_state(gx_input_t *gx, unsigned id, uint16_t joy_idx) } #endif +static int16_t gx_is_pressed( + const input_device_driver_t *joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind *binds, + unsigned port, unsigned id) +{ + const struct retro_keybind *bind = &binds[id]; + /* Auto-binds are per joypad, not per user. */ + const uint64_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info->auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis; + if ((uint16_t)joykey != NO_BTN + && joypad->button( + joypad_info->joy_idx, (uint16_t)joykey)) + return 1; + if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis)) + / 0x8000) > joypad_info->axis_threshold) + return 1; + return 0; +} + static int16_t gx_input_state(void *data, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, @@ -154,40 +176,19 @@ static int16_t gx_input_state(void *data, int16_t ret = 0; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][i].joykey != NO_BTN) - ? binds[port][i].joykey : joypad_info->auto_binds[i].joykey; - const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) - ? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis; - - if ((uint16_t)joykey != NO_BTN && gx->joypad->button( - joypad_info->joy_idx, (uint16_t)joykey)) - { + if ( + gx_is_pressed(gx->joypad, joypad_info, binds[port], + port, i)) ret |= (1 << i); - continue; - } - if (((float)abs(gx->joypad->axis( - joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) - { - ret |= (1 << i); - continue; - } } return ret; } else { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][id].joykey != NO_BTN) - ? binds[port][id].joykey : joypad_info->auto_binds[id].joykey; - const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) - ? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis; - - if ((uint16_t)joykey != NO_BTN && gx->joypad->button( - joypad_info->joy_idx, (uint16_t)joykey)) - return 1; - if (((float)abs(gx->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) + if ( + gx_is_pressed(gx->joypad, joypad_info, binds[port], + port, id)) return 1; } break; diff --git a/input/drivers/ps2_input.c b/input/drivers/ps2_input.c index 1847408158..45a6d78d8d 100644 --- a/input/drivers/ps2_input.c +++ b/input/drivers/ps2_input.c @@ -41,6 +41,28 @@ static void ps2_input_poll(void *data) ps2->joypad->poll(); } +static int16_t ps2_is_pressed( + const input_device_driver_t *joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind *binds, + unsigned port, unsigned id) +{ + const struct retro_keybind *bind = &binds[id]; + /* Auto-binds are per joypad, not per user. */ + const uint64_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info->auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis; + if ((uint16_t)joykey != NO_BTN + && joypad->button( + joypad_info->joy_idx, (uint16_t)joykey)) + return 1; + if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis)) + / 0x8000) > joypad_info->axis_threshold) + return 1; + return 0; +} + static int16_t ps2_input_state(void *data, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, @@ -58,41 +80,17 @@ static int16_t ps2_input_state(void *data, int16_t ret = 0; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][i].joykey != NO_BTN) - ? binds[port][i].joykey : joypad_info->auto_binds[i].joykey; - const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) - ? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis; - - if ((uint16_t)joykey != NO_BTN && ps2->joypad->button( - joypad_info->joy_idx, (uint16_t)joykey)) - { + if (ps2_is_pressed(ps2->joypad, joypad_info, binds[port], + port, i)) ret |= (1 << i); - continue; - } - if (((float)abs(ps2->joypad->axis( - joypad_info->joy_idx, joyaxis)) / 0x8000) - > joypad_info->axis_threshold) - { - ret |= (1 << i); - continue; - } } return ret; } else { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][id].joykey != NO_BTN) - ? binds[port][id].joykey : joypad_info->auto_binds[id].joykey; - const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) - ? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis; - - if ((uint16_t)joykey != NO_BTN && ps2->joypad->button( - joypad_info->joy_idx, (uint16_t)joykey)) - return 1; - if (((float)abs(ps2->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) + if (ps2_is_pressed(ps2->joypad, joypad_info, binds[port], + port, id)) return 1; } break; diff --git a/input/drivers/ps3_input.c b/input/drivers/ps3_input.c index 501b2ea1c6..e8fe14c543 100644 --- a/input/drivers/ps3_input.c +++ b/input/drivers/ps3_input.c @@ -91,9 +91,30 @@ static int16_t ps3_mouse_device_state(ps3_input_t *ps3, return 0; } - #endif +static int16_t ps3_is_pressed( + const input_device_driver_t *joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind *binds, + unsigned port, unsigned id) +{ + const struct retro_keybind *bind = &binds[id]; + /* Auto-binds are per joypad, not per user. */ + const uint64_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info->auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis; + if ((uint16_t)joykey != NO_BTN + && joypad->button( + joypad_info->joy_idx, (uint16_t)joykey)) + return 1; + if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis)) + / 0x8000) > joypad_info->axis_threshold) + return 1; + return 0; +} + static int16_t ps3_input_state(void *data, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, @@ -114,47 +135,25 @@ static int16_t ps3_input_state(void *data, int16_t ret = 0; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][i].joykey != NO_BTN) - ? binds[port][i].joykey : joypad_info->auto_binds[i].joykey; - const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) - ? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis; - - if ((uint16_t)joykey != NO_BTN && ps3->joypad->button( - joypad_info->joy_idx, (uint16_t)joykey)) - { + if ( + ps3_is_pressed(ps3->joypad, joypad_info, binds[port], + port, i)) ret |= (1 << i); - continue; - } - else if (((float)abs(ps3->joypad->axis( - joypad_info->joy_idx, joyaxis)) / 0x8000) - > joypad_info->axis_threshold) - { - ret |= (1 << i); - continue; - } } return ret; } else { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][id].joykey != NO_BTN) - ? binds[port][id].joykey : joypad_info->auto_binds[id].joykey; - const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) - ? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis; - - if ((uint16_t)joykey != NO_BTN && ps3->joypad->button( - joypad_info->joy_idx, (uint16_t)joykey)) - return 1; - if (((float)abs(ps3->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) + if (ps3_is_pressed(ps3->joypad, joypad_info, binds[port], + port, id)) return 1; } break; case RETRO_DEVICE_ANALOG: if (binds[port]) - return input_joypad_analog(ps3->joypad, joypad_info, port, idx, id, binds[port]); + return input_joypad_analog( + ps3->joypad, joypad_info, port, idx, id, binds[port]); break; #if 0 case RETRO_DEVICE_SENSOR_ACCELEROMETER: diff --git a/input/drivers/ps4_input.c b/input/drivers/ps4_input.c index e0029b4da8..abf3a90c95 100644 --- a/input/drivers/ps4_input.c +++ b/input/drivers/ps4_input.c @@ -45,6 +45,28 @@ static void ps4_input_poll(void *data) ps4->joypad->poll(); } +static int16_t ps4_is_pressed( + const input_device_driver_t *joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind *binds, + unsigned port, unsigned id) +{ + const struct retro_keybind *bind = &binds[id]; + /* Auto-binds are per joypad, not per user. */ + const uint64_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info->auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis; + if ((uint16_t)joykey != NO_BTN + && joypad->button( + joypad_info->joy_idx, (uint16_t)joykey)) + return 1; + if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis)) + / 0x8000) > joypad_info->axis_threshold) + return 1; + return 0; +} + static int16_t ps4_input_state(void *data, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, @@ -62,39 +84,19 @@ static int16_t ps4_input_state(void *data, int16_t ret = 0; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][i].joykey != NO_BTN) - ? binds[port][i].joykey : joypad_info->auto_binds[i].joykey; - const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) - ? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis; - - if ((uint16_t)joykey != NO_BTN && ps4->joypad->button( - joypad_info->joy_idx, (uint16_t)joykey)) - { + if ( + ps4_is_pressed(ps4->joypad, joypad_info, binds[port], + port, i)) ret |= (1 << i); - continue; - } - if (((float)abs(ps4->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) - { - ret |= (1 << i); - continue; - } } return ret; } else { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][id].joykey != NO_BTN) - ? binds[port][id].joykey : joypad_info->auto_binds[id].joykey; - const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) - ? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis; - - if ((uint16_t)joykey != NO_BTN && ps4->joypad->button( - joypad_info->joy_idx, (uint16_t)joykey)) - return 1; - if (((float)abs(ps4->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) + if ( + ps4_is_pressed(ps4->joypad, joypad_info, binds[port], + port, id)) return 1; } break; diff --git a/input/drivers/psl1ght_input.c b/input/drivers/psl1ght_input.c index a873d35836..425d259909 100644 --- a/input/drivers/psl1ght_input.c +++ b/input/drivers/psl1ght_input.c @@ -203,6 +203,28 @@ static bool psl1ght_keyboard_port_input_pressed(ps3_input_t *ps3, unsigned id) return false; } +static int16_t psl1ght_is_pressed( + const input_device_driver_t *joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind *binds, + unsigned port, unsigned id) +{ + const struct retro_keybind *bind = &binds[id]; + /* Auto-binds are per joypad, not per user. */ + const uint64_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info->auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis; + if ((uint16_t)joykey != NO_BTN + && joypad->button( + joypad_info->joy_idx, (uint16_t)joykey)) + return 1; + if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis)) + / 0x8000) > joypad_info->axis_threshold) + return 1; + return 0; +} + static int16_t ps3_input_state(void *data, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, @@ -223,45 +245,24 @@ static int16_t ps3_input_state(void *data, int16_t ret = 0; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][i].joykey != NO_BTN) - ? binds[port][i].joykey : joypad_info->auto_binds[i].joykey; - const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) - ? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis; - - if ((uint16_t)joykey != NO_BTN && ps3->joypad->button( - joypad_info->joy_idx, (uint16_t)joykey)) - { + if ( + psl1ght_is_pressed(ps3->joypad, joypad_info, binds[port], + port, i)) ret |= (1 << i); - continue; - } - else if (((float)abs(ps3->joypad->axis( - joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) - { - ret |= (1 << i); - continue; - } else if (psl1ght_keyboard_port_input_pressed(ps3, binds[port][i].key)) ret |= (1 << i); - } return ret; } else { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][id].joykey != NO_BTN) - ? binds[port][id].joykey : joypad_info->auto_binds[id].joykey; - const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) - ? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis; - - if ((uint16_t)joykey != NO_BTN && ps3->joypad->button( - joypad_info->joy_idx, (uint16_t)joykey)) + if ( + psl1ght_is_pressed(ps3->joypad, joypad_info, binds[port], + port, id)) return 1; - if (((float)abs(ps3->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) - return 1; - if (psl1ght_keyboard_port_input_pressed(ps3, binds[port][id].key)) + else if (psl1ght_keyboard_port_input_pressed( + ps3, binds[port][id].key)) return 1; } break; diff --git a/input/drivers/psp_input.c b/input/drivers/psp_input.c index cd682b1cbe..0c2af095aa 100644 --- a/input/drivers/psp_input.c +++ b/input/drivers/psp_input.c @@ -283,6 +283,27 @@ static int16_t psp_input_mouse_state( } #endif +static int16_t psp_is_pressed( + const input_device_driver_t *joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind *binds, + unsigned port, unsigned id) +{ + const struct retro_keybind *bind = &binds[id]; + /* Auto-binds are per joypad, not per user. */ + const uint64_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info->auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis; + if ((uint16_t)joykey != NO_BTN + && joypad->button( + joypad_info->joy_idx, (uint16_t)joykey)) + return 1; + if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis)) + / 0x8000) > joypad_info->axis_threshold) + return 1; + return 0; +} static int16_t psp_input_state(void *data, rarch_joypad_info_t *joypad_info, @@ -306,37 +327,19 @@ static int16_t psp_input_state(void *data, int16_t ret = 0; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][i].joykey != NO_BTN) - ? binds[port][i].joykey : joypad_info->auto_binds[i].joykey; - const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) - ? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis; - - if ((uint16_t)joykey != NO_BTN && psp->joypad->button(joypad_info->joy_idx, (uint16_t)joykey)) - { + if ( + psp_is_pressed(psp->joypad, joypad_info, binds[port], + port, i)) ret |= (1 << i); - continue; - } - if (((float)abs(psp->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) - { - ret |= (1 << i); - continue; - } } return ret; } else { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][id].joykey != NO_BTN) - ? binds[port][id].joykey : joypad_info->auto_binds[id].joykey; - const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) - ? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis; - - if ((uint16_t)joykey != NO_BTN && psp->joypad->button(joypad_info->joy_idx, (uint16_t)joykey)) - return 1; - if (((float)abs(psp->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) + if ( + psp_is_pressed(psp->joypad, joypad_info, binds[port], + port, id)) return 1; } break; diff --git a/input/drivers/switch_input.c b/input/drivers/switch_input.c index 2da699e0dd..73f68f6ee0 100644 --- a/input/drivers/switch_input.c +++ b/input/drivers/switch_input.c @@ -379,6 +379,28 @@ static int16_t switch_input_mouse_state( } #endif +static int16_t switch_is_pressed( + const input_device_driver_t *joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind *binds, + unsigned port, unsigned id) +{ + const struct retro_keybind *bind = &binds[id]; + /* Auto-binds are per joypad, not per user. */ + const uint64_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info->auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis; + if ((uint16_t)joykey != NO_BTN + && joypad->button( + joypad_info->joy_idx, (uint16_t)joykey)) + return 1; + if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis)) + / 0x8000) > joypad_info->axis_threshold) + return 1; + return 0; +} + static int16_t switch_input_state(void *data, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, @@ -399,36 +421,19 @@ static int16_t switch_input_state(void *data, int16_t ret = 0; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][i].joykey != NO_BTN) - ? binds[port][i].joykey : joypad_info->auto_binds[i].joykey; - const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) - ? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis; - - if ((uint16_t)joykey != NO_BTN && sw->joypad->button(joypad_info->joy_idx, (uint16_t)joykey)) - { + if ( + switch_is_pressed(sw->joypad, joypad_info, binds[port], + port, i)) ret |= (1 << i); - continue; - } - if (((float)abs(sw->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) - { - ret |= (1 << i); - continue; - } } return ret; } else { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][id].joykey != NO_BTN) - ? binds[port][id].joykey : joypad_info->auto_binds[id].joykey; - const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) - ? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis; - if ((uint16_t)joykey != NO_BTN && sw->joypad->button(joypad_info->joy_idx, (uint16_t)joykey)) - return 1; - if (((float)abs(sw->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) + if ( + switch_is_pressed(sw->joypad, joypad_info, binds[port], + port, id)) return 1; } break; diff --git a/input/drivers/xdk_xinput_input.c b/input/drivers/xdk_xinput_input.c index 397377dffd..52b567e055 100644 --- a/input/drivers/xdk_xinput_input.c +++ b/input/drivers/xdk_xinput_input.c @@ -48,6 +48,28 @@ static void xdk_input_poll(void *data) xdk->joypad->poll(); } +static int16_t xdk_is_pressed( + const input_device_driver_t *joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind *binds, + unsigned port, unsigned id) +{ + const struct retro_keybind *bind = &binds[id]; + /* Auto-binds are per joypad, not per user. */ + const uint64_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info->auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis; + if ((uint16_t)joykey != NO_BTN + && joypad->button( + joypad_info->joy_idx, (uint16_t)joykey)) + return 1; + if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis)) + / 0x8000) > joypad_info->axis_threshold) + return 1; + return 0; +} + static int16_t xdk_input_state(void *data, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, @@ -69,37 +91,19 @@ static int16_t xdk_input_state(void *data, for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][i].joykey != NO_BTN) - ? binds[port][i].joykey : joypad_info->auto_binds[i].joykey; - const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) - ? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis; - - if ((uint16_t)joykey != NO_BTN && xdk->joypad->button(joypad_info->joy_idx, (uint16_t)joykey)) - { + if ( + xdk_is_pressed(xdk->joypad, joypad_info, binds[port], + port, i)) ret |= (1 << i); - continue; - } - if (((float)abs(xdk->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) - { - ret |= (1 << i); - continue; - } } return ret; } else { - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[port][id].joykey != NO_BTN) - ? binds[port][id].joykey : joypad_info->auto_binds[id].joykey; - const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) - ? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis; - - if ((uint16_t)joykey != NO_BTN && xdk->joypad->button(joypad_info->joy_idx, (uint16_t)joykey)) - return 1; - if (((float)abs(xdk->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold) + if ( + xdk_is_pressed(xdk->joypad, joypad_info, binds[port], + port, id)) return 1; } break;