From 89864b08162c32f90373d660c87078e9a197de70 Mon Sep 17 00:00:00 2001 From: goyuken Date: Mon, 29 Dec 2014 22:56:46 +0000 Subject: [PATCH] GB: add ability to load VBA saves with RTC, although the clock time itself is invariably trashed. seems to work with pokeymans gold --- .../Consoles/Nintendo/Gameboy/Gambatte.cs | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs index d93c7170bd..c5c19832be 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -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); }