Implement time:* 4.0.0 commands (#736)

* Abstract SteadyClockCore to follow Nintendo changes in 4.x

This is the ground work for 4.0.0 support

* Implement TickBasedSteadyClockCore

Preparation for the ephemeral clock.

* Refactor SystemClockCore to follow 4.0.0 changes

* Implement EphemeralNetworkSystemClock

* Implement GetSnapshotClock & GetSnapshotClockFromSystemClockContext

* Implement CalculateStandardUserSystemClockDifferenceByUser & CalculateSpanBetween

* Remove an outdated comment & unused import

* Fix a nit and GetClockSnapshot

* Address comment
This commit is contained in:
Thomas Guillemard 2019-07-25 16:44:51 +02:00 committed by gdkchan
parent d254548548
commit 54b79dffa8
13 changed files with 518 additions and 205 deletions

View file

@ -1,54 +1,16 @@
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Bpc;
using Ryujinx.HLE.Utilities;
using System;
namespace Ryujinx.HLE.HOS.Services.Time.Clock
{
class SteadyClockCore
abstract class SteadyClockCore
{
private long _setupValue;
private ResultCode _setupResultCode;
private bool _isRtcResetDetected;
private TimeSpanType _testOffset;
private TimeSpanType _internalOffset;
private UInt128 _clockSourceId;
private UInt128 _clockSourceId;
private static SteadyClockCore instance;
public static SteadyClockCore Instance
public SteadyClockCore()
{
get
{
if (instance == null)
{
instance = new SteadyClockCore();
}
return instance;
}
}
private SteadyClockCore()
{
_testOffset = new TimeSpanType(0);
_internalOffset = new TimeSpanType(0);
_clockSourceId = new UInt128(Guid.NewGuid().ToByteArray());
}
private SteadyClockTimePoint GetTimePoint(KThread thread)
{
SteadyClockTimePoint result = new SteadyClockTimePoint
{
TimePoint = 0,
ClockSourceId = _clockSourceId
};
TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(thread.Context.ThreadState.CntpctEl0, thread.Context.ThreadState.CntfrqEl0);
result.TimePoint = _setupValue + ticksTimeSpan.ToSeconds();
return result;
_clockSourceId = new UInt128(Guid.NewGuid().ToByteArray());
}
public UInt128 GetClockSourceId()
@ -56,76 +18,45 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
return _clockSourceId;
}
public virtual TimeSpanType GetTestOffset()
{
return new TimeSpanType(0);
}
public virtual void SetTestOffset(TimeSpanType testOffset) {}
public virtual ResultCode GetRtcValue(out ulong rtcValue)
{
rtcValue = 0;
return ResultCode.NotImplemented;
}
public virtual ResultCode GetSetupResultValue()
{
return ResultCode.NotImplemented;
}
public virtual TimeSpanType GetInternalOffset()
{
return new TimeSpanType(0);
}
public virtual void SetInternalOffset(TimeSpanType internalOffset) {}
public virtual SteadyClockTimePoint GetTimePoint(KThread thread)
{
throw new NotImplementedException();
}
public SteadyClockTimePoint GetCurrentTimePoint(KThread thread)
{
SteadyClockTimePoint result = GetTimePoint(thread);
result.TimePoint += _testOffset.ToSeconds();
result.TimePoint += _internalOffset.ToSeconds();
result.TimePoint += GetTestOffset().ToSeconds();
result.TimePoint += GetInternalOffset().ToSeconds();
return result;
}
public TimeSpanType GetTestOffset()
{
return _testOffset;
}
public void SetTestOffset(TimeSpanType testOffset)
{
_testOffset = testOffset;
}
public ResultCode GetRtcValue(out ulong rtcValue)
{
return (ResultCode)IRtcManager.GetExternalRtcValue(out rtcValue);
}
public bool IsRtcResetDetected()
{
return _isRtcResetDetected;
}
public ResultCode GetSetupResultCode()
{
return _setupResultCode;
}
public TimeSpanType GetInternalOffset()
{
return _internalOffset;
}
public void SetInternalOffset(TimeSpanType internalOffset)
{
_internalOffset = internalOffset;
}
public ResultCode GetSetupResultValue()
{
return _setupResultCode;
}
public void ConfigureSetupValue()
{
int retry = 0;
ResultCode result = ResultCode.Success;
while (retry < 20)
{
result = (ResultCode)IRtcManager.GetExternalRtcValue(out ulong rtcValue);
if (result == ResultCode.Success)
{
_setupValue = (long)rtcValue;
break;
}
retry++;
}
_setupResultCode = result;
}
}
}