Add the ability to Get / Set Array data from SysConf

wiimote bd's are now read from (or added to if < 4 exist) SysConf
in theory you should be able to use any valid sysconf file now,
but i would advise against using a dolphin edited SysConf on a wii

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6646 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
LPFaint99 2010-12-22 08:00:08 +00:00
parent 3d68608024
commit 547c18fb55
4 changed files with 127 additions and 15 deletions

View file

@ -55,6 +55,25 @@ struct SSysConfEntry
template<class T>
T GetData() { return *(T*)data; }
bool GetArrayData(u8* dest, u16 destSize)
{
if (dest && destSize >= dataLength)
{
memcpy(dest, data, dataLength);
return true;
}
return false;
}
bool SetArrayData(u8* buffer, u16 bufferSize)
{
if (buffer && bufferSize == dataLength)
{
memcpy(data, buffer, dataLength);
return true;
}
return false;
}
};
class SysConf
@ -95,6 +114,49 @@ public:
return m_Entries.at(index).GetData<T>();
}
bool GetArrayData(const char* sectionName, u8* dest, u16 destSize)
{
if (!m_IsValid)
{
PanicAlert("Trying to read from invalid SYSCONF");
return 0;
}
size_t index = 0;
for (; index < m_Entries.size() - 1; index++)
{
if (strcmp(m_Entries.at(index).name, sectionName) == 0)
break;
}
if (index == m_Entries.size() - 1)
{
PanicAlert("Section %s not found in SYSCONF", sectionName);
return 0;
}
return m_Entries.at(index).GetArrayData(dest, destSize);
}
bool SetArrayData(const char* sectionName, u8* buffer, u16 bufferSize)
{
if (!m_IsValid)
return false;
size_t index = 0;
for (; index < m_Entries.size() - 1; index++)
{
if (strcmp(m_Entries.at(index).name, sectionName) == 0)
break;
}
if (index == m_Entries.size() - 1)
{
PanicAlert("Section %s not found in SYSCONF", sectionName);
return false;
}
return m_Entries.at(index).SetArrayData(buffer, bufferSize);
}
template<class T>
bool SetData(const char* sectionName, T newValue)
{

View file

@ -22,7 +22,9 @@
#include "../HW/WII_IPC.h"
#include "WII_IPC_HLE.h"
#include "WII_IPC_HLE_Device_usb.h"
#include "../ConfigManager.h"
#define WIIMOTESIZE 0x46
#define BTDINFSIZE WIIMOTESIZE * 0x10
// The device class
CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _DeviceID, const std::string& _rDeviceName)
: IWII_IPC_HLE_Device(_DeviceID, _rDeviceName)
@ -33,10 +35,54 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _De
, m_NumCompPackets_Freq(0)
{
// Activate only first Wiimote by default
m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, 0, true));
m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, 1));
m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, 2));
m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, 3));
u8 BT_DINF[BTDINFSIZE];
u8 maxWM = 0;
if (!SConfig::GetInstance().m_SYSCONF->GetArrayData("BT.DINF", BT_DINF, BTDINFSIZE))
{
PanicAlert("Trying to read from invalid SYSCONF\nWiimote bt ids are not available");
}
else
{
maxWM = BT_DINF[0];
bdaddr_t tmpBD;// = BDADDR_ANY;
u8 i = 0;
while (i < maxWM)
{
tmpBD.b[5] = BT_DINF[1 + (i * WIIMOTESIZE)];
tmpBD.b[4] = BT_DINF[2 + (i * WIIMOTESIZE)];
tmpBD.b[3] = BT_DINF[3 + (i * WIIMOTESIZE)];
tmpBD.b[2] = BT_DINF[4 + (i * WIIMOTESIZE)];
tmpBD.b[1] = BT_DINF[5 + (i * WIIMOTESIZE)];
tmpBD.b[0] = BT_DINF[6 + (i * WIIMOTESIZE)];
INFO_LOG(WII_IPC_WIIMOTE, "Wiimote %d BT ID %x,%x,%x,%x,%x,%x", i, tmpBD.b[0], tmpBD.b[1], tmpBD.b[2], tmpBD.b[3], tmpBD.b[4], tmpBD.b[5]);
m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, i, tmpBD, !i));
i++;
}
while (i < 4)
{
const char * wmName = "Nintendo RVL-CNT-01";
BT_DINF[0] = 4;
BT_DINF[1 + (i * WIIMOTESIZE)] = tmpBD.b[5] = i;
BT_DINF[2 + (i * WIIMOTESIZE)] = tmpBD.b[4] = 0x00;
BT_DINF[3 + (i * WIIMOTESIZE)] = tmpBD.b[3] = 0x79;
BT_DINF[4 + (i * WIIMOTESIZE)] = tmpBD.b[2] = 0x19;
BT_DINF[5 + (i * WIIMOTESIZE)] = tmpBD.b[1] = 0x02;
BT_DINF[6 + (i * WIIMOTESIZE)] = tmpBD.b[0] = 0x11;
memcpy((BT_DINF+7 + (i * WIIMOTESIZE)), wmName, 20);
INFO_LOG(WII_IPC_WIIMOTE, "Adding to SYSConf Wiimote %d BT ID %x,%x,%x,%x,%x,%x", i, tmpBD.b[0], tmpBD.b[1], tmpBD.b[2], tmpBD.b[3], tmpBD.b[4], tmpBD.b[5]);
m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, i, tmpBD, !i));
i++;
}
if (BT_DINF[0] != maxWM)
{
// save now so that when games load sysconf file it includes the new wiimotes
if (!SConfig::GetInstance().m_SYSCONF->SetArrayData("BT.DINF", BT_DINF, BTDINFSIZE) || !SConfig::GetInstance().m_SYSCONF->Save())
PanicAlert("Failed to write BT.DINF to SYSCONF");
}
}
// The BCM2045's btaddr:
m_ControllerBD.b[0] = 0x11;

