From 0214f234a839e3ca3a6f3627fee784f885ae5541 Mon Sep 17 00:00:00 2001 From: SuuperW Date: Mon, 23 Dec 2019 10:02:51 -0600 Subject: [PATCH] MelonDS: Re-work sync settings a bit. --- .../Consoles/Nintendo/NDS/MelonDS.cs | 49 ++++++++++++------- .../Consoles/Nintendo/NDS/MelonDS_Settable.cs | 9 ++-- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs index b787161eba..e425773a91 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs @@ -71,7 +71,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS private static extern void FrameAdvance(short buttons, byte touchX, byte touchY); [CoreConstructor("NDS")] - public MelonDS(byte[] file, CoreComm comm) + public MelonDS(byte[] file, CoreComm comm, object settings, object syncsettings) { _serviceProvider = new BasicServiceProvider(this); ControllerDefinition = new ControllerDefinition(); @@ -100,23 +100,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS CoreComm = comm; CoreComm.NominalWidth = 256; CoreComm.NominalHeight = 192; - // MelonDS will look for bios + firmware files at specific locations - byte[] fwBytes; - fwBytes = CoreComm.CoreFileProvider.GetFirmware("NDS", "bios7", false); - if (fwBytes != null) - File.WriteAllBytes("melon/bios7.bin", fwBytes); - else - File.Delete("melon/bios7.bin"); - fwBytes = CoreComm.CoreFileProvider.GetFirmware("NDS", "bios9", false); - if (fwBytes != null) - File.WriteAllBytes("melon/bios9.bin", fwBytes); - else - File.Delete("melon/bios9.bin"); - fwBytes = CoreComm.CoreFileProvider.GetFirmware("NDS", "firmware", false); - if (fwBytes != null) - File.WriteAllBytes("melon/firmware.bin", fwBytes); - else - File.Delete("melon/firmware.bin"); + + SetUpFiles(syncsettings as MelonSyncSettings); if (!Init()) throw new Exception("Failed to init NDS."); @@ -126,5 +111,33 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS LoadROM(f, file.Length); } } + + /// + /// MelonDS expects bios and firmware files at a specific location. + /// + private void SetUpFiles(MelonSyncSettings ss) + { + byte[] fwBytes; + fwBytes = CoreComm.CoreFileProvider.GetFirmware("NDS", "bios7", false); + if (fwBytes != null) + File.WriteAllBytes("melon/bios7.bin", fwBytes); + else + File.Delete("melon/bios7.bin"); + + fwBytes = CoreComm.CoreFileProvider.GetFirmware("NDS", "bios9", false); + if (fwBytes != null) + File.WriteAllBytes("melon/bios9.bin", fwBytes); + else + File.Delete("melon/bios9.bin"); + + fwBytes = CoreComm.CoreFileProvider.GetFirmware("NDS", "firmware", false); + if (fwBytes != null) + { + ss.data.CopyTo(fwBytes, fwBytes.Length - 0x200); // NDS user settings are included in the firmware file. + File.WriteAllBytes("melon/firmware.bin", fwBytes); + } + else + File.Delete("melon/firmware.bin"); + } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Settable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Settable.cs index 939ba7a035..acf3f7081e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Settable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Settable.cs @@ -31,17 +31,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS public bool PutSyncSettings(MelonSyncSettings o) { - fixed (byte* ptr = o.data) - SetUserSettings(ptr); - + // At present, no sync settings can be modified without requiring a reboot. + // Also all sync settings are in the firmware file, which is modified upon core construction. + // So there's nothing to actually do here. return true; } [DllImport(dllPath)] private static extern bool GetUserSettings(byte* dst); - [DllImport(dllPath)] - private static extern bool SetUserSettings(byte* src); - [DllImport(dllPath)] private static extern int getUserSettingsLength(); static int userSettingsLength = getUserSettingsLength();