From c5eed33de0df0ff9ec9c5ca5878b2fe87605ade9 Mon Sep 17 00:00:00 2001 From: Daryl Borth Date: Wed, 5 Sep 2018 19:59:14 -0600 Subject: [PATCH] Add Wii U GamePad support (thanks Fix94!) --- readme.txt | 4 +- source/button_mapping.c | 27 +++- 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 | 42 ++++++- source/input.h | 4 +- source/menu.cpp | 125 +++++++++++------- source/preferences.cpp | 2 + source/snes9xgx.cpp | 2 + source/utils/wiidrc.c | 188 ++++++++++++++++++++++++++++ source/utils/wiidrc.h | 67 ++++++++++ 20 files changed, 492 insertions(+), 85 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 29c2d77..ee60c51 100644 --- a/readme.txt +++ b/readme.txt @@ -16,7 +16,8 @@ Wii homebrew is WiiBrew (www.wiibrew.org). •˜———–—––-- - —————————––––– ———–—––-- - —————————––––– ———–—––-- - ————————• * Based on Snes9x 1.52 -* 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) * SNES Superscope, Mouse, Justifier support * Cheat support * Satellaview (BS-X) support @@ -37,6 +38,7 @@ Wii homebrew is WiiBrew (www.wiibrew.org). * Improved WiiFlow integration * Fixed mangled image when switching between HQ2x and scanlines filters +* Added Wii U GamePad support (thanks Fix94!) [4.3.9 - August 24, 2018] diff --git a/source/button_mapping.c b/source/button_mapping.c index cb1d979..833ea37 100644 --- a/source/button_mapping.c +++ b/source/button_mapping.c @@ -17,6 +17,7 @@ #include #include +#include "utils/wiidrc.h" #include "button_mapping.h" /**************************************************************************** @@ -25,7 +26,7 @@ * and for displaying the name of said button ***************************************************************************/ -CtrlrMap ctrlr_def[5] = { +CtrlrMap ctrlr_def[6] = { // Gamecube controller btn def { CTRLR_GCPAD, @@ -114,7 +115,7 @@ CtrlrMap ctrlr_def[5] = { {WPAD_CLASSIC_BUTTON_ZR, "ZR"} } }, -// Wii U pro controller +// Wii U Pro controller { CTRLR_WUPC, 15, @@ -135,5 +136,27 @@ CtrlrMap ctrlr_def[5] = { {WPAD_CLASSIC_BUTTON_ZL, "ZL"}, {WPAD_CLASSIC_BUTTON_ZR, "ZR"} } +}, +// Wii U Gamepad btn def +{ + CTRLR_WIIDRC, + 15, + { + {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"} + } } }; diff --git a/source/button_mapping.h b/source/button_mapping.h index d7fed54..d858d19 100644 --- a/source/button_mapping.h +++ b/source/button_mapping.h @@ -18,11 +18,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' @@ -35,6 +36,6 @@ typedef struct _ctrlr_map { BtnMap map[15]; // controller button map } CtrlrMap; -extern CtrlrMap ctrlr_def[5]; +extern CtrlrMap ctrlr_def[6]; #endif diff --git a/source/filelist.h b/source/filelist.h index fcde07b..4d4ea37 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_snescontroller_png[]; extern const u32 icon_settings_snescontroller_png_size; diff --git a/source/gui/gui.h b/source/gui/gui.h index 7721611..23a61c3 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!@u4tUUbS!h3=-PCTA9r-vy(Y)&*){**t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aG(@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 ANALOG_SENSITIVITY) wp |= (exp_type == WPAD_EXP_CLASSIC) ? WPAD_CLASSIC_BUTTON_RIGHT : WPAD_BUTTON_RIGHT; + + /* Wii U Gamepad */ + if (wiidrc_ay > ANALOG_SENSITIVITY) + wiidrcp |= WIIDRC_BUTTON_UP; + else if (wiidrc_ay < -ANALOG_SENSITIVITY) + wiidrcp |= WIIDRC_BUTTON_DOWN; + if (wiidrc_ax < -ANALOG_SENSITIVITY) + wiidrcp |= WIIDRC_BUTTON_LEFT; + else if (wiidrc_ax > ANALOG_SENSITIVITY) + wiidrcp |= WIIDRC_BUTTON_RIGHT; #endif /*** Fix offset to pad ***/ @@ -453,6 +486,7 @@ static void decodepad (int chan) || ( (exp_type == WPAD_EXP_CLASSIC && !isWUPC) && (wp & btnmap[CTRL_PAD][CTRLR_CLASSIC][i]) ) // classic controller || ( (exp_type == WPAD_EXP_CLASSIC && isWUPC) && (wp & btnmap[CTRL_PAD][CTRLR_WUPC][i]) ) // wii u pro controller || ( (exp_type == WPAD_EXP_NUNCHUK) && (wp & btnmap[CTRL_PAD][CTRLR_NUNCHUK][i]) ) // nunchuk + wiimote + || ( (wiidrcp & btnmap[CTRL_PAD][CTRLR_WIIDRC][i]) ) // Wii U Gamepad #endif ) S9xReportButton (offset + i, true); @@ -559,7 +593,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 ) { @@ -583,7 +618,8 @@ void ReportButtons () Settings.TurboMode = ( userInput[0].pad.substickX > 70 || - userInput[0].WPAD_StickX(1) > 70 + userInput[0].WPAD_StickX(1) > 70 || + userInput[0].wiidrcdata.substickX > 45 ); // RIGHT on c-stick and on classic controller right joystick if(Settings.TurboMode) { diff --git a/source/input.h b/source/input.h index e17e195..213cc36 100644 --- a/source/input.h +++ b/source/input.h @@ -16,12 +16,14 @@ #include #include +#include "utils/wiidrc.h" #define PI 3.14159265f #define PADCAL 50 +#define WIIDRCCAL 20 #define MAXJP 12 // # of mappable controller buttons -extern u32 btnmap[4][5][12]; +extern u32 btnmap[4][6][12]; extern int rumbleRequest[4]; void ResetControls(int cc = -1, int wc = -1); diff --git a/source/menu.cpp b/source/menu.cpp index f0cd0a0..703e8a3 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -851,10 +851,10 @@ 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; } @@ -864,6 +864,7 @@ static void WindowCredits(void * ptr) // 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; } @@ -897,7 +898,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); @@ -1121,10 +1122,10 @@ static void ControllerWindow() 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); GuiImageData arrowLeft(button_arrow_left_png); GuiImage arrowLeftImg(&arrowLeft); @@ -1201,7 +1202,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); GuiText saveBtnTxt("Save", 22, (GXColor){0, 0, 0, 255}); GuiImage saveBtnImg(&btnLargeOutline); @@ -1620,7 +1621,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); @@ -1891,7 +1892,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); @@ -2353,9 +2354,10 @@ static int MenuSettingsMappingsController() 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()-20); + gamecubeBtnTxt.SetWrap(true, btnLargeOutline.GetWidth()-30); GuiImage gamecubeBtnImg(&btnLargeOutline); GuiImage gamecubeBtnImgOver(&btnLargeOutlineOver); GuiImage gamecubeBtnIcon(&iconGamecube); @@ -2372,24 +2374,6 @@ static int MenuSettingsMappingsController() 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); @@ -2407,8 +2391,26 @@ static int MenuSettingsMappingsController() 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()-20); + classicBtnTxt.SetWrap(true, btnLargeOutline.GetWidth()-30); GuiImage classicBtnImg(&btnLargeOutline); GuiImage classicBtnImgOver(&btnLargeOutlineOver); GuiImage classicBtnIcon(&iconClassic); @@ -2435,7 +2437,7 @@ static int MenuSettingsMappingsController() 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); @@ -2448,6 +2450,24 @@ static int MenuSettingsMappingsController() 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); @@ -2474,8 +2494,14 @@ static int MenuSettingsMappingsController() if(mapMenuCtrlSNES == CTRL_PAD) { - 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 @@ -2509,6 +2535,11 @@ static int MenuSettingsMappingsController() 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; @@ -2566,6 +2597,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; @@ -2605,6 +2639,13 @@ ButtonMappingWindow() 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; @@ -2866,16 +2907,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); @@ -3002,16 +3043,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); @@ -3991,9 +4032,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 baaa9b2..6f6d847 100644 --- a/source/preferences.cpp +++ b/source/preferences.cpp @@ -173,6 +173,7 @@ preparePrefsData () createXMLController(btnmap[CTRL_PAD][CTRLR_WIIMOTE], "btnmap_pad_wiimote", "SNES Pad - Wiimote"); createXMLController(btnmap[CTRL_PAD][CTRLR_CLASSIC], "btnmap_pad_classic", "SNES Pad - Classic Controller"); createXMLController(btnmap[CTRL_PAD][CTRLR_WUPC], "btnmap_pad_wupc", "SNES Pad - Wii U Pro Controller"); + createXMLController(btnmap[CTRL_PAD][CTRLR_WIIDRC], "btnmap_pad_wiidrc", "SNES Pad - Wii U Gamepad"); createXMLController(btnmap[CTRL_PAD][CTRLR_NUNCHUK], "btnmap_pad_nunchuk", "SNES Pad - Nunchuk + Wiimote"); #endif createXMLController(btnmap[CTRL_SCOPE][CTRLR_GCPAD], "btnmap_scope_gcpad", "Superscope - GameCube Controller"); @@ -356,6 +357,7 @@ decodePrefsData () loadXMLController(btnmap[CTRL_PAD][CTRLR_WIIMOTE], "btnmap_pad_wiimote"); loadXMLController(btnmap[CTRL_PAD][CTRLR_CLASSIC], "btnmap_pad_classic"); loadXMLController(btnmap[CTRL_PAD][CTRLR_WUPC], "btnmap_pad_wupc"); + loadXMLController(btnmap[CTRL_PAD][CTRLR_WIIDRC], "btnmap_pad_wiidrc"); loadXMLController(btnmap[CTRL_PAD][CTRLR_NUNCHUK], "btnmap_pad_nunchuk"); loadXMLController(btnmap[CTRL_SCOPE][CTRLR_GCPAD], "btnmap_scope_gcpad"); loadXMLController(btnmap[CTRL_SCOPE][CTRLR_WIIMOTE], "btnmap_scope_wiimote"); diff --git a/source/snes9xgx.cpp b/source/snes9xgx.cpp index 7995acb..fe54c0c 100644 --- a/source/snes9xgx.cpp +++ b/source/snes9xgx.cpp @@ -43,6 +43,7 @@ #include "filebrowser.h" #include "input.h" #include "mem2.h" +#include "utils/wiidrc.h" #include "utils/FreeTypeGX.h" #include "snes9x/snes9x.h" @@ -421,6 +422,7 @@ int main(int argc, char *argv[]) SYS_SetPowerCallback(ShutdownCB); SYS_SetResetCallback(ResetCB); + WiiDRC_Init(); WPAD_Init(); WPAD_SetPowerButtonCallback((WPADShutdownCallback)ShutdownCB); DI_Init(); 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