dual gameboy: with the savestates being recently obsoleted, take this opportunity to make actual text savestates
This commit is contained in:
parent
56afd7c482
commit
047f148f20
|
@ -527,10 +527,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
|||
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
|
||||
class TextStateData
|
||||
internal class TextStateData
|
||||
{
|
||||
public int Frame;
|
||||
public int LagCount;
|
||||
|
@ -539,7 +539,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
|||
public uint frameOverflow;
|
||||
}
|
||||
|
||||
public void SaveStateText(System.IO.TextWriter writer)
|
||||
internal TextState<TextStateData> SaveState()
|
||||
{
|
||||
var s = new TextState<TextStateData>();
|
||||
s.Prepare();
|
||||
|
@ -550,7 +550,24 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
|||
s.ExtraData.Frame = Frame;
|
||||
s.ExtraData.frameOverflow = frameOverflow;
|
||||
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);
|
||||
// write extra copy of stuff we don't use
|
||||
writer.WriteLine();
|
||||
|
@ -560,14 +577,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
|||
public void LoadStateText(System.IO.TextReader reader)
|
||||
{
|
||||
var s = (TextState<TextStateData>)ser.Deserialize(reader, typeof(TextState<TextStateData>));
|
||||
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;
|
||||
LoadState(s);
|
||||
}
|
||||
|
||||
public void SaveStateBinary(System.IO.BinaryWriter writer)
|
||||
|
|
|
@ -7,6 +7,8 @@ using BizHawk.Common.BufferExtensions;
|
|||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Emulation.Cores.Nintendo.SNES;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
||||
{
|
||||
[CoreAttributes(
|
||||
|
@ -291,20 +293,61 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
|||
|
||||
#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)
|
||||
{
|
||||
var temp = SaveStateBinary();
|
||||
temp.SaveAsHex(writer);
|
||||
var s = new DGBSerialized
|
||||
{
|
||||
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
|
||||
// is this needed anymore??
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("Frame {0}", Frame);
|
||||
}
|
||||
|
||||
public void LoadStateText(TextReader reader)
|
||||
{
|
||||
string hex = reader.ReadLine();
|
||||
byte[] state = new byte[hex.Length / 2];
|
||||
state.ReadFromHex(hex);
|
||||
LoadStateBinary(new BinaryReader(new MemoryStream(state)));
|
||||
var s = (DGBSerialized)ser.Deserialize(reader, typeof(DGBSerialized));
|
||||
L.LoadState(s.L);
|
||||
R.LoadState(s.R);
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue