forked from Mirror/Ryujinx
0c87bf9ea4
* Refactor CPU interface * Use IExecutionContext interface on SVC handler, change how CPU interrupts invokes the handlers * Make CpuEngine take a ITickSource rather than returning one The previous implementation had the scenario where the CPU engine had to implement the tick source in mind, like for example, when we have a hypervisor and the game can read CNTPCT on the host directly. However given that we need to do conversion due to different frequencies anyway, it's not worth it. It's better to just let the user pass the tick source and redirect any reads to CNTPCT to the user tick source * XML docs for the public interfaces * PPTC invalidation due to NativeInterface function name changes * Fix build of the CPU tests * PR feedback
72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using Ryujinx.Cpu;
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
|
{
|
|
class StandardSteadyClockCore : SteadyClockCore
|
|
{
|
|
private TimeSpanType _setupValue;
|
|
private TimeSpanType _testOffset;
|
|
private TimeSpanType _internalOffset;
|
|
private TimeSpanType _cachedRawTimePoint;
|
|
|
|
public StandardSteadyClockCore()
|
|
{
|
|
_setupValue = TimeSpanType.Zero;
|
|
_testOffset = TimeSpanType.Zero;
|
|
_internalOffset = TimeSpanType.Zero;
|
|
_cachedRawTimePoint = TimeSpanType.Zero;
|
|
}
|
|
|
|
public override SteadyClockTimePoint GetTimePoint(ITickSource tickSource)
|
|
{
|
|
SteadyClockTimePoint result = new SteadyClockTimePoint
|
|
{
|
|
TimePoint = GetCurrentRawTimePoint(tickSource).ToSeconds(),
|
|
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;
|
|
}
|
|
|
|
public override TimeSpanType GetCurrentRawTimePoint(ITickSource tickSource)
|
|
{
|
|
TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
|
|
|
|
TimeSpanType rawTimePoint = new TimeSpanType(_setupValue.NanoSeconds + ticksTimeSpan.NanoSeconds);
|
|
|
|
if (rawTimePoint.NanoSeconds < _cachedRawTimePoint.NanoSeconds)
|
|
{
|
|
rawTimePoint.NanoSeconds = _cachedRawTimePoint.NanoSeconds;
|
|
}
|
|
|
|
_cachedRawTimePoint = rawTimePoint;
|
|
|
|
return rawTimePoint;
|
|
}
|
|
|
|
public void SetSetupValue(TimeSpanType setupValue)
|
|
{
|
|
_setupValue = setupValue;
|
|
}
|
|
}
|
|
}
|