diff options
| author | Mary <mary@mary.zone> | 2023-05-08 00:15:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-08 00:15:58 +0200 |
| commit | 470a8031a44145f906b50919ce1a4e01d51c15ff (patch) | |
| tree | fbb7634d81f9f071e28e027c52120d4e91f5f2ec /src/Ryujinx.HLE/HOS/Services/Time | |
| parent | 5440d4ad5c5421a474a61e582e524ced5bd65547 (diff) | |
time: Update for 15.0.0 changes and fixes long standing issues (#4822)
* time: Update for 15.0.0 changes
Last time we did an upgrade on the time service was during 9.x era, it was about time to take back that reverse again!
15.0.0 added a new structure on the shared memory to get steady clock raw timepoints with a granularity in nanoseconds.
This commit implements this new part.
I plan to write a follow up with a bit of refactoring of this ancient part of the emulator.
As always, reverse and work done by your truly.
PS: As a reminder, if this change is reused anywhere else, work should be credited as Ryujinx and not my person.
* time: Do not set setup value to posix time
This should fix local and network clock returning 0 under usage with
shared memory.
This probably fix #2430.
* Address gdkchan's comment
* Fix internal offset not working since changes and ensure that user clock have a valid clock id
* time: Report auto correcting clock and hardcode steady clock unique id
Fix Pokemon Sword Pokejobs for real.
* Address gdkchan's comment
Diffstat (limited to 'src/Ryujinx.HLE/HOS/Services/Time')
| -rw-r--r-- | src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/ContinuousAdjustmentTimePoint.cs | 13 | ||||
| -rw-r--r-- | src/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs | 53 |
2 files changed, 50 insertions, 16 deletions
diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/ContinuousAdjustmentTimePoint.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/ContinuousAdjustmentTimePoint.cs new file mode 100644 index 00000000..b57dfaa0 --- /dev/null +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/ContinuousAdjustmentTimePoint.cs @@ -0,0 +1,13 @@ +using System.Runtime.InteropServices; + +namespace Ryujinx.HLE.HOS.Services.Time.Clock.Types +{ + [StructLayout(LayoutKind.Sequential, Pack = 1)] + struct ContinuousAdjustmentTimePoint + { + public ulong ClockOffset; + public long Multiplier; + public long DivisorLog2; + public SystemClockContext Context; + } +} diff --git a/src/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs b/src/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs index 7063290b..6b1e1687 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs @@ -1,8 +1,8 @@ using Ryujinx.Cpu; using Ryujinx.HLE.HOS.Kernel.Memory; using Ryujinx.HLE.HOS.Services.Time.Clock; +using Ryujinx.HLE.HOS.Services.Time.Clock.Types; using Ryujinx.HLE.HOS.Services.Time.Types; -using Ryujinx.HLE.Utilities; using System; using System.Runtime.CompilerServices; using System.Threading; @@ -16,10 +16,11 @@ namespace Ryujinx.HLE.HOS.Services.Time private SharedMemoryStorage _timeSharedMemoryStorage; private int _timeSharedMemorySize; - private const uint SteadyClockContextOffset = 0x00; - private const uint LocalSystemClockContextOffset = 0x38; - private const uint NetworkSystemClockContextOffset = 0x80; + private const uint SteadyClockContextOffset = 0x00; + private const uint LocalSystemClockContextOffset = 0x38; + private const uint NetworkSystemClockContextOffset = 0x80; private const uint AutomaticCorrectionEnabledOffset = 0xC8; + private const uint ContinuousAdjustmentTimePointOffset = 0xD0; public void Initialize(Switch device, KSharedMemory sharedMemory, SharedMemoryStorage timeSharedMemoryStorage, int timeSharedMemorySize) { @@ -39,15 +40,7 @@ namespace Ryujinx.HLE.HOS.Services.Time public void SetupStandardSteadyClock(ITickSource tickSource, UInt128 clockSourceId, TimeSpanType currentTimePoint) { - TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency); - - SteadyClockContext context = new SteadyClockContext - { - InternalOffset = (ulong)(currentTimePoint.NanoSeconds - ticksTimeSpan.NanoSeconds), - ClockSourceId = clockSourceId - }; - - WriteObjectToSharedMemory(SteadyClockContextOffset, 4, context); + UpdateSteadyClock(tickSource, clockSourceId, currentTimePoint); } public void SetAutomaticCorrectionEnabled(bool isAutomaticCorrectionEnabled) @@ -58,10 +51,38 @@ namespace Ryujinx.HLE.HOS.Services.Time public void SetSteadyClockRawTimePoint(ITickSource tickSource, TimeSpanType currentTimePoint) { - SteadyClockContext context = ReadObjectFromSharedMemory<SteadyClockContext>(SteadyClockContextOffset, 4); - TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency); + SteadyClockContext context = ReadObjectFromSharedMemory<SteadyClockContext>(SteadyClockContextOffset, 4); - context.InternalOffset = (ulong)(currentTimePoint.NanoSeconds - ticksTimeSpan.NanoSeconds); + UpdateSteadyClock(tickSource, context.ClockSourceId, currentTimePoint); + } + + private void UpdateSteadyClock(ITickSource tickSource, UInt128 clockSourceId, TimeSpanType currentTimePoint) + { + TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency); + + ContinuousAdjustmentTimePoint adjustmentTimePoint = new ContinuousAdjustmentTimePoint + { + ClockOffset = (ulong)ticksTimeSpan.NanoSeconds, + Multiplier = 1, + DivisorLog2 = 0, + Context = new SystemClockContext + { + Offset = 0, + SteadyTimePoint = new SteadyClockTimePoint + { + ClockSourceId = clockSourceId, + TimePoint = 0 + } + } + }; + + WriteObjectToSharedMemory(ContinuousAdjustmentTimePointOffset, 4, adjustmentTimePoint); + + SteadyClockContext context = new SteadyClockContext + { + InternalOffset = (ulong)(currentTimePoint.NanoSeconds - ticksTimeSpan.NanoSeconds), + ClockSourceId = clockSourceId + }; WriteObjectToSharedMemory(SteadyClockContextOffset, 4, context); } |
