mgbahawk: savestates

This commit is contained in:
nattthebear 2016-10-22 18:09:28 -04:00
parent 029a76fed5
commit b8b9201604
2 changed files with 6 additions and 8 deletions

View File

@ -84,7 +84,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
[DllImport(dll, CallingConvention = cc)] [DllImport(dll, CallingConvention = cc)]
public static extern int BizGetStateMaxSize(IntPtr ctx); public static extern int BizGetStateMaxSize(IntPtr ctx);
[DllImport(dll, CallingConvention = cc)] [DllImport(dll, CallingConvention = cc)]
public static extern int BizGetState(IntPtr ctx, byte[] dest, int maxsize); public static extern bool BizGetState(IntPtr ctx, byte[] dest, int size);
[DllImport(dll, CallingConvention = cc)] [DllImport(dll, CallingConvention = cc)]
public static extern bool BizPutState(IntPtr ctx, byte[] src, int size); public static extern bool BizPutState(IntPtr ctx, byte[] src, int size);

View File

@ -396,11 +396,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
public void SaveStateBinary(BinaryWriter writer) public void SaveStateBinary(BinaryWriter writer)
{ {
int size = LibmGBA.BizGetState(_core, _savebuff, _savebuff.Length); if (!LibmGBA.BizGetState(_core, _savebuff, _savebuff.Length))
if (size < 0)
throw new InvalidOperationException("Core failed to save!"); throw new InvalidOperationException("Core failed to save!");
writer.Write(size); writer.Write(_savebuff.Length);
writer.Write(_savebuff, 0, size); writer.Write(_savebuff, 0, _savebuff.Length);
// other variables // other variables
writer.Write(IsLagFrame); writer.Write(IsLagFrame);
@ -411,10 +410,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
public void LoadStateBinary(BinaryReader reader) public void LoadStateBinary(BinaryReader reader)
{ {
int length = reader.ReadInt32(); int length = reader.ReadInt32();
if (length > _savebuff.Length) if (length != _savebuff.Length)
{ {
_savebuff = new byte[length]; throw new InvalidOperationException("Unexpected state size!");
_savebuff2 = new byte[length + 13];
} }
reader.Read(_savebuff, 0, length); reader.Read(_savebuff, 0, length);
if (!LibmGBA.BizPutState(_core, _savebuff, length)) if (!LibmGBA.BizPutState(_core, _savebuff, length))