GB: add ability to load VBA saves with RTC, although the clock time itself is invariably trashed. seems to work with pokeymans gold

This commit is contained in:
goyuken 2014-12-29 22:56:46 +00:00
parent 09c6072082
commit 89864b0816
1 changed files with 30 additions and 2 deletions

View File

@ -498,10 +498,38 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
return new byte[0];
}
private byte[] FixRTC(byte[] data, int offset)
{
// length - offset is the start of the VBA-only data; so
// length - offset - 4 is the start of the RTC block
int idx = data.Length - offset - 4;
byte[] ret = new byte[idx + 4];
Buffer.BlockCopy(data, 0, ret, 0, idx);
data[idx] = (byte)zerotime;
data[idx + 1] = (byte)(zerotime >> 8);
data[idx + 2] = (byte)(zerotime >> 16);
data[idx + 3] = (byte)(zerotime >> 24);
return ret;
}
public void StoreSaveRam(byte[] data)
{
if (data.Length != LibGambatte.gambatte_savesavedatalength(GambatteState))
throw new ArgumentException("Size of saveram data does not match expected!");
int expected = LibGambatte.gambatte_savesavedatalength(GambatteState);
switch (data.Length - expected)
{
case 0:
break;
default:
throw new ArgumentException("Size of saveram data does not match expected!");
case 44:
data = FixRTC(data, 44);
break;
case 40:
data = FixRTC(data, 40);
break;
}
LibGambatte.gambatte_loadsavedata(GambatteState, data);
}