From c1ef5c549749eeabdf61ef0e6521e5b02d195a40 Mon Sep 17 00:00:00 2001 From: gblues Date: Wed, 3 Jan 2018 19:57:38 -0800 Subject: [PATCH 1/2] Revert "Fix wiiu touchpad scaling" This reverts commit 1d933a6b52e15ec281deb2aff5151292b8ebe655. --- wiiu/include/wiiu/pad_driver.h | 1 + wiiu/input/wpad_driver.c | 85 ++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/wiiu/include/wiiu/pad_driver.h b/wiiu/include/wiiu/pad_driver.h index aa93f4db26..7721077726 100644 --- a/wiiu/include/wiiu/pad_driver.h +++ b/wiiu/include/wiiu/pad_driver.h @@ -36,6 +36,7 @@ #include "../../retroarch.h" #include "../../verbosity.h" #include "../../command.h" +#include "../../gfx/video_driver.h" /** * Magic button sequence that triggers an exit. Useful for if the visuals are diff --git a/wiiu/input/wpad_driver.c b/wiiu/input/wpad_driver.c index 08340c1edd..fa552d2543 100644 --- a/wiiu/input/wpad_driver.c +++ b/wiiu/input/wpad_driver.c @@ -49,54 +49,56 @@ static int16_t scale_touchpad(int16_t from_min, int16_t from_max, return (((value - from_min) * to_range) / from_range) + to_min; } -#if 0 -/** - * Get absolute value of a signed integer using bit manipulation. - */ -static int16_t bitwise_abs(int16_t value) -{ - bool is_negative = value & 0x8000; - if(!is_negative) - return value; - value = value &~ 0x8000; - return ~value & 0x7fff; -} - -/** - * printf doesn't have a concept of a signed hex digit, so we fake it. - */ -static void log_coords(int16_t x, int16_t y) -{ - bool x_negative = x & 0x8000; - bool y_negative = y & 0x8000; - - int16_t x_digit = bitwise_abs(x); - int16_t y_digit = bitwise_abs(y); - - RARCH_LOG("[wpad]: calibrated point: %s%04x, %s%04x\n", - x_negative ? "-" : "", - x_digit, - y_negative ? "-" : "", - y_digit); -} -#endif - -static void get_calibrated_point(VPADTouchData *point, VPADStatus *vpad) +static void get_calibrated_point(VPADTouchData *point, struct video_viewport *viewport, VPADStatus *vpad) { VPADTouchData calibrated720p = {0}; VPADGetTPCalibratedPoint(PAD_GAMEPAD, &calibrated720p, &(vpad->tpNormal)); - point->x = scale_touchpad(12, 1268, -0x7fff, 0x7fff, calibrated720p.x); - point->y = scale_touchpad(12, 708, -0x7fff, 0x7fff, calibrated720p.y); -#if 0 - log_coords(point->x, point->y); -#endif + point->x = scale_touchpad(12, 1268, 0, viewport->full_width, calibrated720p.x); + point->y = scale_touchpad(12, 708, 0, viewport->full_height, calibrated720p.y); +} + +static void apply_clamping(VPADTouchData *point, struct video_viewport *viewport, bool *clamped) +{ + /* clamp the x domain to the viewport */ + if(point->x < viewport->x) + { + point->x = viewport->x; + *clamped = true; + } + else if(point->x > (viewport->x + viewport->width)) + { + point->x = viewport->x + viewport->width; + *clamped = true; + } + + /* clamp the y domain to the viewport */ + if(point->y < viewport->y) + { + point->y = viewport->y; + *clamped = true; + } + else if(point->y > (viewport->y + viewport->height)) + { + point->y = viewport->y + viewport->height; + *clamped = true; + } +} + +static void get_touch_coordinates(VPADTouchData *point, VPADStatus *vpad, bool *clamped) +{ + struct video_viewport viewport = {0}; + + video_driver_get_viewport_info(&viewport); + get_calibrated_point(point, &viewport, vpad); + apply_clamping(point, &viewport, clamped); } static void update_touch_state(int16_t state[3][2], uint64_t *buttons, VPADStatus *vpad) { VPADTouchData point = {0}; + bool touch_clamped = false; if(!vpad->tpNormal.touched || vpad->tpNormal.validity != VPAD_VALID) { @@ -104,12 +106,15 @@ static void update_touch_state(int16_t state[3][2], uint64_t *buttons, VPADStatu return; } - get_calibrated_point(&point, vpad); + get_touch_coordinates(&point, vpad, &touch_clamped); state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_X] = point.x; state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_Y] = point.y; - *buttons |= VPAD_BUTTON_TOUCH; + if(!touch_clamped) + *buttons |= VPAD_BUTTON_TOUCH; + else + *buttons &= ~VPAD_BUTTON_TOUCH; } static void check_panic_button(uint32_t held_buttons) From 80cdb92154f51346b721b7e0f2b98530b7f4720f Mon Sep 17 00:00:00 2001 From: gblues Date: Wed, 3 Jan 2018 21:32:00 -0800 Subject: [PATCH 2/2] Re-re-fix wpad scaling. For real this time. == DETAILS @r-type got me the link to the fixed-fixed version. Which was actually closer to where I was originally! So: - Revert the previous commit - Apply the actual changes needed to fix the problem - Bring in and fix the logging code from the previous implementation == TESTING - Verified that top-left is -0x7fff,-0x7fff and that bottom-right is 0x7fff, 0x7fff. == REVIEW @QuarkTheAwesome @r-type @twinaphex --- wiiu/input/wpad_driver.c | 57 +++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/wiiu/input/wpad_driver.c b/wiiu/input/wpad_driver.c index fa552d2543..8b4e7e0032 100644 --- a/wiiu/input/wpad_driver.c +++ b/wiiu/input/wpad_driver.c @@ -86,18 +86,50 @@ static void apply_clamping(VPADTouchData *point, struct video_viewport *viewport } } -static void get_touch_coordinates(VPADTouchData *point, VPADStatus *vpad, bool *clamped) +static void get_touch_coordinates(VPADTouchData *point, VPADStatus *vpad, struct video_viewport *viewport, bool *clamped) { - struct video_viewport viewport = {0}; - - video_driver_get_viewport_info(&viewport); - get_calibrated_point(point, &viewport, vpad); - apply_clamping(point, &viewport, clamped); + get_calibrated_point(point, viewport, vpad); + apply_clamping(point, viewport, clamped); } +#if 0 +/** + * Get absolute value of a signed integer using bit manipulation. + */ +static int16_t bitwise_abs(int16_t value) +{ + bool is_negative = value & 0x8000; + if(!is_negative) + return value; + + value = value &~ 0x8000; + return (~value & 0x7fff)+1; +} + +/** + * printf doesn't have a concept of a signed hex digit, so we fake it. + */ +static void log_coords(int16_t x, int16_t y) +{ + bool x_negative = x & 0x8000; + bool y_negative = y & 0x8000; + + int16_t x_digit = bitwise_abs(x); + int16_t y_digit = bitwise_abs(y); + + RARCH_LOG("[wpad]: calibrated point: %s%04x, %s%04x\n", + x_negative ? "-" : "", + x_digit, + y_negative ? "-" : "", + y_digit); +} +#endif + static void update_touch_state(int16_t state[3][2], uint64_t *buttons, VPADStatus *vpad) { VPADTouchData point = {0}; + struct video_viewport viewport = {0}; + bool touch_clamped = false; if(!vpad->tpNormal.touched || vpad->tpNormal.validity != VPAD_VALID) @@ -106,10 +138,17 @@ static void update_touch_state(int16_t state[3][2], uint64_t *buttons, VPADStatu return; } - get_touch_coordinates(&point, vpad, &touch_clamped); + video_driver_get_viewport_info(&viewport); + get_touch_coordinates(&point, vpad, &viewport, &touch_clamped); + + state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_X] = scale_touchpad(viewport.x, viewport.x + viewport.width, -0x7fff, 0x7fff, point.x); + state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_Y] = scale_touchpad(viewport.y, viewport.y + viewport.height, -0x7fff, 0x7fff, point.y); + +#if 0 + log_coords(state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_X], + state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_Y]); +#endif - state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_X] = point.x; - state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_Y] = point.y; if(!touch_clamped) *buttons |= VPAD_BUTTON_TOUCH;