From 41a80cd6f9ea064c4f7d54f8198658fa75a560a4 Mon Sep 17 00:00:00 2001 From: Daryl Borth Date: Wed, 5 Sep 2018 20:00:21 -0600 Subject: [PATCH] Add Wii U GamePad support (thanks Fix94!) --- readme.txt | 6 +- source/button_mapping.c | 25 +++- source/button_mapping.h | 9 +- source/filelist.h | 2 + source/gui/gui.h | 23 +++- source/gui/gui_button.cpp | 29 +++-- source/gui/gui_filebrowser.cpp | 6 +- source/gui/gui_keyboard.cpp | 4 +- source/gui/gui_optionbrowser.cpp | 4 +- source/gui/gui_savebrowser.cpp | 4 +- source/gui/gui_trigger.cpp | 33 +++-- source/gui/gui_window.cpp | 2 +- source/images/icon_settings_drc.png | Bin 0 -> 6562 bytes source/input.cpp | 128 +++++++++++++------ source/input.h | 5 +- source/menu.cpp | 127 ++++++++++++------- source/preferences.cpp | 9 +- source/utils/wiidrc.c | 188 ++++++++++++++++++++++++++++ source/utils/wiidrc.h | 67 ++++++++++ source/vbagx.cpp | 4 +- 20 files changed, 547 insertions(+), 128 deletions(-) create mode 100644 source/images/icon_settings_drc.png create mode 100644 source/utils/wiidrc.c create mode 100644 source/utils/wiidrc.h diff --git a/readme.txt b/readme.txt index 9fe979d..b40945e 100644 --- a/readme.txt +++ b/readme.txt @@ -15,7 +15,8 @@ https://github.com/dborth/vbagx/releases -=[ Features ]=- -* Wiimote, Nunchuk, Classic, and Gamecube controller support +* Wiimote, Nunchuk, Classic, Wii U Pro, and Gamecube controller support +* Wii U GamePad support (requires homebrew injection into Wii U VC title) * Rotation sensors, Solar sensors, and Rumble support * Optional special Wii controls built-in for some games * SRAM and State saving @@ -31,7 +32,6 @@ https://github.com/dborth/vbagx/releases * Screenshots can be displayed on the main menu * Fixed pixel ratio mode (1x, 2x, and 3x) * Borders (from Super Game Boy games or custom from .png) -* Wii U Pro Controller support * 240p support ×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ @@ -43,6 +43,8 @@ https://github.com/dborth/vbagx/releases * Restored changes lost from 2.3.0 core upgrade (GameCube virtual memory, optimizations from dancinninjac, GB color palettes, rotation/tilt for WarioWare Twisted, in-game rumble) +* Improved WiiFlow integration +* Added Wii U GamePad support (thanks Fix94!) [2.3.7 - August 28, 2018] diff --git a/source/button_mapping.c b/source/button_mapping.c index a5f7d25..87a51aa 100644 --- a/source/button_mapping.c +++ b/source/button_mapping.c @@ -16,6 +16,7 @@ #include #include +#include "utils/wiidrc.h" #include "button_mapping.h" /**************************************************************************** @@ -24,7 +25,7 @@ * and for displaying the name of said button ***************************************************************************/ -CtrlrMap ctrlr_def[5] = { +CtrlrMap ctrlr_def[6] = { // Gamecube controller btn def { { @@ -134,5 +135,27 @@ CtrlrMap ctrlr_def[5] = { }, 15, CTRLR_WUPC +}, +// Wii U Gamepad btn def +{ + { + {WIIDRC_BUTTON_DOWN, "DOWN"}, + {WIIDRC_BUTTON_UP, "UP"}, + {WIIDRC_BUTTON_LEFT, "LEFT"}, + {WIIDRC_BUTTON_RIGHT, "RIGHT"}, + {WIIDRC_BUTTON_A, "A"}, + {WIIDRC_BUTTON_B, "B"}, + {WIIDRC_BUTTON_X, "X"}, + {WIIDRC_BUTTON_Y, "Y"}, + {WIIDRC_BUTTON_PLUS, "PLUS"}, + {WIIDRC_BUTTON_MINUS, "MINUS"}, + {WIIDRC_BUTTON_HOME, "HOME"}, + {WIIDRC_BUTTON_L, "L"}, + {WIIDRC_BUTTON_R, "R"}, + {WIIDRC_BUTTON_ZL, "ZL"}, + {WIIDRC_BUTTON_ZR, "ZR"} + }, + 15, + CTRLR_WIIDRC } }; diff --git a/source/button_mapping.h b/source/button_mapping.h index 6ab0828..c8e2da5 100644 --- a/source/button_mapping.h +++ b/source/button_mapping.h @@ -17,11 +17,12 @@ enum { CTRLR_WIIMOTE, CTRLR_NUNCHUK, CTRLR_CLASSIC, - CTRLR_WUPC + CTRLR_WUPC, + CTRLR_WIIDRC }; -const char ctrlrName[5][32] = -{ "GameCube Controller", "Wiimote", "Nunchuk + Wiimote", "Classic Controller", "Wii U Pro Controller" }; +const char ctrlrName[6][32] = +{ "GameCube Controller", "Wiimote", "Nunchuk + Wiimote", "Classic Controller", "Wii U Pro Controller", "Wii U Gamepad" }; typedef struct _btn_map { u32 btn; // button 'id' @@ -34,6 +35,6 @@ typedef struct _ctrlr_map { u16 type; // controller type } CtrlrMap; -extern CtrlrMap ctrlr_def[5]; +extern CtrlrMap ctrlr_def[6]; #endif diff --git a/source/filelist.h b/source/filelist.h index c8afada..35394e7 100644 --- a/source/filelist.h +++ b/source/filelist.h @@ -108,6 +108,8 @@ extern const u8 icon_settings_nunchuk_png[]; extern const u32 icon_settings_nunchuk_png_size; extern const u8 icon_settings_wiiupro_png[]; extern const u32 icon_settings_wiiupro_png_size; +extern const u8 icon_settings_drc_png[]; +extern const u32 icon_settings_drc_png_size; extern const u8 icon_settings_file_png[]; extern const u32 icon_settings_file_png_size; diff --git a/source/gui/gui.h b/source/gui/gui.h index a064c12..12c4397 100644 --- a/source/gui/gui.h +++ b/source/gui/gui.h @@ -123,6 +123,16 @@ typedef struct _paddata { u8 triggerR; } PADData; +typedef struct _gamepaddata { + u16 btns_d; + u16 btns_u; + u16 btns_h; + s16 stickX; + s16 stickY; + s16 substickX; + s16 substickY; +} GamePadData; + #define EFFECT_SLIDE_TOP 1 #define EFFECT_SLIDE_BOTTOM 2 #define EFFECT_SLIDE_RIGHT 4 @@ -182,22 +192,26 @@ class GuiTrigger //!\param ch Controller channel number //!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately //!\param gcbtns GameCube controller trigger button(s) - void SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns); + //!\param wiidrcbtns Wii U Gamepad trigger button(s) + void SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns, u16 wiidrcbtns); //!Sets a held trigger. Requires: element is selected, and trigger button is pressed //!\param ch Controller channel number //!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately //!\param gcbtns GameCube controller trigger button(s) - void SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns); + //!\param wiidrcbtns Wii U Gamepad trigger button(s) + void SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns, u16 wiidrcbtns); //!Sets a button-only trigger. Requires: Trigger button is pressed //!\param ch Controller channel number //!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately //!\param gcbtns GameCube controller trigger button(s) - void SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns); + //!\param wiidrcbtns Wii U Gamepad trigger button(s) + void SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns, u16 wiidrcbtns); //!Sets a button-only trigger. Requires: trigger button is pressed and parent window of element is in focus //!\param ch Controller channel number //!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately //!\param gcbtns GameCube controller trigger button(s) - void SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns); + //!\param wiidrcbtns Wii U Gamepad trigger button(s) + void SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns, u16 wiidrcbtns); //!Get X or Y value from Wii Joystick (classic, nunchuk) input //!\param stick Controller stick (left = 0, right = 1) //!\param axis Controller stick axis (x-axis = 0, y-axis = 1) @@ -226,6 +240,7 @@ class GuiTrigger WPADData wpaddata; //!< Wii controller trigger data PADData pad; //!< GameCube controller trigger data + GamePadData wiidrcdata; //!< Wii U Gamepad trigger data WPADData * wpad; //!< Wii controller trigger s32 chan; //!< Trigger controller channel (0-3, -1 for all) u8 type; //!< trigger type (TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS) diff --git a/source/gui/gui_button.cpp b/source/gui/gui_button.cpp index 41a64c0..7a0b9f2 100644 --- a/source/gui/gui_button.cpp +++ b/source/gui/gui_button.cpp @@ -156,8 +156,7 @@ void GuiButton::Draw() label[0]->Draw(); if(labelOver[1]) - - labelOver[1]->Draw(); + labelOver[1]->Draw(); else if(label[1]) label[1]->Draw(); @@ -255,7 +254,7 @@ void GuiButton::Update(GuiTrigger * t) // button triggers if(this->IsClickable()) { - s32 wm_btns, wm_btns_trig, cc_btns, cc_btns_trig; + s32 wm_btns, wm_btns_trig, cc_btns, cc_btns_trig, wiidrc_btns, wiidrc_btns_trig; for(int i=0; i<3; i++) { if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan)) @@ -268,12 +267,16 @@ void GuiButton::Update(GuiTrigger * t) cc_btns = t->wpad->btns_d >> 16; cc_btns_trig = trigger[i]->wpad->btns_d >> 16; + // Wii U Gamepad + wiidrc_btns = t->wiidrcdata.btns_d; + wiidrc_btns_trig = trigger[i]->wiidrcdata.btns_d; + if( (t->wpad->btns_d > 0 && (wm_btns == wm_btns_trig || (cc_btns == cc_btns_trig && t->wpad->exp.type == EXP_CLASSIC))) || - (t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0)) - + (t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0) || + (wiidrc_btns == wiidrc_btns_trig && wiidrc_btns > 0)) { if(t->chan == stateChan || stateChan == -1) { @@ -305,7 +308,7 @@ void GuiButton::Update(GuiTrigger * t) if(this->IsHoldable()) { bool held = false; - s32 wm_btns, wm_btns_h, wm_btns_trig, cc_btns, cc_btns_h, cc_btns_trig; + s32 wm_btns, wm_btns_h, wm_btns_trig, cc_btns, cc_btns_h, cc_btns_trig, wiidrc_btns, wiidrc_btns_h, wiidrc_btns_trig; for(int i=0; i<3; i++) { @@ -320,12 +323,18 @@ void GuiButton::Update(GuiTrigger * t) cc_btns = t->wpad->btns_d >> 16; cc_btns_h = t->wpad->btns_h >> 16; cc_btns_trig = trigger[i]->wpad->btns_h >> 16; - + + // Wii U Gamepad + wiidrc_btns = t->wiidrcdata.btns_d; + wiidrc_btns_h = t->wiidrcdata.btns_h; + wiidrc_btns_trig = trigger[i]->wiidrcdata.btns_h; + if( (t->wpad->btns_d > 0 && (wm_btns == wm_btns_trig || (cc_btns == cc_btns_trig && t->wpad->exp.type == EXP_CLASSIC))) || - (t->pad.btns_d == trigger[i]->pad.btns_h && t->pad.btns_d > 0)) + (t->pad.btns_d == trigger[i]->pad.btns_h && t->pad.btns_d > 0) || + (wiidrc_btns == wiidrc_btns_trig && wiidrc_btns > 0)) { if(trigger[i]->type == TRIGGER_HELD && state == STATE_SELECTED && (t->chan == stateChan || stateChan == -1)) @@ -336,8 +345,8 @@ void GuiButton::Update(GuiTrigger * t) (t->wpad->btns_h > 0 && (wm_btns_h == wm_btns_trig || (cc_btns_h == cc_btns_trig && t->wpad->exp.type == EXP_CLASSIC))) || - (t->pad.btns_h == trigger[i]->pad.btns_h && t->pad.btns_h > 0)) - + (t->pad.btns_h == trigger[i]->pad.btns_h && t->pad.btns_h > 0) || + (wiidrc_btns_h == wiidrc_btns_trig && wiidrc_btns_h > 0)) { if(trigger[i]->type == TRIGGER_HELD) held = true; diff --git a/source/gui/gui_filebrowser.cpp b/source/gui/gui_filebrowser.cpp index 76f584f..8025684 100644 --- a/source/gui/gui_filebrowser.cpp +++ b/source/gui/gui_filebrowser.cpp @@ -25,12 +25,12 @@ GuiFileBrowser::GuiFileBrowser(int w, int h) focus = 0; // allow focus trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); + trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A, WIIDRC_BUTTON_A); trig2 = new GuiTrigger; - trig2->SetSimpleTrigger(-1, WPAD_BUTTON_2, 0); + trig2->SetSimpleTrigger(-1, WPAD_BUTTON_2, 0, 0); trigHeldA = new GuiTrigger; - trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); + trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A, WIIDRC_BUTTON_A); btnSoundOver = new GuiSound(button_over_pcm, button_over_pcm_size, SOUND_PCM); btnSoundClick = new GuiSound(button_click_pcm, button_click_pcm_size, SOUND_PCM); diff --git a/source/gui/gui_keyboard.cpp b/source/gui/gui_keyboard.cpp index db4a964..457f017 100644 --- a/source/gui/gui_keyboard.cpp +++ b/source/gui/gui_keyboard.cpp @@ -122,9 +122,9 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max) keySoundClick = new GuiSound(button_click_pcm, button_click_pcm_size, SOUND_PCM); trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); + trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A, WIIDRC_BUTTON_A); trig2 = new GuiTrigger; - trig2->SetSimpleTrigger(-1, WPAD_BUTTON_2, 0); + trig2->SetSimpleTrigger(-1, WPAD_BUTTON_2, 0, 0); keyBackImg = new GuiImage(keyMedium); keyBackOverImg = new GuiImage(keyMediumOver); diff --git a/source/gui/gui_optionbrowser.cpp b/source/gui/gui_optionbrowser.cpp index 027fbfb..3674cb2 100644 --- a/source/gui/gui_optionbrowser.cpp +++ b/source/gui/gui_optionbrowser.cpp @@ -25,9 +25,9 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l) focus = 0; // allow focus trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); + trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A, WIIDRC_BUTTON_A); trig2 = new GuiTrigger; - trig2->SetSimpleTrigger(-1, WPAD_BUTTON_2, 0); + trig2->SetSimpleTrigger(-1, WPAD_BUTTON_2, 0, 0); btnSoundOver = new GuiSound(button_over_pcm, button_over_pcm_size, SOUND_PCM); btnSoundClick = new GuiSound(button_click_pcm, button_click_pcm_size, SOUND_PCM); diff --git a/source/gui/gui_savebrowser.cpp b/source/gui/gui_savebrowser.cpp index eee3498..5217d82 100644 --- a/source/gui/gui_savebrowser.cpp +++ b/source/gui/gui_savebrowser.cpp @@ -33,9 +33,9 @@ GuiSaveBrowser::GuiSaveBrowser(int w, int h, SaveList * s, int a) focus = 0; // allow focus trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); + trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A, WIIDRC_BUTTON_A); trig2 = new GuiTrigger; - trig2->SetSimpleTrigger(-1, WPAD_BUTTON_2, 0); + trig2->SetSimpleTrigger(-1, WPAD_BUTTON_2, 0, 0); btnSoundOver = new GuiSound(button_over_pcm, button_over_pcm_size, SOUND_PCM); btnSoundClick = new GuiSound(button_click_pcm, button_click_pcm_size, SOUND_PCM); diff --git a/source/gui/gui_trigger.cpp b/source/gui/gui_trigger.cpp index 5fb6090..0d20890 100644 --- a/source/gui/gui_trigger.cpp +++ b/source/gui/gui_trigger.cpp @@ -22,6 +22,7 @@ static u32 delay[4]; GuiTrigger::GuiTrigger() { chan = -1; + memset(&wiidrcdata, 0, sizeof(GamePadData)); memset(&wpaddata, 0, sizeof(WPADData)); memset(&pad, 0, sizeof(PADData)); wpad = &wpaddata; @@ -39,10 +40,11 @@ GuiTrigger::~GuiTrigger() * - Element is selected * - Trigger button is pressed */ -void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns) +void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns, u16 wiidrcbtns) { type = TRIGGER_SIMPLE; chan = ch; + wiidrcdata.btns_d = wiidrcbtns; wpaddata.btns_d = wiibtns; pad.btns_d = gcbtns; } @@ -52,10 +54,11 @@ void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns) * - Element is selected * - Trigger button is pressed and held */ -void GuiTrigger::SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns) +void GuiTrigger::SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns, u16 wiidrcbtns) { type = TRIGGER_HELD; chan = ch; + wiidrcdata.btns_h = wiidrcbtns; wpaddata.btns_h = wiibtns; pad.btns_h = gcbtns; } @@ -64,10 +67,11 @@ void GuiTrigger::SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns) * Sets a button trigger. Requires: * - Trigger button is pressed */ -void GuiTrigger::SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns) +void GuiTrigger::SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns, u16 wiidrcbtns) { type = TRIGGER_BUTTON_ONLY; chan = ch; + wiidrcdata.btns_d = wiidrcbtns; wpaddata.btns_d = wiibtns; pad.btns_d = gcbtns; } @@ -77,10 +81,11 @@ void GuiTrigger::SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns) * - Trigger button is pressed * - Parent window is in focus */ -void GuiTrigger::SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns) +void GuiTrigger::SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns, u16 wiidrcbtns) { type = TRIGGER_BUTTON_ONLY_IN_FOCUS; chan = ch; + wiidrcdata.btns_d = wiidrcbtns; wpaddata.btns_d = wiibtns; pad.btns_d = gcbtns; } @@ -159,11 +164,14 @@ bool GuiTrigger::Left() u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_UP : WPAD_BUTTON_LEFT; if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT) + || (wiidrcdata.btns_d | wiidrcdata.btns_h) & WIIDRC_BUTTON_LEFT || (pad.btns_d | pad.btns_h) & PAD_BUTTON_LEFT || pad.stickX < -PADCAL - || WPAD_StickX(0) < -PADCAL) + || WPAD_StickX(0) < -PADCAL + || wiidrcdata.stickX < -WIIDRCCAL) { if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT) + || wiidrcdata.btns_d & WIIDRC_BUTTON_LEFT || pad.btns_d & PAD_BUTTON_LEFT) { prev[chan] = gettime(); @@ -192,11 +200,14 @@ bool GuiTrigger::Right() u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_DOWN : WPAD_BUTTON_RIGHT; if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT) + || (wiidrcdata.btns_d | wiidrcdata.btns_h) & WIIDRC_BUTTON_RIGHT || (pad.btns_d | pad.btns_h) & PAD_BUTTON_RIGHT || pad.stickX > PADCAL - || WPAD_StickX(0) > PADCAL) + || WPAD_StickX(0) > PADCAL + || wiidrcdata.stickX > WIIDRCCAL) { if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT) + || wiidrcdata.btns_d & WIIDRC_BUTTON_RIGHT || pad.btns_d & PAD_BUTTON_RIGHT) { prev[chan] = gettime(); @@ -225,11 +236,14 @@ bool GuiTrigger::Up() u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_RIGHT : WPAD_BUTTON_UP; if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_UP) + || (wiidrcdata.btns_d | wiidrcdata.btns_h) & WIIDRC_BUTTON_UP || (pad.btns_d | pad.btns_h) & PAD_BUTTON_UP || pad.stickY > PADCAL - || WPAD_StickY(0) > PADCAL) + || WPAD_StickY(0) > PADCAL + || wiidrcdata.stickY > WIIDRCCAL) { if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_UP) + || wiidrcdata.btns_d & WIIDRC_BUTTON_UP || pad.btns_d & PAD_BUTTON_UP) { prev[chan] = gettime(); @@ -258,11 +272,14 @@ bool GuiTrigger::Down() u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_LEFT : WPAD_BUTTON_DOWN; if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN) + || (wiidrcdata.btns_d | wiidrcdata.btns_h) & WIIDRC_BUTTON_DOWN || (pad.btns_d | pad.btns_h) & PAD_BUTTON_DOWN || pad.stickY < -PADCAL - || WPAD_StickY(0) < -PADCAL) + || WPAD_StickY(0) < -PADCAL + || wiidrcdata.stickY < -WIIDRCCAL) { if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN) + || wiidrcdata.btns_d & WIIDRC_BUTTON_DOWN || pad.btns_d & PAD_BUTTON_DOWN) { prev[chan] = gettime(); diff --git a/source/gui/gui_window.cpp b/source/gui/gui_window.cpp index 8c067b2..57e817e 100644 --- a/source/gui/gui_window.cpp +++ b/source/gui/gui_window.cpp @@ -229,7 +229,7 @@ void GuiWindow::ToggleFocus(GuiTrigger * t) } // change focus else if((t->wpad->btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) - || (t->pad.btns_d & PAD_BUTTON_B)) + || (t->pad.btns_d & PAD_BUTTON_B) || (t->wiidrcdata.btns_d & WIIDRC_BUTTON_B)) { for (i = found; i < elemSize; ++i) { diff --git a/source/images/icon_settings_drc.png b/source/images/icon_settings_drc.png new file mode 100644 index 0000000000000000000000000000000000000000..40b5c07bd7a5dfd78c7fd41bd13b101e00f10365 GIT binary patch literal 6562 zcmb7JXFD7~*JgEA31M|BmMGDC&5DE-y$jJobb{;>61|JESiMA8Wo7jcH3-q`uAUG= zbfQM*^<3}s2c8deX1<&=XXZNRp8J|RR$o_xnv#{0fPjEn6ZY8fc1GV0TXND{n>sYR zOhCZmqWM_W_|4o-p1=NtQ+Drs|Mt|>E_+&DHYRT#lU<%wo^|EsNFQrP|4JwRMA$lZ z)l2EcZ)P2(7Y}2_Q!@u4tUUb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3{U$V=t$-pUFSRMUk7mG)^S zaG(@Fs@Buw&i|>5oxMj)AbYX!BKvG27g0|lSnmnbdPuca_j*yH*&(e#ylf#JsJ@BP zdYVQ!Vs26q*-A;ZA|$LI8=RhTC^&#BXfp&b@-lMgNdk|^jKlg7H%{KqcyomtX)M&b#x|d{1ZU77M&Gr;+Fw0M z;~X$P_$$(6BmZ^W*q=l{@un)0?d)_lI?dIWqf9GFO2>%d^e>Q_og7DO3|;^HXh8DaIJ zlWhli5ylsWZLnYWPtg7tAjZPpRwCNF4>pa_8Yp)@>~09Wc$nX?bu1e!2wVAm2C_aK zXS?`!!*}e^lUtY)S5fbn6K3n;&iVqxF%Byg|D8+|?5srCpV+V*0?|*9!pdY4jc#zh zIDE8M6Dq5cq~r#n>!(0iXP{Kv@%=%Gp>eDO4^kFQ+;ot^#m33+?%8j(aB*g~$Ha4+{9Jrrglg1iZ%Vk0gt0>bCR1`Fu;vXYnBwx%w z1ReN-BXVfj6(Z_~f)tFDKgUr(;9*M{3~0(w19H7BZC|3|&zzv2dv^M-bC8zIAHXCiQ` Qy%1= 0); + if(WiiDRC_Inited() && WiiDRC_Connected()) + { + userInput[0].wiidrcdata.btns_d = WiiDRC_ButtonsDown(); + userInput[0].wiidrcdata.btns_u = WiiDRC_ButtonsUp(); + userInput[0].wiidrcdata.btns_h = WiiDRC_ButtonsHeld(); + userInput[0].wiidrcdata.stickX = WiiDRC_lStickX(); + userInput[0].wiidrcdata.stickY = WiiDRC_lStickY(); + userInput[0].wiidrcdata.substickX = WiiDRC_rStickX(); + userInput[0].wiidrcdata.substickY = WiiDRC_rStickY(); + } } /**************************************************************************** @@ -325,6 +362,8 @@ u32 StandardMovement(unsigned short chan) #ifdef HW_RVL s8 wm_ax = userInput[0].WPAD_StickX(0); s8 wm_ay = userInput[0].WPAD_StickY(0); + s16 wiidrc_ax = userInput[chan].wiidrcdata.stickX; + s16 wiidrc_ay = userInput[chan].wiidrcdata.stickY; #endif /*** @@ -350,6 +389,16 @@ u32 StandardMovement(unsigned short chan) J |= VBA_LEFT; else if (wm_ax > ANALOG_SENSITIVITY) J |= VBA_RIGHT; + + /* Wii U Gamepad */ + if (wiidrc_ay > ANALOG_SENSITIVITY) + J |= VBA_UP; + else if (wiidrc_ay < -ANALOG_SENSITIVITY) + J |= VBA_DOWN; + if (wiidrc_ax < -ANALOG_SENSITIVITY) + J |= VBA_LEFT; + else if (wiidrc_ax > ANALOG_SENSITIVITY) + J |= VBA_RIGHT; #endif return J; } @@ -365,33 +414,41 @@ u32 StandardDPad(unsigned short pad) u32 wp = userInput[pad].wpad->btns_h; if (wp & WPAD_BUTTON_RIGHT) J |= VBA_RIGHT; - if (wp & WPAD_BUTTON_LEFT) + else if (wp & WPAD_BUTTON_LEFT) J |= VBA_LEFT; if (wp & WPAD_BUTTON_UP) J |= VBA_UP; - if (wp & WPAD_BUTTON_DOWN) + else if (wp & WPAD_BUTTON_DOWN) J |= VBA_DOWN; if (exp_type == WPAD_EXP_CLASSIC) { if (wp & WPAD_CLASSIC_BUTTON_UP) J |= VBA_UP; - if (wp & WPAD_CLASSIC_BUTTON_DOWN) + else if (wp & WPAD_CLASSIC_BUTTON_DOWN) J |= VBA_DOWN; if (wp & WPAD_CLASSIC_BUTTON_LEFT) J |= VBA_LEFT; - if (wp & WPAD_CLASSIC_BUTTON_RIGHT) + else if (wp & WPAD_CLASSIC_BUTTON_RIGHT) J |= VBA_RIGHT; } - + /* Wii U Gamepad */ + u32 wiidrcp = userInput[pad].wiidrcdata.btns_h; + if (wiidrcp & WIIDRC_BUTTON_UP) + J |= VBA_UP; + else if (wiidrcp & WIIDRC_BUTTON_DOWN) + J |= VBA_DOWN; + if (wiidrcp & WIIDRC_BUTTON_LEFT) + J |= VBA_LEFT; + else if (wiidrcp & WIIDRC_BUTTON_RIGHT) + J |= VBA_RIGHT; #endif - if (jp & PAD_BUTTON_UP) J |= VBA_UP; - if (jp & PAD_BUTTON_DOWN) + else if (jp & PAD_BUTTON_DOWN) J |= VBA_DOWN; if (jp & PAD_BUTTON_LEFT) J |= VBA_LEFT; - if (jp & PAD_BUTTON_RIGHT) + else if (jp & PAD_BUTTON_RIGHT) J |= VBA_RIGHT; return J; } @@ -404,11 +461,11 @@ u32 StandardSideways(unsigned short pad) if (wp & WPAD_BUTTON_RIGHT) J |= VBA_UP; - if (wp & WPAD_BUTTON_LEFT) + else if (wp & WPAD_BUTTON_LEFT) J |= VBA_DOWN; if (wp & WPAD_BUTTON_UP) J |= VBA_LEFT; - if (wp & WPAD_BUTTON_DOWN) + else if (wp & WPAD_BUTTON_DOWN) J |= VBA_RIGHT; if (wp & WPAD_BUTTON_PLUS) @@ -444,11 +501,11 @@ u32 StandardClassic(unsigned short pad) if (wp & WPAD_CLASSIC_BUTTON_RIGHT) J |= VBA_RIGHT; - if (wp & WPAD_CLASSIC_BUTTON_LEFT) + else if (wp & WPAD_CLASSIC_BUTTON_LEFT) J |= VBA_LEFT; if (wp & WPAD_CLASSIC_BUTTON_UP) J |= VBA_UP; - if (wp & WPAD_CLASSIC_BUTTON_DOWN) + else if (wp & WPAD_CLASSIC_BUTTON_DOWN) J |= VBA_DOWN; if (wp & WPAD_CLASSIC_BUTTON_PLUS) @@ -477,11 +534,11 @@ u32 StandardGamecube(unsigned short pad) u32 jp = userInput[pad].pad.btns_h; if (jp & PAD_BUTTON_UP) J |= VBA_UP; - if (jp & PAD_BUTTON_DOWN) + else if (jp & PAD_BUTTON_DOWN) J |= VBA_DOWN; if (jp & PAD_BUTTON_LEFT) J |= VBA_LEFT; - if (jp & PAD_BUTTON_RIGHT) + else if (jp & PAD_BUTTON_RIGHT) J |= VBA_RIGHT; if (jp & PAD_BUTTON_A) J |= VBA_BUTTON_A; @@ -588,9 +645,9 @@ static u32 CCToGC(u32 w) { if (w & WPAD_CLASSIC_BUTTON_FULL_L) gc |= PAD_TRIGGER_L; if (w & WPAD_CLASSIC_BUTTON_FULL_R) gc |= PAD_TRIGGER_R; if (w & WPAD_CLASSIC_BUTTON_UP) gc |= PAD_BUTTON_UP; - if (w & WPAD_CLASSIC_BUTTON_DOWN) gc |= PAD_BUTTON_DOWN; + else if (w & WPAD_CLASSIC_BUTTON_DOWN) gc |= PAD_BUTTON_DOWN; if (w & WPAD_CLASSIC_BUTTON_LEFT) gc |= PAD_BUTTON_LEFT; - if (w & WPAD_CLASSIC_BUTTON_RIGHT) gc |= PAD_BUTTON_RIGHT; + else if (w & WPAD_CLASSIC_BUTTON_RIGHT) gc |= PAD_BUTTON_RIGHT; return gc; } #endif @@ -833,12 +890,14 @@ static u32 DecodeJoy(unsigned short pad) u32 J = StandardMovement(pad); // Turbo feature - if(userInput[0].pad.substickX > 70 || userInput[0].WPAD_Stick(1,0) > 70) + if(userInput[0].pad.substickX > 70 || + userInput[0].WPAD_Stick(1,0) > 70 || + userInput[0].wiidrcdata.substickX > 45) J |= VBA_SPEED; // Report pressed buttons (gamepads) u32 pad_btns_h = userInput[pad].pad.btns_h; // GCN - + u32 wiidrcp_btns_h = userInput[pad].wiidrcdata.btns_h; #ifdef HW_RVL u32 wpad_btns_h = userInput[pad].wpad->btns_h; int wpad_exp_type = userInput[pad].wpad->exp.type; @@ -850,6 +909,7 @@ static u32 DecodeJoy(unsigned short pad) for (u32 i =0; i < MAXJP; ++i) { if ((pad_btns_h & btnmap[CTRLR_GCPAD][i]) // gamecube controller + || ( wiidrcp_btns_h & btnmap[CTRLR_WIIDRC][i] ) //wii u gamepad || ( (wpad_btns_h & btnmap[CTRLR_WIIMOTE][i]) )) J |= vbapadmap[i]; } @@ -857,22 +917,15 @@ static u32 DecodeJoy(unsigned short pad) } else if(wpad_exp_type == WPAD_EXP_CLASSIC) { // classic controller - if (isWUPC) { - for (u32 i =0; i < MAXJP; ++i) - { - if ((pad_btns_h & btnmap[CTRLR_GCPAD][i]) // gamecube controller - || ( (wpad_btns_h & btnmap[CTRLR_WUPC][i]) )) - J |= vbapadmap[i]; - } - } - else { - for (u32 i =0; i < MAXJP; ++i) - { - if ((pad_btns_h & btnmap[CTRLR_GCPAD][i]) // gamecube controller - || ( (wpad_btns_h & btnmap[CTRLR_CLASSIC][i]) )) - J |= vbapadmap[i]; - } + + for (u32 i =0; i < MAXJP; ++i) + { + if ((pad_btns_h & btnmap[CTRLR_GCPAD][i]) // gamecube controller + || ( wiidrcp_btns_h & btnmap[CTRLR_WIIDRC][i] ) //wiiu gamepad + || ( (wpad_btns_h & btnmap[CTRLR_CLASSIC][i]) )) + J |= vbapadmap[i]; } + } else if(wpad_exp_type == WPAD_EXP_NUNCHUK) { // nunchuk + wiimote @@ -884,7 +937,6 @@ static u32 DecodeJoy(unsigned short pad) J |= vbapadmap[i]; } } - else // Check out this trickery! // If all else fails OR if HW_RVL is undefined, the result is the same @@ -892,11 +944,10 @@ static u32 DecodeJoy(unsigned short pad) { for (u32 i = 0; i < MAXJP; ++i) { - if ((pad_btns_h & btnmap[CTRLR_GCPAD][i])) + if ((pad_btns_h & btnmap[CTRLR_GCPAD][i]) || (wiidrcp_btns_h & btnmap[CTRLR_WIIDRC][i])) J |= vbapadmap[i]; } } - return J; } @@ -907,7 +958,8 @@ bool MenuRequested() (userInput[i].pad.substickX < -70) #ifdef HW_RVL || (userInput[i].wpad->btns_h & WPAD_BUTTON_HOME) || - (userInput[i].wpad->btns_h & WPAD_CLASSIC_BUTTON_HOME) + (userInput[i].wpad->btns_h & WPAD_CLASSIC_BUTTON_HOME) || + (userInput[i].wiidrcdata.btns_h & WIIDRC_BUTTON_HOME) #endif ) { diff --git a/source/input.h b/source/input.h index 02c442f..b2c1c1b 100644 --- a/source/input.h +++ b/source/input.h @@ -13,9 +13,10 @@ #include #include +#include "utils/wiidrc.h" -#define PI 3.14159265f #define PADCAL 50 +#define WIIDRCCAL 20 #define MAXJP 10 // # of mappable controller buttons #define VBA_BUTTON_A 1 @@ -32,7 +33,7 @@ #define VBA_CAPTURE 2048 extern int rumbleRequest[4]; -extern u32 btnmap[5][10]; +extern u32 btnmap[6][10]; void ResetControls(int wc = -1); void ShutoffRumble(); diff --git a/source/menu.cpp b/source/menu.cpp index 4eae5a8..cd2d07b 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -832,19 +832,20 @@ static void WindowCredits(void * ptr) Menu_Render(); - if((userInput[0].wpad->btns_d || userInput[0].pad.btns_d) || - (userInput[1].wpad->btns_d || userInput[1].pad.btns_d) || - (userInput[2].wpad->btns_d || userInput[2].pad.btns_d) || - (userInput[3].wpad->btns_d || userInput[3].pad.btns_d)) + if((userInput[0].wpad->btns_d || userInput[0].pad.btns_d || userInput[0].wiidrcdata.btns_d) || + (userInput[1].wpad->btns_d || userInput[1].pad.btns_d || userInput[1].wiidrcdata.btns_d) || + (userInput[2].wpad->btns_d || userInput[2].pad.btns_d || userInput[2].wiidrcdata.btns_d) || + (userInput[3].wpad->btns_d || userInput[3].pad.btns_d || userInput[3].wiidrcdata.btns_d)) { - exit = true; - } + exit = true; + } usleep(THREAD_SLEEP); } // clear buttons pressed for(i=0; i < 4; i++) { + userInput[i].wiidrcdata.btns_d = 0; userInput[i].wpad->btns_d = 0; userInput[i].pad.btns_d = 0; } @@ -878,7 +879,7 @@ static int MenuGameSelection() GuiImageData bgPreviewImg(bg_preview_png); GuiTrigger trigHome; - trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); + trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0, WIIDRC_BUTTON_HOME); GuiText settingsBtnTxt("Settings", 22, (GXColor){0, 0, 0, 255}); GuiImage settingsBtnIcon(&iconSettings); @@ -1097,7 +1098,7 @@ static int MenuGame() GuiImageData batteryBar(battery_bar_png); GuiTrigger trigHome; - trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); + trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0, WIIDRC_BUTTON_HOME); int xOffset=125; if (isBoktai) @@ -1596,7 +1597,7 @@ static int MenuGameSaves(int action) GuiImageData btnCloseOutlineOver(button_small_over_png); GuiTrigger trigHome; - trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); + trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0, WIIDRC_BUTTON_HOME); GuiText backBtnTxt("Go Back", 22, (GXColor){0, 0, 0, 255}); GuiImage backBtnImg(&btnOutline); @@ -1876,7 +1877,7 @@ static int MenuGameSettings() GuiImageData btnCloseOutlineOver(button_small_over_png); GuiTrigger trigHome; - trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); + trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0, WIIDRC_BUTTON_HOME); GuiText mappingBtnTxt("Button Mappings", 22, (GXColor){0, 0, 0, 255}); mappingBtnTxt.SetWrap(true, btnLargeOutline.GetWidth()-30); @@ -2081,6 +2082,8 @@ static int MenuSettingsMappings() GuiImageData iconGamecube(icon_settings_gamecube_png); GuiImageData iconNunchuk(icon_settings_nunchuk_png); GuiImageData iconWiiupro(icon_settings_wiiupro_png); + GuiImageData iconDrc(icon_settings_drc_png); + GuiText gamecubeBtnTxt("GameCube Controller", 22, (GXColor){0, 0, 0, 255}); gamecubeBtnTxt.SetWrap(true, btnLargeOutline.GetWidth()-30); GuiImage gamecubeBtnImg(&btnLargeOutline); @@ -2099,24 +2102,6 @@ static int MenuSettingsMappings() gamecubeBtn.SetTrigger(trig2); gamecubeBtn.SetEffectGrow(); - GuiText wiiuproBtnTxt("Wii U Pro Controller", 22, (GXColor){0, 0, 0, 255}); - wiiuproBtnTxt.SetWrap(true, btnLargeOutline.GetWidth()-20); - GuiImage wiiuproBtnImg(&btnLargeOutline); - GuiImage wiiuproBtnImgOver(&btnLargeOutlineOver); - GuiImage wiiuproBtnIcon(&iconWiiupro); - GuiButton wiiuproBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight()); - wiiuproBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - wiiuproBtn.SetPosition(0, 250); - wiiuproBtn.SetLabel(&wiiuproBtnTxt); - wiiuproBtn.SetImage(&wiiuproBtnImg); - wiiuproBtn.SetImageOver(&wiiuproBtnImgOver); - wiiuproBtn.SetIcon(&wiiuproBtnIcon); - wiiuproBtn.SetSoundOver(&btnSoundOver); - wiiuproBtn.SetSoundClick(&btnSoundClick); - wiiuproBtn.SetTrigger(trigA); - wiiuproBtn.SetTrigger(trig2); - wiiuproBtn.SetEffectGrow(); - GuiText wiimoteBtnTxt("Wiimote", 22, (GXColor){0, 0, 0, 255}); GuiImage wiimoteBtnImg(&btnLargeOutline); GuiImage wiimoteBtnImgOver(&btnLargeOutlineOver); @@ -2134,6 +2119,24 @@ static int MenuSettingsMappings() wiimoteBtn.SetTrigger(trig2); wiimoteBtn.SetEffectGrow(); + GuiText drcBtnTxt("Wii U GamePad", 22, (GXColor){0, 0, 0, 255}); + drcBtnTxt.SetWrap(true, btnLargeOutline.GetWidth()-30); + GuiImage drcBtnImg(&btnLargeOutline); + GuiImage drcBtnImgOver(&btnLargeOutlineOver); + GuiImage drcBtnIcon(&iconDrc); + GuiButton drcBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight()); + drcBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); + drcBtn.SetPosition(200, 120); + drcBtn.SetLabel(&drcBtnTxt); + drcBtn.SetImage(&drcBtnImg); + drcBtn.SetImageOver(&drcBtnImgOver); + drcBtn.SetIcon(&drcBtnIcon); + drcBtn.SetSoundOver(&btnSoundOver); + drcBtn.SetSoundClick(&btnSoundClick); + drcBtn.SetTrigger(trigA); + drcBtn.SetTrigger(trig2); + drcBtn.SetEffectGrow(); + GuiText classicBtnTxt("Classic Controller", 22, (GXColor){0, 0, 0, 255}); classicBtnTxt.SetWrap(true, btnLargeOutline.GetWidth()-30); GuiImage classicBtnImg(&btnLargeOutline); @@ -2162,7 +2165,7 @@ static int MenuSettingsMappings() GuiImage nunchukBtnIcon(&iconNunchuk); GuiButton nunchukBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight()); nunchukBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - nunchukBtn.SetPosition(200, 250); + nunchukBtn.SetPosition(0, 250); nunchukBtn.SetLabel(&nunchukBtnTxt1, 0); nunchukBtn.SetLabel(&nunchukBtnTxt2, 1); nunchukBtn.SetLabel(&nunchukBtnTxt3, 2); @@ -2175,6 +2178,24 @@ static int MenuSettingsMappings() nunchukBtn.SetTrigger(trig2); nunchukBtn.SetEffectGrow(); + GuiText wiiuproBtnTxt("Wii U Pro Controller", 22, (GXColor){0, 0, 0, 255}); + wiiuproBtnTxt.SetWrap(true, btnLargeOutline.GetWidth()-20); + GuiImage wiiuproBtnImg(&btnLargeOutline); + GuiImage wiiuproBtnImgOver(&btnLargeOutlineOver); + GuiImage wiiuproBtnIcon(&iconWiiupro); + GuiButton wiiuproBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight()); + wiiuproBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); + wiiuproBtn.SetPosition(200, 250); + wiiuproBtn.SetLabel(&wiiuproBtnTxt); + wiiuproBtn.SetImage(&wiiuproBtnImg); + wiiuproBtn.SetImageOver(&wiiuproBtnImgOver); + wiiuproBtn.SetIcon(&wiiuproBtnIcon); + wiiuproBtn.SetSoundOver(&btnSoundOver); + wiiuproBtn.SetSoundClick(&btnSoundClick); + wiiuproBtn.SetTrigger(trigA); + wiiuproBtn.SetTrigger(trig2); + wiiuproBtn.SetEffectGrow(); + GuiText backBtnTxt("Go Back", 22, (GXColor){0, 0, 0, 255}); GuiImage backBtnImg(&btnOutline); GuiImage backBtnImgOver(&btnOutlineOver); @@ -2197,8 +2218,15 @@ static int MenuSettingsMappings() w.Append(&gamecubeBtn); #ifdef HW_RVL w.Append(&wiimoteBtn); - w.Append(&nunchukBtn); + + if(WiiDRC_Inited() && WiiDRC_Connected()) { + gamecubeBtn.SetPosition(-200, 120); + wiimoteBtn.SetPosition(0, 120); + w.Append(&drcBtn); + } + w.Append(&classicBtn); + w.Append(&nunchukBtn); w.Append(&wiiuproBtn); #endif w.Append(&backBtn); @@ -2231,6 +2259,11 @@ static int MenuSettingsMappings() menu = MENU_GAMESETTINGS_MAPPINGS_MAP; mapMenuCtrl = CTRLR_WUPC; } + else if(drcBtn.GetState() == STATE_CLICKED) + { + menu = MENU_GAMESETTINGS_MAPPINGS_MAP; + mapMenuCtrl = CTRLR_WIIDRC; + } else if(gamecubeBtn.GetState() == STATE_CLICKED) { menu = MENU_GAMESETTINGS_MAPPINGS_MAP; @@ -2287,6 +2320,9 @@ ButtonMappingWindow() case CTRLR_WUPC: sprintf(msg, "Press any button on the Wii U Pro Controller now. Press Home to clear the existing mapping."); break; + case CTRLR_WIIDRC: + sprintf(msg, "Press any button on the Wii U GamePad now. Press Home to clear the existing mapping."); + break; case CTRLR_NUNCHUK: sprintf(msg, "Press any button on the Wiimote or Nunchuk now. Press Home to clear the existing mapping."); break; @@ -2321,12 +2357,19 @@ ButtonMappingWindow() if(userInput[0].pad.substickX < -70 || userInput[0].pad.substickX > 70 || userInput[0].pad.substickY < -70 || - userInput[0].pad.substickY > 70) + userInput[0].pad.substickY > 70) pressed = WPAD_BUTTON_HOME; if(userInput[0].wpad->btns_d == WPAD_BUTTON_HOME) pressed = WPAD_BUTTON_HOME; } + else if(mapMenuCtrl == CTRLR_WIIDRC) + { + pressed = userInput[0].wiidrcdata.btns_d; + + if(pressed == WIIDRC_BUTTON_HOME) + pressed = WPAD_CLASSIC_BUTTON_HOME; + } else { pressed = userInput[0].wpad->btns_d; @@ -2569,16 +2612,16 @@ static void ScreenZoomWindow() w->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); GuiTrigger trigLeft; - trigLeft.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT); + trigLeft.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT, WIIDRC_BUTTON_LEFT); GuiTrigger trigRight; - trigRight.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT); + trigRight.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT, WIIDRC_BUTTON_RIGHT); GuiTrigger trigUp; - trigUp.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP, PAD_BUTTON_UP); + trigUp.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP, PAD_BUTTON_UP, WIIDRC_BUTTON_UP); GuiTrigger trigDown; - trigDown.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN, PAD_BUTTON_DOWN); + trigDown.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN, PAD_BUTTON_DOWN, WIIDRC_BUTTON_DOWN); GuiImageData arrowLeft(button_arrow_left_png); GuiImage arrowLeftImg(&arrowLeft); @@ -2731,16 +2774,16 @@ static void ScreenPositionWindow() w->SetPosition(0, -10); GuiTrigger trigLeft; - trigLeft.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT); + trigLeft.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT, WIIDRC_BUTTON_LEFT); GuiTrigger trigRight; - trigRight.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT); + trigRight.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT, WIIDRC_BUTTON_RIGHT); GuiTrigger trigUp; - trigUp.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP, PAD_BUTTON_UP); + trigUp.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP, PAD_BUTTON_UP, WIIDRC_BUTTON_UP); GuiTrigger trigDown; - trigDown.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN, PAD_BUTTON_DOWN); + trigDown.SetButtonOnlyInFocusTrigger(-1, WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN, PAD_BUTTON_DOWN, WIIDRC_BUTTON_DOWN); GuiImageData arrowLeft(button_arrow_left_png); GuiImage arrowLeftImg(&arrowLeft); @@ -4127,7 +4170,7 @@ static int MenuPalette() GuiImageData btnCloseOutlineOver(button_small_over_png); GuiTrigger trigHome; - trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); + trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0, WIIDRC_BUTTON_HOME); GuiText bg0BtnTxt("BG 0", 24, GetCol(0)); GuiImage bg0BtnImg(&btnCloseOutline); @@ -4609,9 +4652,9 @@ MainMenu (int menu) #endif trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); + trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A, WIIDRC_BUTTON_A); trig2 = new GuiTrigger; - trig2->SetSimpleTrigger(-1, WPAD_BUTTON_2, 0); + trig2->SetSimpleTrigger(-1, WPAD_BUTTON_2, 0, 0); } mainWindow = new GuiWindow(screenwidth, screenheight); diff --git a/source/preferences.cpp b/source/preferences.cpp index cbbe202..774a315 100644 --- a/source/preferences.cpp +++ b/source/preferences.cpp @@ -217,12 +217,13 @@ preparePrefsData () createXMLSection("Controller", "Controller Settings"); - createXMLSetting("WiiControls", "Match Wii Game", toStr(GCSettings.WiiControls)); createXMLController(btnmap[CTRLR_GCPAD], "gcpadmap", "GameCube Pad"); + createXMLSetting("WiiControls", "Match Wii Game", toStr(GCSettings.WiiControls)); createXMLController(btnmap[CTRLR_WIIMOTE], "wmpadmap", "Wiimote"); createXMLController(btnmap[CTRLR_CLASSIC], "ccpadmap", "Classic Controller"); createXMLController(btnmap[CTRLR_NUNCHUK], "ncpadmap", "Nunchuk"); createXMLController(btnmap[CTRLR_WUPC], "wupcpadmap", "Wii U Pro Controller"); + createXMLController(btnmap[CTRLR_WIIDRC], "drcpadmap", "Wii U Gamepad"); createXMLSection("Emulation", "Emulation Settings"); @@ -525,21 +526,19 @@ decodePrefsData () loadXMLSetting(&GCSettings.PreviewImage, "PreviewImage"); // Controller Settings - - loadXMLSetting(&GCSettings.WiiControls, "WiiControls"); loadXMLController(btnmap[CTRLR_GCPAD], "gcpadmap"); + loadXMLSetting(&GCSettings.WiiControls, "WiiControls"); loadXMLController(btnmap[CTRLR_WIIMOTE], "wmpadmap"); loadXMLController(btnmap[CTRLR_CLASSIC], "ccpadmap"); loadXMLController(btnmap[CTRLR_NUNCHUK], "ncpadmap"); loadXMLController(btnmap[CTRLR_WUPC], "wupcpadmap"); - + loadXMLController(btnmap[CTRLR_WIIDRC], "drcpadmap"); // Emulation Settings loadXMLSetting(&GCSettings.OffsetMinutesUTC, "OffsetMinutesUTC"); loadXMLSetting(&GCSettings.GBHardware, "GBHardware"); loadXMLSetting(&GCSettings.SGBBorder, "SGBBorder"); loadXMLSetting(&GCSettings.BasicPalette, "BasicPalette"); - } mxmlDelete(xml); } diff --git a/source/utils/wiidrc.c b/source/utils/wiidrc.c new file mode 100644 index 0000000..2ded3c3 --- /dev/null +++ b/source/utils/wiidrc.c @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2017 FIX94 + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ +#include +#include +#include +#include "wiidrc.h" + +struct WiiDRCStat { + s16 xAxisLmid; + s16 xAxisRmid; + s16 yAxisLmid; + s16 yAxisRmid; +}; + +struct WiiDRCButtons { + u32 up; + u32 down; + u32 state; +}; + +static struct WiiDRCStat __WiiDRC_Status; +static struct WiiDRCData __WiiDRC_PadData; +static struct WiiDRCButtons __WiiDRC_PadButtons; +static bool __WiiDRC_ShutdownRequested; + +static u32 __WiiDRC_Inited = 0; +static u8 *__WiiDRC_I2CBuf = NULL; +static u8 *__WiiDRC_DRCStateBuf = NULL; + +static bool __WiiDRC_SetI2CBuf() +{ + DCInvalidateRange((void*)0x938B2964, 4); + if(*(vu32*)0x938B2964 == 0x138BB004) //r569 + { + __WiiDRC_I2CBuf = (u8*)0x938BB004; + return true; + } + DCInvalidateRange((void*)0x938B2564, 4); + if(*(vu32*)0x938B2564 == 0x138BB004) //r570 + { + __WiiDRC_I2CBuf = (u8*)0x938BB004; + return true; + } + else if(*(vu32*)0x938B2564 == 0x138BA004) //r590 + { + __WiiDRC_I2CBuf = (u8*)0x938BA004; + return true; + } + return false; +} + +static bool __WiiDRC_SetDRCStateBuf() +{ + //TODO r569 + DCInvalidateRange((void*)0x938B563C, 4); + if(*(vu32*)0x938B563C == 0x138BE770) //r570 + { + __WiiDRC_DRCStateBuf = (u8*)0x938BE770; + return true; + } + DCInvalidateRange((void*)0x938B5724, 4); + if(*(vu32*)0x938B5724 == 0x138BD770) //r590 + { + __WiiDRC_DRCStateBuf = (u8*)0x938BD770; + return true; + } + return false; +} + +bool WiiDRC_Init() +{ + if(__WiiDRC_Inited == 1) + return false; + if(!__WiiDRC_SetI2CBuf()) + return false; + //can fail on r569 for now + __WiiDRC_SetDRCStateBuf(); + + __WiiDRC_Inited = 1; + + WiiDRC_Recalibrate(); //sets up __WiiDRC_Status + memset(&__WiiDRC_PadData,0,sizeof(struct WiiDRCData)); + memset(&__WiiDRC_PadButtons,0,sizeof(struct WiiDRCButtons)); + __WiiDRC_ShutdownRequested = false; + + return true; +} + +bool WiiDRC_Inited() +{ + return !!__WiiDRC_Inited; +} + +bool WiiDRC_Recalibrate() +{ + if(__WiiDRC_Inited == 0) + return false; + + DCInvalidateRange(__WiiDRC_I2CBuf,9); + __WiiDRC_Status.xAxisLmid = (s8)(__WiiDRC_I2CBuf[4]-0x80); + __WiiDRC_Status.yAxisLmid = (s8)(__WiiDRC_I2CBuf[5]-0x80); + __WiiDRC_Status.xAxisRmid = (s8)(__WiiDRC_I2CBuf[6]-0x80); + __WiiDRC_Status.yAxisRmid = (s8)(__WiiDRC_I2CBuf[7]-0x80); + + return true; +} + +bool WiiDRC_ScanPads() +{ + if(__WiiDRC_Inited == 0) + return false; + + DCInvalidateRange(__WiiDRC_I2CBuf,9); + __WiiDRC_ShutdownRequested = !!(__WiiDRC_I2CBuf[1]&0x80); + __WiiDRC_PadData.button = (__WiiDRC_I2CBuf[2]<<8) | (__WiiDRC_I2CBuf[3]); + __WiiDRC_PadData.xAxisL = ((s8)(__WiiDRC_I2CBuf[4]-0x80)) - __WiiDRC_Status.xAxisLmid; + __WiiDRC_PadData.yAxisL = ((s8)(__WiiDRC_I2CBuf[5]-0x80)) - __WiiDRC_Status.yAxisLmid; + __WiiDRC_PadData.xAxisR = ((s8)(__WiiDRC_I2CBuf[6]-0x80)) - __WiiDRC_Status.xAxisRmid; + __WiiDRC_PadData.yAxisR = ((s8)(__WiiDRC_I2CBuf[7]-0x80)) - __WiiDRC_Status.yAxisRmid; + __WiiDRC_PadData.extra = __WiiDRC_I2CBuf[8]; + __WiiDRC_PadData.battery = (__WiiDRC_PadData.extra>>1)&7; + + u16 newstate, oldstate; + + newstate = __WiiDRC_PadData.button; + oldstate = __WiiDRC_PadButtons.state; + __WiiDRC_PadButtons.state = newstate; + __WiiDRC_PadButtons.up = oldstate & ~newstate; + __WiiDRC_PadButtons.down = newstate & (newstate ^ oldstate); + + return true; +} + +bool WiiDRC_Connected() +{ + if(__WiiDRC_DRCStateBuf) + { + DCInvalidateRange(__WiiDRC_DRCStateBuf, 4); + return !!(*(vu32*)__WiiDRC_DRCStateBuf); + } + return true; //default connect +} + +bool WiiDRC_ShutdownRequested() +{ + return __WiiDRC_ShutdownRequested; +} + +const u8 *WiiDRC_GetRawI2CAddr() +{ + return __WiiDRC_I2CBuf; +} +const struct WiiDRCData *WiiDRC_Data() +{ + return &__WiiDRC_PadData; +} +u32 WiiDRC_ButtonsUp() +{ + return __WiiDRC_PadButtons.up; +} +u32 WiiDRC_ButtonsDown() +{ + return __WiiDRC_PadButtons.down; +} +u32 WiiDRC_ButtonsHeld() +{ + return __WiiDRC_PadButtons.state; +} +s16 WiiDRC_lStickX() +{ + return __WiiDRC_PadData.xAxisL; +} +s16 WiiDRC_lStickY() +{ + return __WiiDRC_PadData.yAxisL; +} +s16 WiiDRC_rStickX() +{ + return __WiiDRC_PadData.xAxisR; +} +s16 WiiDRC_rStickY() +{ + return __WiiDRC_PadData.yAxisR; +} diff --git a/source/utils/wiidrc.h b/source/utils/wiidrc.h new file mode 100644 index 0000000..32657f0 --- /dev/null +++ b/source/utils/wiidrc.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2017 FIX94 + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ +#ifndef _WIIDRC_H_ +#define _WIIDRC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct WiiDRCData { + s16 xAxisL; + s16 xAxisR; + s16 yAxisL; + s16 yAxisR; + u16 button; + u8 battery; + u8 extra; +}; + +#define WIIDRC_BUTTON_A 0x8000 +#define WIIDRC_BUTTON_B 0x4000 +#define WIIDRC_BUTTON_X 0x2000 +#define WIIDRC_BUTTON_Y 0x1000 +#define WIIDRC_BUTTON_LEFT 0x0800 +#define WIIDRC_BUTTON_RIGHT 0x0400 +#define WIIDRC_BUTTON_UP 0x0200 +#define WIIDRC_BUTTON_DOWN 0x0100 +#define WIIDRC_BUTTON_ZL 0x0080 +#define WIIDRC_BUTTON_ZR 0x0040 +#define WIIDRC_BUTTON_L 0x0020 +#define WIIDRC_BUTTON_R 0x0010 +#define WIIDRC_BUTTON_PLUS 0x0008 +#define WIIDRC_BUTTON_MINUS 0x0004 +#define WIIDRC_BUTTON_HOME 0x0002 +#define WIIDRC_BUTTON_SYNC 0x0001 + +#define WIIDRC_EXTRA_BUTTON_L3 0x80 +#define WIIDRC_EXTRA_BUTTON_R3 0x40 +#define WIIDRC_EXTRA_BUTTON_TV 0x20 +#define WIIDRC_EXTRA_OVERLAY_TV 0x10 +#define WIIDRC_EXTRA_OVERLAY_POWER 0x01 + +bool WiiDRC_Init(); +bool WiiDRC_Inited(); +bool WiiDRC_Recalibrate(); +bool WiiDRC_ScanPads(); +bool WiiDRC_Connected(); +bool WiiDRC_ShutdownRequested(); +const u8 *WiiDRC_GetRawI2CAddr(); +const struct WiiDRCData *WiiDRC_Data(); +u32 WiiDRC_ButtonsUp(); +u32 WiiDRC_ButtonsDown(); +u32 WiiDRC_ButtonsHeld(); +s16 WiiDRC_lStickX(); +s16 WiiDRC_lStickY(); +s16 WiiDRC_rStickX(); +s16 WiiDRC_rStickY(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/vbagx.cpp b/source/vbagx.cpp index 4b453f8..681dbe7 100644 --- a/source/vbagx.cpp +++ b/source/vbagx.cpp @@ -34,6 +34,7 @@ #include "video.h" #include "gamesettings.h" #include "mem2.h" +#include "utils/wiidrc.h" #include "utils/FreeTypeGX.h" #include "vba/gba/Globals.h" @@ -54,8 +55,6 @@ int ResetRequested = 0; int ExitRequested = 0; char appPath[1024] = { 0 }; - - /**************************************************************************** * Shutdown / Reboot / Exit ***************************************************************************/ @@ -358,6 +357,7 @@ int main(int argc, char *argv[]) SYS_SetPowerCallback(ShutdownCB); SYS_SetResetCallback(ResetCB); + WiiDRC_Init(); WPAD_Init(); WPAD_SetPowerButtonCallback((WPADShutdownCallback)ShutdownCB); DI_Init();