summaryrefslogtreecommitdiff
path: root/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2012-01-03 22:45:48 +0000
committerIan C <ianc@noddybox.co.uk>2012-01-03 22:45:48 +0000
commit50bff99fdd758ead34489814b8e40695e712b0dd (patch)
treeebea5a1ba673a42b6181f7a871c5724c691367b4 /src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
parent647083a1f53bbec58e5058616b84f706b0402911 (diff)
First pass of single byte opcodes done.
Diffstat (limited to 'src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs')
-rw-r--r--src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs80
1 files changed, 72 insertions, 8 deletions
diff --git a/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs b/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
index 0717ef5..13e8582 100644
--- a/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
+++ b/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
@@ -67,16 +67,75 @@ namespace Noddybox.Emulation.EightBit.Z80
// Auxilliary registers and flags
//
- private byte I;
+ private ushort I;
private byte R;
private bool IFF1;
private bool IFF2;
+ private bool raise;
+ private bool nmi;
+ private byte devbyte;
private int IM;
private bool HALT;
private int shift;
#endregion
+ #region Private members
+
+ private void CheckInterrupts()
+ {
+ if (raise)
+ {
+ if (nmi)
+ {
+ if (HALT)
+ {
+ HALT = false;
+ PC++;
+ }
+
+ clock.Add(2);
+ IFF1 = false;
+ nmi = false;
+ PUSH(PC);
+ PC = 0x66;
+ }
+ else if (IFF1)
+ {
+ if (HALT)
+ {
+ HALT = false;
+ PC++;
+ }
+
+ clock.Add(2);
+ IFF1 = false;
+ IFF2 = false;
+
+ switch(IM)
+ {
+ case 1:
+ PUSH(PC);
+ PC = 0x38;
+ break;
+
+ case 2:
+ PUSH(PC);
+ PC = (ushort)((I << 8) + devbyte);
+ break;
+
+ default:
+ DecodeByte(devbyte);
+ break;
+ }
+ }
+
+ raise = false;
+ }
+ }
+
+ #endregion
+
#region ICpu Members
public void Initialise(IMemory memory, IDevice device, Clock clock)
@@ -114,11 +173,17 @@ namespace Noddybox.Emulation.EightBit.Z80
R = 0;
HALT = false;
shift = 0;
+ raise = false;
+ nmi = false;
+ devbyte = 0;
}
public void Step()
{
- // TODO: Single step.
+ CheckInterrupts();
+ AddR(1);
+ shift = 0;
+ DecodeByte(memory.Read(PC++));
}
public void Run()
@@ -131,16 +196,15 @@ namespace Noddybox.Emulation.EightBit.Z80
public void MaskableInterrupt(byte value)
{
- clock.Add(2);
-
- // TODO: INT
+ raise = true;
+ devbyte = value;
+ nmi = false;
}
public void NonMaskableInterrupt(byte value)
{
- clock.Add(2);
-
- // TODO: NMI
+ raise = true;
+ nmi = true;
}
#endregion