summaryrefslogtreecommitdiff
path: root/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs')
-rw-r--r--src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs72
1 files changed, 71 insertions, 1 deletions
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
{
/// <summary>
/// Provides an implementation of a Zilog Z80 processor.
/// </summary>
- 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
}
}