From 1dcc199a63bf8bd72a76b14352263ab6768e21ba Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 31 Dec 2015 11:23:04 -0600 Subject: [PATCH] Fix GCPad recalibration shortcut. Dolphin has supported the recalibration shortcut (X+Y+Start) for quite a long while. So if someont's axises are terrible, you could easily recalibrate. Games even get the initial calibration upon boot(Most of the time). While changing over the GCAdapter code, I was testing to make sure the reset and calibration shortcuts still worked, turns out they didn't work at all. Looking in to the problem, we capture the combination properly, and we wait three seconds until we actually fire that off recalibration. The problem is for Nintendo's SDK to properly handle recalibrating, we need to send back data saying that it needs to recalibrate. On hardware this is done as part of the 64bits of data the controller sends back to us. On holding of the controller, bit 61 of the return value is set, which the Nintendo SDK catches, and then signals immediately afterwards a CMD_ORIGIN command in order to recalibrate the controller. We were outright ignoring this bit, so the library wasn't ever recalibrating. I suspect in the past the class itself used to use the calibration data to to offset the data, but somewhere along the lines it got munged out of existence. The Gamecube adapter does this shortcut in a bit of a unique way, instead of sending the command and having the library support it and what have you. Once holding the shortcut for the amount of time, the adapter reports back that the controller has actually been disconnected. Then when you let go of the combination, the adapter states that a new device has been connected to that port, and the recalibration happens because a new device is "connected." This fixes controller calibration for both emulated GC controllers and also the Wii Gamecube Adapter. --- Source/Core/Core/ConfigManager.cpp | 2 ++ Source/Core/Core/ConfigManager.h | 1 + Source/Core/Core/HW/SI_DeviceGCAdapter.cpp | 9 +++++++++ Source/Core/Core/HW/SI_DeviceGCAdapter.h | 2 +- Source/Core/Core/HW/SI_DeviceGCController.cpp | 14 +++++++++++-- Source/Core/Core/HW/SI_DeviceGCController.h | 20 ++++++++----------- .../DolphinWX/Config/GCAdapterConfigDiag.cpp | 5 +++++ .../DolphinWX/Config/GCAdapterConfigDiag.h | 5 +++++ 8 files changed, 43 insertions(+), 15 deletions(-) diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 5e9901f5d8..47c789ec43 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -255,6 +255,7 @@ void SConfig::SaveCoreSettings(IniFile& ini) { core->Set(StringFromFormat("SIDevice%i", i), m_SIDevice[i]); core->Set(StringFromFormat("AdapterRumble%i", i), m_AdapterRumble[i]); + core->Set(StringFromFormat("SimulateKonga%i", i), m_AdapterKonga[i]); } core->Set("WiiSDCard", m_WiiSDCard); core->Set("WiiKeyboard", m_WiiKeyboard); @@ -509,6 +510,7 @@ void SConfig::LoadCoreSettings(IniFile& ini) { core->Get(StringFromFormat("SIDevice%i", i), (u32*)&m_SIDevice[i], (i == 0) ? SIDEVICE_GC_CONTROLLER : SIDEVICE_NONE); core->Get(StringFromFormat("AdapterRumble%i", i), &m_AdapterRumble[i], true); + core->Get(StringFromFormat("SimulateKonga%i", i), &m_AdapterKonga[i], false); } core->Get("WiiSDCard", &m_WiiSDCard, false); core->Get("WiiKeyboard", &m_WiiKeyboard, false); diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 880e93bc8a..7325c27da9 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -266,6 +266,7 @@ struct SConfig : NonCopyable // Input settings bool m_BackgroundInput; bool m_AdapterRumble[4]; + bool m_AdapterKonga[4]; SysConf* m_SYSCONF; diff --git a/Source/Core/Core/HW/SI_DeviceGCAdapter.cpp b/Source/Core/Core/HW/SI_DeviceGCAdapter.cpp index 70215aa6a8..23ce9aac0c 100644 --- a/Source/Core/Core/HW/SI_DeviceGCAdapter.cpp +++ b/Source/Core/Core/HW/SI_DeviceGCAdapter.cpp @@ -4,9 +4,18 @@ #include "Common/MsgHandler.h" #include "Common/Logging/Log.h" +#include "Core/ConfigManager.h" #include "Core/Movie.h" #include "Core/HW/SI_DeviceGCAdapter.h" +CSIDevice_GCAdapter::CSIDevice_GCAdapter(SIDevices device, int _iDeviceNumber) + : CSIDevice_GCController(device, _iDeviceNumber) +{ + // get the correct pad number that should rumble locally when using netplay + const u8 numPAD = NetPlay_InGamePadToLocalPad(ISIDevice::m_iDeviceNumber); + m_simulate_konga = SConfig::GetInstance().m_AdapterKonga[numPAD]; +} + GCPadStatus CSIDevice_GCAdapter::GetPadStatus() { GCPadStatus PadStatus; diff --git a/Source/Core/Core/HW/SI_DeviceGCAdapter.h b/Source/Core/Core/HW/SI_DeviceGCAdapter.h index 05c73253fc..e171e3a5a0 100644 --- a/Source/Core/Core/HW/SI_DeviceGCAdapter.h +++ b/Source/Core/Core/HW/SI_DeviceGCAdapter.h @@ -12,7 +12,7 @@ class CSIDevice_GCAdapter : public CSIDevice_GCController { public: - CSIDevice_GCAdapter(SIDevices device, int _iDeviceNumber) : CSIDevice_GCController(device, _iDeviceNumber) {} + CSIDevice_GCAdapter(SIDevices device, int _iDeviceNumber); GCPadStatus GetPadStatus() override; int RunBuffer(u8* _pBuffer, int _iLength) override; diff --git a/Source/Core/Core/HW/SI_DeviceGCController.cpp b/Source/Core/Core/HW/SI_DeviceGCController.cpp index 3b2a191b2e..cf6eb50ff5 100644 --- a/Source/Core/Core/HW/SI_DeviceGCController.cpp +++ b/Source/Core/Core/HW/SI_DeviceGCController.cpp @@ -160,6 +160,8 @@ GCPadStatus CSIDevice_GCController::GetPadStatus() bool CSIDevice_GCController::GetData(u32& _Hi, u32& _Low) { GCPadStatus PadStatus = GetPadStatus(); + if (HandleButtonCombos(PadStatus) == COMBO_ORIGIN) + PadStatus.button |= PAD_GET_ORIGIN; _Hi = MapPadStatus(PadStatus); @@ -208,7 +210,12 @@ bool CSIDevice_GCController::GetData(u32& _Hi, u32& _Low) _Low |= (u32)((u8)PadStatus.substickX << 24); // All 8 bits } - HandleButtonCombos(PadStatus); + // Unset all bits except those that represent + // A, B, X, Y, Start and the error bits, as they + // are not used. + if (m_simulate_konga) + _Hi &= ~0x20FFFFFF; + return true; } @@ -222,7 +229,7 @@ u32 CSIDevice_GCController::MapPadStatus(const GCPadStatus& pad_status) return _Hi; } -void CSIDevice_GCController::HandleButtonCombos(const GCPadStatus& pad_status) +CSIDevice_GCController::EButtonCombo CSIDevice_GCController::HandleButtonCombos(const GCPadStatus& pad_status) { // Keep track of the special button combos (embedded in controller hardware... :( ) EButtonCombo tempCombo; @@ -255,8 +262,11 @@ void CSIDevice_GCController::HandleButtonCombos(const GCPadStatus& pad_status) m_Origin.uTrigger_R = pad_status.triggerRight; } m_LastButtonCombo = COMBO_NONE; + return tempCombo; } } + + return COMBO_NONE; } // SendCommand diff --git a/Source/Core/Core/HW/SI_DeviceGCController.h b/Source/Core/Core/HW/SI_DeviceGCController.h index 855ae89127..ca772131dc 100644 --- a/Source/Core/Core/HW/SI_DeviceGCController.h +++ b/Source/Core/Core/HW/SI_DeviceGCController.h @@ -79,6 +79,9 @@ protected: // Type of button combo from the last/current poll EButtonCombo m_LastButtonCombo; + // Set this if we want to simulate the "TaruKonga" DK Bongo controller + bool m_simulate_konga = false; + public: // Constructor @@ -98,14 +101,15 @@ public: virtual GCPadStatus GetPadStatus(); virtual u32 MapPadStatus(const GCPadStatus& pad_status); - virtual void HandleButtonCombos(const GCPadStatus& pad_status); + virtual EButtonCombo HandleButtonCombos(const GCPadStatus& pad_status); // Send and Receive pad input from network static bool NetPlay_GetInput(u8 numPAD, GCPadStatus* status); static u8 NetPlay_InGamePadToLocalPad(u8 numPAD); -private: +protected: void Calibrate(); + void HandleMoviePadStatus(GCPadStatus* PadStatus); }; @@ -113,16 +117,8 @@ private: class CSIDevice_TaruKonga : public CSIDevice_GCController { public: - CSIDevice_TaruKonga(SIDevices device, int _iDeviceNumber) : CSIDevice_GCController(device, _iDeviceNumber) { } - - bool GetData(u32& _Hi, u32& _Low) override + CSIDevice_TaruKonga(SIDevices device, int _iDeviceNumber) : CSIDevice_GCController(device, _iDeviceNumber) { - CSIDevice_GCController::GetData(_Hi, _Low); - - // Unset all bits except those that represent - // A, B, X, Y, Start and the error bits, as they - // are not used. - _Hi &= ~0x20FFFFFF; - return true; + m_simulate_konga = true; } }; diff --git a/Source/Core/DolphinWX/Config/GCAdapterConfigDiag.cpp b/Source/Core/DolphinWX/Config/GCAdapterConfigDiag.cpp index 21d64a686d..f72ad9d992 100644 --- a/Source/Core/DolphinWX/Config/GCAdapterConfigDiag.cpp +++ b/Source/Core/DolphinWX/Config/GCAdapterConfigDiag.cpp @@ -24,6 +24,10 @@ GCAdapterConfigDiag::GCAdapterConfigDiag(wxWindow* const parent, const wxString& gamecube_rumble->SetValue(SConfig::GetInstance().m_AdapterRumble[m_pad_id]); gamecube_rumble->Bind(wxEVT_CHECKBOX, &GCAdapterConfigDiag::OnAdapterRumble, this); + wxCheckBox* const gamecube_konga = new wxCheckBox(this, wxID_ANY, _("Simulate DK TaruKonga")); + gamecube_konga->SetValue(SConfig::GetInstance().m_AdapterKonga[m_pad_id]); + gamecube_konga->Bind(wxEVT_CHECKBOX, &GCAdapterConfigDiag::OnAdapterKonga, this); + m_adapter_status = new wxStaticText(this, wxID_ANY, _("Adapter Not Detected")); #if defined(__LIBUSB__) || defined (_WIN32) @@ -44,6 +48,7 @@ GCAdapterConfigDiag::GCAdapterConfigDiag(wxWindow* const parent, const wxString& szr->Add(m_adapter_status, 0, wxEXPAND); szr->Add(gamecube_rumble, 0, wxEXPAND); + szr->Add(gamecube_konga, 0, wxEXPAND); szr->Add(CreateButtonSizer(wxOK | wxNO_DEFAULT), 0, wxEXPAND|wxALL, 5); SetLayoutAdaptationMode(wxDIALOG_ADAPTATION_MODE_ENABLED); diff --git a/Source/Core/DolphinWX/Config/GCAdapterConfigDiag.h b/Source/Core/DolphinWX/Config/GCAdapterConfigDiag.h index fa7bf471d8..4c86f55a2e 100644 --- a/Source/Core/DolphinWX/Config/GCAdapterConfigDiag.h +++ b/Source/Core/DolphinWX/Config/GCAdapterConfigDiag.h @@ -32,4 +32,9 @@ private: { SConfig::GetInstance().m_AdapterRumble[m_pad_id] = event.IsChecked(); } + + void OnAdapterKonga(wxCommandEvent& event) + { + SConfig::GetInstance().m_AdapterKonga[m_pad_id] = event.IsChecked(); + } };