From 998b64d14c9d055562d8c1611813d40af4cb030b Mon Sep 17 00:00:00 2001 From: Ian C Date: Fri, 9 Mar 2012 23:01:13 +0000 Subject: Further bug fixes to Z80. Now starts the Spectrum ROM OK. --- src/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (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 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 +// +// 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 halfcarry_add_table = + new ReadOnlyArray + (new Z80Flags[8] + {Z80Flags.None, Z80Flags.HalfCarry, Z80Flags.HalfCarry, Z80Flags.HalfCarry, + Z80Flags.None, Z80Flags.None, Z80Flags.None, Z80Flags.HalfCarry}); + + private readonly ReadOnlyArray halfcarry_sub_table = + new ReadOnlyArray + (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 overflow_add_table = + new ReadOnlyArray + (new Z80Flags[8] + {Z80Flags.None, Z80Flags.None, Z80Flags.None, Z80Flags.PV, + Z80Flags.PV, Z80Flags.None, Z80Flags.None, Z80Flags.None}); + + private readonly ReadOnlyArray overflow_sub_table = + new ReadOnlyArray + (new Z80Flags[8] + {Z80Flags.None, Z80Flags.PV, Z80Flags.None, Z80Flags.None, + Z80Flags.None, Z80Flags.None, Z80Flags.PV, Z80Flags.None}); + // Machine accessors // private IMemory memory; -- cgit v1.3