Skip to content

Commit

Permalink
Merge pull request #3083 from JosJuice/ipc-ticks
Browse files Browse the repository at this point in the history
Use correct GetTicksPerSecond() value in IPC delays
  • Loading branch information
shuffle2 committed Oct 4, 2015
2 parents 9878004 + 3fdae38 commit 8bb35c8
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 123 deletions.
20 changes: 8 additions & 12 deletions Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp
Expand Up @@ -57,10 +57,6 @@ They will also generate a true or false return for UpdateInterrupts() in WII_IPC

#include "Core/PowerPC/PowerPC.h"

const u32 IPC_DEFAULT_DELAY = SystemTimers::GetTicksPerSecond() / 4000; // 250 us
const IPCCommandResult IPC_NO_REPLY = { false, 0 };
const IPCCommandResult IPC_DEFAULT_REPLY = { true, IPC_DEFAULT_DELAY };

namespace WII_IPC_HLE_Interface
{

Expand Down Expand Up @@ -353,7 +349,7 @@ void DoState(PointerWrap &p)

void ExecuteCommand(u32 _Address)
{
IPCCommandResult result = IPC_NO_REPLY;
IPCCommandResult result = IWII_IPC_HLE_Device::GetNoReply();

IPCCommandType Command = static_cast<IPCCommandType>(Memory::Read_U32(_Address));
s32 DeviceID = Memory::Read_U32(_Address + 8);
Expand Down Expand Up @@ -392,7 +388,7 @@ void ExecuteCommand(u32 _Address)
if (j == ES_MAX_COUNT)
{
Memory::Write_U32(FS_EESEXHAUSTED, _Address + 4);
result = IPC_DEFAULT_REPLY;
result = IWII_IPC_HLE_Device::GetDefaultReply();
}
}
else if (DeviceName.find("/dev/") == 0)
Expand All @@ -410,7 +406,7 @@ void ExecuteCommand(u32 _Address)
{
WARN_LOG(WII_IPC_HLE, "Unimplemented device: %s", DeviceName.c_str());
Memory::Write_U32(FS_ENOENT, _Address+4);
result = IPC_DEFAULT_REPLY;
result = IWII_IPC_HLE_Device::GetDefaultReply();
}
}
else
Expand All @@ -429,7 +425,7 @@ void ExecuteCommand(u32 _Address)
else
{
Memory::Write_U32(FS_EFDEXHAUSTED, _Address + 4);
result = IPC_DEFAULT_REPLY;
result = IWII_IPC_HLE_Device::GetDefaultReply();
}
break;
}
Expand All @@ -452,7 +448,7 @@ void ExecuteCommand(u32 _Address)
else
{
Memory::Write_U32(FS_EINVAL, _Address + 4);
result = IPC_DEFAULT_REPLY;
result = IWII_IPC_HLE_Device::GetDefaultReply();
}
break;
}
Expand All @@ -465,7 +461,7 @@ void ExecuteCommand(u32 _Address)
else
{
Memory::Write_U32(FS_EINVAL, _Address + 4);
result = IPC_DEFAULT_REPLY;
result = IWII_IPC_HLE_Device::GetDefaultReply();
}
break;
}
Expand All @@ -478,7 +474,7 @@ void ExecuteCommand(u32 _Address)
else
{
Memory::Write_U32(FS_EINVAL, _Address + 4);
result = IPC_DEFAULT_REPLY;
result = IWII_IPC_HLE_Device::GetDefaultReply();
}
break;
}
Expand All @@ -491,7 +487,7 @@ void ExecuteCommand(u32 _Address)
else
{
Memory::Write_U32(FS_EINVAL, _Address + 4);
result = IPC_DEFAULT_REPLY;
result = IWII_IPC_HLE_Device::GetDefaultReply();
}
break;
}
Expand Down
4 changes: 0 additions & 4 deletions Source/Core/Core/IPC_HLE/WII_IPC_HLE.h
Expand Up @@ -35,10 +35,6 @@ enum IPCCommandType : u32
IPC_REP_ASYNC = 8
};

extern const u32 IPC_DEFAULT_DELAY;
extern const IPCCommandResult IPC_NO_REPLY;
extern const IPCCommandResult IPC_DEFAULT_REPLY;

namespace WII_IPC_HLE_Interface
{

Expand Down
19 changes: 12 additions & 7 deletions Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device.h
Expand Up @@ -126,7 +126,7 @@ class IWII_IPC_HLE_Device
WARN_LOG(WII_IPC_HLE, "%s does not support Open()", m_Name.c_str());
Memory::Write_U32(FS_ENOENT, _CommandAddress + 4);
m_Active = true;
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}

virtual IPCCommandResult Close(u32 _CommandAddress, bool _bForce = false)
Expand All @@ -135,10 +135,10 @@ class IWII_IPC_HLE_Device
if (!_bForce)
Memory::Write_U32(FS_EINVAL, _CommandAddress + 4);
m_Active = false;
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}

#define UNIMPLEMENTED_CMD(cmd) WARN_LOG(WII_IPC_HLE, "%s does not support "#cmd"()", m_Name.c_str()); return IPC_DEFAULT_REPLY;
#define UNIMPLEMENTED_CMD(cmd) WARN_LOG(WII_IPC_HLE, "%s does not support "#cmd"()", m_Name.c_str()); return GetDefaultReply();
virtual IPCCommandResult Seek(u32) { UNIMPLEMENTED_CMD(Seek) }
virtual IPCCommandResult Read(u32) { UNIMPLEMENTED_CMD(Read) }
virtual IPCCommandResult Write(u32) { UNIMPLEMENTED_CMD(Write) }
Expand All @@ -151,6 +151,11 @@ class IWII_IPC_HLE_Device
virtual bool IsHardware() { return m_Hardware; }
virtual bool IsOpened() { return m_Active; }

