commit ayuanx's patch from issue 1634. Fixes quite a few IPC + IPC_HLE + IPC_HLE_USB + wiimote problems, see the issue for full details

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4606 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman
2009-11-24 05:03:47 +00:00
parent 55dc7efaa4
commit 6a46befc2a
20 changed files with 1171 additions and 1090 deletions

View File

@ -62,8 +62,8 @@ namespace HW
SystemTimers::Init();
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
{
WII_IPC_HLE_Interface::Init();
WII_IPCInterface::Init();
WII_IPC_HLE_Interface::Init();
}
}
@ -80,8 +80,8 @@ namespace HW
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
{
WII_IPC_HLE_Interface::Shutdown();
WII_IPCInterface::Shutdown();
WII_IPC_HLE_Interface::Shutdown();
}
State_Shutdown();
@ -100,12 +100,17 @@ namespace HW
GPFifo::DoState(p);
ExpansionInterface::DoState(p);
AudioInterface::DoState(p);
WII_IPCInterface::DoState(p);
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
{
WII_IPCInterface::DoState(p);
WII_IPC_HLE_Interface::DoState(p);
}
}
// Restart Wiimote
void InitWiimote()
{
WII_IPCInterface::Init();
WII_IPC_HLE_Interface::Init();
}
}

View File

@ -102,6 +102,7 @@ broadway: 729
// So, ratio is 1 / (1/4 * 1/3 = 1/12) = 12.
// note: ZWW is ok and faster with TIMER_RATIO=8 though.
// !!! POSSIBLE STABLE PERF BOOST HACK THERE !!!
enum
{
TIMER_RATIO = 12
@ -174,15 +175,14 @@ void AudioFifoCallback(u64 userdata, int cyclesLate)
void IPC_HLE_UpdateCallback(u64 userdata, int cyclesLate)
{
WII_IPC_HLE_Interface::UpdateDevices();
CoreTiming::ScheduleEvent(IPC_HLE_PERIOD-cyclesLate, et_IPC_HLE);
if (Core::GetStartupParameter().bWii)
WII_IPC_HLE_Interface::Update();
CoreTiming::ScheduleEvent(VideoInterface::GetTicksPerLine()-cyclesLate, et_IPC_HLE);
}
void VICallback(u64 userdata, int cyclesLate)
{
if (Core::GetStartupParameter().bWii)
WII_IPC_HLE_Interface::Update();
VideoInterface::Update();
CoreTiming::ScheduleEvent(VideoInterface::GetTicksPerLine() - cyclesLate, et_VI);
}
@ -252,6 +252,9 @@ void Init()
if (!UsingDSPLLE)
DSP_PERIOD = (int)(GetTicksPerSecond() * 0.003f);
// AyuanX: TO BE TWEAKED
// If this update frequency is too high, WiiMote could easily jam the IPC Bus
// but if it is too low, sometimes IPC gets overflown by CPU :~~~(
IPC_HLE_PERIOD = (int)(GetTicksPerSecond() * 0.003f);
}
else

View File

@ -85,36 +85,46 @@ union UIPC_Config
};
// STATE_TO_SAVE
UIPC_Status g_IPC_Status;
UIPC_Config g_IPC_Config;
UIPC_Control g_IPC_Control;
u32 g_Address = 0;
u32 g_Reply = 0;
u32 g_SensorBarPower = 0;
bool g_ExeCmd = false;
u32 g_Address = NULL;
u32 g_Reply = NULL;
u32 g_ReplyHead = NULL;
u32 g_ReplyTail = NULL;
u32 g_SensorBarPower = NULL;
UIPC_Status g_IPC_Status(NULL);
UIPC_Config g_IPC_Config(NULL);
UIPC_Control g_IPC_Control(NULL);
void DoState(PointerWrap &p)
{
p.Do(g_ExeCmd);
p.Do(g_Address);
p.Do(g_Reply);
p.Do(g_ReplyHead);
p.Do(g_ReplyTail);
p.Do(g_SensorBarPower);
p.Do(g_IPC_Status);
p.Do(g_IPC_Config);
p.Do(g_IPC_Control);
p.Do(g_Address);
p.Do(g_Reply);
p.Do(g_SensorBarPower);
}
void UpdateInterrupts();
// Init
void Init()
{
g_Address = 0;
g_Reply = 0;
g_SensorBarPower = 0;
g_ExeCmd = false;
g_Address = NULL;
g_Reply = NULL;
g_ReplyHead = NULL;
g_ReplyTail = NULL;
g_SensorBarPower = NULL;
g_IPC_Status = UIPC_Status(NULL);
g_IPC_Config = UIPC_Config(NULL);
g_IPC_Control = UIPC_Control(NULL);
}
g_IPC_Status = UIPC_Status();
g_IPC_Config = UIPC_Config();
g_IPC_Control = UIPC_Control();
void Reset()
{
Init();
}
void Shutdown()
@ -127,16 +137,16 @@ void Read32(u32& _rReturnValue, const u32 _Address)
{
case IPC_CONTROL_REGISTER:
_rReturnValue = g_IPC_Control.Hex;
INFO_LOG(WII_IPC, "IOP: Read32 from IPC_CONTROL_REGISTER(0x04) = 0x%08x", _rReturnValue);
INFO_LOG(WII_IPC, "IOP: Read32, IPC_CONTROL_REGISTER(0x04) = 0x%08x [R:%i A:%i E:%i]",
_rReturnValue, (_rReturnValue>>2)&1, (_rReturnValue>>1)&1, _rReturnValue&1);
// if ((REASON_REG & 0x14) == 0x14) CALL IPCReplayHanlder
// if ((REASON_REG & 0x22) != 0x22) Jumps to the end
break;
case IPC_REPLY_REGISTER: // looks a little bit like a callback function
_rReturnValue = g_Reply;
INFO_LOG(WII_IPC, "IOP: Write32 to IPC_REPLAY_REGISTER(0x08) = 0x%08x ", _rReturnValue);
INFO_LOG(WII_IPC, "IOP: Read32, IPC_REPLY_REGISTER(0x08) = 0x%08x ", _rReturnValue);
break;
case IPC_SENSOR_BAR_POWER_REGISTER:
@ -146,7 +156,7 @@ void Read32(u32& _rReturnValue, const u32 _Address)
default:
_dbg_assert_msg_(WII_IPC, 0, "IOP: Read32 from 0x%08x", _Address);
break;
}
}
}
void Write32(const u32 _Value, const u32 _Address)
@ -157,30 +167,36 @@ void Write32(const u32 _Value, const u32 _Address)
case IPC_COMMAND_REGISTER: // __ios_Ipc2 ... a value from __responses is loaded
{
g_Address = _Value;
INFO_LOG(WII_IPC, "IOP: Write32 to IPC_ADDRESS_REGISTER(0x00) = 0x%08x", g_Address);
INFO_LOG(WII_IPC, "IOP: Write32, IPC_ADDRESS_REGISTER(0x00) = 0x%08x", g_Address);
}
break;
case IPC_CONTROL_REGISTER:
{
INFO_LOG(WII_IPC, "IOP: Write32 to IPC_CONTROL_REGISTER(0x04) = 0x%08x (old: 0x%08x)", _Value, g_IPC_Control.Hex);
INFO_LOG(WII_IPC, "IOP: Write32, IPC_CONTROL_REGISTER(0x04) = 0x%08x [R:%i A:%i E:%i] (old: 0x%08x) ",
_Value, (_Value>>2)&1, (_Value>>1)&1, _Value&1, g_IPC_Control.Hex);
UIPC_Control TempControl(_Value);
_dbg_assert_msg_(WII_IPC, TempControl.pad == 0, "IOP: Write to UIPC_Control.pad", _Address);
if (TempControl.AckReady) { g_IPC_Control.AckReady = 0; }
if (TempControl.ReplyReady) { g_IPC_Control.ReplyReady = 0; }
if (TempControl.Relaunch) { g_IPC_Control.Relaunch = 0; }
// Ayuanx: What is this Relaunch bit used for ???
// I have done considerable amount of tests that show no use of it at all
// So I'm commenting this out
//
//if (TempControl.Relaunch) { g_IPC_Control.Relaunch = 0; }
g_IPC_Control.Relaunch = TempControl.Relaunch;
g_IPC_Control.unk5 = TempControl.unk5;
g_IPC_Control.unk6 = TempControl.unk6;
g_IPC_Control.pad = TempControl.pad;
if (TempControl.ExecuteCmd)
{
WII_IPC_HLE_Interface::AckCommand(g_Address);
}
g_ExeCmd = true;
}
}
break;
@ -189,21 +205,22 @@ void Write32(const u32 _Value, const u32 _Address)
UIPC_Status NewStatus(_Value);
if (NewStatus.INTERRUPT) g_IPC_Status.INTERRUPT = 0; // clear interrupt
INFO_LOG(WII_IPC, "IOP: Write32 to IPC_STATUS_REGISTER(0x30) = 0x%08x", _Value);
INFO_LOG(WII_IPC, "IOP: Write32, IPC_STATUS_REGISTER(0x30) = 0x%08x", _Value);
}
break;
case IPC_CONFIG_REGISTER: // __OSInterruptInit (0x40000000)
{
INFO_LOG(WII_IPC, "IOP: Write32 to IPC_CONFIG_REGISTER(0x33) = 0x%08x", _Value);
INFO_LOG(WII_IPC, "IOP: Write32, IPC_CONFIG_REGISTER(0x33) = 0x%08x", _Value);
g_IPC_Config.Hex = _Value;
if (_Value&0x40000000)
{
WII_IPC_HLE_Interface::Reset();
}
if (_Value&0x40000000)
{
INFO_LOG(WII_IPC, "Reset triggered, Resetting ...");
Reset();
WII_IPC_HLE_Interface::Reset();
}
}
break;
@ -217,11 +234,58 @@ void Write32(const u32 _Value, const u32 _Address)
}
break;
}
// update the interrupts
UpdateInterrupts();
}
u32 GetAddress()
{
return ((g_ExeCmd) ? g_Address : NULL);
}
void GenerateAck()
{
g_ExeCmd = false;
g_IPC_Control.AckReady = 1;
UpdateInterrupts();
}
void GenerateReply(u32 _Address)
{
g_Reply = _Address;
g_IPC_Control.ReplyReady = 1;
UpdateInterrupts();
}
void EnqReply(u32 _Address)
{
// AyuanX: Replies are stored in a FIFO (depth 2), like ping-pong, and 2 is fairly enough
// Simple structure of fixed length will do good for DoState
//
if (g_ReplyHead == NULL)
{
g_ReplyHead = g_ReplyTail;
g_ReplyTail = _Address;
}
else
{
ERROR_LOG(WII_IPC, "Reply FIFO is full, something must be wrong!");
PanicAlert("WII_IPC: Reply FIFO is full, something must be wrong!");
}
}
u32 DeqReply()
{
u32 _Address = (g_ReplyHead) ? g_ReplyHead : g_ReplyTail;
if (g_ReplyHead)
g_ReplyHead = NULL;
else
g_ReplyTail = NULL;
return _Address;
}
void UpdateInterrupts()
{
if ((g_IPC_Control.AckReady == 1) ||
@ -246,22 +310,6 @@ bool IsReady()
return ((g_IPC_Control.ReplyReady == 0) && (g_IPC_Control.AckReady == 0) && (g_IPC_Status.INTERRUPT == 0));
}
void GenerateAck(u32 _AnswerAddress)
{
g_Reply = _AnswerAddress;
g_IPC_Control.AckReady = 1;
UpdateInterrupts();
}
void GenerateReply(u32 _AnswerAddress)
{
g_Reply = _AnswerAddress;
g_IPC_Control.ReplyReady = 1;
UpdateInterrupts();
}
} // end of namespace IPC

