重新组织PersisdentPath路径,现在每个模拟器核心具有单独的隔离路径

修复Nes核心,读取SRAM失败的bug(SRAM是NES原生存档数据)
暂时移除ROMDB,因为目前发现这个映射并不准确
将
This commit is contained in:
ALIENJACK\alien 2025-01-13 17:36:05 +08:00
parent b6e6e750d4
commit ad5b792fcd
10 changed files with 54 additions and 23 deletions

View File

@ -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

View File

@ -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<Sprite, string> callback)

View File

@ -21,8 +21,8 @@ namespace AxibugEmuOnline.Client
/// <summary> 指示该Rom文件的存放路径 </summary>
public string LocalFilePath =>
IsUserRom ?
$"{App.PersistentDataPath}/UserRoms/{Platform}/{FileName}" :
$"{App.PersistentDataPath}/RemoteRoms/{Platform}/{FileName}";
$"{App.PersistentDataPath(Platform)}/UserRoms/{FileName}" :
$"{App.PersistentDataPath(Platform)}/RemoteRoms/{FileName}";
/// <summary> 指示该Rom文件是否已下载完毕 </summary>
public bool RomReady => hasLocalFile;

View File

@ -61,7 +61,7 @@ namespace AxibugEmuOnline.Client
/// <summary> 清除所有下载的Rom文件 </summary>
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);
}

View File

@ -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)

View File

@ -216,6 +216,9 @@ namespace AxibugEmuOnline.Client
return ControllerMapper;
}
public void Dispose() { }
public void Dispose()
{
StopGame();
}
}
}

View File

@ -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];
}
}
}

View File

@ -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

View File

@ -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);

View File

@ -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";