aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs')
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs83
1 files changed, 29 insertions, 54 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs b/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs
index 1bc5bee7..370e7d73 100644
--- a/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs
@@ -1,49 +1,30 @@
using Ryujinx.HLE.HOS.Kernel.Threading;
-using Ryujinx.HLE.HOS.Services.Pcv.Bpc;
namespace Ryujinx.HLE.HOS.Services.Time.Clock
{
class StandardSteadyClockCore : SteadyClockCore
{
- private long _setupValue;
- private ResultCode _setupResultCode;
- private bool _isRtcResetDetected;
+ private TimeSpanType _setupValue;
private TimeSpanType _testOffset;
private TimeSpanType _internalOffset;
+ private TimeSpanType _cachedRawTimePoint;
- private static StandardSteadyClockCore _instance;
-
- public static StandardSteadyClockCore Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new StandardSteadyClockCore();
- }
-
- return _instance;
- }
- }
-
- private StandardSteadyClockCore()
+ public StandardSteadyClockCore()
{
- _testOffset = new TimeSpanType(0);
- _internalOffset = new TimeSpanType(0);
+ _setupValue = TimeSpanType.Zero;
+ _testOffset = TimeSpanType.Zero;
+ _internalOffset = TimeSpanType.Zero;
+ _cachedRawTimePoint = TimeSpanType.Zero;
}
public override SteadyClockTimePoint GetTimePoint(KThread thread)
{
SteadyClockTimePoint result = new SteadyClockTimePoint
{
- TimePoint = 0,
+ TimePoint = GetCurrentRawTimePoint(thread).ToSeconds(),
ClockSourceId = GetClockSourceId()
};
- TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(thread.Context.CntpctEl0, thread.Context.CntfrqEl0);
-
- result.TimePoint = _setupValue + ticksTimeSpan.ToSeconds();
-
return result;
}
@@ -57,16 +38,6 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
_testOffset = testOffset;
}
- public override ResultCode GetRtcValue(out ulong rtcValue)
- {
- return (ResultCode)IRtcManager.GetExternalRtcValue(out rtcValue);
- }
-
- public bool IsRtcResetDetected()
- {
- return _isRtcResetDetected;
- }
-
public override TimeSpanType GetInternalOffset()
{
return _internalOffset;
@@ -77,31 +48,35 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
_internalOffset = internalOffset;
}
- public override ResultCode GetSetupResultValue()
+ public override TimeSpanType GetCurrentRawTimePoint(KThread thread)
{
- return _setupResultCode;
- }
+ TimeSpanType ticksTimeSpan;
- public void ConfigureSetupValue()
- {
- int retry = 0;
+ // 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);
+ }
- ResultCode result = ResultCode.Success;
+ TimeSpanType rawTimePoint = new TimeSpanType(_setupValue.NanoSeconds + ticksTimeSpan.NanoSeconds);
- while (retry < 20)
+ if (rawTimePoint.NanoSeconds < _cachedRawTimePoint.NanoSeconds)
{
- result = (ResultCode)IRtcManager.GetExternalRtcValue(out ulong rtcValue);
+ rawTimePoint.NanoSeconds = _cachedRawTimePoint.NanoSeconds;
+ }
- if (result == ResultCode.Success)
- {
- _setupValue = (long)rtcValue;
- break;
- }
+ _cachedRawTimePoint = rawTimePoint;
- retry++;
- }
+ return rawTimePoint;
+ }
- _setupResultCode = result;
+ public void SetSetupValue(TimeSpanType setupValue)
+ {
+ _setupValue = setupValue;
}
}
}