2019-07-25 10:44:51 -04:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
|
|
|
|
{
|
|
|
|
|
class StandardSteadyClockCore : SteadyClockCore
|
|
|
|
|
{
|
2019-10-07 23:48:49 -04:00
|
|
|
|
private TimeSpanType _setupValue;
|
2019-07-25 10:44:51 -04:00
|
|
|
|
private TimeSpanType _testOffset;
|
|
|
|
|
private TimeSpanType _internalOffset;
|
2019-10-07 23:48:49 -04:00
|
|
|
|
private TimeSpanType _cachedRawTimePoint;
|
2019-07-25 10:44:51 -04:00
|
|
|
|
|
2019-10-07 23:48:49 -04:00
|
|
|
|
public StandardSteadyClockCore()
|
2019-07-25 10:44:51 -04:00
|
|
|
|
{
|
2019-10-07 23:48:49 -04:00
|
|
|
|
_setupValue = TimeSpanType.Zero;
|
|
|
|
|
_testOffset = TimeSpanType.Zero;
|
|
|
|
|
_internalOffset = TimeSpanType.Zero;
|
|
|
|
|
_cachedRawTimePoint = TimeSpanType.Zero;
|
2019-07-25 10:44:51 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override SteadyClockTimePoint GetTimePoint(KThread thread)
|
|
|
|
|
{
|
|
|
|
|
SteadyClockTimePoint result = new SteadyClockTimePoint
|
|
|
|
|
{
|
2019-10-07 23:48:49 -04:00
|
|
|
|
TimePoint = GetCurrentRawTimePoint(thread).ToSeconds(),
|
2019-07-25 10:44:51 -04: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-07 23:48:49 -04:00
|
|
|
|
public override TimeSpanType GetCurrentRawTimePoint(KThread thread)
|
2019-07-25 10:44:51 -04:00
|
|
|
|
{
|
2019-10-07 23:48:49 -04:00
|
|
|
|
TimeSpanType ticksTimeSpan;
|
2019-07-25 10:44:51 -04:00
|
|
|
|
|
2019-10-07 23:48:49 -04: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 10:44:51 -04:00
|
|
|
|
|
2019-10-07 23:48:49 -04:00
|
|
|
|
TimeSpanType rawTimePoint = new TimeSpanType(_setupValue.NanoSeconds + ticksTimeSpan.NanoSeconds);
|
2019-07-25 10:44:51 -04:00
|
|
|
|
|
2019-10-07 23:48:49 -04:00
|
|
|
|
if (rawTimePoint.NanoSeconds < _cachedRawTimePoint.NanoSeconds)
|
2019-07-25 10:44:51 -04:00
|
|
|
|
{
|
2019-10-07 23:48:49 -04:00
|
|
|
|
rawTimePoint.NanoSeconds = _cachedRawTimePoint.NanoSeconds;
|
|
|
|
|
}
|
2019-07-25 10:44:51 -04:00
|
|
|
|
|
2019-10-07 23:48:49 -04:00
|
|
|
|
_cachedRawTimePoint = rawTimePoint;
|
2019-07-25 10:44:51 -04:00
|
|
|
|
|
2019-10-07 23:48:49 -04:00
|
|
|
|
return rawTimePoint;
|
|
|
|
|
}
|
2019-07-25 10:44:51 -04:00
|
|
|
|
|
2019-10-07 23:48:49 -04:00
|
|
|
|
public void SetSetupValue(TimeSpanType setupValue)
|
|
|
|
|
{
|
|
|
|
|
_setupValue = setupValue;
|
2019-07-25 10:44:51 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|