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.
This commit is contained in:
Shawn Hoffman 2011-10-23 07:01:17 -07:00
parent ba119e8c05
commit 105e7e4eb4
13 changed files with 114 additions and 87 deletions

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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<std::recursive_mutex> lk(g_plugin.controls_lock, std::try_to_lock);

View File

@ -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);
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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

View File

@ -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<EBufferCommands>(_pBuffer[3]);
// Handle it
switch (command)
{
// Read the command
EBufferCommands command = static_cast<EBufferCommands>(_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<u8*>(&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<u8*>(&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<u8*>(&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<u8*>(&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)

View File

@ -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

View File

@ -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)

View File

@ -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;

View File

@ -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)