From a4faa857c0fda98ca4b3c9ae7f85726753267e35 Mon Sep 17 00:00:00 2001 From: Stefan Date: Fri, 30 Oct 2015 07:25:43 +0100 Subject: [PATCH] input: add sanity check for analog dpad mode Don't remap dpad joyaxis if analog joyaxis values are not valid. Joyaxis values are not valid if up and down or left and right are equal. -Fix for https://github.com/libretro/RetroArch/issues/1780. If no analog left or right is configured (retroarch.cfg, autoconf) default analog joyaxis values are "-1". -Make this wish https://github.com/libretro/RetroArch/issues/609 obsolete. --- input/input_common.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/input/input_common.c b/input/input_common.c index d6d1670eb9..665dfe459f 100644 --- a/input/input_common.c +++ b/input/input_common.c @@ -457,12 +457,28 @@ void input_push_analog_dpad(struct retro_keybind *binds, unsigned mode) switch (mode) { case ANALOG_DPAD_LSTICK: - j = RARCH_ANALOG_LEFT_X_PLUS + 3; - inherit_joyaxis = true; + /* check if analog left is defined. * + * if plus and minus are equal abort. */ + if (!((binds[RARCH_ANALOG_LEFT_X_PLUS].joyaxis == + binds[RARCH_ANALOG_LEFT_X_MINUS].joyaxis) || + (binds[RARCH_ANALOG_LEFT_Y_PLUS].joyaxis == + binds[RARCH_ANALOG_LEFT_Y_MINUS].joyaxis))) + { + j = RARCH_ANALOG_LEFT_X_PLUS + 3; + inherit_joyaxis = true; + } break; case ANALOG_DPAD_RSTICK: - j = RARCH_ANALOG_RIGHT_X_PLUS + 3; - inherit_joyaxis = true; + /* check if analog right is defined. * + * if plus and minus are equal abort. */ + if (!((binds[RARCH_ANALOG_RIGHT_X_PLUS].joyaxis == + binds[RARCH_ANALOG_RIGHT_X_MINUS].joyaxis) || + (binds[RARCH_ANALOG_RIGHT_Y_PLUS].joyaxis == + binds[RARCH_ANALOG_RIGHT_Y_MINUS].joyaxis))) + { + j = RARCH_ANALOG_RIGHT_X_PLUS + 3; + inherit_joyaxis = true; + } break; }