View File

@ -24,18 +24,23 @@ namespace WII_IPCInterface
{
void Init();
void Reset();
void Shutdown();
void DoState(PointerWrap &p);
void Update();
bool IsReady();
void GenerateReply(u32 _AnswerAddress);
void GenerateAck(u32 _AnswerAddress);
void Read32(u32& _rReturnValue, const u32 _Address);
void Write32(const u32 _Value, const u32 _Address);
u32 GetAddress();
void GenerateAck();
void GenerateReply(u32 _Address);
void InsertReply(u32 _Address);
void EnqReply(u32 _Address);
u32 DeqReply();
void UpdateInterrupts();
bool IsReady();
} // end of namespace AudioInterface
#endif

View File

@ -66,6 +66,7 @@
#include "../Debugger/Debugger_SymbolMap.h"
#include "../PowerPC/PowerPC.h"
namespace WII_IPC_HLE_Interface
{
@ -74,11 +75,6 @@ TDeviceMap g_DeviceMap;
// STATE_TO_SAVE
u32 g_LastDeviceID = 0x13370000;
std::list<u32> g_Ack;
u32 g_AckNumber = 0;
std::queue<std::pair<u32,std::string> > g_ReplyQueue;
void ExecuteCommand(u32 _Address);
std::string g_DefaultContentFile;
// General IPC functions
@ -89,27 +85,22 @@ void Init()
void Reset()
{
// AyuanX: We really should save this to state or build the map and devices statically
// Mem dynamic allocation is too risky when doing state save/load
TDeviceMap::const_iterator itr = g_DeviceMap.begin();
while (itr != g_DeviceMap.end())
{
delete itr->second;
++itr;
if (itr->second)
delete itr->second;
++itr;
}
g_DeviceMap.clear();
while (!g_ReplyQueue.empty())
{
g_ReplyQueue.pop();
}
g_Ack.clear();
}
void Shutdown()
{
Reset();
g_LastDeviceID = 0x13370000;
g_AckNumber = 0;
g_DefaultContentFile.clear();
}
@ -237,31 +228,7 @@ IWII_IPC_HLE_Device* CreateDevice(u32 _DeviceID, const std::string& _rDeviceName
debugging I also noticed that the Ioctl arguments are stored temporarily in
0x933e.... with the same .... as in the _CommandAddress. */
// ----------------
bool AckCommand(u32 _Address)
{
#if MAX_LOG_LEVEL >= DEBUG_LEVEL
Debugger::PrintCallstack(LogTypes::WII_IPC_HLE, LogTypes::LDEBUG);
#endif
INFO_LOG(WII_IPC_HLE, "AckCommand: 0%08x (num: %i) PC=0x%08x", _Address, g_AckNumber, PC);
std::list<u32>::iterator itr = g_Ack.begin();
while (itr != g_Ack.end())
{
if (*itr == _Address)
{
ERROR_LOG(WII_IPC_HLE, "execute a command two times");
PanicAlert("execute a command two times");
return false;
}
itr++;
}
g_Ack.push_back(_Address);
g_AckNumber++;
return true;
}
// Let the game read the setting.txt file
void CopySettingsFile(std::string DeviceName)
@ -289,12 +256,30 @@ void CopySettingsFile(std::string DeviceName)
}
}
void DoState(PointerWrap &p)
{
p.Do(g_LastDeviceID);
//p.Do(g_DefaultContentFile);
// AyuanX: I think maybe we really should create devices statically at initilization
IWII_IPC_HLE_Device* pDevice = AccessDeviceByID(GetDeviceIDByName(std::string("/dev/usb/oh1/57e/305")));
if (pDevice)
pDevice->DoState(p);
else
PanicAlert("WII_IPC_HLE: Save/Load State failed, /dev/usb/oh1/57e/305 doesn't exist!");
}
void ExecuteCommand(u32 _Address)
{
bool GenerateReply = false;
bool CmdSuccess = false;
u32 ClosedDeviceID = 0;
ECommandType Command = static_cast<ECommandType>(Memory::Read_U32(_Address));
u32 DeviceID = Memory::Read_U32(_Address + 8);
IWII_IPC_HLE_Device* pDevice = AccessDeviceByID(DeviceID);
INFO_LOG(WII_IPC_HLE, "-->> Execute Command Address: 0x%08x (code: %x, device: %x) ", _Address, Command, DeviceID);
switch (Command)
{
case COMMAND_OPEN_DEVICE:
@ -308,7 +293,7 @@ void ExecuteCommand(u32 _Address)
if(DeviceName.find("setting.txt") != std::string::npos) CopySettingsFile(DeviceName);
u32 Mode = Memory::Read_U32(_Address + 0x10);
u32 DeviceID = GetDeviceIDByName(DeviceName);
DeviceID = GetDeviceIDByName(DeviceName);
// check if a device with this name has been created already
if (DeviceID == 0)
@ -317,16 +302,16 @@ void ExecuteCommand(u32 _Address)
// alternatively we could pre create all devices and put them in a directory tree structure
// then this would just return a pointer to the wanted device.
u32 CurrentDeviceID = g_LastDeviceID;
IWII_IPC_HLE_Device* pDevice = CreateDevice(CurrentDeviceID, DeviceName);
pDevice = CreateDevice(CurrentDeviceID, DeviceName);
g_DeviceMap[CurrentDeviceID] = pDevice;
g_LastDeviceID++;
GenerateReply = pDevice->Open(_Address, Mode);
CmdSuccess = pDevice->Open(_Address, Mode);
if(pDevice->GetDeviceName().find("/dev/") == std::string::npos
|| pDevice->GetDeviceName().c_str() == std::string("/dev/fs"))
{
INFO_LOG(WII_IPC_FILEIO, "IOP: Open (Device=%s, DeviceID=%08x, Mode=%i, GenerateReply=%i)",
pDevice->GetDeviceName().c_str(), CurrentDeviceID, Mode, (int)GenerateReply);
INFO_LOG(WII_IPC_FILEIO, "IOP: Open (Device=%s, DeviceID=%08x, Mode=%i, CmdSuccess=%i)",
pDevice->GetDeviceName().c_str(), CurrentDeviceID, Mode, (int)CmdSuccess);
}
else
{
@ -337,13 +322,13 @@ void ExecuteCommand(u32 _Address)
else
{
// The device has already been opened and was not closed, reuse the same DeviceID.
pDevice = AccessDeviceByID(DeviceID);
IWII_IPC_HLE_Device* pDevice = AccessDeviceByID(DeviceID);
// If we return -6 here after a Open > Failed > CREATE_FILE > ReOpen call
// If we return -6 here after a Open > Failed > CREATE_FILE > ReOpen call
// sequence Mario Galaxy and Mario Kart Wii will not start writing to the file,
// it will just (seemingly) wait for one or two seconds and then give an error
// message. So I'm trying to return the DeviceID instead to make it write to the file.
// (Which was most likely the reason it created the file in the first place.) */
// (Which was most likely the reason it created the file in the first place.)
// F|RES: prolly the re-open is just a mode change
@ -359,81 +344,69 @@ void ExecuteCommand(u32 _Address)
// Open > Failed > ... other stuff > ReOpen call sequence, in that case
// we have no file and no file handle, so we call Open again to basically
// get a -106 error so that the game call CreateFile and then ReOpen again.
if(pDevice->ReturnFileHandle())
Memory::Write_U32(DeviceID, _Address + 4);
else
GenerateReply = pDevice->Open(_Address, newMode);
pDevice->Open(_Address, newMode);
}
else
{
// We have already opened this device, return -6
Memory::Write_U32(u32(-6), _Address + 4);
}
GenerateReply = true;
}
CmdSuccess = true;
}
}
break;
case COMMAND_CLOSE_DEVICE:
{
u32 DeviceID = Memory::Read_U32(_Address + 8);
IWII_IPC_HLE_Device* pDevice = AccessDeviceByID(DeviceID);
{
if (pDevice != NULL)
{
pDevice->Close(_Address);
// Delete the device when CLOSE is called, this does not effect
// GenerateReply() for any other purpose than the logging because
// it's a true / false only function //
// it's a true / false only function
ClosedDeviceID = DeviceID;
GenerateReply = true;
CmdSuccess = true;
}
}
break;
case COMMAND_READ:
{
u32 DeviceID = Memory::Read_U32(_Address+8);
IWII_IPC_HLE_Device* pDevice = AccessDeviceByID(DeviceID);
if (pDevice != NULL)
GenerateReply = pDevice->Read(_Address);
CmdSuccess = pDevice->Read(_Address);
}
break;
case COMMAND_WRITE:
{
u32 DeviceID = Memory::Read_U32(_Address+8);
IWII_IPC_HLE_Device* pDevice = AccessDeviceByID(DeviceID);
if (pDevice != NULL)
GenerateReply = pDevice->Write(_Address);
CmdSuccess = pDevice->Write(_Address);
}
break;
case COMMAND_SEEK:
{
u32 DeviceID = Memory::Read_U32(_Address+8);
IWII_IPC_HLE_Device* pDevice = AccessDeviceByID(DeviceID);
if (pDevice != NULL)
GenerateReply = pDevice->Seek(_Address);
CmdSuccess = pDevice->Seek(_Address);
}
break;
case COMMAND_IOCTL:
{
u32 DeviceID = Memory::Read_U32(_Address+8);
IWII_IPC_HLE_Device* pDevice = AccessDeviceByID(DeviceID);
if (pDevice != NULL)
GenerateReply = pDevice->IOCtl(_Address);
CmdSuccess = pDevice->IOCtl(_Address);
}
break;
case COMMAND_IOCTLV:
{
u32 DeviceID = Memory::Read_U32(_Address+8);
IWII_IPC_HLE_Device* pDevice = AccessDeviceByID(DeviceID);
if (pDevice)
GenerateReply = pDevice->IOCtlV(_Address);
CmdSuccess = pDevice->IOCtlV(_Address);
}
break;
@ -443,88 +416,101 @@ void ExecuteCommand(u32 _Address)
break;
}
// It seems that the original hardware overwrites the command after it has been
// executed. We write 8 which is not any valid command.
Memory::Write_U32(8, _Address);
//
// AyuanX: Is this really necessary?
// My experiment says no, so I'm just commenting this out
//
//Memory::Write_U32(8, _Address);
// Generate a reply to the IPC command
if (GenerateReply)
if (CmdSuccess)
{
// Get device id
// Generate a reply to the IPC command
WII_IPCInterface::EnqReply(_Address);
u32 DeviceID = Memory::Read_U32(_Address + 8);
IWII_IPC_HLE_Device* pDevice = NULL;
// Get the device from the device map
if (DeviceID != 0) {
if (g_DeviceMap.find(DeviceID) != g_DeviceMap.end())
pDevice = g_DeviceMap[DeviceID];
if (pDevice != NULL) {
// Write reply, this will later be executed in Update()
g_ReplyQueue.push(std::pair<u32, std::string>(_Address, pDevice->GetDeviceName()));
} else {
// DeviceID == 0 means it's used for devices that weren't created yet
if (DeviceID != 0)
{
if (g_DeviceMap.find(DeviceID) == g_DeviceMap.end())
ERROR_LOG(WII_IPC_HLE, "IOP: Reply to unknown device ID (DeviceID=%i)", DeviceID);
g_ReplyQueue.push(std::pair<u32, std::string>(_Address, "unknown"));
}
if (ClosedDeviceID > 0 && ClosedDeviceID == DeviceID)
if (ClosedDeviceID > 0 && (ClosedDeviceID == DeviceID))
DeleteDeviceByID(DeviceID);
} else {
// 0 is ok, as it's used for devices that weren't created yet
g_ReplyQueue.push(std::pair<u32, std::string>(_Address, "unknown"));
}
}
else
{
//INFO_LOG(WII_IPC_HLE, "<<-- Failed or Not Ready to Reply to Command Address: 0x%08x ", _Address);
}
}
// ===================================================
/* This is called continuously from SystemTimers.cpp and WII_IPCInterface::IsReady()
is controlled from WII_IPC.cpp. */
// ----------------
void UpdateDevices()
{
if (WII_IPCInterface::IsReady())
{
// check if an executed must be updated
TDeviceMap::const_iterator itr = g_DeviceMap.begin();
while(itr != g_DeviceMap.end())
{
u32 CommandAddr = itr->second->Update();
if (CommandAddr != 0)
{
g_ReplyQueue.push(std::pair<u32, std::string>(CommandAddr, itr->second->GetDeviceName()));
}
++itr;
}
}
}
// This is called continuously from SystemTimers.cpp
// ---------------------------------------------------
void Update()
{
if (WII_IPCInterface::IsReady())
if (WII_IPCInterface::IsReady() == false)
return;
UpdateDevices();
// if we have a reply to send
u32 _Reply = WII_IPCInterface::DeqReply();
if (_Reply != NULL)
{
// Check if we have to execute an acknowledge command...
if (!g_ReplyQueue.empty())
{
WII_IPCInterface::GenerateReply(g_ReplyQueue.front().first);
g_ReplyQueue.pop();
return;
}
WII_IPCInterface::GenerateReply(_Reply);
INFO_LOG(WII_IPC_HLE, "<<-- Reply to Command Address: 0x%08x", _Reply);
return;
}
// ...no we don't, we can now execute the IPC command
if (g_ReplyQueue.empty() && !g_Ack.empty())
{
u32 _Address = g_Ack.front();
g_Ack.pop_front();
DEBUG_LOG(WII_IPC_HLE, "-- Execute Ack (0x%08x)", _Address);
ExecuteCommand(_Address);
DEBUG_LOG(WII_IPC_HLE, "-- End of ExecuteAck (0x%08x)", _Address);
// If there is a a new command
u32 _Address = WII_IPCInterface::GetAddress();
if (_Address != NULL)
{
WII_IPCInterface::GenerateAck();
INFO_LOG(WII_IPC_HLE, "||-- Acknowledge Command Address: 0x%08x", _Address);
// Go back to WII_IPC.cpp and generate an acknowledgement
WII_IPCInterface::GenerateAck(_Address);
}
ExecuteCommand(_Address);
// AyuanX: Since current HLE time slot is empty, we can piggyback a reply
// Besides, this trick makes a Ping-Pong Reply FIFO never get full
// I don't know whether original hardware supports this feature or not
// but it works here and we gain 1/3 extra bandwidth
//
u32 _Reply = WII_IPCInterface::DeqReply();
if (_Reply != NULL)
{
WII_IPCInterface::GenerateReply(_Reply);
INFO_LOG(WII_IPC_HLE, "<<-- Reply to Command Address: 0x%08x", _Reply);
}
#if MAX_LOG_LEVEL >= DEBUG_LEVEL
Debugger::PrintCallstack(LogTypes::WII_IPC_HLE, LogTypes::LDEBUG);
#endif
return;
}
}
void UpdateDevices()
{
// check if a device must be updated
TDeviceMap::const_iterator itr = g_DeviceMap.begin();
while(itr != g_DeviceMap.end())
{
if (itr->second->Update())
{
break;
}
++itr;
}
}
} // end of namespace IPC

