From fc4b7cba2c083b3920f2d74e0cb4b08cf7a5a278 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 4 Jan 2023 20:01:44 -0300 Subject: Make PPTC state non-static (#4157) * Make PPTC state non-static * DiskCacheLoadState can be null --- Ryujinx.Cpu/Jit/JitCpuContext.cs | 12 ++++++++++ Ryujinx.Cpu/Jit/JitDiskCacheLoadState.cs | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 Ryujinx.Cpu/Jit/JitDiskCacheLoadState.cs (limited to 'Ryujinx.Cpu/Jit') diff --git a/Ryujinx.Cpu/Jit/JitCpuContext.cs b/Ryujinx.Cpu/Jit/JitCpuContext.cs index d6892ea7..02465a0b 100644 --- a/Ryujinx.Cpu/Jit/JitCpuContext.cs +++ b/Ryujinx.Cpu/Jit/JitCpuContext.cs @@ -37,5 +37,17 @@ namespace Ryujinx.Cpu.Jit { _translator.InvalidateJitCacheRegion(address, size); } + + /// + public IDiskCacheLoadState LoadDiskCache(string titleIdText, string displayVersion, bool enabled) + { + return new JitDiskCacheLoadState(_translator.LoadDiskCache(titleIdText, displayVersion, enabled)); + } + + /// + public void PrepareCodeRange(ulong address, ulong size) + { + _translator.PrepareCodeRange(address, size); + } } } diff --git a/Ryujinx.Cpu/Jit/JitDiskCacheLoadState.cs b/Ryujinx.Cpu/Jit/JitDiskCacheLoadState.cs new file mode 100644 index 00000000..7a4b670b --- /dev/null +++ b/Ryujinx.Cpu/Jit/JitDiskCacheLoadState.cs @@ -0,0 +1,38 @@ +using ARMeilleure.Translation.PTC; +using System; + +namespace Ryujinx.Cpu.Jit +{ + public class JitDiskCacheLoadState : IDiskCacheLoadState + { + /// + public event Action StateChanged; + + private readonly IPtcLoadState _loadState; + + public JitDiskCacheLoadState(IPtcLoadState loadState) + { + loadState.PtcStateChanged += LoadStateChanged; + _loadState = loadState; + } + + private void LoadStateChanged(PtcLoadingState newState, int current, int total) + { + LoadState state = newState switch + { + PtcLoadingState.Start => LoadState.Unloaded, + PtcLoadingState.Loading => LoadState.Loading, + PtcLoadingState.Loaded => LoadState.Loaded, + _ => throw new ArgumentException($"Invalid load state \"{newState}\".") + }; + + StateChanged?.Invoke(state, current, total); + } + + /// + public void Cancel() + { + _loadState.Continue(); + } + } +} \ No newline at end of file -- cgit v1.2.3