DolphinDevice: expose elapsed ms in GetSystemTime

This commit is contained in:
Shawn Hoffman 2022-07-17 19:56:13 -07:00
parent 09089eeee0
commit 49218f9695
2 changed files with 33 additions and 20 deletions

View File

@ -33,24 +33,6 @@ enum
}; };
IPCReply GetSystemTime(const IOCtlVRequest& request)
{
if (!request.HasNumberOfValidVectors(0, 1))
{
return IPCReply(IPC_EINVAL);
}
if (request.io_vectors[0].size != 4)
{
return IPCReply(IPC_EINVAL);
}
const u32 milliseconds = Common::Timer::NowMs();
Memory::Write_U32(milliseconds, request.io_vectors[0].address);
return IPCReply(IPC_SUCCESS);
}
IPCReply GetVersion(const IOCtlVRequest& request) IPCReply GetVersion(const IOCtlVRequest& request)
{ {
if (!request.HasNumberOfValidVectors(0, 1)) if (!request.HasNumberOfValidVectors(0, 1))
@ -159,6 +141,32 @@ IPCReply GetRealProductCode(const IOCtlVRequest& request)
} // namespace } // namespace
IPCReply DolphinDevice::GetSystemTime(const IOCtlVRequest& request) const
{
if (!request.HasNumberOfValidVectors(0, 1))
{
return IPCReply(IPC_EINVAL);
}
if (request.io_vectors[0].size != 4)
{
return IPCReply(IPC_EINVAL);
}
// This ioctl is used by emulated software to judge if emulation is running too fast or slow.
// By using Common::Timer, the same clock Dolphin uses internally for the same task is exposed.
// Return elapsed time instead of current timestamp to make buggy emulated code less likely to
// have issuses.
const u32 milliseconds = static_cast<u32>(m_timer.ElapsedMs());
Memory::Write_U32(milliseconds, request.io_vectors[0].address);
return IPCReply(IPC_SUCCESS);
}
DolphinDevice::DolphinDevice(Kernel& ios, const std::string& device_name) : Device(ios, device_name)
{
m_timer.Start();
}
std::optional<IPCReply> DolphinDevice::IOCtlV(const IOCtlVRequest& request) std::optional<IPCReply> DolphinDevice::IOCtlV(const IOCtlVRequest& request)
{ {
if (Core::WantsDeterminism()) if (Core::WantsDeterminism())

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include "Common/Timer.h"
#include "Core/IOS/Device.h" #include "Core/IOS/Device.h"
namespace IOS::HLE namespace IOS::HLE
@ -10,8 +11,12 @@ namespace IOS::HLE
class DolphinDevice final : public Device class DolphinDevice final : public Device
{ {
public: public:
// Inherit the constructor from the Device class, since we don't need to do anything special. DolphinDevice(Kernel& ios, const std::string& device_name);
using Device::Device;
std::optional<IPCReply> IOCtlV(const IOCtlVRequest& request) override; std::optional<IPCReply> IOCtlV(const IOCtlVRequest& request) override;
private:
IPCReply GetSystemTime(const IOCtlVRequest& request) const;
Common::Timer m_timer;
}; };
} // namespace IOS::HLE } // namespace IOS::HLE