View File

@ -18,9 +18,10 @@
#ifndef _WII_IPC_HLE_H_
#define _WII_IPC_HLE_H_
#include "ChunkFile.h"
namespace WII_IPC_HLE_Interface
{
// Init
void Init();
@ -30,6 +31,9 @@ void Shutdown();
// Reset
void Reset();
// Do State
void DoState(PointerWrap &p);
// Set default content file
void SetDefaultContentFile(const std::string& _rFilename);
@ -39,8 +43,7 @@ void Update();
// Update Devices
void UpdateDevices();
// Acknowledge command
bool AckCommand(u32 _Address);
void ExecuteCommand(u32 _Address);
enum ECommandType
{

View File

@ -22,6 +22,8 @@
#include "../HW/Memmap.h"
#include "../HW/CPU.h"
class PointerWrap;
class IWII_IPC_HLE_Device
{
public:
@ -34,6 +36,9 @@ public:
virtual ~IWII_IPC_HLE_Device()
{}
virtual void DoState(PointerWrap &p)
{}
const std::string& GetDeviceName() const { return m_Name; }
u32 GetDeviceID() const { return m_DeviceID; }
@ -114,14 +119,12 @@ protected:
}
}
// STATE_TO_SAVE
const u32 m_Address;
u32 Parameter;
u32 NumberInBuffer;
u32 NumberPayloadBuffer;
u32 BufferVector;
u32 BufferSize;
struct SBuffer { u32 m_Address, m_Size; };
std::vector<SBuffer> InBuffer;
@ -152,9 +155,8 @@ protected:
LogTypes::LOG_LEVELS Verbosity = LogTypes::LDEBUG)
{
GENERIC_LOG(LogType, Verbosity, "======= DumpAsync ======");
// write return value
u32 BufferOffset = BufferVector;
Memory::Write_U32(1, _CommandAddress + 0x4);
for (u32 i = 0; i < NumberInBuffer; i++)
{
@ -180,8 +182,6 @@ protected:
u32 OutBuffer = Memory::Read_U32(BufferOffset); BufferOffset += 4;
u32 OutBufferSize = Memory::Read_U32(BufferOffset); BufferOffset += 4;
Memory::Write_U32(1, _CommandAddress + 0x4);
GENERIC_LOG(LogType, LogTypes::LINFO, "%s - IOCtlV OutBuffer[%i]:", GetDeviceName().c_str(), i);
GENERIC_LOG(LogType, LogTypes::LINFO, " OutBuffer: 0x%08x (0x%x):", OutBuffer, OutBufferSize);

File diff suppressed because it is too large Load Diff

View File

@ -18,11 +18,11 @@
#ifndef _WII_IPC_HLE_DEVICE_USB_H_
#define _WII_IPC_HLE_DEVICE_USB_H_
#include "WII_IPC_HLE_Device.h"
#include "hci.h"
#include <vector>
#include <queue>
#include "WII_IPC_HLE.h"
#include "WII_IPC_HLE_Device.h"
#include "WII_IPC_HLE_WiiMote.h"
@ -38,13 +38,6 @@ union UACLHeader
u32 Hex;
};
struct ACLFrame
{
u16 ConnectionHandle;
u8* data;
u32 size;
};
struct SQueuedEvent
{
u8 m_buffer[1024];
@ -58,7 +51,7 @@ struct SQueuedEvent
if (m_size > 1024)
{
// i know this code sux...
PanicAlert("SQueuedEvent: allocate a to big buffer!!");
PanicAlert("SQueuedEvent: allocate too big buffer!!");
}
}
};
@ -79,7 +72,8 @@ public:
virtual u32 Update();
void SendACLFrame(u16 _ConnectionHandle, u8* _pData, u32 _Size);
void SendACLPacket(u16 _ConnectionHandle, u8* _pData, u32 _Size);
void PurgeACLFrame();
//hack for wiimote plugin
@ -89,6 +83,8 @@ public:
CWII_IPC_HLE_WiiMote* AccessWiiMote(const bdaddr_t& _rAddr);
CWII_IPC_HLE_WiiMote* AccessWiiMote(u16 _ConnectionHandle);
void DoState(PointerWrap &p);
private:
enum
@ -106,7 +102,7 @@ private:
enum
{
HCI_EVENT_ENDPOINT = 0x81,
ACL_DATA_ENDPOINT_READ = 0x02,
ACL_DATA_BLK_OUT = 0x02,
ACL_DATA_ENDPOINT = 0x82,
};
@ -121,6 +117,39 @@ private:
u32 m_PayLoadAddr;
u32 m_PayLoadSize;
u32 m_Address;
};
struct ACLFrame
{
u32 m_number;
u8 m_data[1024];
ACLFrame(int num)
: m_number(num)
{
}
};
struct CtrlBuffer
{
u32 m_address;
u32 m_buffer;
CtrlBuffer(u32 _Address)
: m_address(_Address)
{
if(_Address == NULL)
{
m_buffer = NULL;
}
else
{
u32 _BufferVector = Memory::Read_U32(_Address + 0x18);
u32 _InBufferNum = Memory::Read_U32(_Address + 0x10);
m_buffer = Memory::Read_U32(_BufferVector + _InBufferNum * 8);
}
}
};
bdaddr_t m_ControllerBD;
@ -138,13 +167,14 @@ private:
u16 m_HostNumSCOPackets;
typedef std::queue<SQueuedEvent> CEventQueue;
typedef std::queue<ACLFrame> CACLFrameQueue;
CEventQueue m_EventQueue;
CACLFrameQueue m_AclFrameQue;
SIOCtlVBuffer* m_pACLBuffer;
SIOCtlVBuffer* m_pHCIBuffer;
// STATE_TO_SAVE
SHCICommandMessage m_CtrlSetup;
CtrlBuffer m_HCIBuffer;
CtrlBuffer m_ACLBuffer;
ACLFrame m_ACLFrame;
u32 m_LastCmd;
int m_PacketCount;
// Events
void AddEventToQueue(const SQueuedEvent& _event);

