From 50bff99fdd758ead34489814b8e40695e712b0dd Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 3 Jan 2012 22:45:48 +0000 Subject: First pass of single byte opcodes done. --- src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs | 80 ++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 8 deletions(-) (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 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 -- cgit v1.2.3