implement ClearSaveRam in gambatte core, and fix a bug with using memory domains before any frames have been run

This commit is contained in:
goyuken 2012-09-14 21:29:35 +00:00
parent 17567b4952
commit 4101efb92d
2 changed files with 20 additions and 4 deletions

View File

@ -161,6 +161,22 @@ namespace BizHawk.Emulation.Consoles.GB
LibGambatte.gambatte_loadsavedata(GambatteState, data); LibGambatte.gambatte_loadsavedata(GambatteState, data);
} }
/// <summary>
/// reset cart save ram, if any, to initial state
/// </summary>
public void ClearSaveRam()
{
int length = LibGambatte.gambatte_savesavedatalength(GambatteState);
if (length == 0)
return;
byte[] clear = new byte[length];
for (int i = 0; i < clear.Length; i++)
clear[i] = 0xff; // this exactly matches what gambatte core does
StoreSaveRam(clear);
}
public bool SaveRamModified public bool SaveRamModified
{ {
@ -278,9 +294,10 @@ namespace BizHawk.Emulation.Consoles.GB
CachedMemory = new byte[length]; CachedMemory = new byte[length];
writeneeded = false; writeneeded = false;
readneeded = false; // needs to be true in case a read is attempted before the first frame advance
readneeded = true;
} }
bool readneeded; bool readneeded;
bool writeneeded; bool writeneeded;

View File

@ -3436,8 +3436,7 @@ namespace BizHawk.MultiClient
if (Global.Emulator is LibsnesCore) if (Global.Emulator is LibsnesCore)
((LibsnesCore)Global.Emulator).StoreSaveRam(sram); ((LibsnesCore)Global.Emulator).StoreSaveRam(sram);
else if (Global.Emulator is Gameboy) else if (Global.Emulator is Gameboy)
// todo: i don't like this at all. there's no guarantee that a 0-filled sram is even an accurate clear? ((Gameboy)Global.Emulator).ClearSaveRam();
throw new Exception("Please fix me!");
else else
Array.Copy(sram, Global.Emulator.ReadSaveRam, Global.Emulator.ReadSaveRam.Length); Array.Copy(sram, Global.Emulator.ReadSaveRam, Global.Emulator.ReadSaveRam.Length);
} }