2019-07-14 20:50:11 +00:00
|
|
|
|
using Ryujinx.HLE.Utilities;
|
2019-07-15 17:52:35 +00:00
|
|
|
|
using System;
|
2019-07-14 20:50:11 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
|
|
|
|
{
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
|
struct TimeSpanType
|
|
|
|
|
{
|
2019-07-25 14:44:51 +00:00
|
|
|
|
private const long NanoSecondsPerSecond = 1000000000;
|
|
|
|
|
|
2019-07-15 17:52:35 +00:00
|
|
|
|
public long NanoSeconds;
|
2019-07-14 20:50:11 +00:00
|
|
|
|
|
2019-07-15 17:52:35 +00:00
|
|
|
|
public TimeSpanType(long nanoSeconds)
|
2019-07-14 20:50:11 +00:00
|
|
|
|
{
|
|
|
|
|
NanoSeconds = nanoSeconds;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-15 17:52:35 +00:00
|
|
|
|
public long ToSeconds()
|
2019-07-14 20:50:11 +00:00
|
|
|
|
{
|
2019-07-25 14:44:51 +00:00
|
|
|
|
return NanoSeconds / NanoSecondsPerSecond;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TimeSpanType FromSeconds(long seconds)
|
|
|
|
|
{
|
|
|
|
|
return new TimeSpanType(seconds * NanoSecondsPerSecond);
|
2019-07-14 20:50:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TimeSpanType FromTicks(ulong ticks, ulong frequency)
|
|
|
|
|
{
|
2019-07-25 14:44:51 +00:00
|
|
|
|
return FromSeconds((long)ticks / (long)frequency);
|
2019-07-14 20:50:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
|
struct SteadyClockTimePoint
|
|
|
|
|
{
|
2019-07-15 17:52:35 +00:00
|
|
|
|
public long TimePoint;
|
2019-07-14 20:50:11 +00:00
|
|
|
|
public UInt128 ClockSourceId;
|
2019-07-15 17:52:35 +00:00
|
|
|
|
|
|
|
|
|
public ResultCode GetSpanBetween(SteadyClockTimePoint other, out long outSpan)
|
|
|
|
|
{
|
|
|
|
|
outSpan = 0;
|
|
|
|
|
|
|
|
|
|
if (ClockSourceId == other.ClockSourceId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
outSpan = checked(other.TimePoint - TimePoint);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
catch (OverflowException)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.Overflow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultCode.Overflow;
|
|
|
|
|
}
|
2019-07-14 20:50:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
|
struct SystemClockContext
|
|
|
|
|
{
|
2019-07-15 17:52:35 +00:00
|
|
|
|
public long Offset;
|
2019-07-14 20:50:11 +00:00
|
|
|
|
public SteadyClockTimePoint SteadyTimePoint;
|
|
|
|
|
}
|
2019-07-25 14:44:51 +00:00
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Size = 0xD0)]
|
|
|
|
|
struct ClockSnapshot
|
|
|
|
|
{
|
|
|
|
|
public SystemClockContext UserContext;
|
|
|
|
|
public SystemClockContext NetworkContext;
|
|
|
|
|
public long UserTime;
|
|
|
|
|
public long NetworkTime;
|
|
|
|
|
public CalendarTime UserCalendarTime;
|
|
|
|
|
public CalendarTime NetworkCalendarTime;
|
|
|
|
|
public CalendarAdditionalInfo UserCalendarAdditionalTime;
|
|
|
|
|
public CalendarAdditionalInfo NetworkCalendarAdditionalTime;
|
|
|
|
|
public SteadyClockTimePoint SteadyClockTimePoint;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x24)]
|
|
|
|
|
public char[] LocationName;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.I1)]
|
|
|
|
|
public bool IsAutomaticCorrectionEnabled;
|
|
|
|
|
public byte Type;
|
|
|
|
|
public ushort Unknown;
|
|
|
|
|
|
|
|
|
|
public static ResultCode GetCurrentTime(out long currentTime, SteadyClockTimePoint steadyClockTimePoint, SystemClockContext context)
|
|
|
|
|
{
|
|
|
|
|
currentTime = 0;
|
|
|
|
|
|
|
|
|
|
if (steadyClockTimePoint.ClockSourceId == context.SteadyTimePoint.ClockSourceId)
|
|
|
|
|
{
|
|
|
|
|
currentTime = steadyClockTimePoint.TimePoint + context.Offset;
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultCode.TimeMismatch;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-14 20:50:11 +00:00
|
|
|
|
}
|