summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2012-02-28 23:22:49 +0000
committerIan C <ianc@noddybox.co.uk>2012-02-28 23:22:49 +0000
commita937b96b20e61cd0770119da3327c15575779793 (patch)
tree7802d59939ba5f6b9f15923fb3cd5a27ae8c3b83
parent7c9c5af6d495d6ac60b5cb59b8e0cd9a17318e9a (diff)
Added ability to set/get the state of Z80 registers.
-rw-r--r--native/Noddybox.Emulation.EightBit.Z80.Test/Program.cs1
-rw-r--r--native/Noddybox.Emulation.EightBit.Z80.Test/TestMachine.cs16
-rw-r--r--src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs163
3 files changed, 175 insertions, 5 deletions
diff --git a/native/Noddybox.Emulation.EightBit.Z80.Test/Program.cs b/native/Noddybox.Emulation.EightBit.Z80.Test/Program.cs
index 5e708ea..0f2a19d 100644
--- a/native/Noddybox.Emulation.EightBit.Z80.Test/Program.cs
+++ b/native/Noddybox.Emulation.EightBit.Z80.Test/Program.cs
@@ -30,6 +30,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Test
{
static void Main(string[] args)
{
+ new TestMachine("Test", null, null);
}
}
}
diff --git a/native/Noddybox.Emulation.EightBit.Z80.Test/TestMachine.cs b/native/Noddybox.Emulation.EightBit.Z80.Test/TestMachine.cs
index 4b74d9f..09e868b 100644
--- a/native/Noddybox.Emulation.EightBit.Z80.Test/TestMachine.cs
+++ b/native/Noddybox.Emulation.EightBit.Z80.Test/TestMachine.cs
@@ -28,28 +28,40 @@ namespace Noddybox.Emulation.EightBit.Z80.Test
private readonly Z80Cpu z80 = new Z80Cpu();
private readonly Clock clock = new Clock(100000, 50);
+ private void Output(ConsoleColor pen, ConsoleColor paper, string format, params object[] p)
+ {
+ Console.ForegroundColor = pen;
+ Console.BackgroundColor = paper;
+ Console.WriteLine(format, p);
+ Console.ResetColor();
+ }
+
byte IMemory.Read(ushort address)
{
+ Output(ConsoleColor.Green, ConsoleColor.Black, "Reading {0:X2} from {1:X4}", mem[address], address);
return mem[address];
}
void IMemory.Write(ushort address, byte value)
{
+ Output(ConsoleColor.Red, ConsoleColor.Black, "Writing {0:X2} to {1:X4}", value, address);
mem[address] = value;
}
byte IDevice.Read(ushort device)
{
+ Output(ConsoleColor.Green, ConsoleColor.DarkGray, "Reading 00 from device {1:X4}", device);
return 0;
}
void IDevice.Write(ushort device, byte value)
{
- // Nothing
+ Output(ConsoleColor.Red, ConsoleColor.DarkGray, "Writing {0:X2} to device {1:X4}", value, device);
}
- public TestMachine()
+ public TestMachine(string name, List<string> input, List<string> expected)
{
+ Output(ConsoleColor.Black, ConsoleColor.White, "Running test {0}", name);
}
}
}
diff --git a/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs b/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
index f937ea9..676a1b1 100644
--- a/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
+++ b/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
@@ -72,14 +72,14 @@ namespace Noddybox.Emulation.EightBit.Z80
// Auxilliary registers and flags
//
- private ushort I;
+ private byte I;
private byte R;
private bool IFF1;
private bool IFF2;
private bool raise;
private bool nmi;
private byte devbyte;
- private int IM;
+ private byte IM;
private bool HALT;
private int shift;
@@ -126,7 +126,7 @@ namespace Noddybox.Emulation.EightBit.Z80
case 2:
PUSH(PC);
- PC = (ushort)((I << 8) + devbyte);
+ PC = (ushort)(((ushort)I << 8) + devbyte);
break;
default:
@@ -287,6 +287,163 @@ namespace Noddybox.Emulation.EightBit.Z80
#endregion
+ #region Public members
+
+ /// <summary>
+ /// Set/get the current state of the accumulator.
+ /// </summary>
+ public byte Acummulator
+ {
+ get {return A;}
+ set {A = value;}
+ }
+
+ /// <summary>
+ /// Set/get the current state of the flag register.
+ /// </summary>
+ public Z80Flags StatusFlags
+ {
+ get {return F;}
+ set {F = value;}
+ }
+
+ /// <summary>
+ /// The current state of the BC register pair.
+ /// </summary>
+ public Register16 BC_Register
+ {
+ get { return BC; }
+ set { BC = value; }
+ }
+
+ /// <summary>
+ /// The current state of the DE register pair.
+ /// </summary>
+ public Register16 DE_Register
+ {
+ get { return DE; }
+ set { DE = value; }
+ }
+
+ /// <summary>
+ /// The current state of the HL register pair.
+ /// </summary>
+ public Register16 HL_Register
+ {
+ get { return HL; }
+ set { HL = value; }
+ }
+
+ /// <summary>
+ /// The current state of the stack pointer.
+ /// </summary>
+ public ushort StackPointer
+ {
+ get { return SP; }
+ set { SP = value; }
+ }
+
+ /// <summary>
+ /// The current state of the program counter.
+ /// </summary>
+ public ushort ProgramCounter
+ {
+ get { return PC; }
+ set { PC = value; }
+ }
+
+ /// <summary>
+ /// The alternate AF' register.
+ /// </summary>
+ public Register16 AF_Alternate
+ {
+ get { return AF_; }
+ set { AF_ = value; }
+ }
+
+ /// <summary>
+ /// The alternate BC' register.
+ /// </summary>
+ public Register16 BC_Alternate
+ {
+ get { return BC_; }
+ set { BC_ = value; }
+ }
+
+ /// <summary>
+ /// The alternate DE' register.
+ /// </summary>
+ public Register16 DE_Alternate
+ {
+ get { return DE_; }
+ set { DE_ = value; }
+ }
+
+ /// <summary>
+ /// The alternate HL' register.
+ /// </summary>
+ public Register16 HL_Alternate
+ {
+ get { return HL_; }
+ set { HL_ = value; }
+ }
+
+ /// <summary>
+ /// The state of the HALT line.
+ /// </summary>
+ public bool HaltLine
+ {
+ get { return HALT; }
+ set { HALT = value; }
+ }
+
+ /// <summary>
+ /// The state of the IFF1 register.
+ /// </summary>
+ public bool IFF1_Regsiter
+ {
+ get { return IFF1; }
+ set { IFF1 = value; }
+ }
+
+ /// <summary>
+ /// The state of the IFF2 register.
+ /// </summary>
+ public bool IFF2_Regsiter
+ {
+ get { return IFF2; }
+ set { IFF2 = value; }
+ }
+
+ /// <summary>
+ /// The state of the IM register.
+ /// </summary>
+ public byte IM_Register
+ {
+ get { return IM; }
+ set { IM = value; }
+ }
+
+ /// <summary>
+ /// The state of the RAM refresh register.
+ /// </summary>
+ public byte Refresh
+ {
+ get { return R; }
+ set { R = value; }
+ }
+
+ /// <summary>
+ /// The state of the interrupt vector register.
+ /// </summary>
+ public byte InterruptVector
+ {
+ get { return I; }
+ set { I = value; }
+ }
+
+ #endregion
+
#region Events
/// <summary>