2022-05-31 19:29:35 +00:00
|
|
|
|
using Ryujinx.Cpu;
|
2019-07-25 14:44:51 +00:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
|
|
|
|
{
|
|
|
|
|
class StandardSteadyClockCore : SteadyClockCore
|
|
|
|
|
{
|
2019-10-08 03:48:49 +00:00
|
|
|
|
private TimeSpanType _setupValue;
|
2019-07-25 14:44:51 +00:00
|
|
|
|
private TimeSpanType _testOffset;
|
|
|
|
|
private TimeSpanType _internalOffset;
|
2019-10-08 03:48:49 +00:00
|
|
|
|
private TimeSpanType _cachedRawTimePoint;
|
2019-07-25 14:44:51 +00:00
|
|
|
|
|
2019-10-08 03:48:49 +00:00
|
|
|
|
public StandardSteadyClockCore()
|
2019-07-25 14:44:51 +00:00
|
|
|
|
{
|
2019-10-08 03:48:49 +00:00
|
|
|
|
_setupValue = TimeSpanType.Zero;
|
|
|
|
|
_testOffset = TimeSpanType.Zero;
|
|
|
|
|
_internalOffset = TimeSpanType.Zero;
|
|
|
|
|
_cachedRawTimePoint = TimeSpanType.Zero;
|
2019-07-25 14:44:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 19:29:35 +00:00
|
|
|
|
public override SteadyClockTimePoint GetTimePoint(ITickSource tickSource)
|
2019-07-25 14:44:51 +00:00
|
|
|
|
{
|
|
|
|
|
SteadyClockTimePoint result = new SteadyClockTimePoint
|
|
|
|
|
{
|
2022-05-31 19:29:35 +00:00
|
|
|
|
TimePoint = GetCurrentRawTimePoint(tickSource).ToSeconds(),
|
2019-07-25 14:44:51 +00: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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 19:29:35 +00:00
|
|
|
|
public override TimeSpanType GetCurrentRawTimePoint(ITickSource tickSource)
|
2019-07-25 14:44:51 +00:00
|
|
|
|
{
|
2022-05-31 19:29:35 +00:00
|
|
|
|
TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
|
2019-07-25 14:44:51 +00:00
|
|
|
|
|
2019-10-08 03:48:49 +00:00
|
|
|
|
TimeSpanType rawTimePoint = new TimeSpanType(_setupValue.NanoSeconds + ticksTimeSpan.NanoSeconds);
|
2019-07-25 14:44:51 +00:00
|
|
|
|
|
2019-10-08 03:48:49 +00:00
|
|
|
|
if (rawTimePoint.NanoSeconds < _cachedRawTimePoint.NanoSeconds)
|
2019-07-25 14:44:51 +00:00
|
|
|
|
{
|
2019-10-08 03:48:49 +00:00
|
|
|
|
rawTimePoint.NanoSeconds = _cachedRawTimePoint.NanoSeconds;
|
|
|
|
|
}
|
2019-07-25 14:44:51 +00:00
|
|
|
|
|
2019-10-08 03:48:49 +00:00
|
|
|
|
_cachedRawTimePoint = rawTimePoint;
|
2019-07-25 14:44:51 +00:00
|
|
|
|
|
2019-10-08 03:48:49 +00:00
|
|
|
|
return rawTimePoint;
|
|
|
|
|
}
|
2019-07-25 14:44:51 +00:00
|
|
|
|
|
2019-10-08 03:48:49 +00:00
|
|
|
|
public void SetSetupValue(TimeSpanType setupValue)
|
|
|
|
|
{
|
|
|
|
|
_setupValue = setupValue;
|
2019-07-25 14:44:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|