ref: 2f7db28da82774886b27924fcc130a51d239497b
parent: 5ca12ae22ae5ad4be29b38ecb5c9c885b6cc724a
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Apr 20 08:46:36 EDT 2020
Wii U backend cleanup
--- a/src/Backends/WiiU/Misc.cpp
+++ b/src/Backends/WiiU/Misc.cpp
@@ -8,7 +8,7 @@
#include <whb/proc.h>
#include <whb/sdcard.h>
-static unsigned long tick_delta;
+static unsigned long ticks_per_second;
bool Backend_Init(void)
{
@@ -22,10 +22,10 @@
WPADInit();
KPADInit();
+ // Enable Wii U Pro Controllers to be connected
WPADEnableURCC(1);
-// WPADEnableWiiRemote(1);
- tick_delta = OSGetSystemInfo()->busClockSpeed / 4;
+ ticks_per_second = OSGetSystemInfo()->busClockSpeed / 4;
return true;
}
@@ -89,6 +89,7 @@
{
memset(keyboard_state, 0, sizeof(bool) * BACKEND_KEYBOARD_TOTAL);
+ // Read gamepad
static uint32_t vpad_buttons;
VPADStatus vpad_status;
@@ -95,17 +96,18 @@
if (VPADRead(VPAD_CHAN_0, &vpad_status, 1, NULL) == 1)
vpad_buttons = vpad_status.hold;
- keyboard_state[BACKEND_KEYBOARD_UP] = vpad_buttons & (VPAD_BUTTON_UP | VPAD_STICK_L_EMULATION_UP);
- keyboard_state[BACKEND_KEYBOARD_DOWN] = vpad_buttons & (VPAD_BUTTON_DOWN | VPAD_STICK_L_EMULATION_DOWN);
- keyboard_state[BACKEND_KEYBOARD_LEFT] = vpad_buttons & (VPAD_BUTTON_LEFT | VPAD_STICK_L_EMULATION_LEFT);
- keyboard_state[BACKEND_KEYBOARD_RIGHT] = vpad_buttons & (VPAD_BUTTON_RIGHT | VPAD_STICK_L_EMULATION_RIGHT);
- keyboard_state[BACKEND_KEYBOARD_Z] = vpad_buttons & VPAD_BUTTON_A; // Jump
- keyboard_state[BACKEND_KEYBOARD_X] = vpad_buttons & VPAD_BUTTON_B; // Shoot
- keyboard_state[BACKEND_KEYBOARD_Q] = vpad_buttons & (VPAD_BUTTON_Y | VPAD_BUTTON_PLUS); // Inventory
- keyboard_state[BACKEND_KEYBOARD_W] = vpad_buttons & (VPAD_BUTTON_X | VPAD_BUTTON_MINUS); // Map
- keyboard_state[BACKEND_KEYBOARD_A] = vpad_buttons & (VPAD_BUTTON_L | VPAD_BUTTON_ZL | VPAD_STICK_R_EMULATION_LEFT); // Weapon left
- keyboard_state[BACKEND_KEYBOARD_S] = vpad_buttons & (VPAD_BUTTON_R | VPAD_BUTTON_ZR | VPAD_STICK_R_EMULATION_RIGHT); // Weapon right
+ keyboard_state[BACKEND_KEYBOARD_UP] |= vpad_buttons & (VPAD_BUTTON_UP | VPAD_STICK_L_EMULATION_UP);
+ keyboard_state[BACKEND_KEYBOARD_DOWN] |= vpad_buttons & (VPAD_BUTTON_DOWN | VPAD_STICK_L_EMULATION_DOWN);
+ keyboard_state[BACKEND_KEYBOARD_LEFT] |= vpad_buttons & (VPAD_BUTTON_LEFT | VPAD_STICK_L_EMULATION_LEFT);
+ keyboard_state[BACKEND_KEYBOARD_RIGHT] |= vpad_buttons & (VPAD_BUTTON_RIGHT | VPAD_STICK_L_EMULATION_RIGHT);
+ keyboard_state[BACKEND_KEYBOARD_Z] |= vpad_buttons & VPAD_BUTTON_A; // Jump
+ keyboard_state[BACKEND_KEYBOARD_X] |= vpad_buttons & VPAD_BUTTON_B; // Shoot
+ keyboard_state[BACKEND_KEYBOARD_Q] |= vpad_buttons & (VPAD_BUTTON_Y | VPAD_BUTTON_PLUS); // Inventory
+ keyboard_state[BACKEND_KEYBOARD_W] |= vpad_buttons & (VPAD_BUTTON_X | VPAD_BUTTON_MINUS); // Map
+ keyboard_state[BACKEND_KEYBOARD_A] |= vpad_buttons & (VPAD_BUTTON_L | VPAD_BUTTON_ZL | VPAD_STICK_R_EMULATION_LEFT); // Weapon left
+ keyboard_state[BACKEND_KEYBOARD_S] |= vpad_buttons & (VPAD_BUTTON_R | VPAD_BUTTON_ZR | VPAD_STICK_R_EMULATION_RIGHT); // Weapon right
+ // Read Wii U Pro Controller
static uint32_t kpad_buttons;
KPADStatus kpad_status;
@@ -116,8 +118,8 @@
keyboard_state[BACKEND_KEYBOARD_DOWN] |= kpad_buttons & (WPAD_PRO_BUTTON_DOWN | WPAD_PRO_STICK_L_EMULATION_DOWN);
keyboard_state[BACKEND_KEYBOARD_LEFT] |= kpad_buttons & (WPAD_PRO_BUTTON_LEFT | WPAD_PRO_STICK_L_EMULATION_LEFT);
keyboard_state[BACKEND_KEYBOARD_RIGHT] |= kpad_buttons & (WPAD_PRO_BUTTON_RIGHT | WPAD_PRO_STICK_L_EMULATION_RIGHT);
- keyboard_state[BACKEND_KEYBOARD_Z] |= kpad_buttons & WPAD_PRO_BUTTON_A; // Jump
- keyboard_state[BACKEND_KEYBOARD_X] |= kpad_buttons & WPAD_PRO_BUTTON_B; // Shoot
+ keyboard_state[BACKEND_KEYBOARD_Z] |= kpad_buttons & WPAD_PRO_BUTTON_A; // Jump
+ keyboard_state[BACKEND_KEYBOARD_X] |= kpad_buttons & WPAD_PRO_BUTTON_B; // Shoot
keyboard_state[BACKEND_KEYBOARD_Q] |= kpad_buttons & (WPAD_PRO_BUTTON_Y | WPAD_PRO_BUTTON_PLUS); // Inventory
keyboard_state[BACKEND_KEYBOARD_W] |= kpad_buttons & (WPAD_PRO_BUTTON_X | WPAD_PRO_BUTTON_MINUS); // Map
keyboard_state[BACKEND_KEYBOARD_A] |= kpad_buttons & (WPAD_PRO_TRIGGER_L | WPAD_PRO_TRIGGER_ZL | WPAD_PRO_STICK_R_EMULATION_LEFT); // Weapon left
@@ -133,11 +135,13 @@
ATTRIBUTE_FORMAT_PRINTF(1, 2) void Backend_PrintError(const char *format, ...)
{
(void)format;
+ // We might be able to funnel this into `WHBLogPrintf`...
}
ATTRIBUTE_FORMAT_PRINTF(1, 2) void Backend_PrintInfo(const char *format, ...)
{
(void)format;
+ // We might be able to funnel this into `WHBLogPrintf`...
}
unsigned long Backend_GetTicks(void)
@@ -152,10 +156,10 @@
last_tick = current_tick;
- return (accumulator * 1000) / tick_delta;
+ return (accumulator * 1000) / ticks_per_second;
}
void Backend_Delay(unsigned int ticks)
{
- OSSleepTicks((ticks * tick_delta) / 1000);
+ OSSleepTicks((ticks * ticks_per_second) / 1000);
}