diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 7665af6360..561062e37d 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -1393,7 +1393,7 @@ namespace BizHawk.Client.EmuHawk // GBA meteor core might not know how big the saveram ought to be, so just send it the whole file // GBA vba-next core will try to eat anything, regardless of size - if (Global.Emulator is GBA || Global.Emulator is VBANext) + if (Global.Emulator is GBA || Global.Emulator is VBANext || Global.Emulator is MGBAHawk) { sram = File.ReadAllBytes(PathManager.SaveRamPath(Global.Game)); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/LibmGBA.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/LibmGBA.cs index 1c4b677a1b..f2c7db00ea 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/LibmGBA.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/LibmGBA.cs @@ -42,5 +42,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA [DllImport(dll, CallingConvention = cc)] public static extern void BizGetMemoryAreas(IntPtr ctx, [Out]MemoryAreas dst); + + [DllImport(dll, CallingConvention = cc)] + public static extern int BizGetSaveRamSize(IntPtr ctx); + [DllImport(dll, CallingConvention = cc)] + public static extern void BizGetSaveRam(IntPtr ctx, byte[] dest); + [DllImport(dll, CallingConvention = cc)] + public static extern void BizPutSaveRam(IntPtr ctx, byte[] src); } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs index c62861a40c..3e34c18320 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs @@ -9,7 +9,7 @@ using System.Runtime.InteropServices; namespace BizHawk.Emulation.Cores.Nintendo.GBA { [CoreAttributes("mGBA", "endrift", true, false, "NOT DONE", "NOT DONE", false)] - public class MGBAHawk : IEmulator, IVideoProvider, ISyncSoundProvider, IGBAGPUViewable + public class MGBAHawk : IEmulator, IVideoProvider, ISyncSoundProvider, IGBAGPUViewable, ISaveRam { IntPtr core; @@ -167,5 +167,47 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA public void SetScanlineCallback(Action callback, int scanline) { } + + #region ISaveRam + + public byte[] CloneSaveRam() + { + byte[] ret = new byte[LibmGBA.BizGetSaveRamSize(core)]; + if (ret.Length > 0) + { + LibmGBA.BizGetSaveRam(core, ret); + return ret; + } + else + { + return null; + } + } + + public void StoreSaveRam(byte[] data) + { + int len = LibmGBA.BizGetSaveRamSize(core); + if (len > data.Length) + { + byte[] _tmp = new byte[len]; + Array.Copy(data, _tmp, data.Length); + for (int i = data.Length; i < len; i++) + _tmp[i] = 0xff; + data = _tmp; + } + else if (len < data.Length) + { + // we could continue from this, but we don't expect it + throw new InvalidOperationException("Saveram will be truncated!"); + } + LibmGBA.BizPutSaveRam(core, data); + } + + public bool SaveRamModified + { + get { return LibmGBA.BizGetSaveRamSize(core) > 0; } + } + + #endregion } }