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.cs104
1 files changed, 90 insertions, 14 deletions
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 <http://www.gnu.org/licenses/>.
+// along with Noddybox.Emulation. If not, see <http://www.gnu.org/licenses/>.
//
// 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
+
+ /// <summary>
+ /// The CPU has been halted.
+ /// </summary>
+ public event EventHandler<Z80CpuEventArgs> HaltEvent;
+
+ /// <summary>
+ /// A no-operation ED opcode has been executed. Useful for placing
+ /// hooks into the Z80 code.
+ /// </summary>
+ public event EventHandler<Z80CpuEventArgs> EDNopEvent;
+
+ /// <summary>
+ /// Called to raise <see cref="HaltEvent"/>
+ /// </summary>
+ /// <param name="e">The event arguments.</param>
+ protected void OnHaltEvent(Z80CpuEventArgs e)
+ {
+ EventHandler<Z80CpuEventArgs> handler = HaltEvent;
+
+ if (handler != null)
+ {
+ handler(this, e);
+ }
+ }
+
+ /// <summary>
+ /// Called to raise <see cref="EDNopEvent"/>
+ /// </summary>
+ /// <param name="e">The event arguments.</param>
+ protected void OnEDNopEvent(Z80CpuEventArgs e)
+ {
+ EventHandler<Z80CpuEventArgs> 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
}
}