support reading the old vba-next savwerams in the mgba core

This commit is contained in:
goyuken 2015-06-06 17:42:47 +00:00
parent f5c8bece3a
commit f57c3b86f0
1 changed files with 25 additions and 0 deletions

View File

@ -189,8 +189,33 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
}
}
private static byte[] LegacyFix(byte[] saveram)
{
// at one point vbanext-hawk had a special saveram format which we want to load.
var br = new BinaryReader(new MemoryStream(saveram, false));
br.ReadBytes(8); // header;
int flashSize = br.ReadInt32();
int eepromsize = br.ReadInt32();
byte[] flash = br.ReadBytes(flashSize);
byte[] eeprom = br.ReadBytes(eepromsize);
if (flash.Length == 0)
return eeprom;
else if (eeprom.Length == 0)
return flash;
else
{
// well, isn't this a sticky situation!
return flash; // woops
}
}
public void StoreSaveRam(byte[] data)
{
if (data.Take(8).SequenceEqual(Encoding.ASCII.GetBytes("GBABATT\0")))
{
data = LegacyFix(data);
}
int len = LibmGBA.BizGetSaveRamSize(core);
if (len > data.Length)
{