From 11d53755f5fcb9158f4fe3abaa3c0b480a461fe7 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sat, 23 Jun 2012 22:59:38 +0000 Subject: Added classes for save/load of emulation state. Added to Z80 CPU. --- src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs | 72 ++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) (limited to 'src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs') diff --git a/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs b/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs index d575476..a802142 100644 --- a/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs +++ b/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs @@ -22,13 +22,14 @@ // Any introduced bugs in that code are mine, and not the original authors. // using System; +using System.IO; namespace Noddybox.Emulation.EightBit.Z80 { /// /// Provides an implementation of a Zilog Z80 processor. /// - public partial class Z80Cpu : ICpu + public partial class Z80Cpu : ICpu, IEmulationState { #region Private types @@ -608,5 +609,74 @@ namespace Noddybox.Emulation.EightBit.Z80 } #endregion + + #region IEmulationState Members + + public int Version + { + get { return 1; } + } + + public void SaveState(EmulationStateSaveManager manager) + { + BinaryWriter str = manager.Stream; + + str.Write(A); + str.Write((int)F); + str.Write(BC.reg); + str.Write(DE.reg); + str.Write(HL.reg); + str.Write(IX.reg); + str.Write(IY.reg); + str.Write(PC); + str.Write(SP); + str.Write(AF_.reg); + str.Write(BC_.reg); + str.Write(DE_.reg); + str.Write(HL_.reg); + str.Write(I); + str.Write(R); + str.Write(IFF1); + str.Write(IFF2); + str.Write(raise); + str.Write(nmi); + str.Write(devbyte); + str.Write(IM); + str.Write(HALT); + str.Write(shift); + str.Write(executedInstructions); + } + + public void LoadState(EmulationStateLoadManager manager) + { + BinaryReader str = manager.Stream; + + A = str.ReadByte(); + F = (Z80Flags)str.ReadInt32(); + BC.reg = str.ReadUInt16(); + DE.reg = str.ReadUInt16(); + HL.reg = str.ReadUInt16(); + IX.reg = str.ReadUInt16(); + IY.reg = str.ReadUInt16(); + PC = str.ReadUInt16(); + SP = str.ReadUInt16(); + AF_.reg = str.ReadUInt16(); + BC_.reg = str.ReadUInt16(); + DE_.reg = str.ReadUInt16(); + HL_.reg = str.ReadUInt16(); + I = str.ReadByte(); + R = str.ReadByte(); + IFF1 = str.ReadBoolean(); + IFF2 = str.ReadBoolean(); + raise = str.ReadBoolean(); + nmi = str.ReadBoolean(); + devbyte = str.ReadByte(); + IM = str.ReadByte(); + HALT = str.ReadBoolean(); + shift = str.ReadInt32(); + executedInstructions = str.ReadUInt32(); + } + + #endregion } } -- cgit v1.2.3