From a00e548533eed5b1aead479e70a117eb05458a5f Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 8 Jan 2012 22:37:21 +0000 Subject: Added rest of ED opcodes and GPL fixed headers. --- src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs | 104 ++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 14 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 78f0bfa..f937ea9 100644 --- a/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs +++ b/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs @@ -11,7 +11,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with Foobar. If not, see . +// along with Noddybox.Emulation. If not, see . // // Copyright (c) 2012 Ian Cowburn // @@ -26,20 +26,11 @@ namespace Noddybox.Emulation.EightBit.Z80 { #region Private types - [Flags] - private enum Z80Flags + private enum EventType { - None = 0x00, - Carry = 0x01, - Neg = 0x02, - PV = 0x04, - Hidden3 = 0x08, - HalfCarry = 0x10, - Hidden5 = 0x20, - Zero = 0x40, - Sign = 0x80, - Hidden = Hidden3 | Hidden5 - }; + HALT, + EDHook + } #endregion @@ -295,5 +286,90 @@ namespace Noddybox.Emulation.EightBit.Z80 } #endregion + + #region Events + + /// + /// The CPU has been halted. + /// + public event EventHandler HaltEvent; + + /// + /// A no-operation ED opcode has been executed. Useful for placing + /// hooks into the Z80 code. + /// + public event EventHandler EDNopEvent; + + /// + /// Called to raise + /// + /// The event arguments. + protected void OnHaltEvent(Z80CpuEventArgs e) + { + EventHandler handler = HaltEvent; + + if (handler != null) + { + handler(this, e); + } + } + + /// + /// Called to raise + /// + /// The event arguments. + protected void OnEDNopEvent(Z80CpuEventArgs e) + { + EventHandler handler = EDNopEvent; + + if (handler != null) + { + handler(this, e); + } + } + + private void TriggerEvent(EventType type, byte opcode) + { + Z80CpuEventArgs e = new Z80CpuEventArgs + { + Opcode = opcode, + A = this.A, + F = this.F, + BC = this.BC, + DE = this.DE, + HL = this.HL, + SP = this.SP, + PC = this.PC, + AF_ = this.AF_, + BC_ = this.BC_, + DE_ = this.DE_, + HL_ = this.HL_ + }; + + switch(type) + { + case EventType.HALT: + OnHaltEvent(e); + break; + + case EventType.EDHook: + OnEDNopEvent(e); + break; + } + + A = e.A; + F = e.F; + BC = e.BC; + DE = e.DE; + HL = e.HL; + SP = e.SP; + PC = e.PC; + AF_ = e.AF_; + BC_ = e.BC_; + DE_ = e.DE_; + HL_ = e.HL_; + } + + #endregion } } -- cgit v1.3