From ad5b792fcd125dbd6806d785ffdb458b3f0d5328 Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Mon, 13 Jan 2025 17:36:05 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E7=BB=84=E7=BB=87PersisdentP?= =?UTF-8?q?ath=E8=B7=AF=E5=BE=84,=E7=8E=B0=E5=9C=A8=E6=AF=8F=E4=B8=AA?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8=E6=A0=B8=E5=BF=83=E5=85=B7=E6=9C=89?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E7=9A=84=E9=9A=94=E7=A6=BB=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8DNes=E6=A0=B8=E5=BF=83,=E8=AF=BB=E5=8F=96SR?= =?UTF-8?q?AM=E5=A4=B1=E8=B4=A5=E7=9A=84bug(SRAM=E6=98=AFNES=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=E5=AD=98=E6=A1=A3=E6=95=B0=E6=8D=AE)=20=E6=9A=82?= =?UTF-8?q?=E6=97=B6=E7=A7=BB=E9=99=A4ROMDB,=E5=9B=A0=E4=B8=BA=E7=9B=AE?= =?UTF-8?q?=E5=89=8D=E5=8F=91=E7=8E=B0=E8=BF=99=E4=B8=AA=E6=98=A0=E5=B0=84?= =?UTF-8?q?=E5=B9=B6=E4=B8=8D=E5=87=86=E7=A1=AE=20=E5=B0=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Script/AppMain/App.cs | 16 ++++++++++++---- .../Script/AppMain/Manager/CacheManager.cs | 2 +- .../Script/AppMain/Manager/RomLib/RomFile.cs | 4 ++-- .../Script/AppMain/Manager/RomLib/RomLib.cs | 2 +- .../Script/AppMain/NesEmulator/CoreSupporter.cs | 12 ++++++------ .../Script/AppMain/NesEmulator/NesEmulator.cs | 5 ++++- .../Assets/VirtualNes.Core/APU.cs | 12 ++++++++++++ .../Assets/VirtualNes.Core/NES.cs | 12 ++++++++++-- .../Assets/VirtualNes.Core/ROM.cs | 10 +++++----- .../Supporter/EmulatorConfig/CfgPath.cs | 2 +- 10 files changed, 54 insertions(+), 23 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs index 2f394d93..acc9f9b0 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs @@ -49,11 +49,19 @@ namespace AxibugEmuOnline.Client.ClientCore #endregion + + static string s_persistentRoot = #if UNITY_PSP2 && !UNITY_EDITOR //PSV真机 - public static string PersistentDataPath => "ux0:data/AxibugEmu"; + "ux0:data/AxibugEmu"; #else - public static string PersistentDataPath => Application.persistentDataPath; + Application.persistentDataPath; #endif + public static string PersistentDataPath(RomPlatformType emuPlatform) + { + return s_persistentRoot + "/" + emuPlatform.ToString(); + } + public static string PersistentDataRoot() => s_persistentRoot; + public static void Init(bool isTest = false, string testSrvIP = "", bool bUseLocalWebApi = false, string mLocalWebApi = "") { log = new LogManager(OnLogOut); @@ -100,8 +108,8 @@ namespace AxibugEmuOnline.Client.ClientCore private static void PSP2Init() { //PSVita最好手动创建目录 - if (!Directory.Exists(PersistentDataPath)) - Directory.CreateDirectory(PersistentDataPath); + if (!Directory.Exists("ux0:data/AxibugEmu")) + Directory.CreateDirectory("ux0:data/AxibugEmu"); #if UNITY_PSP2 //创建PSV弹窗UI diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs index bb1cba26..2f96ef4f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs @@ -9,7 +9,7 @@ namespace AxibugEmuOnline.Client { public class CacheManager { - static readonly string CacheDirPath = $"{App.PersistentDataPath}/Caches"; + static readonly string CacheDirPath = $"{App.PersistentDataRoot()}/Caches"; static readonly string TextureCacheDirPath = $"{CacheDirPath}/Texture"; public void GetSpriteCache(string url, Action callback) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs index e1f9c464..a7c9b111 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs @@ -21,8 +21,8 @@ namespace AxibugEmuOnline.Client /// 指示该Rom文件的存放路径 public string LocalFilePath => IsUserRom ? - $"{App.PersistentDataPath}/UserRoms/{Platform}/{FileName}" : - $"{App.PersistentDataPath}/RemoteRoms/{Platform}/{FileName}"; + $"{App.PersistentDataPath(Platform)}/UserRoms/{FileName}" : + $"{App.PersistentDataPath(Platform)}/RemoteRoms/{FileName}"; /// 指示该Rom文件是否已下载完毕 public bool RomReady => hasLocalFile; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomLib.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomLib.cs index 3f9e4d3d..c361faa0 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomLib.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomLib.cs @@ -61,7 +61,7 @@ namespace AxibugEmuOnline.Client /// 清除所有下载的Rom文件 public void ClearRomFile() { - var path = $"{App.PersistentDataPath}/RemoteRoms/{m_platform}"; + var path = $"{App.PersistentDataPath(m_platform)}/RemoteRoms"; if (Directory.Exists(path)) Directory.Delete(path, true); } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/CoreSupporter.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/CoreSupporter.cs index f3b0cc93..45cbc277 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/CoreSupporter.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/CoreSupporter.cs @@ -48,7 +48,7 @@ namespace AxibugEmuOnline.Client public void SaveSRAMToFile(byte[] sramContent, string romName) { - string sramDirectoryPath = $"{App.PersistentDataPath}/sav"; + string sramDirectoryPath = $"{App.PersistentDataPath(AxibugProtobuf.RomPlatformType.Nes)}/{Config.path.szSavePath}"; Directory.CreateDirectory(sramDirectoryPath); romName = Path.GetFileNameWithoutExtension(romName); File.WriteAllBytes($"{sramDirectoryPath}/{romName}.sav", sramContent); @@ -56,7 +56,7 @@ namespace AxibugEmuOnline.Client public void SaveDISKToFile(byte[] diskFileContent, string romName) { - string diskFileDirectoryPath = $"{App.PersistentDataPath}/dsv"; + string diskFileDirectoryPath = $"{App.PersistentDataPath(AxibugProtobuf.RomPlatformType.Nes)}/dsv"; Directory.CreateDirectory(diskFileDirectoryPath); romName = Path.GetFileNameWithoutExtension(romName); File.WriteAllBytes($"{diskFileDirectoryPath}/{romName}.dsv", diskFileContent); @@ -65,14 +65,14 @@ namespace AxibugEmuOnline.Client public EmulatorConfig Config { get; private set; } = new EmulatorConfig(); public void PrepareDirectory(string directPath) { - Directory.CreateDirectory($"{App.PersistentDataPath}/{directPath}"); + Directory.CreateDirectory($"{App.PersistentDataPath(AxibugProtobuf.RomPlatformType.Nes)}/{directPath}"); } public void SaveFile(byte[] fileData, string directPath, string fileName) { PrepareDirectory(directPath); - var fileFullpath = $"{App.PersistentDataPath}/{directPath}/{fileName}"; + var fileFullpath = $"{App.PersistentDataPath(AxibugProtobuf.RomPlatformType.Nes)}/{directPath}/{fileName}"; File.WriteAllBytes(fileFullpath, fileData); } @@ -80,7 +80,8 @@ namespace AxibugEmuOnline.Client { try { - var data = File.ReadAllBytes($"{App.PersistentDataPath}/{directPath}/{fileName}"); + var path = $"{App.PersistentDataPath(AxibugProtobuf.RomPlatformType.Nes)}/{directPath}/{fileName}"; + var data = File.ReadAllBytes(path); if (data == null) return null; return new MemoryStream(data); } @@ -88,7 +89,6 @@ namespace AxibugEmuOnline.Client { return null; } - } public bool TryGetMapperNo(ROM rom, out int mapperNo) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs index 49ccc8ce..fcc1027f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs @@ -216,6 +216,9 @@ namespace AxibugEmuOnline.Client return ControllerMapper; } - public void Dispose() { } + public void Dispose() + { + StopGame(); + } } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/APU.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/APU.cs index 03ab741c..1c705271 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/APU.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/APU.cs @@ -319,6 +319,12 @@ namespace VirtualNes.Core return false; } + internal void QueueClear() + { + queue.Clear(); + exqueue.Clear(); + } + private void QueueFlush() { while (queue.wrptr != queue.rdptr) @@ -651,5 +657,11 @@ namespace VirtualNes.Core public int rdptr; public int wrptr; public QUEUEDATA[] data = new QUEUEDATA[8192]; + + public void Clear() + { + rdptr = 0;wrptr = 0; + data = new QUEUEDATA[8192]; + } } } diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs index e334a584..8c07370e 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs @@ -355,6 +355,7 @@ namespace VirtualNes.Core private void LoadDISK() { //todo : 磁碟机读取支持 + Debuger.LogError($"磁碟机尚未支持"); } private void LoadSRAM() @@ -1070,6 +1071,10 @@ namespace VirtualNes.Core public void Dispose() { + SaveSRAM(); + SaveDISK(); + SaveTurboFile(); + cpu?.Dispose(); ppu?.Dispose(); apu?.Dispose(); @@ -1081,7 +1086,7 @@ namespace VirtualNes.Core { int i; if (rom.IsNSF()) return; - if (rom.IsSAVERAM()) return; + if (!rom.IsSAVERAM()) return; for (i = 0; i < SAVERAM_SIZE; i++) { @@ -1841,10 +1846,11 @@ namespace VirtualNes.Core ); - cpu.SetDmaCycles(state.reg.cpureg.DMA_cycles); emul_cycles = state.reg.cpureg.emul_cycles; base_cycles = state.reg.cpureg.base_cycles; + cpu.SetDmaCycles(state.reg.cpureg.DMA_cycles); + // LOAD PPU STATE MMU.PPUREG[0] = state.reg.ppureg.reg0; MMU.PPUREG[1] = state.reg.ppureg.reg1; @@ -1857,6 +1863,8 @@ namespace VirtualNes.Core MMU.PPU56Toggle = state.reg.ppureg.toggle56; } + apu.QueueClear(); + //RAM STATE { // SAVE RAM STATE diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ROM.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ROM.cs index 53a10051..addb70d6 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ROM.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ROM.cs @@ -244,11 +244,11 @@ namespace VirtualNes.Core FileNameCheck(fname); - if (Supporter.S.TryGetMapperNo(this, out int mapperNo)) - { - Debuger.Log($"ROMDB Set Mapper #{mapper:000} to #{mapperNo:000}"); - mapper = mapperNo; - } + //if (Supporter.S.TryGetMapperNo(this, out int mapperNo)) + //{ + // Debuger.Log($"ROMDB Set Mapper #{mapper:000} to #{mapperNo:000}"); + // mapper = mapperNo; + //} RomPatch.DoPatch(ref crc, ref lpPRG, ref lpCHR, ref mapper, ref header); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/EmulatorConfig/CfgPath.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/EmulatorConfig/CfgPath.cs index b6c8e545..f417488f 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/EmulatorConfig/CfgPath.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/EmulatorConfig/CfgPath.cs @@ -12,7 +12,7 @@ public bool bIpsPath = true; public string szRomPath = "roms"; - public string szSavePath = "save"; + public string szSavePath = "sav"; public string szStatePath = "state"; public string szSnapshotPath = "snapshot"; public string szMoviePath = "movie";