2022-11-09 20:22:43 +01:00
|
|
|
|
using Ryujinx.Common.Utilities;
|
|
|
|
|
using Ryujinx.Cpu;
|
2019-07-14 22:50:11 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
|
|
|
|
{
|
2019-07-25 16:44:51 +02:00
|
|
|
|
abstract class SteadyClockCore
|
2019-07-14 22:50:11 +02:00
|
|
|
|
{
|
2019-07-25 16:44:51 +02:00
|
|
|
|
private UInt128 _clockSourceId;
|
2019-10-08 05:48:49 +02:00
|
|
|
|
private bool _isRtcResetDetected;
|
|
|
|
|
private bool _isInitialized;
|
2019-07-14 22:50:11 +02:00
|
|
|
|
|
2019-07-25 16:44:51 +02:00
|
|
|
|
public SteadyClockCore()
|
2019-07-14 22:50:11 +02:00
|
|
|
|
{
|
2022-11-09 20:22:43 +01:00
|
|
|
|
_clockSourceId = UInt128Utils.CreateRandom();
|
2019-10-08 05:48:49 +02:00
|
|
|
|
_isRtcResetDetected = false;
|
|
|
|
|
_isInitialized = false;
|
2019-07-14 22:50:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UInt128 GetClockSourceId()
|
|
|
|
|
{
|
|
|
|
|
return _clockSourceId;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-08 05:48:49 +02:00
|
|
|
|
public void SetClockSourceId(UInt128 clockSourceId)
|
|
|
|
|
{
|
|
|
|
|
_clockSourceId = clockSourceId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetRtcReset()
|
|
|
|
|
{
|
|
|
|
|
_isRtcResetDetected = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-25 16:44:51 +02:00
|
|
|
|
public virtual TimeSpanType GetTestOffset()
|
2019-07-14 22:50:11 +02:00
|
|
|
|
{
|
2019-07-25 16:44:51 +02:00
|
|
|
|
return new TimeSpanType(0);
|
2019-07-14 22:50:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-25 16:44:51 +02:00
|
|
|
|
public virtual void SetTestOffset(TimeSpanType testOffset) {}
|
2019-07-14 22:50:11 +02:00
|
|
|
|
|
2019-10-08 05:48:49 +02:00
|
|
|
|
public ResultCode GetRtcValue(out ulong rtcValue)
|
2019-07-15 19:52:35 +02:00
|
|
|
|
{
|
2019-07-25 16:44:51 +02:00
|
|
|
|
rtcValue = 0;
|
2019-07-15 19:52:35 +02:00
|
|
|
|
|
2019-07-25 16:44:51 +02:00
|
|
|
|
return ResultCode.NotImplemented;
|
2019-07-15 19:52:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-08 05:48:49 +02:00
|
|
|
|
public bool IsRtcResetDetected()
|
2019-07-15 19:52:35 +02:00
|
|
|
|
{
|
2019-10-08 05:48:49 +02:00
|
|
|
|
return _isRtcResetDetected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode GetSetupResultValue()
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.Success;
|
2019-07-15 19:52:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-25 16:44:51 +02:00
|
|
|
|
public virtual TimeSpanType GetInternalOffset()
|
2019-07-14 22:50:11 +02:00
|
|
|
|
{
|
2019-07-25 16:44:51 +02:00
|
|
|
|
return new TimeSpanType(0);
|
2019-07-14 22:50:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-25 16:44:51 +02:00
|
|
|
|
public virtual void SetInternalOffset(TimeSpanType internalOffset) {}
|
2019-07-15 19:52:35 +02:00
|
|
|
|
|
2022-05-31 21:29:35 +02:00
|
|
|
|
public virtual SteadyClockTimePoint GetTimePoint(ITickSource tickSource)
|
2019-07-15 19:52:35 +02:00
|
|
|
|
{
|
2019-07-25 16:44:51 +02:00
|
|
|
|
throw new NotImplementedException();
|
2019-07-15 19:52:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 21:29:35 +02:00
|
|
|
|
public virtual TimeSpanType GetCurrentRawTimePoint(ITickSource tickSource)
|
2019-10-08 05:48:49 +02:00
|
|
|
|
{
|
2022-05-31 21:29:35 +02:00
|
|
|
|
SteadyClockTimePoint timePoint = GetTimePoint(tickSource);
|
2019-10-08 05:48:49 +02:00
|
|
|
|
|
|
|
|
|
return TimeSpanType.FromSeconds(timePoint.TimePoint);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 21:29:35 +02:00
|
|
|
|
public SteadyClockTimePoint GetCurrentTimePoint(ITickSource tickSource)
|
2019-07-15 19:52:35 +02:00
|
|
|
|
{
|
2022-05-31 21:29:35 +02:00
|
|
|
|
SteadyClockTimePoint result = GetTimePoint(tickSource);
|
2019-07-15 19:52:35 +02:00
|
|
|
|
|
2019-07-25 16:44:51 +02:00
|
|
|
|
result.TimePoint += GetTestOffset().ToSeconds();
|
|
|
|
|
result.TimePoint += GetInternalOffset().ToSeconds();
|
2019-07-15 19:52:35 +02:00
|
|
|
|
|
2019-07-25 16:44:51 +02:00
|
|
|
|
return result;
|
2019-07-15 19:52:35 +02:00
|
|
|
|
}
|
2019-10-08 05:48:49 +02:00
|
|
|
|
|
|
|
|
|
public bool IsInitialized()
|
|
|
|
|
{
|
|
|
|
|
return _isInitialized;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MarkInitialized()
|
|
|
|
|
{
|
|
|
|
|
_isInitialized = true;
|
|
|
|
|
}
|
2019-07-14 22:50:11 +02:00
|
|
|
|
}
|
|
|
|
|
}
|