dual gameboy: with the savestates being recently obsoleted, take this opportunity to make actual text savestates

This commit is contained in:
goyuken 2014-08-18 17:21:17 +00:00
parent 56afd7c482
commit 047f148f20
2 changed files with 70 additions and 17 deletions

View File

@ -527,10 +527,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
savebuff2 = new byte[savebuff.Length + 4 + 21]; savebuff2 = new byte[savebuff.Length + 4 + 21];
} }
JsonSerializer ser = new JsonSerializer() { Formatting = Formatting.Indented }; JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
// other data in the text state besides core // other data in the text state besides core
class TextStateData internal class TextStateData
{ {
public int Frame; public int Frame;
public int LagCount; public int LagCount;
@ -539,7 +539,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
public uint frameOverflow; public uint frameOverflow;
} }
public void SaveStateText(System.IO.TextWriter writer) internal TextState<TextStateData> SaveState()
{ {
var s = new TextState<TextStateData>(); var s = new TextState<TextStateData>();
s.Prepare(); s.Prepare();
@ -550,7 +550,24 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
s.ExtraData.Frame = Frame; s.ExtraData.Frame = Frame;
s.ExtraData.frameOverflow = frameOverflow; s.ExtraData.frameOverflow = frameOverflow;
s.ExtraData._cycleCount = _cycleCount; s.ExtraData._cycleCount = _cycleCount;
return s;
}
internal void LoadState(TextState<TextStateData> s)
{
s.Prepare();
var ff = s.GetFunctionPointersLoad();
LibGambatte.gambatte_newstateload_ex(GambatteState, ref ff);
IsLagFrame = s.ExtraData.IsLagFrame;
LagCount = s.ExtraData.LagCount;
Frame = s.ExtraData.Frame;
frameOverflow = s.ExtraData.frameOverflow;
_cycleCount = s.ExtraData._cycleCount;
}
public void SaveStateText(System.IO.TextWriter writer)
{
var s = SaveState();
ser.Serialize(writer, s); ser.Serialize(writer, s);
// write extra copy of stuff we don't use // write extra copy of stuff we don't use
writer.WriteLine(); writer.WriteLine();
@ -560,14 +577,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
public void LoadStateText(System.IO.TextReader reader) public void LoadStateText(System.IO.TextReader reader)
{ {
var s = (TextState<TextStateData>)ser.Deserialize(reader, typeof(TextState<TextStateData>)); var s = (TextState<TextStateData>)ser.Deserialize(reader, typeof(TextState<TextStateData>));
s.Prepare(); LoadState(s);
var ff = s.GetFunctionPointersLoad();
LibGambatte.gambatte_newstateload_ex(GambatteState, ref ff);
IsLagFrame = s.ExtraData.IsLagFrame;
LagCount = s.ExtraData.LagCount;
Frame = s.ExtraData.Frame;
frameOverflow = s.ExtraData.frameOverflow;
_cycleCount = s.ExtraData._cycleCount;
} }
public void SaveStateBinary(System.IO.BinaryWriter writer) public void SaveStateBinary(System.IO.BinaryWriter writer)

View File

@ -7,6 +7,8 @@ using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.SNES; using BizHawk.Emulation.Cores.Nintendo.SNES;
using Newtonsoft.Json;
namespace BizHawk.Emulation.Cores.Nintendo.Gameboy namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
{ {
[CoreAttributes( [CoreAttributes(
@ -291,20 +293,61 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
#region savestates #region savestates
JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
private class DGBSerialized
{
public TextState<Gameboy.TextStateData> L;
public TextState<Gameboy.TextStateData> R;
// other data
public bool IsLagFrame;
public int LagCount;
public int Frame;
public int overflowL;
public int overflowR;
public int LatchL;
public int LatchR;
public bool cableconnected;
public bool cablediscosignal;
}
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
var temp = SaveStateBinary(); var s = new DGBSerialized
temp.SaveAsHex(writer); {
L = L.SaveState(),
R = R.SaveState(),
IsLagFrame = IsLagFrame,
LagCount = LagCount,
Frame = Frame,
overflowL = overflowL,
overflowR = overflowR,
LatchL = LatchL,
LatchR = LatchR,
cableconnected = cableconnected,
cablediscosignal = cablediscosignal
};
ser.Serialize(writer, s);
// write extra copy of stuff we don't use // write extra copy of stuff we don't use
// is this needed anymore??
writer.WriteLine();
writer.WriteLine("Frame {0}", Frame); writer.WriteLine("Frame {0}", Frame);
} }
public void LoadStateText(TextReader reader) public void LoadStateText(TextReader reader)
{ {
string hex = reader.ReadLine(); var s = (DGBSerialized)ser.Deserialize(reader, typeof(DGBSerialized));
byte[] state = new byte[hex.Length / 2]; L.LoadState(s.L);
state.ReadFromHex(hex); R.LoadState(s.R);
LoadStateBinary(new BinaryReader(new MemoryStream(state))); IsLagFrame = s.IsLagFrame;
LagCount = s.LagCount;
Frame = s.Frame;
overflowL = s.overflowL;
overflowR = s.overflowR;
LatchL = s.LatchL;
LatchR = s.LatchR;
cableconnected = s.cableconnected;
cablediscosignal = s.cablediscosignal;
} }
public void SaveStateBinary(BinaryWriter writer) public void SaveStateBinary(BinaryWriter writer)