View file

@ -35,8 +35,9 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305* GetUsbPointer()
return s_Usb;
}
CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number, bool ready)
: m_HIDControlChannel_Connected(false)
CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number, bdaddr_t _BD, bool ready)
: m_BD(_BD)
, m_HIDControlChannel_Connected(false)
, m_HIDControlChannel_ConnectedWait(false)
, m_HIDControlChannel_Config(false)
, m_HIDControlChannel_ConfigWait(false)
@ -46,7 +47,6 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305*
, m_HIDInterruptChannel_ConfigWait(false)
, m_Name("Nintendo RVL-CNT-01")
, m_pHost(_pHost)
{
DEBUG_LOG(WII_IPC_WIIMOTE, "Wiimote: #%i Constructed", _Number);
@ -56,13 +56,17 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305*
m_ConnectionHandle = 0x100 + _Number;
memset(m_LinkKey, 0xA0 + _Number, 16);
m_BD.b[0] = 0x11;
m_BD.b[1] = 0x02;
m_BD.b[2] = 0x19;
m_BD.b[3] = 0x79;
m_BD.b[4] = 0x00;
m_BD.b[5] = _Number;
bdaddr_t _nullBD = BDADDR_ANY;
if (memcmp(&m_BD, &_nullBD, sizeof(bdaddr_t))==0)
{
m_BD.b[0] = 0x11;
m_BD.b[1] = 0x02;
m_BD.b[2] = 0x19;
m_BD.b[3] = 0x79;
m_BD.b[4] = 0x00;
m_BD.b[5] = _Number;
}
uclass[0]= 0x00;
uclass[1]= 0x04;
uclass[2]= 0x48;

View file

@ -49,7 +49,7 @@ private:
class CWII_IPC_HLE_WiiMote
{
public:
CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number, bool ready = false);
CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number, bdaddr_t _BD, bool ready = false);
virtual ~CWII_IPC_HLE_WiiMote() {}