Apple II - wire up savestates (binary only, for now)
This commit is contained in:
parent
159f1d9da2
commit
fccf9f06a9
|
@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
|
|||
isPorted: true,
|
||||
isReleased: false
|
||||
)]
|
||||
public partial class AppleII : IEmulator
|
||||
public partial class AppleII : IEmulator, IStatable
|
||||
{
|
||||
[CoreConstructor("AppleII")]
|
||||
public AppleII(CoreComm comm, GameInfo game, byte[] rom, object Settings)
|
||||
|
@ -250,6 +250,56 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IStatable
|
||||
|
||||
public bool BinarySaveStatesPreferred { get { return false; } }
|
||||
|
||||
[FeatureNotImplemented]
|
||||
public void SaveStateText(TextWriter writer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[FeatureNotImplemented]
|
||||
public void LoadStateText(TextReader reader)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void SaveStateBinary(BinaryWriter writer)
|
||||
{
|
||||
_machine.SaveState(writer);
|
||||
}
|
||||
|
||||
public void LoadStateBinary(BinaryReader reader)
|
||||
{
|
||||
_machine.LoadState(reader);
|
||||
}
|
||||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
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;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,6 +204,23 @@ namespace Jellyfish.Virtu
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: don't copy paste
|
||||
public void LoadState(BinaryReader reader)
|
||||
{
|
||||
string signature = reader.ReadString();
|
||||
var version = new Version(reader.ReadString());
|
||||
if ((signature != StateSignature) || (version != new Version(Machine.Version))) // avoid state version mismatch (for now)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
foreach (var component in Components)
|
||||
{
|
||||
_debugService.WriteMessage("Loading machine '{0}'", component.GetType().Name);
|
||||
component.LoadState(reader, version);
|
||||
//_debugService.WriteMessage("Loaded machine '{0}'", component.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadState(Stream stream)
|
||||
{
|
||||
using (var reader = new BinaryReader(stream))
|
||||
|
@ -228,6 +245,18 @@ namespace Jellyfish.Virtu
|
|||
_storageService.Save(Machine.StateFileName, stream => SaveState(stream));
|
||||
}
|
||||
|
||||
public void SaveState(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(StateSignature);
|
||||
writer.Write(Machine.Version);
|
||||
foreach (var component in Components)
|
||||
{
|
||||
_debugService.WriteMessage("Saving machine '{0}'", component.GetType().Name);
|
||||
component.SaveState(writer);
|
||||
//_debugService.WriteMessage("Saved machine '{0}'", component.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveState(Stream stream)
|
||||
{
|
||||
using (var writer = new BinaryWriter(stream))
|
||||
|
|
Loading…
Reference in New Issue