View File

@ -33,6 +33,7 @@ static CWII_IPC_HLE_Device_usb_oh1_57e_305* s_Usb;
CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number)
: m_Connected(false)
, m_Linked(false)
, m_HIDControlChannel_Connected(false)
, m_HIDControlChannel_ConnectedWait(false)
, m_HIDControlChannel_Config(false)
@ -47,7 +48,7 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305*
{
s_Usb = _pHost;
INFO_LOG(WII_IPC_WIIMOTE, "Wiimote %i constructed", _Number);
INFO_LOG(WII_IPC_WIIMOTE, "Wiimote #%i constructed", _Number);
m_BD.b[0] = 0x11;
m_BD.b[1] = 0x02;
@ -89,25 +90,24 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305*
//
//
bool CWII_IPC_HLE_WiiMote::Update()
bool CWII_IPC_HLE_WiiMote::LinkChannel()
{
if (m_Connected == false)
if ((m_Connected == false) || (m_Linked == true))
return false;
// try to connect HIDP_CONTROL_CHANNEL
// try to connect HID_CONTROL_CHANNEL
if (!m_HIDControlChannel_Connected)
{
if (m_HIDControlChannel_ConnectedWait)
return false;
m_HIDControlChannel_ConnectedWait = true;
SendConnectionRequest(0x0040, HIDP_CONTROL_CHANNEL);
// The CID is fixed, other CID will be rejected
SendConnectionRequest(0x0040, HID_CONTROL_CHANNEL);
return true;
}
// try to config HIDP_CONTROL_CHANNEL
// try to config HID_CONTROL_CHANNEL
if (!m_HIDControlChannel_Config)
{
if (m_HIDControlChannel_ConfigWait)
@ -127,6 +127,7 @@ bool CWII_IPC_HLE_WiiMote::Update()
return false;
m_HIDInterruptChannel_ConnectedWait = true;
// The CID is fixed, other CID will be rejected
SendConnectionRequest(0x0041, HID_INTERRUPT_CHANNEL);
return true;
}
@ -144,11 +145,75 @@ bool CWII_IPC_HLE_WiiMote::Update()
return true;
}
m_Linked = true;
UpdateStatus();
return false;
}
// ===================================================
/* Send a status report to the status bar. */
// ----------------
void CWII_IPC_HLE_WiiMote::ShowStatus(const void* _pData)
{
// Check if it's enabled
SCoreStartupParameter& StartUp = SConfig::GetInstance().m_LocalCoreStartupParameter;
bool LedsOn = StartUp.bWiiLeds;
bool SpeakersOn = StartUp.bWiiSpeakers;
const u8* data = (const u8*)_pData;
// Get the last four bits with LED info
if (LedsOn)
{
if (data[1] == 0x11)
{
int led_bits = (data[2] >> 4);
Host_UpdateLeds(led_bits);
}
}
int speaker_bits = 0;
if (SpeakersOn)
{
u8 Bits = 0;
switch (data[1])
{
case 0x14: // Enable and disable speakers
if (data[2] == 0x02) // Off
Bits = 0;
else if (data[2] == 0x06) // On
Bits = 1;
Host_UpdateSpeakerStatus(0, Bits);
break;
case 0x19: // Mute and unmute
// Get the value
if (data[2] == 0x02) // Unmute
Bits = 1;
else if (data[2] == 0x06) // Mute
Bits = 0;
Host_UpdateSpeakerStatus(1, Bits);
break;
// Write to speaker registry, or write sound
case 0x16:
case 0x18:
// Turn on the activity light
Host_UpdateSpeakerStatus(2, 1);
break;
}
}
}
// Turn off the activity icon again
void CWII_IPC_HLE_WiiMote::UpdateStatus()
{
// Check if it's enabled
if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bWiiSpeakers)
return;
Host_UpdateStatus();
}
//
//
@ -165,11 +230,13 @@ bool CWII_IPC_HLE_WiiMote::Update()
void CWII_IPC_HLE_WiiMote::EventConnectionAccepted()
{
m_Connected = true;
m_Linked = false;
}
void CWII_IPC_HLE_WiiMote::EventDisconnect()
{
m_Connected = false;
m_Linked = false;
}
bool CWII_IPC_HLE_WiiMote::EventPagingChanged(u8 _pageMode)
@ -210,22 +277,20 @@ void CWII_IPC_HLE_WiiMote::EventCommandWriteLinkPolicy()
//
// ===================================================
/* This function send ACL frams from the Wii to Wiimote_ControlChannel() in the Wiimote.
It's called from SendToDevice() in WII_IPC_HLE_Device_usb.cpp. */
// ----------------
void CWII_IPC_HLE_WiiMote::SendACLFrame(u8* _pData, u32 _Size)
// This function receives L2CAP commands from the CPU
// It's called from SendToDevice() in WII_IPC_HLE_Device_usb.cpp.
// ---------------------------------------------------
void CWII_IPC_HLE_WiiMote::ExecuteL2capCmd(u8* _pData, u32 _Size)
{
// Debugger::PrintDataBuffer(LogTypes::WIIMOTE, _pData, _Size, "SendACLFrame: ");
// Debugger::PrintDataBuffer(LogTypes::WIIMOTE, _pData, _Size, "SendACLPacket: ");
// parse the command
SL2CAP_Header* pHeader = (SL2CAP_Header*)_pData;
u8* pData = _pData + sizeof(SL2CAP_Header);
u32 DataSize = _Size - sizeof(SL2CAP_Header);
INFO_LOG(WII_IPC_WIIMOTE, "L2Cap-SendFrame: Channel 0x%04x, Len 0x%x, DataSize 0x%x",
pHeader->CID, pHeader->Length, DataSize);
INFO_LOG(WII_IPC_WIIMOTE, "++++++++++++++++++++++++++++++++++++++");
INFO_LOG(WII_IPC_WIIMOTE, "Execute L2CAP Command: Cid 0x%04x, Len 0x%x, DataSize 0x%x", pHeader->CID, pHeader->Length, DataSize);
if(pHeader->Length != DataSize)
{
@ -241,8 +306,9 @@ void CWII_IPC_HLE_WiiMote::SendACLFrame(u8* _pData, u32 _Size)
default:
{
_dbg_assert_msg_(WII_IPC_WIIMOTE, DoesChannelExist(pHeader->CID), "SendACLFrame to unknown channel %i", pHeader->CID);
_dbg_assert_msg_(WII_IPC_WIIMOTE, DoesChannelExist(pHeader->CID), "L2CAP: SendACLPacket to unknown channel %i", pHeader->CID);
CChannelMap::iterator itr= m_Channel.find(pHeader->CID);
Common::PluginWiimote* mote = CPluginManager::GetInstance().GetWiimote(0);
if (itr != m_Channel.end())
{
@ -253,13 +319,15 @@ void CWII_IPC_HLE_WiiMote::SendACLFrame(u8* _pData, u32 _Size)
HandleSDP(pHeader->CID, pData, DataSize);
break;
case HIDP_CONTROL_CHANNEL:
case HID_CONTROL_CHANNEL:
mote->Wiimote_ControlChannel(rChannel.DCID, pData, DataSize);
// Call Wiimote Plugin
break;
case HID_INTERRUPT_CHANNEL:
ShowStatus(pData);
mote->Wiimote_InterruptChannel(rChannel.DCID, pData, DataSize);
// Call Wiimote Plugin
break;
default:
@ -272,72 +340,6 @@ void CWII_IPC_HLE_WiiMote::SendACLFrame(u8* _pData, u32 _Size)
break;
}
}
// ===================================================
/* Send a status report to the status bar. */
// ----------------
void CWII_IPC_HLE_WiiMote::ShowStatus(const void* _pData)
{
// Check if it's enabled
SCoreStartupParameter& StartUp = SConfig::GetInstance().m_LocalCoreStartupParameter;
bool LedsOn = StartUp.bWiiLeds;
bool SpeakersOn = StartUp.bWiiSpeakers;
const u8* data = (const u8*)_pData;
// Get the last four bits with LED info
if (LedsOn)
{
if (data[1] == 0x11)
{
int led_bits = (data[2] >> 4);
Host_UpdateLeds(led_bits);
}
}
int speaker_bits = 0;
if (SpeakersOn)
{
u8 Bits = 0;
switch (data[1])
{
case 0x14: // Enable and disable speakers
if (data[2] == 0x02) // Off
Bits = 0;
else if (data[2] == 0x06) // On
Bits = 1;
Host_UpdateSpeakerStatus(0, Bits);
break;
case 0x19: // Mute and unmute
// Get the value
if (data[2] == 0x02) // Unmute
Bits = 1;
else if (data[2] == 0x06) // Mute
Bits = 0;
Host_UpdateSpeakerStatus(1, Bits);
break;
// Write to speaker registry, or write sound
case 0x16:
case 0x18:
// Turn on the activity light
Host_UpdateSpeakerStatus(2, 1);
break;
}
}
}
// Turn off the activity icon again
void CWII_IPC_HLE_WiiMote::UpdateStatus()
{
// Check if it's enabled
if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bWiiSpeakers)
return;
Host_UpdateStatus();
}
// ================
void CWII_IPC_HLE_WiiMote::SignalChannel(u8* _pData, u32 _Size)
@ -350,34 +352,34 @@ void CWII_IPC_HLE_WiiMote::SignalChannel(u8* _pData, u32 _Size)
switch(pCommand->code)
{
case L2CAP_CONN_REQ:
CommandConnectionReq(pCommand->ident, _pData, pCommand->len);
case L2CAP_COMMAND_REJ:
ERROR_LOG(WII_IPC_WIIMOTE, "SignalChannel - L2CAP_COMMAND_REJ (something went wrong)."
"Try to replace your SYSCONF file with a new copy."
,pCommand->code);
PanicAlert(
"SignalChannel - L2CAP_COMMAND_REJ (something went wrong)."
"Try to replace your SYSCONF file with a new copy."
,pCommand->code);
break;
case L2CAP_CONF_REQ:
CommandCofigurationReq(pCommand->ident, _pData, pCommand->len);
case L2CAP_CONN_REQ:
ReceiveConnectionReq(pCommand->ident, _pData, pCommand->len);
break;
case L2CAP_CONN_RSP:
CommandConnectionResponse(pCommand->ident, _pData, pCommand->len);
ReceiveConnectionResponse(pCommand->ident, _pData, pCommand->len);
break;
case L2CAP_DISCONN_REQ:
CommandDisconnectionReq(pCommand->ident, _pData, pCommand->len);
case L2CAP_CONF_REQ:
ReceiveConfigurationReq(pCommand->ident, _pData, pCommand->len);
break;
case L2CAP_CONF_RSP:
CommandConfigurationResponse(pCommand->ident, _pData, pCommand->len);
ReceiveConfigurationResponse(pCommand->ident, _pData, pCommand->len);
break;
case L2CAP_COMMAND_REJ:
ERROR_LOG(WII_IPC_WIIMOTE, "SignalChannel - L2CAP_COMMAND_REJ (something went wrong). Try to replace your"
"SYSCONF file with a new copy."
,pCommand->code);
PanicAlert(
"SignalChannel - L2CAP_COMMAND_REJ (something went wrong). Try to replace your"
"SYSCONF file with a new copy."
,pCommand->code);
case L2CAP_DISCONN_REQ:
ReceiveDisconnectionReq(pCommand->ident, _pData, pCommand->len);
break;
default:
@ -390,21 +392,18 @@ void CWII_IPC_HLE_WiiMote::SignalChannel(u8* _pData, u32 _Size)
}
}
//
//
//
//
// --- Send Commands To Device
// --- Receive Commands from CPU
//
//
//
//
//
void CWII_IPC_HLE_WiiMote::CommandConnectionReq(u8 _Ident, u8* _pData, u32 _Size)
void CWII_IPC_HLE_WiiMote::ReceiveConnectionReq(u8 _Ident, u8* _pData, u32 _Size)
{
SL2CAP_CommandConnectionReq* pCommandConnectionReq = (SL2CAP_CommandConnectionReq*)_pData;
@ -414,7 +413,7 @@ void CWII_IPC_HLE_WiiMote::CommandConnectionReq(u8 _Ident, u8* _pData, u32 _Size
rChannel.SCID = pCommandConnectionReq->scid;
rChannel.DCID = pCommandConnectionReq->scid;
INFO_LOG(WII_IPC_WIIMOTE, " CommandConnectionReq");
INFO_LOG(WII_IPC_WIIMOTE, "[ACL] ReceiveConnectionRequest");
DEBUG_LOG(WII_IPC_WIIMOTE, " Ident: 0x%02x", _Ident);
DEBUG_LOG(WII_IPC_WIIMOTE, " PSM: 0x%04x", rChannel.PSM);
DEBUG_LOG(WII_IPC_WIIMOTE, " SCID: 0x%04x", rChannel.SCID);
@ -427,31 +426,58 @@ void CWII_IPC_HLE_WiiMote::CommandConnectionReq(u8 _Ident, u8* _pData, u32 _Size
Rsp.result = 0x00;
Rsp.status = 0x00;
INFO_LOG(WII_IPC_WIIMOTE, "[ACL] SendConnectionResponse");
SendCommandToACL(_Ident, L2CAP_CONN_RSP, sizeof(SL2CAP_ConnectionResponse), (u8*)&Rsp);
}
// update state machine
if (rChannel.PSM == HIDP_CONTROL_CHANNEL)
void CWII_IPC_HLE_WiiMote::ReceiveConnectionResponse(u8 _Ident, u8* _pData, u32 _Size)
{
l2cap_conn_rsp* rsp = (l2cap_conn_rsp*)_pData;
_dbg_assert_(WII_IPC_WIIMOTE, _Size == sizeof(l2cap_conn_rsp));
INFO_LOG(WII_IPC_WIIMOTE, "[ACL] ReceiveConnectionResponse");
DEBUG_LOG(WII_IPC_WIIMOTE, " DCID: 0x%04x", rsp->dcid);
DEBUG_LOG(WII_IPC_WIIMOTE, " SCID: 0x%04x", rsp->scid);
DEBUG_LOG(WII_IPC_WIIMOTE, " Result: 0x%04x", rsp->result);
DEBUG_LOG(WII_IPC_WIIMOTE, " Status: 0x%04x", rsp->status);
_dbg_assert_(WII_IPC_WIIMOTE, rsp->result == 0);
_dbg_assert_(WII_IPC_WIIMOTE, rsp->status == 0);
_dbg_assert_(WII_IPC_WIIMOTE, DoesChannelExist(rsp->scid));
SChannel& rChannel = m_Channel[rsp->scid];
rChannel.DCID = rsp->dcid;
//
// AyuanX: I'm commenting this out because CPU thinks he is faster than WiiMote
// and basically CPU will take the initiative to config channel
// in any case we don't want to race against CPU, or we are doomed
// so we wait for CPU to request first
//
/*
if (rChannel.PSM == HID_CONTROL_CHANNEL)
m_HIDControlChannel_Connected = true;
if (rChannel.PSM == HID_INTERRUPT_CHANNEL)
m_HIDInterruptChannel_Connected = true;
*/
}
void CWII_IPC_HLE_WiiMote::CommandCofigurationReq(u8 _Ident, u8* _pData, u32 _Size)
void CWII_IPC_HLE_WiiMote::ReceiveConfigurationReq(u8 _Ident, u8* _pData, u32 _Size)
{
INFO_LOG(WII_IPC_WIIMOTE, "*******************************************************");
u32 Offset = 0;
SL2CAP_CommandConfigurationReq* pCommandConfigReq = (SL2CAP_CommandConfigurationReq*)_pData;
_dbg_assert_(WII_IPC_WIIMOTE, pCommandConfigReq->flags == 0x00); // 1 means that the options are send in multi-packets
_dbg_assert_(WII_IPC_WIIMOTE, DoesChannelExist(pCommandConfigReq->dcid));
SChannel& rChannel = m_Channel[pCommandConfigReq->dcid];
INFO_LOG(WII_IPC_WIIMOTE, " CommandCofigurationReq");
INFO_LOG(WII_IPC_WIIMOTE, " Ident: 0x%02x", _Ident);
INFO_LOG(WII_IPC_WIIMOTE, " DCID: 0x%04x", pCommandConfigReq->dcid);
INFO_LOG(WII_IPC_WIIMOTE, " Flags: 0x%04x", pCommandConfigReq->flags);
INFO_LOG(WII_IPC_WIIMOTE, "[ACL] ReceiveConfigurationRequest");
DEBUG_LOG(WII_IPC_WIIMOTE, " Ident: 0x%02x", _Ident);
DEBUG_LOG(WII_IPC_WIIMOTE, " DCID: 0x%04x", pCommandConfigReq->dcid);
DEBUG_LOG(WII_IPC_WIIMOTE, " Flags: 0x%04x", pCommandConfigReq->flags);
Offset += sizeof(SL2CAP_CommandConfigurationReq);
@ -478,7 +504,11 @@ void CWII_IPC_HLE_WiiMote::CommandCofigurationReq(u8 _Ident, u8* _pData, u32 _Si
_dbg_assert_(WII_IPC_WIIMOTE, pOptions->length == 2);
SL2CAP_OptionsMTU* pMTU = (SL2CAP_OptionsMTU*)&_pData[Offset];
rChannel.MTU = pMTU->MTU;
INFO_LOG(WII_IPC_WIIMOTE, " Config MTU: 0x%04x", pMTU->MTU);
DEBUG_LOG(WII_IPC_WIIMOTE, " Config MTU: 0x%04x", pMTU->MTU);
// AyuanX: My experiment shows that the MTU is always set to 640 bytes
// This means that we only need temp_frame_size of 640B instead 1024B
// Actually I've never seen a frame bigger than 64B
// But... who cares of several KB mem today? Never mind
}
break;
@ -487,7 +517,7 @@ void CWII_IPC_HLE_WiiMote::CommandCofigurationReq(u8 _Ident, u8* _pData, u32 _Si
_dbg_assert_(WII_IPC_WIIMOTE, pOptions->length == 2);
SL2CAP_OptionsFlushTimeOut* pFlushTimeOut = (SL2CAP_OptionsFlushTimeOut*)&_pData[Offset];
rChannel.FlushTimeOut = pFlushTimeOut->TimeOut;
INFO_LOG(WII_IPC_WIIMOTE, " Config FlushTimeOut: 0x%04x", pFlushTimeOut->TimeOut);
DEBUG_LOG(WII_IPC_WIIMOTE, " Config FlushTimeOut: 0x%04x", pFlushTimeOut->TimeOut);
}
break;
@ -503,44 +533,25 @@ void CWII_IPC_HLE_WiiMote::CommandCofigurationReq(u8 _Ident, u8* _pData, u32 _Si
RespLen += OptionSize;
}
INFO_LOG(WII_IPC_WIIMOTE, "[ACL] SendConfigurationResponse");
SendCommandToACL(_Ident, L2CAP_CONF_RSP, RespLen, TempBuffer);
INFO_LOG(WII_IPC_WIIMOTE, "*******************************************************");
}
void CWII_IPC_HLE_WiiMote::CommandConnectionResponse(u8 _Ident, u8* _pData, u32 _Size)
{
l2cap_conn_rsp* rsp = (l2cap_conn_rsp*)_pData;
_dbg_assert_(WII_IPC_WIIMOTE, _Size == sizeof(l2cap_conn_rsp));
INFO_LOG(WII_IPC_WIIMOTE, " CommandConnectionResponse");
DEBUG_LOG(WII_IPC_WIIMOTE, " DCID: 0x%04x", rsp->dcid);
DEBUG_LOG(WII_IPC_WIIMOTE, " SCID: 0x%04x", rsp->scid);
DEBUG_LOG(WII_IPC_WIIMOTE, " Result: 0x%04x", rsp->result);
DEBUG_LOG(WII_IPC_WIIMOTE, " Status: 0x%04x", rsp->status);
_dbg_assert_(WII_IPC_WIIMOTE, rsp->result == 0);
_dbg_assert_(WII_IPC_WIIMOTE, rsp->status == 0);
_dbg_assert_(WII_IPC_WIIMOTE, DoesChannelExist(rsp->scid));
SChannel& rChannel = m_Channel[rsp->scid];
rChannel.DCID = rsp->dcid;
// update state machine
if (rChannel.PSM == HIDP_CONTROL_CHANNEL)
if (rChannel.PSM == HID_CONTROL_CHANNEL)
m_HIDControlChannel_Connected = true;
if (rChannel.PSM == HID_INTERRUPT_CHANNEL)
m_HIDInterruptChannel_Connected = true;
}
void CWII_IPC_HLE_WiiMote::CommandConfigurationResponse(u8 _Ident, u8* _pData, u32 _Size)
void CWII_IPC_HLE_WiiMote::ReceiveConfigurationResponse(u8 _Ident, u8* _pData, u32 _Size)
{
l2cap_conf_rsp* rsp = (l2cap_conf_rsp*)_pData;
_dbg_assert_(WII_IPC_WIIMOTE, _Size == sizeof(l2cap_conf_rsp));
INFO_LOG(WII_IPC_WIIMOTE, " CommandConfigurationResponse");
INFO_LOG(WII_IPC_WIIMOTE, "[ACL] ReceiveConfigurationResponse");
DEBUG_LOG(WII_IPC_WIIMOTE, " SCID: 0x%04x", rsp->scid);
DEBUG_LOG(WII_IPC_WIIMOTE, " Flags: 0x%04x", rsp->flags);
DEBUG_LOG(WII_IPC_WIIMOTE, " Result: 0x%04x", rsp->result);
@ -549,21 +560,22 @@ void CWII_IPC_HLE_WiiMote::CommandConfigurationResponse(u8 _Ident, u8* _pData, u
// update state machine
SChannel& rChannel = m_Channel[rsp->scid];
if (rChannel.PSM == HIDP_CONTROL_CHANNEL)
if (rChannel.PSM == HID_CONTROL_CHANNEL)
m_HIDControlChannel_Config = true;
if (rChannel.PSM == HID_INTERRUPT_CHANNEL)
m_HIDInterruptChannel_Config = true;
}
void CWII_IPC_HLE_WiiMote::CommandDisconnectionReq(u8 _Ident, u8* _pData, u32 _Size)
void CWII_IPC_HLE_WiiMote::ReceiveDisconnectionReq(u8 _Ident, u8* _pData, u32 _Size)
{
SL2CAP_CommandDisconnectionReq* pCommandDisconnectionReq = (SL2CAP_CommandDisconnectionReq*)_pData;
// create the channel
_dbg_assert_(WII_IPC_WIIMOTE, m_Channel.find(pCommandDisconnectionReq->scid) != m_Channel.end());
INFO_LOG(WII_IPC_WIIMOTE, " CommandDisconnectionReq");
INFO_LOG(WII_IPC_WIIMOTE, "[ACL] ReceiveDisconnectionReq");
DEBUG_LOG(WII_IPC_WIIMOTE, " Ident: 0x%02x", _Ident);
DEBUG_LOG(WII_IPC_WIIMOTE, " SCID: 0x%04x", pCommandDisconnectionReq->dcid);
DEBUG_LOG(WII_IPC_WIIMOTE, " DCID: 0x%04x", pCommandDisconnectionReq->scid);
@ -573,23 +585,22 @@ void CWII_IPC_HLE_WiiMote::CommandDisconnectionReq(u8 _Ident, u8* _pData, u32 _S
Rsp.scid = pCommandDisconnectionReq->scid;
Rsp.dcid = pCommandDisconnectionReq->dcid;
INFO_LOG(WII_IPC_WIIMOTE, "[ACL] SendDisconnectionResponse");
SendCommandToACL(_Ident, L2CAP_DISCONN_RSP, sizeof(SL2CAP_CommandDisconnectionResponse), (u8*)&Rsp);
}
//
//
//
//
// --- Send Commands To Device
// --- Send Commands To CPU
//
//
//
//
//
// We assume WiiMote is always connected
void CWII_IPC_HLE_WiiMote::SendConnectionRequest(u16 scid, u16 psm)
{
// create the channel
@ -601,13 +612,14 @@ void CWII_IPC_HLE_WiiMote::SendConnectionRequest(u16 scid, u16 psm)
cr.psm = psm;
cr.scid = scid;
INFO_LOG(WII_IPC_WIIMOTE, " SendConnectionRequest()");
INFO_LOG(WII_IPC_WIIMOTE, "[ACL] SendConnectionRequest");
DEBUG_LOG(WII_IPC_WIIMOTE, " Psm: 0x%04x", cr.psm);
DEBUG_LOG(WII_IPC_WIIMOTE, " Scid: 0x%04x", cr.scid);
SendCommandToACL(L2CAP_CONN_REQ, L2CAP_CONN_REQ, sizeof(l2cap_conn_req), (u8*)&cr);
}
// We don't initiatively disconnet Wiimote though ...
void CWII_IPC_HLE_WiiMote::SendDisconnectRequest(u16 scid)
{
// create the channel
@ -617,7 +629,7 @@ void CWII_IPC_HLE_WiiMote::SendDisconnectRequest(u16 scid)
cr.dcid = rChannel.DCID;
cr.scid = rChannel.SCID;
INFO_LOG(WII_IPC_WIIMOTE, " SendDisconnectionRequest()");
INFO_LOG(WII_IPC_WIIMOTE, "[ACL] SendDisconnectionRequest");
DEBUG_LOG(WII_IPC_WIIMOTE, " Dcid: 0x%04x", cr.dcid);
DEBUG_LOG(WII_IPC_WIIMOTE, " Scid: 0x%04x", cr.scid);
@ -659,13 +671,10 @@ void CWII_IPC_HLE_WiiMote::SendConfigurationRequest(u16 scid, u16* MTU, u16* Flu
*(u16*)&Buffer[Offset] = *FlushTimeOut; Offset += 2;
}
INFO_LOG(WII_IPC_WIIMOTE, " SendConfigurationRequest()");
INFO_LOG(WII_IPC_WIIMOTE, "[ACL] SendConfigurationRequest");
DEBUG_LOG(WII_IPC_WIIMOTE, " Dcid: 0x%04x", cr->dcid);
DEBUG_LOG(WII_IPC_WIIMOTE, " Flags: 0x%04x", cr->flags);
// hack:
static u8 ident = 99;
ident++;
SendCommandToACL(L2CAP_CONF_REQ, L2CAP_CONF_REQ, Offset, Buffer);
}
@ -681,7 +690,6 @@ void CWII_IPC_HLE_WiiMote::SendConfigurationRequest(u16 scid, u16* MTU, u16* Flu
//
//
#define SDP_UINT8 0x08
#define SDP_UINT16 0x09
#define SDP_UINT32 0x0A
@ -718,7 +726,7 @@ void CWII_IPC_HLE_WiiMote::SDPSendServiceSearchResponse(u16 cid, u16 Transaction
pHeader->Length = (u16)(Offset - sizeof(SL2CAP_Header));
m_pHost->SendACLFrame(GetConnectionHandle(), DataFrame, pHeader->Length + sizeof(SL2CAP_Header));
m_pHost->SendACLPacket(GetConnectionHandle(), DataFrame, pHeader->Length + sizeof(SL2CAP_Header));
}
u32 ParseCont(u8* pCont)
@ -746,10 +754,12 @@ int ParseAttribList(u8* pAttribIDList, u16& _startID, u16& _endID)
u32 attribOffset = 0;
CBigEndianBuffer attribList(pAttribIDList);
u8 sequence = attribList.Read8(attribOffset); attribOffset++; _dbg_assert_(WII_IPC_WIIMOTE, sequence == SDP_SEQ8);
u8 sequence = attribList.Read8(attribOffset); attribOffset++;
u8 seqSize = attribList.Read8(attribOffset); attribOffset++;
u8 typeID = attribList.Read8(attribOffset); attribOffset++;
_dbg_assert_(WII_IPC_WIIMOTE, sequence == SDP_SEQ8);
if (typeID == SDP_UINT32)
{
_startID = attribList.Read16(attribOffset); attribOffset += 2;
@ -759,7 +769,7 @@ int ParseAttribList(u8* pAttribIDList, u16& _startID, u16& _endID)
{
_startID = attribList.Read16(attribOffset); attribOffset += 2;
_endID = _startID;
WARN_LOG(WII_IPC_WIIMOTE, "Read just a single attrib - not tested");
DEBUG_LOG(WII_IPC_WIIMOTE, "Read just a single attrib - not tested");
PanicAlert("Read just a single attrib - not tested");
}
@ -799,9 +809,9 @@ void CWII_IPC_HLE_WiiMote::SDPSendServiceAttributeResponse(u16 cid, u16 Transact
memcpy(buffer.GetPointer(Offset), pPacket, packetSize); Offset += packetSize;
pHeader->Length = (u16)(Offset - sizeof(SL2CAP_Header));
m_pHost->SendACLFrame(GetConnectionHandle(), DataFrame, pHeader->Length + sizeof(SL2CAP_Header));
m_pHost->SendACLPacket(GetConnectionHandle(), DataFrame, pHeader->Length + sizeof(SL2CAP_Header));
// Debugger::PrintDataBuffer(LogTypes::WIIMOTE, DataFrame, pHeader->Length + sizeof(SL2CAP_Header), "test response: ");
// Debugger::PrintDataBuffer(LogTypes::WIIMOTE, DataFrame, pHeader->Length + sizeof(SL2CAP_Header), "test response: ");
}
void CWII_IPC_HLE_WiiMote::HandleSDP(u16 cid, u8* _pData, u32 _Size)
@ -812,7 +822,7 @@ void CWII_IPC_HLE_WiiMote::HandleSDP(u16 cid, u8* _pData, u32 _Size)
switch(buffer.Read8(0))
{
// SDP_ServiceSearchRequest
// SDP_ServiceSearchRequest
case 0x02:
{
WARN_LOG(WII_IPC_WIIMOTE, "!!! SDP_ServiceSearchRequest !!!");
@ -829,7 +839,7 @@ void CWII_IPC_HLE_WiiMote::HandleSDP(u16 cid, u8* _pData, u32 _Size)
}
break;
// SDP_ServiceAttributeRequest
// SDP_ServiceAttributeRequest
case 0x04:
{
WARN_LOG(WII_IPC_WIIMOTE, "!!! SDP_ServiceAttributeRequest !!!");
@ -867,8 +877,6 @@ void CWII_IPC_HLE_WiiMote::HandleSDP(u16 cid, u8* _pData, u32 _Size)
//
//
void CWII_IPC_HLE_WiiMote::SendCommandToACL(u8 _Ident, u8 _Code, u8 _CommandLength, u8* _pCommandData)
{
u8 DataFrame[1024];
@ -885,22 +893,22 @@ void CWII_IPC_HLE_WiiMote::SendCommandToACL(u8 _Ident, u8 _Code, u8 _CommandLeng
memcpy(&DataFrame[Offset], _pCommandData, _CommandLength);
INFO_LOG(WII_IPC_WIIMOTE, " SendCommandToACL (answer)");
DEBUG_LOG(WII_IPC_WIIMOTE, " SendCommandToACL (to CPU)");
DEBUG_LOG(WII_IPC_WIIMOTE, " Ident: 0x%02x", _Ident);
DEBUG_LOG(WII_IPC_WIIMOTE, " Code: 0x%02x", _Code);
// send ....
m_pHost->SendACLFrame(GetConnectionHandle(), DataFrame, pHeader->Length + sizeof(SL2CAP_Header));
m_pHost->SendACLPacket(GetConnectionHandle(), DataFrame, pHeader->Length + sizeof(SL2CAP_Header));
// Debugger::PrintDataBuffer(LogTypes::WIIMOTE, DataFrame, pHeader->Length + sizeof(SL2CAP_Header), "m_pHost->SendACLFrame: ");
// Debugger::PrintDataBuffer(LogTypes::WIIMOTE, DataFrame, pHeader->Length + sizeof(SL2CAP_Header), "m_pHost->SendACLPacket: ");
}
// ===================================================
/* On a second boot the _dbg_assert_(WII_IPC_WIIMOTE, DoesChannelExist(scid)) makes a report. However
the game eventually starts and the Wiimote connects, but it takes at least ten seconds. */
// ----------------
void CWII_IPC_HLE_WiiMote::SendL2capData(u16 scid, const void* _pData, u32 _Size)
// On a second boot the _dbg_assert_(WII_IPC_WIIMOTE, DoesChannelExist(scid)) makes a report.
// However the game eventually starts and the Wiimote connects, but it takes at least ten seconds.
// ---------------------------------------------------
void CWII_IPC_HLE_WiiMote::ReceiveL2capData(u16 scid, const void* _pData, u32 _Size)
{
// Allocate DataFrame
u8 DataFrame[1024];
@ -921,11 +929,11 @@ void CWII_IPC_HLE_WiiMote::SendL2capData(u16 scid, const void* _pData, u32 _Size
// Update Offset to the final size of the report
Offset += _Size;
// Send the report
m_pHost->SendACLFrame(GetConnectionHandle(), DataFrame, Offset);
// Update the status bar
Host_SetWiiMoteConnectionState(2);
// Send the report
m_pHost->SendACLPacket(GetConnectionHandle(), DataFrame, Offset);
}
@ -942,7 +950,7 @@ namespace Core
DEBUG_LOG(WII_IPC_WIIMOTE, " Data: %s", ArrayToString(pData, _Size, 0, 50).c_str());
DEBUG_LOG(WII_IPC_WIIMOTE, " Channel: %u", _channelID);
s_Usb->m_WiiMotes[0].SendL2capData(_channelID, _pData, _Size);
s_Usb->m_WiiMotes[0].ReceiveL2capData(_channelID, _pData, _Size);
DEBUG_LOG(WII_IPC_WIIMOTE, "=========================================================");
}
}

View File

@ -26,7 +26,7 @@ class CWII_IPC_HLE_Device_usb_oh1_57e_305;
enum
{
SDP_CHANNEL = 0x01,
HIDP_CONTROL_CHANNEL = 0x11,
HID_CONTROL_CHANNEL = 0x11,
HID_INTERRUPT_CHANNEL= 0x13,
// L2CAP command codes
@ -192,9 +192,13 @@ public:
// ugly Host handling....
// we really have to clean all this code
bool Update();
bool LinkChannel();
bool IsConnected() const { return m_Connected; }
bool IsLinked() const { return m_Linked; }
void ShowStatus(const void* _pData); // Show status
void UpdateStatus(); // Update status
void ExecuteL2capCmd(u8* _pData, u32 _Size); // From CPU
void ReceiveL2capData(u16 scid, const void* _pData, u32 _Size); // From wiimote
void EventConnectionAccepted();
void EventDisconnect();
@ -202,33 +206,20 @@ public:
void EventCommandWriteLinkPolicy();
const bdaddr_t& GetBD() const { return m_BD; }
const uint8_t* GetClass() const { return uclass; }
u16 GetConnectionHandle() const { return m_ControllerConnectionHandle; }
const u8* GetFeatures() const { return features; }
const char* GetName() const { return m_Name.c_str(); }
u8 GetLMPVersion() const { return lmp_version; }
u16 GetLMPSubVersion() const { return lmp_subversion; }
u8 GetManufactorID() const { return 0xF; } // Broadcom Corporation
void SendACLFrame(u8* _pData, u32 _Size); // To wiimote
void ShowStatus(const void* _pData); // Show status
void UpdateStatus(); // Update status
void SendL2capData(u16 scid, const void* _pData, u32 _Size); // From wiimote
const u8* GetLinkKey() const { return m_LinkKey; }
private:
// state machine
bool m_Connected;
bool m_Linked;
bool m_HIDControlChannel_Connected;
bool m_HIDControlChannel_ConnectedWait;
bool m_HIDControlChannel_Config;
@ -238,25 +229,15 @@ private:
bool m_HIDInterruptChannel_Config;
bool m_HIDInterruptChannel_ConfigWait;
// STATE_TO_SAVE
bdaddr_t m_BD;
u16 m_ControllerConnectionHandle;
uint8_t uclass[HCI_CLASS_SIZE];
u8 features[HCI_FEATURES_SIZE];
u8 lmp_version;
u16 lmp_subversion;
u8 m_LinkKey[16];
std::string m_Name;
CWII_IPC_HLE_Device_usb_oh1_57e_305* m_pHost;
struct SChannel
@ -285,13 +266,11 @@ private:
void SendConfigurationRequest(u16 _SCID, u16* _pMTU = NULL, u16* _pFlushTimeOut = NULL);
void SendDisconnectRequest(u16 _SCID);
void CommandConnectionReq(u8 _Ident, u8* _pData, u32 _Size);
void CommandCofigurationReq(u8 _Ident, u8* _pData, u32 _Size);
void CommandConnectionResponse(u8 _Ident, u8* _pData, u32 _Size);
void CommandDisconnectionReq(u8 _Ident, u8* _pData, u32 _Size);
void CommandConfigurationResponse(u8 _Ident, u8* _pData, u32 _Size);
void ReceiveConnectionReq(u8 _Ident, u8* _pData, u32 _Size);
void ReceiveConnectionResponse(u8 _Ident, u8* _pData, u32 _Size);
void ReceiveDisconnectionReq(u8 _Ident, u8* _pData, u32 _Size);
void ReceiveConfigurationReq(u8 _Ident, u8* _pData, u32 _Size);
void ReceiveConfigurationResponse(u8 _Ident, u8* _pData, u32 _Size);
// some new ugly stuff
//