Wii U backend cleanup
This commit is contained in:
parent
5ca12ae22a
commit
2f7db28da8
1 changed files with 21 additions and 17 deletions
|
@ -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 @@ bool Backend_Init(void)
|
|||
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,23 +89,25 @@ void Backend_GetKeyboardState(bool *keyboard_state)
|
|||
{
|
||||
memset(keyboard_state, 0, sizeof(bool) * BACKEND_KEYBOARD_TOTAL);
|
||||
|
||||
// Read gamepad
|
||||
static uint32_t vpad_buttons;
|
||||
|
||||
VPADStatus vpad_status;
|
||||
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 @@ void Backend_GetKeyboardState(bool *keyboard_state)
|
|||
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 @@ void Backend_ShowMessageBox(const char *title, const char *message)
|
|||
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 @@ unsigned long Backend_GetTicks(void)
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue