diff --git a/src/pc/controller/controller_3ds.c b/src/pc/controller/controller_3ds.c index 4d088c3..40f14b6 100644 --- a/src/pc/controller/controller_3ds.c +++ b/src/pc/controller/controller_3ds.c @@ -91,7 +91,7 @@ static void controller_3ds_read(OSContPad *pad) pad->stick_y = pos.dy / 2; } -static void controller_3ds_rawkey(void) +static u32 controller_3ds_rawkey(void) { return VK_INVALID; } diff --git a/src/pc/controller/controller_sdl1.c b/src/pc/controller/controller_sdl1.c index dbedf83..3510367 100644 --- a/src/pc/controller/controller_sdl1.c +++ b/src/pc/controller/controller_sdl1.c @@ -227,17 +227,31 @@ static void controller_sdl_read(OSContPad *pad) { uint32_t magnitude_sq = (uint32_t)(leftx * leftx) + (uint32_t)(lefty * lefty); uint32_t stickDeadzoneActual = configStickDeadzone * DEADZONE_STEP; if (magnitude_sq > (uint32_t)(stickDeadzoneActual * stickDeadzoneActual)) { + #if 0 // not used but leaving just in case pad->stick_x = leftx / 0x100; int stick_y = -lefty / 0x100; pad->stick_y = stick_y == 128 ? 127 : stick_y; + #else + // Game expects stick coordinates within -80..80 + // 32768 / 409 = ~80 + pad->stick_x = leftx / 409; + pad->stick_y = -lefty / 409; + #endif } magnitude_sq = (uint32_t)(rightx * rightx) + (uint32_t)(righty * righty); stickDeadzoneActual = configStickDeadzone * DEADZONE_STEP; if (magnitude_sq > (uint32_t)(stickDeadzoneActual * stickDeadzoneActual)) { + #if 0 // not used but leaving just in case pad->ext_stick_x = rightx / 0x100; int stick_y = -righty / 0x100; pad->ext_stick_y = stick_y == 128 ? 127 : stick_y; + #else + // Game expects stick coordinates within -80..80 + // 32768 / 409 = ~80 + pad->ext_stick_x = rightx / 409; + pad->ext_stick_y = -righty / 409; + #endif } } diff --git a/src/pc/controller/controller_sdl2.c b/src/pc/controller/controller_sdl2.c index c5ef2db..31050d0 100644 --- a/src/pc/controller/controller_sdl2.c +++ b/src/pc/controller/controller_sdl2.c @@ -255,17 +255,31 @@ static void controller_sdl_read(OSContPad *pad) { uint32_t magnitude_sq = (uint32_t)(leftx * leftx) + (uint32_t)(lefty * lefty); uint32_t stickDeadzoneActual = configStickDeadzone * DEADZONE_STEP; if (magnitude_sq > (uint32_t)(stickDeadzoneActual * stickDeadzoneActual)) { + #if 0 // not used but leaving just in case pad->stick_x = leftx / 0x100; int stick_y = -lefty / 0x100; pad->stick_y = stick_y == 128 ? 127 : stick_y; + #else + // Game expects stick coordinates within -80..80 + // 32768 / 409 = ~80 + pad->stick_x = leftx / 409; + pad->stick_y = -lefty / 409; + #endif } magnitude_sq = (uint32_t)(rightx * rightx) + (uint32_t)(righty * righty); stickDeadzoneActual = configStickDeadzone * DEADZONE_STEP; if (magnitude_sq > (uint32_t)(stickDeadzoneActual * stickDeadzoneActual)) { + #if 0 // not used but leaving just in case pad->ext_stick_x = rightx / 0x100; int stick_y = -righty / 0x100; pad->ext_stick_y = stick_y == 128 ? 127 : stick_y; + #else + // Game expects stick coordinates within -80..80 + // 32768 / 409 = ~80 + pad->ext_stick_x = rightx / 409; + pad->ext_stick_y = -righty / 409; + #endif } } diff --git a/src/pc/controller/controller_wiiu.c b/src/pc/controller/controller_wiiu.c index c99ada0..0bc88fb 100644 --- a/src/pc/controller/controller_wiiu.c +++ b/src/pc/controller/controller_wiiu.c @@ -14,6 +14,9 @@ #include "controller_api.h" #include "../configfile.h" +int16_t rightx; +int16_t righty; + extern void KPADShutdown(); struct WiiUKeymap { @@ -86,6 +89,13 @@ static void read_vpad(OSContPad *pad) { if (status.leftStick.y != 0) { pad->stick_y = (s8) round(status.leftStick.y * 80); } + + if (status.rightStick.x != 0) { + rightx = (int16_t) round(status.rightStick.x * 32767); + } + if (status.rightStick.y != 0) { + righty = (int16_t) round(status.rightStick.y * 32767); + } } static void read_wpad(OSContPad* pad) { @@ -122,25 +132,29 @@ static void read_wpad(OSContPad* pad) { uint32_t wm = status.hold; KPADVec2D stick; + KPADVec2D rStick; bool gamepadStickNotSet = pad->stick_x == 0 && pad->stick_y == 0; + bool gamepadRightStickNotSet = rightx == 0 && righty == 0; if (status.extensionType == WPAD_EXT_NUNCHUK || status.extensionType == WPAD_EXT_MPLUS_NUNCHUK) { uint32_t ext = status.nunchuck.hold; stick = status.nunchuck.stick; + rStick = (KPADVec2D) {0.0, 0.0}; if (wm & WPAD_BUTTON_A) pad->button |= A_BUTTON; if (wm & WPAD_BUTTON_B) pad->button |= B_BUTTON; if (wm & WPAD_BUTTON_PLUS) pad->button |= START_BUTTON; - if (wm & WPAD_BUTTON_UP) pad->button |= U_CBUTTONS; - if (wm & WPAD_BUTTON_DOWN) pad->button |= D_CBUTTONS; - if (wm & WPAD_BUTTON_LEFT) pad->button |= L_CBUTTONS; - if (wm & WPAD_BUTTON_RIGHT) pad->button |= R_CBUTTONS; + if (wm & WPAD_BUTTON_UP) { pad->button |= U_CBUTTONS; rStick.y += 1.0; } + if (wm & WPAD_BUTTON_DOWN) { pad->button |= D_CBUTTONS; rStick.y -= 1.0; } + if (wm & WPAD_BUTTON_LEFT) { pad->button |= L_CBUTTONS; rStick.x -= 1.0; } + if (wm & WPAD_BUTTON_RIGHT) { pad->button |= R_CBUTTONS; rStick.x += 1.0; } if (ext & WPAD_NUNCHUK_BUTTON_C) pad->button |= R_TRIG; if (ext & WPAD_NUNCHUK_BUTTON_Z) pad->button |= Z_TRIG; } else if (status.extensionType == WPAD_EXT_CLASSIC || status.extensionType == WPAD_EXT_MPLUS_CLASSIC) { uint32_t ext = status.classic.hold; stick = status.classic.leftStick; + rStick = status.classic.rightStick; for (size_t i = 0; i < num_buttons; i++) { if (ext & map[i].classicButton) { pad->button |= map[i].n64Button; @@ -153,6 +167,7 @@ static void read_wpad(OSContPad* pad) { } else if (status.extensionType == WPAD_EXT_PRO_CONTROLLER) { uint32_t ext = status.pro.hold; stick = status.pro.leftStick; + rStick = status.pro.rightStick; for (size_t i = 0; i < num_buttons; i++) { if (ext & map[i].proButton) { pad->button |= map[i].n64Button; @@ -173,12 +188,24 @@ static void read_wpad(OSContPad* pad) { pad->stick_y = (s8) round(stick.y * 80); } } + + if (gamepadRightStickNotSet) { + if (rStick.x != 0) { + rightx = (int16_t) round(rStick.x * 32767); + } + if (rStick.y != 0) { + righty = (int16_t) round(rStick.y * 32767); + } + } } static void controller_wiiu_read(OSContPad* pad) { pad->stick_x = 0; pad->stick_y = 0; + rightx = 0; + righty = 0; + read_vpad(pad); read_wpad(pad); }