diff --git a/input/drivers_joypad/android_joypad.c b/input/drivers_joypad/android_joypad.c index aadc90f52b..b3af92c0a3 100644 --- a/input/drivers_joypad/android_joypad.c +++ b/input/drivers_joypad/android_joypad.c @@ -31,19 +31,22 @@ static bool android_joypad_init(void *data) static bool android_joypad_button(unsigned port, uint16_t joykey) { - uint8_t *buf = android_keyboard_state_get(port); + unsigned hat_dir = 0; + uint8_t *buf = android_keyboard_state_get(port); struct android_app *android_app = (struct android_app*)g_android; if (port >= MAX_PADS) return false; - if (GET_HAT_DIR(joykey)) + hat_dir = GET_HAT_DIR(joykey); + + if (hat_dir) { unsigned h = GET_HAT(joykey); if (h > 0) return false; - switch (GET_HAT_DIR(joykey)) + switch (hat_dir) { case HAT_LEFT_MASK: return android_app->hat_state[port][0] == -1; diff --git a/input/drivers_joypad/dinput_joypad.c b/input/drivers_joypad/dinput_joypad.c index 174da9f086..db5db60810 100644 --- a/input/drivers_joypad/dinput_joypad.c +++ b/input/drivers_joypad/dinput_joypad.c @@ -325,6 +325,7 @@ static bool dinput_joypad_init(void *data) static bool dinput_joypad_button(unsigned port_num, uint16_t joykey) { const struct dinput_joypad *pad = NULL; + unsigned hat_dir = 0; if (joykey == NO_BTN) return false; @@ -333,8 +334,11 @@ static bool dinput_joypad_button(unsigned port_num, uint16_t joykey) if (!pad->joypad) return false; + hat_dir = GET_HAT_DIR(joykey); + /* Check hat. */ - if (GET_HAT_DIR(joykey)) + + if (hat_dir) { unsigned pov; unsigned hat = GET_HAT(joykey); @@ -349,7 +353,7 @@ static bool dinput_joypad_button(unsigned port_num, uint16_t joykey) /* Magic numbers I'm not sure where originate from. */ if (pov < 36000) { - switch (GET_HAT_DIR(joykey)) + switch (hat_dir) { case HAT_UP_MASK: return (pov >= 31500) || (pov <= 4500); diff --git a/input/drivers_joypad/sdl_joypad.c b/input/drivers_joypad/sdl_joypad.c index 705f8b3ff8..59e7c69b86 100644 --- a/input/drivers_joypad/sdl_joypad.c +++ b/input/drivers_joypad/sdl_joypad.c @@ -290,6 +290,8 @@ error: static bool sdl_joypad_button(unsigned port, uint16_t joykey) { sdl_joypad_t *pad = NULL; + unsigned hat_dir = 0; + if (joykey == NO_BTN) return false; @@ -297,17 +299,19 @@ static bool sdl_joypad_button(unsigned port, uint16_t joykey) if (!pad->joypad) return false; + hat_dir = GET_HAT_DIR(joykey); /* Check hat. */ - if (GET_HAT_DIR(joykey)) + if (hat_dir) { uint8_t dir; uint16_t hat = GET_HAT(joykey); + if (hat >= pad->num_hats) return false; dir = sdl_pad_get_hat(pad, hat); - switch (GET_HAT_DIR(joykey)) + switch (hat_dir) { case HAT_UP_MASK: return dir & SDL_HAT_UP; @@ -333,7 +337,7 @@ static bool sdl_joypad_button(unsigned port, uint16_t joykey) static int16_t sdl_joypad_axis(unsigned port, uint32_t joyaxis) { sdl_joypad_t *pad; - int16_t val; + int16_t val = 0; if (joyaxis == AXIS_NONE) return 0; @@ -342,7 +346,6 @@ static int16_t sdl_joypad_axis(unsigned port, uint32_t joyaxis) if (!pad->joypad) return false; - val = 0; if (AXIS_NEG_GET(joyaxis) < pad->num_axes) { val = sdl_pad_get_axis(pad, AXIS_NEG_GET(joyaxis)); @@ -391,9 +394,9 @@ static void sdl_joypad_poll(void) #ifdef HAVE_SDL2 static bool sdl_joypad_set_rumble(unsigned pad, enum retro_rumble_effect effect, uint16_t strength) { + SDL_HapticEffect efx; sdl_joypad_t *joypad = (sdl_joypad_t*)&sdl_pads[pad]; - SDL_HapticEffect efx; memset(&efx, 0, sizeof(efx)); if (!joypad->joypad || !joypad->haptic) diff --git a/input/drivers_joypad/udev_joypad.c b/input/drivers_joypad/udev_joypad.c index 5374cde59e..fe4e0fff3e 100644 --- a/input/drivers_joypad/udev_joypad.c +++ b/input/drivers_joypad/udev_joypad.c @@ -561,14 +561,15 @@ error: return false; } -static bool udev_joypad_hat(const struct udev_joypad *pad, uint16_t hat) +static bool udev_joypad_hat(const struct udev_joypad *pad, uint16_t hat, + unsigned hat_dir) { unsigned h = GET_HAT(hat); if (h >= NUM_HATS) return false; - switch (GET_HAT_DIR(hat)) + switch (hat_dir) { case HAT_LEFT_MASK: return pad->hats[h][0] < 0; @@ -586,9 +587,10 @@ static bool udev_joypad_hat(const struct udev_joypad *pad, uint16_t hat) static bool udev_joypad_button(unsigned port, uint16_t joykey) { const struct udev_joypad *pad = (const struct udev_joypad*)&udev_pads[port]; + unsigned hat_dir = GET_HAT_DIR(joykey); - if (GET_HAT_DIR(joykey)) - return udev_joypad_hat(pad, joykey); + if (hat_dir) + return udev_joypad_hat(pad, joykey, hat_dir); return joykey < UDEV_NUM_BUTTONS && BIT64_GET(pad->buttons, joykey); } diff --git a/input/drivers_joypad/xinput_joypad.c b/input/drivers_joypad/xinput_joypad.c index 8959b027ac..2f790ab814 100644 --- a/input/drivers_joypad/xinput_joypad.c +++ b/input/drivers_joypad/xinput_joypad.c @@ -318,9 +318,10 @@ static const uint16_t button_index_to_bitmap_code[] = { static bool xinput_joypad_button(unsigned port_num, uint16_t joykey) { - uint16_t btn_word; int xuser; + uint16_t btn_word = 0; unsigned num_buttons = 0; + unsigned hat_dir = 0; if (joykey == NO_BTN) return false; @@ -333,10 +334,11 @@ static bool xinput_joypad_button(unsigned port_num, uint16_t joykey) return false; btn_word = g_xinput_states[xuser].xstate.Gamepad.wButtons; + hat_dir = GET_HAT_DIR(joykey); - if (GET_HAT_DIR(joykey)) + if (hat_dir) { - switch (GET_HAT_DIR(joykey)) + switch (hat_dir) { case HAT_UP_MASK: return btn_word & XINPUT_GAMEPAD_DPAD_UP; @@ -347,6 +349,7 @@ static bool xinput_joypad_button(unsigned port_num, uint16_t joykey) case HAT_RIGHT_MASK: return btn_word & XINPUT_GAMEPAD_DPAD_RIGHT; } + return false; /* hat requested and no hat button down. */ }