BizHawk/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs

113 lines
2.4 KiB
C#
Raw Normal View History

2015-03-21 21:45:12 +00:00
using BizHawk.Emulation.Common;
using System.IO;
2015-05-18 00:14:00 +00:00
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
2015-03-21 21:45:12 +00:00
namespace BizHawk.Emulation.Cores.Computers.AppleII
{
public partial class AppleII : IStatable
{
public bool BinarySaveStatesPreferred { get { return false; } }
2015-03-21 21:45:12 +00:00
2015-05-18 00:14:00 +00:00
private class OtherData
{
public int Frame;
public int LagCount;
public bool IsLagFrame;
public int CurrentDisk;
public JObject Core;
}
private JsonSerializer ser = new JsonSerializer();
2015-03-21 21:45:12 +00:00
[FeatureNotImplemented]
public void SaveStateText(TextWriter writer)
{
2015-05-18 00:14:00 +00:00
var w = new JTokenWriter();
_machine.Serialize(w);
2015-03-21 21:45:12 +00:00
2015-05-18 00:14:00 +00:00
var o = new OtherData
{
Frame = Frame,
LagCount = LagCount,
IsLagFrame = IsLagFrame,
CurrentDisk = CurrentDisk,
Core = (JObject)w.Token,
};
var jw = new JsonTextWriter(writer) { Formatting = Newtonsoft.Json.Formatting.Indented };
ser.Serialize(jw, o);
2015-03-21 21:45:12 +00:00
}
public void LoadStateText(TextReader reader)
{
2015-05-18 00:14:00 +00:00
var o = (OtherData)ser.Deserialize(reader, typeof(OtherData));
Frame = o.Frame;
LagCount = o.LagCount;
IsLagFrame = o.IsLagFrame;
CurrentDisk = o.CurrentDisk;
2015-03-21 21:45:12 +00:00
2015-05-18 00:14:00 +00:00
var r = new JTokenReader(o.Core);
try
{
_machine = Jellyfish.Virtu.Machine.Deserialize(r);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
throw;
}
// should not be needed.
// InitDisk();
2015-03-21 21:45:12 +00:00
}
public void SaveStateBinary(BinaryWriter writer)
{
2015-05-18 00:14:00 +00:00
/*
writer.Write(Frame);
writer.Write(LagCount);
writer.Write(IsLagFrame);
writer.Write(CurrentDisk);
2015-03-21 21:45:12 +00:00
_machine.SaveState(writer);
2015-05-18 00:14:00 +00:00
*/
2015-03-21 21:45:12 +00:00
}
public void LoadStateBinary(BinaryReader reader)
{
2015-05-18 00:14:00 +00:00
/*
Frame = reader.ReadInt32();
LagCount = reader.ReadInt32();
IsLagFrame = reader.ReadBoolean();
CurrentDisk = reader.ReadInt32();
InitDisk();
2015-03-21 21:45:12 +00:00
_machine.LoadState(reader);
2015-05-18 00:14:00 +00:00
*/
2015-03-21 21:45:12 +00:00
}
public byte[] SaveStateBinary()
{
2015-05-18 00:14:00 +00:00
return new byte[16];
2015-03-21 21:45:12 +00:00
if (_stateBuffer == null)
{
var stream = new MemoryStream();
var writer = new BinaryWriter(stream);
SaveStateBinary(writer);
_stateBuffer = stream.ToArray();
writer.Close();
return _stateBuffer;
}
else
{
var stream = new MemoryStream(_stateBuffer);
var writer = new BinaryWriter(stream);
SaveStateBinary(writer);
writer.Close();
return _stateBuffer;
}
}
private byte[] _stateBuffer;
}
}