From 2e3102879b2d3059f4ce0efc1a0ecd4bc3142a99 Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 28 Dec 2011 00:11:12 +0000 Subject: Added some more base classes and started on the Z80 implementation. --- .../Noddybox.Emulation.EightBit.Z80.csproj | 75 +++++++++ .../Properties/AssemblyInfo.cs | 37 +++++ Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs | 167 +++++++++++++++++++++ 3 files changed, 279 insertions(+) create mode 100644 Noddybox.Emulation.EightBit.Z80/Noddybox.Emulation.EightBit.Z80.csproj create mode 100644 Noddybox.Emulation.EightBit.Z80/Properties/AssemblyInfo.cs create mode 100644 Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs (limited to 'Noddybox.Emulation.EightBit.Z80') diff --git a/Noddybox.Emulation.EightBit.Z80/Noddybox.Emulation.EightBit.Z80.csproj b/Noddybox.Emulation.EightBit.Z80/Noddybox.Emulation.EightBit.Z80.csproj new file mode 100644 index 0000000..60cb7ff --- /dev/null +++ b/Noddybox.Emulation.EightBit.Z80/Noddybox.Emulation.EightBit.Z80.csproj @@ -0,0 +1,75 @@ + + + + Debug + AnyCPU + 10.0.20506 + 2.0 + {7F257886-40D3-4E2A-BA9C-C5FEE93C08E9} + {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Noddybox.Emulation.EightBit.Z80 + Noddybox.Emulation.EightBit.Z80 + v4.0 + $(TargetFrameworkVersion) + WindowsPhone71 + Silverlight + false + true + true + + + true + full + false + Bin\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + + + + + + + + + + + + + + {ADC7A871-4DED-4A92-A447-2D784AB60FAF} + Noddybox.Emulation.EightBit + + + {A2478066-4DFD-4042-BF98-963922DC97F8} + Noddybox.Emulation + + + + + + + \ No newline at end of file diff --git a/Noddybox.Emulation.EightBit.Z80/Properties/AssemblyInfo.cs b/Noddybox.Emulation.EightBit.Z80/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..52b6054 --- /dev/null +++ b/Noddybox.Emulation.EightBit.Z80/Properties/AssemblyInfo.cs @@ -0,0 +1,37 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Resources; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Noddybox.Emulation.EightBit.Z80")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Noddybox.Emulation.EightBit.Z80")] +[assembly: AssemblyCopyright("Copyright © 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3b53cbb7-adc4-4405-ba85-4b345a46ed11")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: NeutralResourcesLanguageAttribute("en-US")] diff --git a/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs b/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs new file mode 100644 index 0000000..d967bb9 --- /dev/null +++ b/Noddybox.Emulation.EightBit.Z80/Z80Cpu.cs @@ -0,0 +1,167 @@ +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; + +namespace Noddybox.Emulation.EightBit.Z80 +{ + /// + /// Provides an implementation of a Zilog Z80 processor. + /// + public partial class Z80Cpu : ICpu + { + #region Private types + + [Flags] + private enum Z80Flags + { + None = 0x00, + Carry = 0x01, + Neg = 0x02, + PV = 0x04, + Hidden3 = 0x08, + HalfCarry = 0x10, + Hidden5 = 0x20, + Zero = 0x40, + Sign = 0x80 + }; + + #endregion + + #region Private data + + // Lookup tables + // + private Z80Flags[] PSZtable = new Z80Flags[512]; + private Z80Flags[] SZtable = new Z80Flags[512]; + private Z80Flags[] Ptable = new Z80Flags[512]; + private Z80Flags[] Stable = new Z80Flags[512]; + private Z80Flags[] Ztable = new Z80Flags[512]; + + // Machine accessors + // + private IMemory memory; + private IDevice device; + private Clock clock; + + // Main registers + // + private byte A; + private byte F; + private byte R; + private byte IFF1; + private byte IFF2; + private IRegister16 BC = Register16Factory.Create(); + private IRegister16 DE = Register16Factory.Create(); + private IRegister16 HL = Register16Factory.Create(); + private IRegister16 IX = Register16Factory.Create(); + private IRegister16 IY = Register16Factory.Create(); + private IRegister16 SP = Register16Factory.Create(); + private IRegister16 PC = Register16Factory.Create(); + + // Alternate registers + // + private IRegister16 AF_ = Register16Factory.Create(); + private IRegister16 BC_ = Register16Factory.Create(); + private IRegister16 DE_ = Register16Factory.Create(); + private IRegister16 HL_ = Register16Factory.Create(); + + #endregion + + #region ICpu Members + + public void Initialise(IMemory memory, IDevice device, Clock clock) + { + this.memory = memory; + this.device = device; + this.clock = clock; + + Reset(); + } + + public void Reset() + { + // TODO: Initial register settings. + } + + public void Step() + { + // TODO: Single step. + } + + public void Run() + { + // TODO: Run for a frame + } + + public void MaskableInterrupt(byte value) + { + // TODO: INT + } + + public void NonMaskableInterrupt(byte value) + { + // TODO: NMI + } + + #endregion + + #region Constructors + + public Z80Cpu() + { + // Setup lookup tables + // + for(int f = 0; f < 256; f++) + { + Z80Flags p = Z80Flags.None; + Z80Flags z = Z80Flags.None; + Z80Flags s = Z80Flags.None; + int parity = 0; + + for(int b=0; b < 8; b++) + { + if ((f & (1<