SteadyClockCore.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using Ryujinx.HLE.HOS.Kernel.Threading;
  2. using Ryujinx.HLE.Utilities;
  3. using System;
  4. namespace Ryujinx.HLE.HOS.Services.Time.Clock
  5. {
  6. abstract class SteadyClockCore
  7. {
  8. private UInt128 _clockSourceId;
  9. private bool _isRtcResetDetected;
  10. private bool _isInitialized;
  11. public SteadyClockCore()
  12. {
  13. _clockSourceId = new UInt128(Guid.NewGuid().ToByteArray());
  14. _isRtcResetDetected = false;
  15. _isInitialized = false;
  16. }
  17. public UInt128 GetClockSourceId()
  18. {
  19. return _clockSourceId;
  20. }
  21. public void SetClockSourceId(UInt128 clockSourceId)
  22. {
  23. _clockSourceId = clockSourceId;
  24. }
  25. public void SetRtcReset()
  26. {
  27. _isRtcResetDetected = true;
  28. }
  29. public virtual TimeSpanType GetTestOffset()
  30. {
  31. return new TimeSpanType(0);
  32. }
  33. public virtual void SetTestOffset(TimeSpanType testOffset) {}
  34. public ResultCode GetRtcValue(out ulong rtcValue)
  35. {
  36. rtcValue = 0;
  37. return ResultCode.NotImplemented;
  38. }
  39. public bool IsRtcResetDetected()
  40. {
  41. return _isRtcResetDetected;
  42. }
  43. public ResultCode GetSetupResultValue()
  44. {
  45. return ResultCode.Success;
  46. }
  47. public virtual TimeSpanType GetInternalOffset()
  48. {
  49. return new TimeSpanType(0);
  50. }
  51. public virtual void SetInternalOffset(TimeSpanType internalOffset) {}
  52. public virtual SteadyClockTimePoint GetTimePoint(KThread thread)
  53. {
  54. throw new NotImplementedException();
  55. }
  56. public virtual TimeSpanType GetCurrentRawTimePoint(KThread thread)
  57. {
  58. SteadyClockTimePoint timePoint = GetTimePoint(thread);
  59. return TimeSpanType.FromSeconds(timePoint.TimePoint);
  60. }
  61. public SteadyClockTimePoint GetCurrentTimePoint(KThread thread)
  62. {
  63. SteadyClockTimePoint result = GetTimePoint(thread);
  64. result.TimePoint += GetTestOffset().ToSeconds();
  65. result.TimePoint += GetInternalOffset().ToSeconds();
  66. return result;
  67. }
  68. public bool IsInitialized()
  69. {
  70. return _isInitialized;
  71. }
  72. public void MarkInitialized()
  73. {
  74. _isInitialized = true;
  75. }
  76. }
  77. }