saverams in mgba, maybe

This commit is contained in:
goyuken 2015-06-06 12:49:31 +00:00
parent 6db0d41aa6
commit 4a5f87387c
3 changed files with 51 additions and 2 deletions

View File

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

View File

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

View File

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