summaryrefslogtreecommitdiff
path: root/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2012-03-09 23:01:13 +0000
committerIan C <ianc@noddybox.co.uk>2012-03-09 23:01:13 +0000
commit998b64d14c9d055562d8c1611813d40af4cb030b (patch)
treeecb3402a5c7302d86c5a364308b6d0b173e00e5c /src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
parent31203bc854656ff92844364903de9abee9daea8b (diff)
Further bug fixes to Z80. Now starts the Spectrum ROM OK.
Diffstat (limited to 'src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs')
-rw-r--r--src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs b/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
index 2da155e..74a8df1 100644
--- a/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
+++ b/src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs
@@ -15,6 +15,12 @@
//
// Copyright (c) 2012 Ian Cowburn
//
+// Some of the concepts and code in here are taken from FUSE, the open source UNIX
+// Spectrum emulator Copyright (c) 1999-2003 Philip Kendall.
+// See <http://fuse-emulator.sourceforge.net/>
+//
+// Any introduced bugs in that code are mine, and not the original authors.
+//
using System;
namespace Noddybox.Emulation.EightBit.Z80
@@ -45,6 +51,40 @@ namespace Noddybox.Emulation.EightBit.Z80
private Z80Flags[] Ztable = new Z80Flags[512];
private Z80Flags[] H35table = new Z80Flags[512];
+ // Whether a half carry occurred or not can be determined by looking at
+ // the 3rd bit of the two arguments and the result; these are hashed
+ // into this table in the form r12, where r is the 3rd bit of the
+ // result, 1 is the 3rd bit of the 1st argument and 2 is the
+ // third bit of the 2nd argument; the tables differ for add and subtract
+ // operations.
+ //
+ private readonly ReadOnlyArray<Z80Flags> halfcarry_add_table =
+ new ReadOnlyArray<Z80Flags>
+ (new Z80Flags[8]
+ {Z80Flags.None, Z80Flags.HalfCarry, Z80Flags.HalfCarry, Z80Flags.HalfCarry,
+ Z80Flags.None, Z80Flags.None, Z80Flags.None, Z80Flags.HalfCarry});
+
+ private readonly ReadOnlyArray<Z80Flags> halfcarry_sub_table =
+ new ReadOnlyArray<Z80Flags>
+ (new Z80Flags[8]
+ {Z80Flags.None, Z80Flags.None, Z80Flags.HalfCarry, Z80Flags.None,
+ Z80Flags.HalfCarry, Z80Flags.None, Z80Flags.HalfCarry, Z80Flags.HalfCarry});
+
+ // Similarly, overflow can be determined by looking at the 7th bits; again
+ // the hash into this table is r12
+ //
+ private readonly ReadOnlyArray<Z80Flags> overflow_add_table =
+ new ReadOnlyArray<Z80Flags>
+ (new Z80Flags[8]
+ {Z80Flags.None, Z80Flags.None, Z80Flags.None, Z80Flags.PV,
+ Z80Flags.PV, Z80Flags.None, Z80Flags.None, Z80Flags.None});
+
+ private readonly ReadOnlyArray<Z80Flags> overflow_sub_table =
+ new ReadOnlyArray<Z80Flags>
+ (new Z80Flags[8]
+ {Z80Flags.None, Z80Flags.PV, Z80Flags.None, Z80Flags.None,
+ Z80Flags.None, Z80Flags.None, Z80Flags.PV, Z80Flags.None});
+
// Machine accessors
//
private IMemory memory;