2019-07-25 16:44:51 +02:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
|
|
|
|
{
|
|
|
|
|
class StandardSteadyClockCore : SteadyClockCore
|
|
|
|
|
{
|
2019-10-08 05:48:49 +02:00
|
|
|
|
private TimeSpanType _setupValue;
|
2019-07-25 16:44:51 +02:00
|
|
|
|
private TimeSpanType _testOffset;
|
|
|
|
|
private TimeSpanType _internalOffset;
|
2019-10-08 05:48:49 +02:00
|
|
|
|
private TimeSpanType _cachedRawTimePoint;
|
2019-07-25 16:44:51 +02:00
|
|
|
|
|
2019-10-08 05:48:49 +02:00
|
|
|
|
public StandardSteadyClockCore()
|
2019-07-25 16:44:51 +02:00
|
|
|
|
{
|
2019-10-08 05:48:49 +02:00
|
|
|
|
_setupValue = TimeSpanType.Zero;
|
|
|
|
|
_testOffset = TimeSpanType.Zero;
|
|
|
|
|
_internalOffset = TimeSpanType.Zero;
|
|
|
|
|
_cachedRawTimePoint = TimeSpanType.Zero;
|
2019-07-25 16:44:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override SteadyClockTimePoint GetTimePoint(KThread thread)
|
|
|
|
|
{
|
|
|
|
|
SteadyClockTimePoint result = new SteadyClockTimePoint
|
|
|
|
|
{
|
2019-10-08 05:48:49 +02:00
|
|
|
|
TimePoint = GetCurrentRawTimePoint(thread).ToSeconds(),
|
2019-07-25 16:44:51 +02:00
|
|
|
|
ClockSourceId = GetClockSourceId()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override TimeSpanType GetTestOffset()
|
|
|
|
|
{
|
|
|
|
|
return _testOffset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetTestOffset(TimeSpanType testOffset)
|
|
|
|
|
{
|
|
|
|
|
_testOffset = testOffset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override TimeSpanType GetInternalOffset()
|
|
|
|
|
{
|
|
|
|
|
return _internalOffset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetInternalOffset(TimeSpanType internalOffset)
|
|
|
|
|
{
|
|
|
|
|
_internalOffset = internalOffset;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-08 05:48:49 +02:00
|
|
|
|
public override TimeSpanType GetCurrentRawTimePoint(KThread thread)
|
2019-07-25 16:44:51 +02:00
|
|
|
|
{
|
2019-10-08 05:48:49 +02:00
|
|
|
|
TimeSpanType ticksTimeSpan;
|
2019-07-25 16:44:51 +02:00
|
|
|
|
|
2019-10-08 05:48:49 +02:00
|
|
|
|
// As this may be called before the guest code, we support passing a null thread to make this api usable.
|
|
|
|
|
if (thread == null)
|
|
|
|
|
{
|
|
|
|
|
ticksTimeSpan = TimeSpanType.FromSeconds(0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ticksTimeSpan = TimeSpanType.FromTicks(thread.Context.CntpctEl0, thread.Context.CntfrqEl0);
|
|
|
|
|
}
|
2019-07-25 16:44:51 +02:00
|
|
|
|
|
2019-10-08 05:48:49 +02:00
|
|
|
|
TimeSpanType rawTimePoint = new TimeSpanType(_setupValue.NanoSeconds + ticksTimeSpan.NanoSeconds);
|
2019-07-25 16:44:51 +02:00
|
|
|
|
|
2019-10-08 05:48:49 +02:00
|
|
|
|
if (rawTimePoint.NanoSeconds < _cachedRawTimePoint.NanoSeconds)
|
2019-07-25 16:44:51 +02:00
|
|
|
|
{
|
2019-10-08 05:48:49 +02:00
|
|
|
|
rawTimePoint.NanoSeconds = _cachedRawTimePoint.NanoSeconds;
|
|
|
|
|
}
|
2019-07-25 16:44:51 +02:00
|
|
|
|
|
2019-10-08 05:48:49 +02:00
|
|
|
|
_cachedRawTimePoint = rawTimePoint;
|
2019-07-25 16:44:51 +02:00
|
|
|
|
|
2019-10-08 05:48:49 +02:00
|
|
|
|
return rawTimePoint;
|
|
|
|
|
}
|
2019-07-25 16:44:51 +02:00
|
|
|
|
|
2019-10-08 05:48:49 +02:00
|
|
|
|
public void SetSetupValue(TimeSpanType setupValue)
|
|
|
|
|
{
|
|
|
|
|
_setupValue = setupValue;
|
2019-07-25 16:44:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|