Add Wiimote + Classic Controller support

This commit is contained in:
askot 2015-08-21 23:09:16 -07:00
parent 3d14cd0b5b
commit 90597dc6df
1 changed files with 47 additions and 17 deletions

View File

@ -8,6 +8,7 @@
#include <fat.h> #include <fat.h>
#include <gccore.h> #include <gccore.h>
#include <malloc.h> #include <malloc.h>
#include <wiiuse/wpad.h>
#include "util/common.h" #include "util/common.h"
@ -52,6 +53,7 @@ static struct GUIFont* font;
int main() { int main() {
VIDEO_Init(); VIDEO_Init();
PAD_Init(); PAD_Init();
WPAD_Init();
AUDIO_Init(0); AUDIO_Init(0);
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ); AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
AUDIO_RegisterDMACallback(_audioDMA); AUDIO_RegisterDMACallback(_audioDMA);
@ -195,35 +197,50 @@ int main() {
#endif #endif
PAD_ScanPads(); PAD_ScanPads();
u16 padkeys = PAD_ButtonsHeld(0); u16 padkeys = PAD_ButtonsHeld(0);
WPAD_ScanPads();
u32 wiiPad = WPAD_ButtonsHeld(0);
u32 ext = 0;
uint16_t keys = 0; uint16_t keys = 0;
if (padkeys & PAD_BUTTON_A) { WPAD_Probe(0, &ext);
if ((padkeys & PAD_BUTTON_A) || (wiiPad & WPAD_BUTTON_2) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & (WPAD_CLASSIC_BUTTON_A | WPAD_CLASSIC_BUTTON_Y)))) {
keys |= 1 << GBA_KEY_A; keys |= 1 << GBA_KEY_A;
} }
if (padkeys & PAD_BUTTON_B) { if ((padkeys & PAD_BUTTON_B) || (wiiPad & WPAD_BUTTON_1) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & (WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_X)))) {
keys |= 1 << GBA_KEY_B; keys |= 1 << GBA_KEY_B;
} }
if (padkeys & PAD_TRIGGER_L) { if ((padkeys & PAD_TRIGGER_L) || (wiiPad & WPAD_BUTTON_B) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & WPAD_CLASSIC_BUTTON_FULL_L))) {
keys |= 1 << GBA_KEY_L; keys |= 1 << GBA_KEY_L;
} }
if (padkeys & PAD_TRIGGER_R) { if ((padkeys & PAD_TRIGGER_R) || (wiiPad & WPAD_BUTTON_A) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & WPAD_CLASSIC_BUTTON_FULL_R))) {
keys |= 1 << GBA_KEY_R; keys |= 1 << GBA_KEY_R;
} }
if (padkeys & PAD_BUTTON_START) { if ((padkeys & PAD_BUTTON_START) || (wiiPad & WPAD_BUTTON_PLUS) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & WPAD_CLASSIC_BUTTON_PLUS))) {
keys |= 1 << GBA_KEY_START; keys |= 1 << GBA_KEY_START;
} }
if (padkeys & (PAD_BUTTON_X | PAD_BUTTON_Y)) { if ((padkeys & (PAD_BUTTON_X | PAD_BUTTON_Y))|| (wiiPad & WPAD_BUTTON_MINUS) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & WPAD_CLASSIC_BUTTON_MINUS))) {
keys |= 1 << GBA_KEY_SELECT; keys |= 1 << GBA_KEY_SELECT;
} }
if (padkeys & PAD_BUTTON_LEFT) { if ((padkeys & PAD_BUTTON_LEFT)|| (wiiPad & WPAD_BUTTON_UP) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & WPAD_CLASSIC_BUTTON_LEFT))) {
keys |= 1 << GBA_KEY_LEFT; keys |= 1 << GBA_KEY_LEFT;
} }
if (padkeys & PAD_BUTTON_RIGHT) { if ((padkeys & PAD_BUTTON_RIGHT) || (wiiPad & WPAD_BUTTON_DOWN) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & WPAD_CLASSIC_BUTTON_RIGHT))) {
keys |= 1 << GBA_KEY_RIGHT; keys |= 1 << GBA_KEY_RIGHT;
} }
if (padkeys & PAD_BUTTON_UP) { if ((padkeys & PAD_BUTTON_UP) || (wiiPad & WPAD_BUTTON_RIGHT) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & WPAD_CLASSIC_BUTTON_UP))) {
keys |= 1 << GBA_KEY_UP; keys |= 1 << GBA_KEY_UP;
} }
if (padkeys & PAD_BUTTON_DOWN) { if ((padkeys & PAD_BUTTON_DOWN) || (wiiPad & WPAD_BUTTON_LEFT) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & WPAD_CLASSIC_BUTTON_DOWN))) {
keys |= 1 << GBA_KEY_DOWN; keys |= 1 << GBA_KEY_DOWN;
} }
int x = PAD_StickX(0); int x = PAD_StickX(0);
@ -240,7 +257,7 @@ int main() {
if (y > 0x40) { if (y > 0x40) {
keys |= 1 << GBA_KEY_UP; keys |= 1 << GBA_KEY_UP;
} }
if (padkeys & PAD_TRIGGER_Z) { if ((padkeys & PAD_TRIGGER_Z) || (wiiPad & WPAD_BUTTON_HOME) || (wiiPad & WPAD_CLASSIC_BUTTON_HOME)) {
break; break;
} }
GBAContextFrame(&context, keys); GBAContextFrame(&context, keys);
@ -350,23 +367,36 @@ static void _drawEnd(void) {
static int _pollInput(void) { static int _pollInput(void) {
PAD_ScanPads(); PAD_ScanPads();
u16 padkeys = PAD_ButtonsHeld(0); u16 padkeys = PAD_ButtonsHeld(0);
WPAD_ScanPads();
u32 wiiPad = WPAD_ButtonsHeld(0);
u32 ext = 0;
int keys = 0; int keys = 0;
if (padkeys & PAD_BUTTON_A) {
WPAD_Probe(0, &ext);
if ((padkeys & PAD_BUTTON_A) || (wiiPad & WPAD_BUTTON_2) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & (WPAD_CLASSIC_BUTTON_A | WPAD_CLASSIC_BUTTON_Y)))) {
keys |= 1 << GUI_INPUT_SELECT; keys |= 1 << GUI_INPUT_SELECT;
} }
if (padkeys & PAD_BUTTON_B) { if ((padkeys & PAD_BUTTON_B) || (wiiPad & WPAD_BUTTON_1) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & (WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_X)))) {
keys |= 1 << GUI_INPUT_BACK; keys |= 1 << GUI_INPUT_BACK;
} }
if (padkeys & PAD_BUTTON_LEFT) { if ((padkeys & PAD_BUTTON_LEFT)|| (wiiPad & WPAD_BUTTON_UP) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & WPAD_CLASSIC_BUTTON_LEFT))) {
keys |= 1 << GUI_INPUT_LEFT; keys |= 1 << GUI_INPUT_LEFT;
} }
if (padkeys & PAD_BUTTON_RIGHT) { if ((padkeys & PAD_BUTTON_RIGHT) || (wiiPad & WPAD_BUTTON_DOWN) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & WPAD_CLASSIC_BUTTON_RIGHT))) {
keys |= 1 << GUI_INPUT_RIGHT; keys |= 1 << GUI_INPUT_RIGHT;
} }
if (padkeys & PAD_BUTTON_UP) { if ((padkeys & PAD_BUTTON_UP) || (wiiPad & WPAD_BUTTON_RIGHT) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & WPAD_CLASSIC_BUTTON_UP))) {
keys |= 1 << GUI_INPUT_UP; keys |= 1 << GUI_INPUT_UP;
} }
if (padkeys & PAD_BUTTON_DOWN) { if ((padkeys & PAD_BUTTON_DOWN) || (wiiPad & WPAD_BUTTON_LEFT) ||
((ext == WPAD_EXP_CLASSIC) && (wiiPad & WPAD_CLASSIC_BUTTON_DOWN))) {
keys |= 1 << GUI_INPUT_DOWN; keys |= 1 << GUI_INPUT_DOWN;
} }
return keys; return keys;