From 6a8138bf267fa9d8f2dec92b8104f00521897158 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Tue, 11 Aug 2020 21:23:29 +0200 Subject: [PATCH 1/7] Wii U: Use VPad/KPad instead of SDL input --- src/pc/controller/controller_entry_point.c | 4 + src/pc/controller/controller_sdl.c | 2 +- src/pc/controller/controller_wiiu.c | 134 +++++++++++++++++++++ src/pc/controller/controller_wiiu.h | 8 ++ 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 src/pc/controller/controller_wiiu.c create mode 100644 src/pc/controller/controller_wiiu.h diff --git a/src/pc/controller/controller_entry_point.c b/src/pc/controller/controller_entry_point.c index 5083789561..af9d170dd1 100644 --- a/src/pc/controller/controller_entry_point.c +++ b/src/pc/controller/controller_entry_point.c @@ -8,6 +8,8 @@ #if defined(_WIN32) || defined(_WIN64) #include "controller_xinput.h" +#elif defined(TARGET_WII_U) +#include "controller_wiiu.h" #else #include "controller_sdl.h" #endif @@ -20,6 +22,8 @@ static struct ControllerAPI *controller_implementations[] = { &controller_recorded_tas, #if defined(_WIN32) || defined(_WIN64) &controller_xinput, +#elif defined(__WIIU__) + &controller_wiiu, #else &controller_sdl, #endif diff --git a/src/pc/controller/controller_sdl.c b/src/pc/controller/controller_sdl.c index 1af2faf7cb..9b4831ad6a 100644 --- a/src/pc/controller/controller_sdl.c +++ b/src/pc/controller/controller_sdl.c @@ -1,4 +1,4 @@ -#if !defined(_WIN32) && !defined(_WIN64) +#if !defined(_WIN32) && !defined(_WIN64) && !defined(TARGET_WII_U) #include #include diff --git a/src/pc/controller/controller_wiiu.c b/src/pc/controller/controller_wiiu.c new file mode 100644 index 0000000000..2334c55550 --- /dev/null +++ b/src/pc/controller/controller_wiiu.c @@ -0,0 +1,134 @@ +#include +#include + +#include + +#include +#include +#include + +#include "controller_api.h" + +static void controller_wiiu_init(void) { + VPADInit(); + KPADInit(); + WPADEnableURCC(1); + WPADEnableWiiRemote(1); +} + +static void read_vpad(OSContPad *pad) { + VPADStatus status; + VPADReadError err; + uint32_t v; + + VPADRead(VPAD_CHAN_0, &status, 1, &err); + v = status.hold; + + if (v & VPAD_BUTTON_B || v & VPAD_BUTTON_A) pad->button |= A_BUTTON; + if (v & VPAD_BUTTON_Y || v & VPAD_BUTTON_X) pad->button |= B_BUTTON; + if (v & VPAD_BUTTON_ZL || v & VPAD_BUTTON_L) pad->button |= Z_TRIG; + if (v & VPAD_BUTTON_R || v & VPAD_BUTTON_ZR) pad->button |= R_TRIG; + if (v & VPAD_BUTTON_PLUS) pad->button |= START_BUTTON; + if (v & VPAD_STICK_R_EMULATION_UP) pad->button |= U_CBUTTONS; + if (v & VPAD_STICK_R_EMULATION_RIGHT) pad->button |= R_CBUTTONS; + if (v & VPAD_STICK_R_EMULATION_DOWN) pad->button |= D_CBUTTONS; + if (v & VPAD_STICK_R_EMULATION_LEFT) pad->button |= L_CBUTTONS; + + if (status.leftStick.x < 0) + pad->stick_x = (s8) (status.leftStick.x * 128); + else + pad->stick_x = (s8) (status.leftStick.x * 127); + + if (status.leftStick.y < 0) + pad->stick_y = (s8) (status.leftStick.y * 128); + else + pad->stick_y = (s8) (status.leftStick.y * 127); + +} + +static void read_wpad(OSContPad* pad) { + // Disconnect any extra controllers + for (int i = 1; i < 4; i++) { + WPADExtensionType ext; + int res = WPADProbe(i, &ext); + if (res == 0) { + WPADDisconnect(i); + } + } + + KPADStatus status; + int err; + int read = KPADReadEx(WPAD_CHAN_0, &status, 1, &err); + if (read == 0) + return; + + uint32_t wm = status.hold; + KPADVec2D stick; + bool disconnect = false; + if (status.hold & WPAD_BUTTON_MINUS) + disconnect = true; + + if (status.extensionType == WPAD_EXT_NUNCHUK || status.extensionType == WPAD_EXT_MPLUS_NUNCHUK) { + uint32_t ext = status.nunchuck.hold; + stick = status.nunchuck.stick; + + 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 (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; + if (ext & (WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_A)) pad->button |= A_BUTTON; + if (ext & (WPAD_CLASSIC_BUTTON_Y | WPAD_CLASSIC_BUTTON_X)) pad->button |= B_BUTTON; + if (ext & (WPAD_CLASSIC_BUTTON_ZL | WPAD_CLASSIC_BUTTON_L)) pad->button |= Z_TRIG; + if (ext & (WPAD_CLASSIC_BUTTON_ZR | WPAD_CLASSIC_BUTTON_R)) pad->button |= R_TRIG; + if (ext & WPAD_CLASSIC_STICK_R_EMULATION_UP) pad->button |= U_CBUTTONS; + if (ext & WPAD_CLASSIC_STICK_R_EMULATION_DOWN) pad->button |= D_CBUTTONS; + if (ext & WPAD_CLASSIC_STICK_R_EMULATION_LEFT) pad->button |= L_CBUTTONS; + if (ext & WPAD_CLASSIC_STICK_R_EMULATION_RIGHT) pad->button |= R_CBUTTONS; + if (ext & WPAD_CLASSIC_BUTTON_PLUS) pad->button |= START_BUTTON; + if (ext & WPAD_CLASSIC_BUTTON_MINUS) disconnect = true; + } else if (status.extensionType == WPAD_EXT_PRO_CONTROLLER) { + uint32_t ext = status.pro.hold; + stick = status.pro.leftStick; + if (ext & (WPAD_PRO_BUTTON_B | WPAD_PRO_BUTTON_A)) pad->button |= A_BUTTON; + if (ext & (WPAD_PRO_BUTTON_Y | WPAD_PRO_BUTTON_X)) pad->button |= B_BUTTON; + if (ext & (WPAD_PRO_TRIGGER_ZL | WPAD_PRO_TRIGGER_L)) pad->button |= Z_TRIG; + if (ext & (WPAD_PRO_TRIGGER_ZR | WPAD_PRO_TRIGGER_R)) pad->button |= R_TRIG; + if (ext & WPAD_PRO_STICK_R_EMULATION_UP) pad->button |= U_CBUTTONS; + if (ext & WPAD_PRO_STICK_R_EMULATION_DOWN) pad->button |= D_CBUTTONS; + if (ext & WPAD_PRO_STICK_R_EMULATION_LEFT) pad->button |= L_CBUTTONS; + if (ext & WPAD_PRO_STICK_R_EMULATION_RIGHT) pad->button |= R_CBUTTONS; + if (ext & WPAD_PRO_BUTTON_PLUS) pad->button |= START_BUTTON; + if (ext & WPAD_PRO_BUTTON_MINUS) disconnect = true; + } + + if (stick.x < 0) + pad->stick_x = (s8) (stick.x * 128); + else + pad->stick_x = (s8) (stick.x * 127); + + if (stick.y < 0) + pad->stick_y = (s8) (stick.y * 128); + else + pad->stick_y = (s8) (stick.y * 127); + + if (disconnect) + WPADDisconnect(WPAD_CHAN_0); +} + +static void controller_wiiu_read(OSContPad* pad) { + read_vpad(pad); + read_wpad(pad); +} + +struct ControllerAPI controller_wiiu = { + controller_wiiu_init, + controller_wiiu_read +}; diff --git a/src/pc/controller/controller_wiiu.h b/src/pc/controller/controller_wiiu.h new file mode 100644 index 0000000000..64cd0415f8 --- /dev/null +++ b/src/pc/controller/controller_wiiu.h @@ -0,0 +1,8 @@ +#ifndef CONTROLLER_WIIU_H +#define CONTROLLER_WIIU_H + +#include "controller_api.h" + +extern struct ControllerAPI controller_wiiu; + +#endif From 3aebb238164380dcd9a8453ba1337de5169fa798 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Tue, 11 Aug 2020 22:38:08 +0200 Subject: [PATCH 2/7] Wii U: Make face button arrangement configurable, and mappings easier to deal with. --- src/pc/configfile.c | 7 ++- src/pc/configfile.h | 3 + src/pc/controller/controller_wiiu.c | 95 ++++++++++++++++++++--------- 3 files changed, 74 insertions(+), 31 deletions(-) diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 10ff1e687e..12f14bd8d8 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -44,7 +44,9 @@ unsigned int configKeyStickUp = 0x11; unsigned int configKeyStickDown = 0x1F; unsigned int configKeyStickLeft = 0x1E; unsigned int configKeyStickRight = 0x20; - +#ifdef TARGET_WII_U +bool configN64FaceButtons = 1; +#endif static const struct ConfigOption options[] = { {.name = "fullscreen", .type = CONFIG_TYPE_BOOL, .boolValue = &configFullscreen}, @@ -61,6 +63,9 @@ static const struct ConfigOption options[] = { {.name = "key_stickdown", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickDown}, {.name = "key_stickleft", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickLeft}, {.name = "key_stickright", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickRight}, +#ifdef TARGET_WII_U + {.name = "n64_face_buttons", .type = CONFIG_TYPE_BOOL, .boolValue = &configN64FaceButtons} +#endif }; // Reads an entire line from a file (excluding the newline character) and returns an allocated string diff --git a/src/pc/configfile.h b/src/pc/configfile.h index ae9070b7b9..280ae27fd3 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -15,6 +15,9 @@ extern unsigned int configKeyStickUp; extern unsigned int configKeyStickDown; extern unsigned int configKeyStickLeft; extern unsigned int configKeyStickRight; +#ifdef TARGET_WII_U +extern bool configN64FaceButtons; +#endif void configfile_load(const char *filename); void configfile_save(const char *filename); diff --git a/src/pc/controller/controller_wiiu.c b/src/pc/controller/controller_wiiu.c index 2334c55550..667e4f4fd2 100644 --- a/src/pc/controller/controller_wiiu.c +++ b/src/pc/controller/controller_wiiu.c @@ -8,12 +8,56 @@ #include #include "controller_api.h" +#include "../configfile.h" + +uint32_t vpad_jump_buttons = VPAD_BUTTON_B | VPAD_BUTTON_A; +uint32_t classic_jump_buttons = WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_A; +uint32_t pro_jump_buttons = WPAD_PRO_BUTTON_B | WPAD_PRO_BUTTON_A; +uint32_t vpad_punch_buttons = VPAD_BUTTON_Y | VPAD_BUTTON_X; +uint32_t classic_punch_buttons = WPAD_CLASSIC_BUTTON_Y | WPAD_CLASSIC_BUTTON_X; +uint32_t pro_punch_buttons = WPAD_PRO_BUTTON_Y | WPAD_PRO_BUTTON_X; + +struct WiiUKeymap { + uint32_t n64Button; + uint32_t vpadButton; + uint32_t classicButton; + uint32_t proButton; +}; + +// Button shortcuts +#define VB(btn) VPAD_BUTTON_##btn +#define CB(btn) WPAD_CLASSIC_BUTTON_##btn +#define PB(btn) WPAD_PRO_BUTTON_##btn +#define PT(btn) WPAD_PRO_TRIGGER_##btn + +// Stick emulation +#define SE(dir) VPAD_STICK_R_EMULATION_##dir, WPAD_CLASSIC_STICK_R_EMULATION_##dir, WPAD_PRO_STICK_R_EMULATION_##dir + +struct WiiUKeymap map[] = { + { B_BUTTON, VB(X) | VB(A), CB(X) | CB(A), PB(X) | PB(A) }, + { A_BUTTON, VB(Y) | VB(B), CB(Y) | CB(B), PB(Y) | PB(B) }, + { START_BUTTON, VB(PLUS), CB(PLUS), PB(PLUS) }, + { Z_TRIG, VB(L) | VB(ZL), CB(L) | CB(ZL), PT(L) | PT(ZL) }, + { R_TRIG, VB(R) | VB(ZR), CB(R) | CB(ZR), PT(R) | PT(ZR) }, + { U_CBUTTONS, SE(UP) }, + { D_CBUTTONS, SE(DOWN) }, + { L_CBUTTONS, SE(LEFT) }, + { R_CBUTTONS, SE(RIGHT) } +}; +size_t num_buttons = sizeof(map) / sizeof(map[0]); static void controller_wiiu_init(void) { VPADInit(); KPADInit(); WPADEnableURCC(1); WPADEnableWiiRemote(1); + + if (configN64FaceButtons) { + struct WiiUKeymap b = { B_BUTTON, VB(Y) | VB(X), CB(Y) | CB(X), PB(Y) | PB(X) }; + struct WiiUKeymap a = { A_BUTTON, VB(B) | VB(A), CB(B) | CB(A), PB(B) | PB(A) }; + map[0] = b; + map[1] = a; + } } static void read_vpad(OSContPad *pad) { @@ -24,15 +68,11 @@ static void read_vpad(OSContPad *pad) { VPADRead(VPAD_CHAN_0, &status, 1, &err); v = status.hold; - if (v & VPAD_BUTTON_B || v & VPAD_BUTTON_A) pad->button |= A_BUTTON; - if (v & VPAD_BUTTON_Y || v & VPAD_BUTTON_X) pad->button |= B_BUTTON; - if (v & VPAD_BUTTON_ZL || v & VPAD_BUTTON_L) pad->button |= Z_TRIG; - if (v & VPAD_BUTTON_R || v & VPAD_BUTTON_ZR) pad->button |= R_TRIG; - if (v & VPAD_BUTTON_PLUS) pad->button |= START_BUTTON; - if (v & VPAD_STICK_R_EMULATION_UP) pad->button |= U_CBUTTONS; - if (v & VPAD_STICK_R_EMULATION_RIGHT) pad->button |= R_CBUTTONS; - if (v & VPAD_STICK_R_EMULATION_DOWN) pad->button |= D_CBUTTONS; - if (v & VPAD_STICK_R_EMULATION_LEFT) pad->button |= L_CBUTTONS; + for (int i = 0; i < num_buttons; i++) { + if (v & map[i].vpadButton) { + pad->button |= map[i].n64Button; + } + } if (status.leftStick.x < 0) pad->stick_x = (s8) (status.leftStick.x * 128); @@ -43,7 +83,6 @@ static void read_vpad(OSContPad *pad) { pad->stick_y = (s8) (status.leftStick.y * 128); else pad->stick_y = (s8) (status.leftStick.y * 127); - } static void read_wpad(OSContPad* pad) { @@ -84,29 +123,25 @@ static void read_wpad(OSContPad* pad) { } else if (status.extensionType == WPAD_EXT_CLASSIC || status.extensionType == WPAD_EXT_MPLUS_CLASSIC) { uint32_t ext = status.classic.hold; stick = status.classic.leftStick; - if (ext & (WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_A)) pad->button |= A_BUTTON; - if (ext & (WPAD_CLASSIC_BUTTON_Y | WPAD_CLASSIC_BUTTON_X)) pad->button |= B_BUTTON; - if (ext & (WPAD_CLASSIC_BUTTON_ZL | WPAD_CLASSIC_BUTTON_L)) pad->button |= Z_TRIG; - if (ext & (WPAD_CLASSIC_BUTTON_ZR | WPAD_CLASSIC_BUTTON_R)) pad->button |= R_TRIG; - if (ext & WPAD_CLASSIC_STICK_R_EMULATION_UP) pad->button |= U_CBUTTONS; - if (ext & WPAD_CLASSIC_STICK_R_EMULATION_DOWN) pad->button |= D_CBUTTONS; - if (ext & WPAD_CLASSIC_STICK_R_EMULATION_LEFT) pad->button |= L_CBUTTONS; - if (ext & WPAD_CLASSIC_STICK_R_EMULATION_RIGHT) pad->button |= R_CBUTTONS; - if (ext & WPAD_CLASSIC_BUTTON_PLUS) pad->button |= START_BUTTON; - if (ext & WPAD_CLASSIC_BUTTON_MINUS) disconnect = true; + for (size_t i = 0; i < num_buttons; i++) { + if (ext & map[i].classicButton) { + pad->button |= map[i].n64Button; + } + } + if (ext & WPAD_CLASSIC_BUTTON_MINUS) { + disconnect = true; + } } else if (status.extensionType == WPAD_EXT_PRO_CONTROLLER) { uint32_t ext = status.pro.hold; stick = status.pro.leftStick; - if (ext & (WPAD_PRO_BUTTON_B | WPAD_PRO_BUTTON_A)) pad->button |= A_BUTTON; - if (ext & (WPAD_PRO_BUTTON_Y | WPAD_PRO_BUTTON_X)) pad->button |= B_BUTTON; - if (ext & (WPAD_PRO_TRIGGER_ZL | WPAD_PRO_TRIGGER_L)) pad->button |= Z_TRIG; - if (ext & (WPAD_PRO_TRIGGER_ZR | WPAD_PRO_TRIGGER_R)) pad->button |= R_TRIG; - if (ext & WPAD_PRO_STICK_R_EMULATION_UP) pad->button |= U_CBUTTONS; - if (ext & WPAD_PRO_STICK_R_EMULATION_DOWN) pad->button |= D_CBUTTONS; - if (ext & WPAD_PRO_STICK_R_EMULATION_LEFT) pad->button |= L_CBUTTONS; - if (ext & WPAD_PRO_STICK_R_EMULATION_RIGHT) pad->button |= R_CBUTTONS; - if (ext & WPAD_PRO_BUTTON_PLUS) pad->button |= START_BUTTON; - if (ext & WPAD_PRO_BUTTON_MINUS) disconnect = true; + for (int i = 0; i < num_buttons; i++) { + if (ext & map[i].proButton) { + pad->button |= map[i].n64Button; + } + } + if (ext & WPAD_PRO_BUTTON_MINUS) { + disconnect = true; + } } if (stick.x < 0) From e6a2c5c6d67b8d89e31f84b35e56371af19951f4 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 12 Aug 2020 00:04:06 +0200 Subject: [PATCH 3/7] Wii U: Don't break the controls if the gamepad is not connected. --- src/pc/controller/controller_wiiu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pc/controller/controller_wiiu.c b/src/pc/controller/controller_wiiu.c index 667e4f4fd2..65fa41c7ce 100644 --- a/src/pc/controller/controller_wiiu.c +++ b/src/pc/controller/controller_wiiu.c @@ -66,6 +66,10 @@ static void read_vpad(OSContPad *pad) { uint32_t v; VPADRead(VPAD_CHAN_0, &status, 1, &err); + + if (err != 0) + return; + v = status.hold; for (int i = 0; i < num_buttons; i++) { From daa36557704c24ac2f04897dd33ff902d20b35e8 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 12 Aug 2020 00:24:47 +0200 Subject: [PATCH 4/7] Wii U: Fix GamePad analog stick not working while controller is connected --- src/pc/controller/controller_wiiu.c | 50 ++++++++++++++++------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/src/pc/controller/controller_wiiu.c b/src/pc/controller/controller_wiiu.c index 65fa41c7ce..1030e6963e 100644 --- a/src/pc/controller/controller_wiiu.c +++ b/src/pc/controller/controller_wiiu.c @@ -1,5 +1,6 @@ #include #include +#include #include @@ -24,6 +25,10 @@ struct WiiUKeymap { uint32_t proButton; }; +typedef struct Vec2D { + float x, y; +} Vec2D; + // Button shortcuts #define VB(btn) VPAD_BUTTON_##btn #define CB(btn) WPAD_CLASSIC_BUTTON_##btn @@ -60,7 +65,7 @@ static void controller_wiiu_init(void) { } } -static void read_vpad(OSContPad *pad) { +static Vec2D read_vpad(OSContPad *pad) { VPADStatus status; VPADReadError err; uint32_t v; @@ -68,28 +73,20 @@ static void read_vpad(OSContPad *pad) { VPADRead(VPAD_CHAN_0, &status, 1, &err); if (err != 0) - return; + return (Vec2D) { 0, 0 }; v = status.hold; - for (int i = 0; i < num_buttons; i++) { + for (size_t i = 0; i < num_buttons; i++) { if (v & map[i].vpadButton) { pad->button |= map[i].n64Button; } } - if (status.leftStick.x < 0) - pad->stick_x = (s8) (status.leftStick.x * 128); - else - pad->stick_x = (s8) (status.leftStick.x * 127); - - if (status.leftStick.y < 0) - pad->stick_y = (s8) (status.leftStick.y * 128); - else - pad->stick_y = (s8) (status.leftStick.y * 127); + return (Vec2D) { status.leftStick.x, status.leftStick.y }; } -static void read_wpad(OSContPad* pad) { +static Vec2D read_wpad(OSContPad* pad) { // Disconnect any extra controllers for (int i = 1; i < 4; i++) { WPADExtensionType ext; @@ -103,7 +100,7 @@ static void read_wpad(OSContPad* pad) { int err; int read = KPADReadEx(WPAD_CHAN_0, &status, 1, &err); if (read == 0) - return; + return (Vec2D) { 0, 0 }; uint32_t wm = status.hold; KPADVec2D stick; @@ -138,7 +135,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; - for (int i = 0; i < num_buttons; i++) { + for (size_t i = 0; i < num_buttons; i++) { if (ext & map[i].proButton) { pad->button |= map[i].n64Button; } @@ -148,6 +145,21 @@ static void read_wpad(OSContPad* pad) { } } + if (disconnect) + WPADDisconnect(WPAD_CHAN_0); + + return (Vec2D) { stick.x, stick.y }; +} + +static void controller_wiiu_read(OSContPad* pad) { + Vec2D vstick = read_vpad(pad); + Vec2D wstick = read_wpad(pad); + + Vec2D stick = wstick; + if (vstick.x != 0 && vstick.y != 0) { + stick = vstick; + } + if (stick.x < 0) pad->stick_x = (s8) (stick.x * 128); else @@ -157,14 +169,6 @@ static void read_wpad(OSContPad* pad) { pad->stick_y = (s8) (stick.y * 128); else pad->stick_y = (s8) (stick.y * 127); - - if (disconnect) - WPADDisconnect(WPAD_CHAN_0); -} - -static void controller_wiiu_read(OSContPad* pad) { - read_vpad(pad); - read_wpad(pad); } struct ControllerAPI controller_wiiu = { From fa31e6dceb261542d6181967a6151ac3655e3e8e Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 12 Aug 2020 18:15:39 +0200 Subject: [PATCH 5/7] Wii U: Default to the Virtual Console button layout --- src/pc/configfile.c | 2 +- src/pc/controller/controller_wiiu.c | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 12f14bd8d8..f0d3afa15a 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -45,7 +45,7 @@ unsigned int configKeyStickDown = 0x1F; unsigned int configKeyStickLeft = 0x1E; unsigned int configKeyStickRight = 0x20; #ifdef TARGET_WII_U -bool configN64FaceButtons = 1; +bool configN64FaceButtons = 0; #endif static const struct ConfigOption options[] = { diff --git a/src/pc/controller/controller_wiiu.c b/src/pc/controller/controller_wiiu.c index 1030e6963e..36f18c9ce5 100644 --- a/src/pc/controller/controller_wiiu.c +++ b/src/pc/controller/controller_wiiu.c @@ -39,8 +39,8 @@ typedef struct Vec2D { #define SE(dir) VPAD_STICK_R_EMULATION_##dir, WPAD_CLASSIC_STICK_R_EMULATION_##dir, WPAD_PRO_STICK_R_EMULATION_##dir struct WiiUKeymap map[] = { - { B_BUTTON, VB(X) | VB(A), CB(X) | CB(A), PB(X) | PB(A) }, - { A_BUTTON, VB(Y) | VB(B), CB(Y) | CB(B), PB(Y) | PB(B) }, + { B_BUTTON, VB(B), CB(B), PB(B) }, + { A_BUTTON, VB(A), CB(A), PB(A) }, { START_BUTTON, VB(PLUS), CB(PLUS), PB(PLUS) }, { Z_TRIG, VB(L) | VB(ZL), CB(L) | CB(ZL), PT(L) | PT(ZL) }, { R_TRIG, VB(R) | VB(ZR), CB(R) | CB(ZR), PT(R) | PT(ZR) }, @@ -58,10 +58,8 @@ static void controller_wiiu_init(void) { WPADEnableWiiRemote(1); if (configN64FaceButtons) { - struct WiiUKeymap b = { B_BUTTON, VB(Y) | VB(X), CB(Y) | CB(X), PB(Y) | PB(X) }; - struct WiiUKeymap a = { A_BUTTON, VB(B) | VB(A), CB(B) | CB(A), PB(B) | PB(A) }; - map[0] = b; - map[1] = a; + map[0] = (struct WiiUKeymap) { B_BUTTON, VB(Y) | VB(X), CB(Y) | CB(X), PB(Y) | PB(X) }; + map[1] = (struct WiiUKeymap) { A_BUTTON, VB(B) | VB(A), CB(B) | CB(A), PB(B) | PB(A) }; } } From 9383c313bb897872f8fbae01b5b1e6d7d82ea54a Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 12 Aug 2020 18:25:42 +0200 Subject: [PATCH 6/7] Wii U: Actually save configuration file, also clean up initialization --- src/pc/controller/controller_entry_point.c | 2 -- src/pc/controller/controller_keyboard.c | 4 ---- src/pc/pc_main.c | 23 ++++++---------------- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/pc/controller/controller_entry_point.c b/src/pc/controller/controller_entry_point.c index af9d170dd1..d3d545e632 100644 --- a/src/pc/controller/controller_entry_point.c +++ b/src/pc/controller/controller_entry_point.c @@ -30,9 +30,7 @@ static struct ControllerAPI *controller_implementations[] = { #ifdef __linux__ &controller_wup, #endif -#ifndef __WIIU__ &controller_keyboard, -#endif }; s32 osContInit(UNUSED OSMesgQueue *mq, u8 *controllerBits, UNUSED OSContStatus *status) { diff --git a/src/pc/controller/controller_keyboard.c b/src/pc/controller/controller_keyboard.c index 4ad5da08f6..a49b86a841 100644 --- a/src/pc/controller/controller_keyboard.c +++ b/src/pc/controller/controller_keyboard.c @@ -1,5 +1,3 @@ -#ifndef __WIIU__ - #include #include @@ -88,5 +86,3 @@ struct ControllerAPI controller_keyboard = { keyboard_init, keyboard_read }; - -#endif diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index a064eb4671..059978dee4 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -163,21 +163,6 @@ void main_func(void) { main_pool_init(pool, pool + sizeof(pool) / sizeof(pool[0])); gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT); -#ifdef TARGET_WII_U - WHBLogPrint("Main pool initialized."); - - rendering_api = &gfx_whb_api; - wm_api = &gfx_sdl; - configFullscreen = true; - - gfx_init(wm_api, rendering_api, "Super Mario 64 PC-Port", true); - - WHBLogPrint("Gfx initialized."); - - wm_api->set_fullscreen_changed_callback(NULL); - wm_api->set_keyboard_callbacks(NULL, NULL, NULL); - -#else configfile_load(CONFIG_FILE); atexit(save_config); @@ -186,7 +171,12 @@ void main_func(void) { request_anim_frame(on_anim_frame); #endif -#if defined(ENABLE_DX12) +#if defined(TARGET_WII_U) + WHBLogPrint("Main pool initialized."); + rendering_api = &gfx_whb_api; + wm_api = &gfx_sdl; + configFullscreen = true; +#elif defined(ENABLE_DX12) rendering_api = &gfx_direct3d12_api; wm_api = &gfx_dxgi_api; #elif defined(ENABLE_DX11) @@ -206,7 +196,6 @@ void main_func(void) { wm_api->set_fullscreen_changed_callback(on_fullscreen_changed); wm_api->set_keyboard_callbacks(keyboard_on_key_down, keyboard_on_key_up, keyboard_on_all_keys_up); -#endif #if HAVE_WASAPI if (audio_api == NULL && audio_wasapi.init()) { From d72fe25e7aa1f9badeadb4e917f7ada13f42589a Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 12 Aug 2020 20:21:02 +0200 Subject: [PATCH 7/7] Wii U: Enable X/Y for A/B layout. --- src/pc/controller/controller_wiiu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pc/controller/controller_wiiu.c b/src/pc/controller/controller_wiiu.c index 36f18c9ce5..b132c484df 100644 --- a/src/pc/controller/controller_wiiu.c +++ b/src/pc/controller/controller_wiiu.c @@ -39,8 +39,8 @@ typedef struct Vec2D { #define SE(dir) VPAD_STICK_R_EMULATION_##dir, WPAD_CLASSIC_STICK_R_EMULATION_##dir, WPAD_PRO_STICK_R_EMULATION_##dir struct WiiUKeymap map[] = { - { B_BUTTON, VB(B), CB(B), PB(B) }, - { A_BUTTON, VB(A), CB(A), PB(A) }, + { B_BUTTON, VB(B) | VB(Y), CB(B) | CB(Y), PB(B) | PB(Y) }, + { A_BUTTON, VB(A) | VB(X), CB(A) | CB(X), PB(A) | PB(X) }, { START_BUTTON, VB(PLUS), CB(PLUS), PB(PLUS) }, { Z_TRIG, VB(L) | VB(ZL), CB(L) | CB(ZL), PT(L) | PT(ZL) }, { R_TRIG, VB(R) | VB(ZR), CB(R) | CB(ZR), PT(R) | PT(ZR) },