From 105e7e4eb41b8ccaf439f1dad1ae393ed9dac710 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Sun, 23 Oct 2011 07:01:17 -0700 Subject: [PATCH] Added TaruKonga (DK Bongos) support. Separated SI Device IDs from the enums used for config/gui since quite a few device types all have the gc controller SI ID. --- Source/Core/Core/Src/ConfigManager.cpp | 2 +- Source/Core/Core/Src/ConfigManager.h | 2 +- Source/Core/Core/Src/HW/DVDInterface.cpp | 2 +- Source/Core/Core/Src/HW/GCPad.cpp | 2 - Source/Core/Core/Src/HW/SI.cpp | 12 +-- Source/Core/Core/Src/HW/SI.h | 4 +- Source/Core/Core/Src/HW/SI_Device.cpp | 24 +++--- Source/Core/Core/Src/HW/SI_Device.h | 20 ++++- .../Core/Src/HW/SI_DeviceGCController.cpp | 85 ++++++++----------- .../Core/Core/Src/HW/SI_DeviceGCController.h | 17 +++- Source/Core/Core/Src/Movie.cpp | 6 +- Source/Core/DolphinWX/Src/ConfigMain.cpp | 23 +++-- Source/Core/DolphinWX/Src/FrameTools.cpp | 2 +- 13 files changed, 114 insertions(+), 87 deletions(-) diff --git a/Source/Core/Core/Src/ConfigManager.cpp b/Source/Core/Core/Src/ConfigManager.cpp index 3d68189db3..e70b021a0c 100644 --- a/Source/Core/Core/Src/ConfigManager.cpp +++ b/Source/Core/Core/Src/ConfigManager.cpp @@ -366,7 +366,7 @@ void SConfig::LoadSettings() for (int i = 0; i < 4; ++i) { sprintf(sidevicenum, "SIDevice%i", i); - ini.Get("Core", sidevicenum, (u32*)&m_SIDevice[i], i==0 ? SI_GC_CONTROLLER:SI_NONE); + ini.Get("Core", sidevicenum, (u32*)&m_SIDevice[i], (i == 0) ? SIDEVICE_GC_CONTROLLER : SIDEVICE_NONE); } ini.Get("Core", "WiiSDCard", &m_WiiSDCard, false); diff --git a/Source/Core/Core/Src/ConfigManager.h b/Source/Core/Core/Src/ConfigManager.h index 585e3689d6..35ac8269e9 100644 --- a/Source/Core/Core/Src/ConfigManager.h +++ b/Source/Core/Core/Src/ConfigManager.h @@ -52,7 +52,7 @@ struct SConfig : NonCopyable //this is necessary to save after loading a savestate bool b_reloadMCOnState; TEXIDevices m_EXIDevice[3]; - TSIDevices m_SIDevice[4]; + SIDevices m_SIDevice[4]; std::string m_bba_mac; // interface language diff --git a/Source/Core/Core/Src/HW/DVDInterface.cpp b/Source/Core/Core/Src/HW/DVDInterface.cpp index cea7486426..205cd00448 100644 --- a/Source/Core/Core/Src/HW/DVDInterface.cpp +++ b/Source/Core/Core/Src/HW/DVDInterface.cpp @@ -522,7 +522,7 @@ void GenerateDIInterrupt(DI_InterruptType _DVDInterrupt) void ExecuteCommand(UDICR& _DICR) { // _dbg_assert_(DVDINTERFACE, _DICR.RW == 0); // only DVD to Memory - int GCAM = ((SConfig::GetInstance().m_SIDevice[0] == SI_AM_BASEBOARD) + int GCAM = ((SConfig::GetInstance().m_SIDevice[0] == SIDEVICE_AM_BASEBOARD) && (SConfig::GetInstance().m_EXIDevice[2] == EXIDEVICE_AM_BASEBOARD)) ? 1 : 0; diff --git a/Source/Core/Core/Src/HW/GCPad.cpp b/Source/Core/Core/Src/HW/GCPad.cpp index 65b920409e..4c1b4dabdd 100644 --- a/Source/Core/Core/Src/HW/GCPad.cpp +++ b/Source/Core/Core/Src/HW/GCPad.cpp @@ -62,8 +62,6 @@ void GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) { memset(_pPADStatus, 0, sizeof(*_pPADStatus)); _pPADStatus->err = PAD_ERR_NONE; - // wtf is this? - _pPADStatus->button = PAD_USE_ORIGIN; std::unique_lock lk(g_plugin.controls_lock, std::try_to_lock); diff --git a/Source/Core/Core/Src/HW/SI.cpp b/Source/Core/Core/Src/HW/SI.cpp index 178550b445..cd80c14daf 100644 --- a/Source/Core/Core/Src/HW/SI.cpp +++ b/Source/Core/Core/Src/HW/SI.cpp @@ -247,9 +247,9 @@ void Init() g_Channel[i].m_InLo.Hex = 0; if (Movie::IsUsingPad(i)) - AddDevice(SI_GC_CONTROLLER, i); + AddDevice(SIDEVICE_GC_CONTROLLER, i); else if (Movie::IsRecordingInput() || Movie::IsPlayingInput()) - AddDevice(SI_NONE, i); + AddDevice(SIDEVICE_NONE, i); else AddDevice(SConfig::GetInstance().m_SIDevice[i], i); } @@ -538,7 +538,7 @@ void RemoveDevice(int _iDeviceNumber) g_Channel[_iDeviceNumber].m_pDevice = NULL; } -void AddDevice(const TSIDevices _device, int _iDeviceNumber) +void AddDevice(const SIDevices _device, int _iDeviceNumber) { //_dbg_assert_(SERIALINTERFACE, _iDeviceNumber < NUMBER_OF_CHANNELS); @@ -572,14 +572,14 @@ void ChangeDeviceCallback(u64 userdata, int cyclesLate) SetNoResponse(channel); - AddDevice((TSIDevices)(u32)userdata, channel); + AddDevice((SIDevices)(u32)userdata, channel); } -void ChangeDevice(TSIDevices device, int channel) +void ChangeDevice(SIDevices device, int channel) { // Called from GUI, so we need to make it thread safe. // Let the hardware see no device for .5b cycles - CoreTiming::ScheduleEvent_Threadsafe(0, changeDevice, ((u64)channel << 32) | SI_NONE); + CoreTiming::ScheduleEvent_Threadsafe(0, changeDevice, ((u64)channel << 32) | SIDEVICE_NONE); CoreTiming::ScheduleEvent_Threadsafe(500000000, changeDevice, ((u64)channel << 32) | device); } diff --git a/Source/Core/Core/Src/HW/SI.h b/Source/Core/Core/Src/HW/SI.h index 59e38df9c8..c1eb336798 100644 --- a/Source/Core/Core/Src/HW/SI.h +++ b/Source/Core/Core/Src/HW/SI.h @@ -31,10 +31,10 @@ void DoState(PointerWrap &p); void UpdateDevices(); void RemoveDevice(int _iDeviceNumber); -void AddDevice(const TSIDevices _device, int _iDeviceNumber); +void AddDevice(const SIDevices _device, int _iDeviceNumber); void ChangeDeviceCallback(u64 userdata, int cyclesLate); -void ChangeDevice(TSIDevices device, int channel); +void ChangeDevice(SIDevices device, int channel); void Read32(u32& _uReturnValue, const u32 _iAddress); void Write32(const u32 _iValue, const u32 _iAddress); diff --git a/Source/Core/Core/Src/HW/SI_Device.cpp b/Source/Core/Core/Src/HW/SI_Device.cpp index c1a65ebcb8..6c0c40f40d 100644 --- a/Source/Core/Core/Src/HW/SI_Device.cpp +++ b/Source/Core/Core/Src/HW/SI_Device.cpp @@ -68,25 +68,29 @@ public: // F A C T O R Y -ISIDevice* SIDevice_Create(TSIDevices _SIDevice, int _iDeviceNumber) +ISIDevice* SIDevice_Create(const SIDevices device, const int port_number) { - switch(_SIDevice) + switch (device) { - case SI_GC_CONTROLLER: - return new CSIDevice_GCController(_iDeviceNumber); + case SIDEVICE_GC_CONTROLLER: + return new CSIDevice_GCController(port_number); break; - case SI_GBA: - return new CSIDevice_GBA(_iDeviceNumber); + case SIDEVICE_GC_TARUKONGA: + return new CSIDevice_TaruKonga(port_number); break; - case SI_AM_BASEBOARD: - return new CSIDevice_AMBaseboard(_iDeviceNumber); + case SIDEVICE_GC_GBA: + return new CSIDevice_GBA(port_number); break; - case SI_NONE: + case SIDEVICE_AM_BASEBOARD: + return new CSIDevice_AMBaseboard(port_number); + break; + + case SIDEVICE_NONE: default: - return new CSIDevice_Null(_iDeviceNumber); + return new CSIDevice_Null(port_number); break; } } diff --git a/Source/Core/Core/Src/HW/SI_Device.h b/Source/Core/Core/Src/HW/SI_Device.h index 642a54d918..2ed982ad0a 100644 --- a/Source/Core/Core/Src/HW/SI_Device.h +++ b/Source/Core/Core/Src/HW/SI_Device.h @@ -57,7 +57,7 @@ public: virtual void SendCommand(u32 _Cmd, u8 _Poll) = 0; }; -// SI Device IDs +// SI Device IDs for emulator use enum TSIDevices { SI_NONE = SI_ERROR_NO_RESPONSE, @@ -72,6 +72,22 @@ enum TSIDevices SI_AM_BASEBOARD = 0x10110800 // gets ORd with dipswitch state }; -extern ISIDevice* SIDevice_Create(TSIDevices _SIDevice, int _iDeviceNumber); +// For configuration use, since some devices can have the same SI Device ID +enum SIDevices +{ + SIDEVICE_NONE, + SIDEVICE_N64_MIC, + SIDEVICE_N64_KEYBOARD, + SIDEVICE_N64_MOUSE, + SIDEVICE_N64_CONTROLLER, + SIDEVICE_GC_GBA, + SIDEVICE_GC_CONTROLLER, + SIDEVICE_GC_KEYBOARD, + SIDEVICE_GC_STEERING, + SIDEVICE_GC_TARUKONGA, + SIDEVICE_AM_BASEBOARD +}; + +extern ISIDevice* SIDevice_Create(const SIDevices device, const int port_number); #endif diff --git a/Source/Core/Core/Src/HW/SI_DeviceGCController.cpp b/Source/Core/Core/Src/HW/SI_DeviceGCController.cpp index 601fb98f02..abb4bf8dec 100644 --- a/Source/Core/Core/Src/HW/SI_DeviceGCController.cpp +++ b/Source/Core/Core/Src/HW/SI_DeviceGCController.cpp @@ -59,60 +59,49 @@ int CSIDevice_GCController::RunBuffer(u8* _pBuffer, int _iLength) // For debug logging only ISIDevice::RunBuffer(_pBuffer, _iLength); - int iPosition = 0; - while (iPosition < _iLength) + // Read the command + EBufferCommands command = static_cast(_pBuffer[3]); + + // Handle it + switch (command) { - // Read the command - EBufferCommands command = static_cast(_pBuffer[iPosition ^ 3]); - iPosition++; + case CMD_RESET: + *(u32*)&_pBuffer[0] = SI_GC_CONTROLLER; + break; - // Handle it - switch (command) + case CMD_ORIGIN: { - case CMD_RESET: + INFO_LOG(SERIALINTERFACE, "PAD - Get Origin"); + u8* pCalibration = reinterpret_cast(&m_Origin); + for (int i = 0; i < (int)sizeof(SOrigin); i++) { - *(u32*)&_pBuffer[0] = SI_GC_CONTROLLER; - iPosition = _iLength; // Break the while loop + _pBuffer[i ^ 3] = *pCalibration++; } - break; - - case CMD_ORIGIN: - { - INFO_LOG(SERIALINTERFACE, "PAD - Get Origin"); - u8* pCalibration = reinterpret_cast(&m_Origin); - for (int i = 0; i < (int)sizeof(SOrigin); i++) - { - _pBuffer[i ^ 3] = *pCalibration++; - } - } - iPosition = _iLength; - break; - - // Recalibrate (FiRES: i am not 100 percent sure about this) - case CMD_RECALIBRATE: - { - INFO_LOG(SERIALINTERFACE, "PAD - Recalibrate"); - u8* pCalibration = reinterpret_cast(&m_Origin); - for (int i = 0; i < (int)sizeof(SOrigin); i++) - { - _pBuffer[i ^ 3] = *pCalibration++; - } - } - iPosition = _iLength; - break; - - // DEFAULT - default: - { - ERROR_LOG(SERIALINTERFACE, "unknown SI command (0x%x)", command); - PanicAlert("SI: Unknown command"); - iPosition = _iLength; - } - break; } + break; + + // Recalibrate (FiRES: i am not 100 percent sure about this) + case CMD_RECALIBRATE: + { + INFO_LOG(SERIALINTERFACE, "PAD - Recalibrate"); + u8* pCalibration = reinterpret_cast(&m_Origin); + for (int i = 0; i < (int)sizeof(SOrigin); i++) + { + _pBuffer[i ^ 3] = *pCalibration++; + } + } + break; + + // DEFAULT + default: + { + ERROR_LOG(SERIALINTERFACE, "unknown SI command (0x%x)", command); + PanicAlert("SI: Unknown command"); + } + break; } - return iPosition; + return _iLength; } @@ -156,9 +145,7 @@ bool CSIDevice_GCController::GetData(u32& _Hi, u32& _Low) // Thankfully changing mode does not change the high bits ;) _Hi = (u32)((u8)PadStatus.stickY); _Hi |= (u32)((u8)PadStatus.stickX << 8); - _Hi |= (u32)((u16)PadStatus.button << 16); - _Hi |= 0x00800000; // F|RES: means that the pad must be "combined" with the origin to match the "final" OSPad-Struct - //_Hi |= 0x20000000; // ? + _Hi |= (u32)((u16)(PadStatus.button | PAD_USE_ORIGIN) << 16); // Low bits are packed differently per mode if (m_Mode == 0 || m_Mode == 5 || m_Mode == 6 || m_Mode == 7) diff --git a/Source/Core/Core/Src/HW/SI_DeviceGCController.h b/Source/Core/Core/Src/HW/SI_DeviceGCController.h index 5493417793..81e0d9d03f 100644 --- a/Source/Core/Core/Src/HW/SI_DeviceGCController.h +++ b/Source/Core/Core/Src/HW/SI_DeviceGCController.h @@ -30,7 +30,6 @@ private: // Commands enum EBufferCommands { - CMD_INVALID = 0xFFFFFFFF, CMD_RESET = 0x00, CMD_ORIGIN = 0x41, CMD_RECALIBRATE = 0x42, @@ -111,4 +110,20 @@ public: // Send a command directly virtual void SendCommand(u32 _Cmd, u8 _Poll); }; + + +// "TaruKonga", the DK Bongo controller +class CSIDevice_TaruKonga : public CSIDevice_GCController +{ +public: + CSIDevice_TaruKonga(int _iDeviceNumber) : CSIDevice_GCController(_iDeviceNumber) { } + + virtual bool GetData(u32& _Hi, u32& _Low) + { + CSIDevice_GCController::GetData(_Hi, _Low); + _Hi &= ~PAD_USE_ORIGIN << 16; + return true; + } +}; + #endif diff --git a/Source/Core/Core/Src/Movie.cpp b/Source/Core/Core/Src/Movie.cpp index d340496c33..818d77cd35 100644 --- a/Source/Core/Core/Src/Movie.cpp +++ b/Source/Core/Core/Src/Movie.cpp @@ -181,7 +181,7 @@ void ChangePads(bool instantly) int controllers = 0; for (int i = 0; i < 4; i++) - if (SConfig::GetInstance().m_SIDevice[i] == SI_GC_CONTROLLER) + if (SConfig::GetInstance().m_SIDevice[i] == SIDEVICE_GC_CONTROLLER) controllers |= (1 << i); if (instantly && (g_numPads & 0x0F) == controllers) @@ -189,9 +189,9 @@ void ChangePads(bool instantly) for (int i = 0; i < 4; i++) if (instantly) // Changes from savestates need to be instantaneous - SerialInterface::AddDevice(IsUsingPad(i) ? SI_GC_CONTROLLER : SI_NONE, i); + SerialInterface::AddDevice(IsUsingPad(i) ? SIDEVICE_GC_CONTROLLER : SIDEVICE_NONE, i); else - SerialInterface::ChangeDevice(IsUsingPad(i) ? SI_GC_CONTROLLER : SI_NONE, i); + SerialInterface::ChangeDevice(IsUsingPad(i) ? SIDEVICE_GC_CONTROLLER : SIDEVICE_NONE, i); } void ChangeWiiPads(bool instantly) diff --git a/Source/Core/DolphinWX/Src/ConfigMain.cpp b/Source/Core/DolphinWX/Src/ConfigMain.cpp index 31000173ae..c364267362 100644 --- a/Source/Core/DolphinWX/Src/ConfigMain.cpp +++ b/Source/Core/DolphinWX/Src/ConfigMain.cpp @@ -78,6 +78,7 @@ static const wxLanguage langIds[] = #define DEV_DUMMY_STR _trans("Dummy") #define SIDEV_STDCONT_STR _trans("Standard Controller") +#define SIDEV_BONGO_STR _trans("TaruKonga (Bongos)") #define SIDEV_GBA_STR "GBA" #define SIDEV_AM_BB_STR _trans("AM-Baseboard") @@ -388,6 +389,7 @@ void CConfigMain::InitializeGUIValues() wxArrayString SIDevices; SIDevices.Add(_(DEV_NONE_STR)); SIDevices.Add(_(SIDEV_STDCONT_STR)); + SIDevices.Add(_(SIDEV_BONGO_STR)); SIDevices.Add(_(SIDEV_GBA_STR)); SIDevices.Add(_(SIDEV_AM_BB_STR)); @@ -436,15 +438,18 @@ void CConfigMain::InitializeGUIValues() switch (SConfig::GetInstance().m_SIDevice[i]) { - case SI_GC_CONTROLLER: + case SIDEVICE_GC_CONTROLLER: GCSIDevice[i]->SetStringSelection(SIDevices[1]); break; - case SI_GBA: + case SIDEVICE_GC_TARUKONGA: GCSIDevice[i]->SetStringSelection(SIDevices[2]); break; - case SI_AM_BASEBOARD: + case SIDEVICE_GC_GBA: GCSIDevice[i]->SetStringSelection(SIDevices[3]); break; + case SIDEVICE_AM_BASEBOARD: + GCSIDevice[i]->SetStringSelection(SIDevices[4]); + break; default: GCSIDevice[i]->SetStringSelection(SIDevices[0]); break; @@ -1043,15 +1048,17 @@ void CConfigMain::ChooseMemcardPath(std::string& strMemcard, bool isSlotA) void CConfigMain::ChooseSIDevice(std::string deviceName, int deviceNum) { - TSIDevices tempType; + SIDevices tempType; if (!deviceName.compare(CSTR_TRANS(SIDEV_STDCONT_STR))) - tempType = SI_GC_CONTROLLER; + tempType = SIDEVICE_GC_CONTROLLER; + else if (!deviceName.compare(CSTR_TRANS(SIDEV_BONGO_STR))) + tempType = SIDEVICE_GC_TARUKONGA; else if (!deviceName.compare(SIDEV_GBA_STR)) - tempType = SI_GBA; + tempType = SIDEVICE_GC_GBA; else if (!deviceName.compare(CSTR_TRANS(SIDEV_AM_BB_STR))) - tempType = SI_AM_BASEBOARD; + tempType = SIDEVICE_AM_BASEBOARD; else - tempType = SI_NONE; + tempType = SIDEVICE_NONE; SConfig::GetInstance().m_SIDevice[deviceNum] = tempType; diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index be24228c98..32b7d48477 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -723,7 +723,7 @@ void CFrame::OnRecord(wxCommandEvent& WXUNUSED (event)) } for (int i = 0; i < 4; i++) { - if (SConfig::GetInstance().m_SIDevice[i] == SI_GC_CONTROLLER) + if (SConfig::GetInstance().m_SIDevice[i] == SIDEVICE_GC_CONTROLLER) controllers |= (1 << i); if (g_wiimote_sources[i] != WIIMOTE_SRC_NONE)