From 4a14a990665f766e349b9027dbf980bc39f395f6 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sat, 31 Dec 2011 00:10:45 +0000 Subject: Development check-in. --- Noddybox.Emulation.EightBit/IMemory.cs | 11 ++- Noddybox.Emulation.EightBit/IRegister16.cs | 37 --------- .../Noddybox.Emulation.EightBit.csproj | 5 +- Noddybox.Emulation.EightBit/Register16.cs | 88 ++++++++++++++++++++++ Noddybox.Emulation.EightBit/Register16BigEndian.cs | 56 -------------- Noddybox.Emulation.EightBit/Register16Factory.cs | 34 --------- .../Register16LittleEndian.cs | 56 -------------- 7 files changed, 94 insertions(+), 193 deletions(-) delete mode 100644 Noddybox.Emulation.EightBit/IRegister16.cs create mode 100644 Noddybox.Emulation.EightBit/Register16.cs delete mode 100644 Noddybox.Emulation.EightBit/Register16BigEndian.cs delete mode 100644 Noddybox.Emulation.EightBit/Register16Factory.cs delete mode 100644 Noddybox.Emulation.EightBit/Register16LittleEndian.cs (limited to 'Noddybox.Emulation.EightBit') diff --git a/Noddybox.Emulation.EightBit/IMemory.cs b/Noddybox.Emulation.EightBit/IMemory.cs index ee41500..2aa63d9 100644 --- a/Noddybox.Emulation.EightBit/IMemory.cs +++ b/Noddybox.Emulation.EightBit/IMemory.cs @@ -15,8 +15,7 @@ using System.Windows.Shapes; namespace Noddybox.Emulation.EightBit { /// - /// Defines an interface for memory. Note that ints are used rather than smaller unsigned types due to the pain of - /// doing boolean operations on anything else in C# without copious casting. + /// Defines an interface for memory. /// public interface IMemory { @@ -24,14 +23,14 @@ namespace Noddybox.Emulation.EightBit /// Reads a byte at a given address. /// /// The address to read. - /// The value at that address in the lower 8-bits. - int Read(int address); + /// The value at that address. + byte Read(ushort address); /// /// Writes a byte at a given address. /// /// The address to write to. - /// The value to write. Only the lower 8-bits are taken. - void Write(int address, int value); + /// The value to write. + void Write(ushort address, byte value); } } diff --git a/Noddybox.Emulation.EightBit/IRegister16.cs b/Noddybox.Emulation.EightBit/IRegister16.cs deleted file mode 100644 index 4356756..0000000 --- a/Noddybox.Emulation.EightBit/IRegister16.cs +++ /dev/null @@ -1,37 +0,0 @@ -// -// Copyright (c) 2012 Ian Cowburn -// -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 -{ - /// - /// Provides a common 8-bit register pattern, which is two 8-bit registers rolled into one. - /// - public interface IRegister16 - { - /// - /// Get/set the low byte of the 16-bit register. - /// - byte Low {get; set;} - - /// - /// Get/set the high byte of the 16-bit register. - /// - byte High {get; set;} - - /// - /// Get/set the value of the 16-bit register. - /// - ushort Value {get; set;} - } -} diff --git a/Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj b/Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj index 801adae..2136f3c 100644 --- a/Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj +++ b/Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj @@ -53,11 +53,8 @@ - - - - + diff --git a/Noddybox.Emulation.EightBit/Register16.cs b/Noddybox.Emulation.EightBit/Register16.cs new file mode 100644 index 0000000..06c9c01 --- /dev/null +++ b/Noddybox.Emulation.EightBit/Register16.cs @@ -0,0 +1,88 @@ +// +// Copyright (c) 2012 Ian Cowburn +// +using System; +using System.Runtime.InteropServices; + +namespace Noddybox.Emulation.EightBit +{ + /// + /// Provides a common 8-bit register pattern, which is two 8-bit registers rolled into one. + /// While this could be done at runtime using this + /// method was chosen for speed reasons; interfaces cannot define fields, which is sensible + /// enoough, but accessing fields directly would allow ref variables to be used with this type's + /// fields. + /// + [StructLayout(LayoutKind.Explicit)] + public struct Register16 + { +#if TARGET_IS_BIGENDIAN + + /// + /// The 16-bit register. + /// + [FieldOffset(0)] + public ushort reg; + + /// + /// The high 8-bits of the register. + /// + [FieldOffset(0)] + public byte high; + + /// + /// The low 8-bits of the register. + /// + [FieldOffset(1)] + public byte low; + +#else + + /// + /// The 16-bit register. + /// + [FieldOffset(0)] + public ushort reg; + + /// + /// The low 8-bits of the register. + /// + [FieldOffset(0)] + public byte low; + + /// + /// The high 8-bits of the register. + /// + [FieldOffset(1)] + public byte high; + +#endif + + /// + /// Public constructor. This is provided to stop the compiler complaining when you use the struct as it + /// doesn't realise that setting will also set and . + /// + /// The 16-bit value to assign. + public Register16(ushort val) + { + high = 0; + low = 0; + reg = val; + } + + /// + /// Used to verify the compile-time setting at runtime. + /// + public static void Verify() + { + Register16 r = new Register16(0); + + r.reg = 0x1234; + + if (r.low != 0x24 || r.high != 0x12) + { + throw new Exception("Compile time endian setting incorrect"); + } + } + } +} diff --git a/Noddybox.Emulation.EightBit/Register16BigEndian.cs b/Noddybox.Emulation.EightBit/Register16BigEndian.cs deleted file mode 100644 index e7a3780..0000000 --- a/Noddybox.Emulation.EightBit/Register16BigEndian.cs +++ /dev/null @@ -1,56 +0,0 @@ -// -// Copyright (c) 2012 Ian Cowburn -// -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; -using System.Runtime.InteropServices; - -namespace Noddybox.Emulation.EightBit -{ - [StructLayout(LayoutKind.Explicit)] - public struct Register16BigEndian : IRegister16 - { - #region Register fields - - [FieldOffset(0)] - ushort reg; - - [FieldOffset(1)] - byte low; - - [FieldOffset(0)] - byte high; - - #endregion - - #region IRegister16 Members - - public byte Low - { - get {return low;} - set {low = value;} - } - - public byte High - { - get {return high;} - set {high = value;} - } - - public ushort Value - { - get {return reg;} - set {reg = value;} - } - - #endregion - } -} diff --git a/Noddybox.Emulation.EightBit/Register16Factory.cs b/Noddybox.Emulation.EightBit/Register16Factory.cs deleted file mode 100644 index 249e668..0000000 --- a/Noddybox.Emulation.EightBit/Register16Factory.cs +++ /dev/null @@ -1,34 +0,0 @@ -// -// Copyright (c) 2012 Ian Cowburn -// -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 -{ - /// - /// Defines a common 16-bit register, which is two bytes which are separately addressable. - /// - public static class Register16Factory - { - public static IRegister16 Create() - { - if (BitConverter.IsLittleEndian) - { - return new Register16LittleEndian(); - } - else - { - return new Register16BigEndian(); - } - } - } -} diff --git a/Noddybox.Emulation.EightBit/Register16LittleEndian.cs b/Noddybox.Emulation.EightBit/Register16LittleEndian.cs deleted file mode 100644 index ccecdaf..0000000 --- a/Noddybox.Emulation.EightBit/Register16LittleEndian.cs +++ /dev/null @@ -1,56 +0,0 @@ -// -// Copyright (c) 2012 Ian Cowburn -// -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; -using System.Runtime.InteropServices; - -namespace Noddybox.Emulation.EightBit -{ - [StructLayout(LayoutKind.Explicit)] - public struct Register16LittleEndian : IRegister16 - { - #region Register fields - - [FieldOffset(0)] - ushort reg; - - [FieldOffset(0)] - byte low; - - [FieldOffset(1)] - byte high; - - #endregion - - #region IRegister16 Members - - public byte Low - { - get {return low;} - set {low = value;} - } - - public byte High - { - get {return high;} - set {high = value;} - } - - public ushort Value - { - get {return reg;} - set {reg = value;} - } - - #endregion - } -} -- cgit v1.2.3