// Returns an IPCCommandResult for a reply that takes 250 us (arbitrarily chosen value)
static IPCCommandResult GetDefaultReply() { return { true, SystemTimers::GetTicksPerSecond() / 4000 }; }
// Returns an IPCCommandResult with no reply. Useful for async commands that will generate a reply later
static IPCCommandResult GetNoReply() { return { false, 0 }; }

std::string m_Name;
protected:

Expand Down Expand Up @@ -228,27 +233,27 @@ class CWII_IPC_HLE_Device_stub : public IWII_IPC_HLE_Device
WARN_LOG(WII_IPC_HLE, "%s faking Open()", m_Name.c_str());
Memory::Write_U32(GetDeviceID(), CommandAddress + 4);
m_Active = true;
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}
IPCCommandResult Close(u32 CommandAddress, bool bForce = false) override
{
WARN_LOG(WII_IPC_HLE, "%s faking Close()", m_Name.c_str());
if (!bForce)
Memory::Write_U32(FS_SUCCESS, CommandAddress + 4);
m_Active = false;
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}

IPCCommandResult IOCtl(u32 CommandAddress) override
{
WARN_LOG(WII_IPC_HLE, "%s faking IOCtl()", m_Name.c_str());
Memory::Write_U32(FS_SUCCESS, CommandAddress + 4);
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}
IPCCommandResult IOCtlV(u32 CommandAddress) override
{
WARN_LOG(WII_IPC_HLE, "%s faking IOCtlV()", m_Name.c_str());
Memory::Write_U32(FS_SUCCESS, CommandAddress + 4);
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}
};
12 changes: 6 additions & 6 deletions Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp
Expand Up @@ -47,15 +47,15 @@ IPCCommandResult CWII_IPC_HLE_Device_di::Open(u32 _CommandAddress, u32 _Mode)
{
Memory::Write_U32(GetDeviceID(), _CommandAddress + 4);
m_Active = true;
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}

IPCCommandResult CWII_IPC_HLE_Device_di::Close(u32 _CommandAddress, bool _bForce)
{
if (!_bForce)
Memory::Write_U32(0, _CommandAddress + 4);
m_Active = false;
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}

IPCCommandResult CWII_IPC_HLE_Device_di::IOCtl(u32 _CommandAddress)
Expand All @@ -72,9 +72,9 @@ IPCCommandResult CWII_IPC_HLE_Device_di::IOCtl(u32 _CommandAddress)
if (ready_to_execute)
StartIOCtl(_CommandAddress);

// DVDInterface handles the timing, and we handle the reply,
// so WII_IPC_HLE shouldn't do any of that.
return IPC_NO_REPLY;
// DVDInterface handles the timing and we handle the reply,
// so WII_IPC_HLE shouldn't handle anything.
return GetNoReply();
}

void CWII_IPC_HLE_Device_di::StartIOCtl(u32 command_address)
Expand Down Expand Up @@ -175,5 +175,5 @@ IPCCommandResult CWII_IPC_HLE_Device_di::IOCtlV(u32 _CommandAddress)
}

Memory::Write_U32(ReturnValue, _CommandAddress + 4);
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}
12 changes: 6 additions & 6 deletions Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp
Expand Up @@ -96,7 +96,7 @@ IPCCommandResult CWII_IPC_HLE_Device_FileIO::Close(u32 _CommandAddress, bool _bF
if (_CommandAddress && !_bForce)
Memory::Write_U32(0, _CommandAddress + 4);
m_Active = false;
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}

IPCCommandResult CWII_IPC_HLE_Device_FileIO::Open(u32 _CommandAddress, u32 _Mode)
Expand Down Expand Up @@ -131,7 +131,7 @@ IPCCommandResult CWII_IPC_HLE_Device_FileIO::Open(u32 _CommandAddress, u32 _Mode
if (_CommandAddress)
Memory::Write_U32(ReturnValue, _CommandAddress+4);
m_Active = true;
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}

// This isn't theadsafe, but it's only called from the CPU thread.
Expand Down Expand Up @@ -238,7 +238,7 @@ IPCCommandResult CWII_IPC_HLE_Device_FileIO::Seek(u32 _CommandAddress)
}
Memory::Write_U32(ReturnValue, _CommandAddress + 0x4);

return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}

IPCCommandResult CWII_IPC_HLE_Device_FileIO::Read(u32 _CommandAddress)
Expand Down Expand Up @@ -277,7 +277,7 @@ IPCCommandResult CWII_IPC_HLE_Device_FileIO::Read(u32 _CommandAddress)
}

Memory::Write_U32(ReturnValue, _CommandAddress + 0x4);
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}

IPCCommandResult CWII_IPC_HLE_Device_FileIO::Write(u32 _CommandAddress)
Expand Down Expand Up @@ -310,7 +310,7 @@ IPCCommandResult CWII_IPC_HLE_Device_FileIO::Write(u32 _CommandAddress)
}

Memory::Write_U32(ReturnValue, _CommandAddress + 0x4);
return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}

IPCCommandResult CWII_IPC_HLE_Device_FileIO::IOCtl(u32 _CommandAddress)
Expand Down Expand Up @@ -353,7 +353,7 @@ IPCCommandResult CWII_IPC_HLE_Device_FileIO::IOCtl(u32 _CommandAddress)

Memory::Write_U32(ReturnValue, _CommandAddress + 0x4);

return IPC_DEFAULT_REPLY;
return GetDefaultReply();
}

void CWII_IPC_HLE_Device_FileIO::DoState(PointerWrap &p)
Expand Down

0 comments on commit 8bb35c8

Please sign in to comment.