summaryrefslogtreecommitdiff
path: root/Noddybox.Emulation.EightBit
diff options
context:
space:
mode:
Diffstat (limited to 'Noddybox.Emulation.EightBit')
-rw-r--r--Noddybox.Emulation.EightBit/IMemory.cs11
-rw-r--r--Noddybox.Emulation.EightBit/IRegister16.cs37
-rw-r--r--Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj5
-rw-r--r--Noddybox.Emulation.EightBit/Register16.cs88
-rw-r--r--Noddybox.Emulation.EightBit/Register16BigEndian.cs56
-rw-r--r--Noddybox.Emulation.EightBit/Register16Factory.cs34
-rw-r--r--Noddybox.Emulation.EightBit/Register16LittleEndian.cs56
7 files changed, 94 insertions, 193 deletions
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
{
/// <summary>
- /// 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.
/// </summary>
public interface IMemory
{
@@ -24,14 +23,14 @@ namespace Noddybox.Emulation.EightBit
/// Reads a byte at a given address.
/// </summary>
/// <param name="address">The address to read.</param>
- /// <returns>The value at that address in the lower 8-bits.</returns>
- int Read(int address);
+ /// <returns>The value at that address.</returns>
+ byte Read(ushort address);
/// <summary>
/// Writes a byte at a given address.
/// </summary>
/// <param name="address">The address to write to.</param>
- /// <param name="value">The value to write. Only the lower 8-bits are taken.</param>
- void Write(int address, int value);
+ /// <param name="value">The value to write.</param>
+ 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
-{
- /// <summary>
- /// Provides a common 8-bit register pattern, which is two 8-bit registers rolled into one.
- /// </summary>
- public interface IRegister16
- {
- /// <summary>
- /// Get/set the low byte of the 16-bit register.
- /// </summary>
- byte Low {get; set;}
-
- /// <summary>
- /// Get/set the high byte of the 16-bit register.
- /// </summary>
- byte High {get; set;}
-
- /// <summary>
- /// Get/set the value of the 16-bit register.
- /// </summary>
- 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 @@
<Compile Include="ICpu.cs" />
<Compile Include="IDevice.cs" />
<Compile Include="IMemory.cs" />
- <Compile Include="IRegister16.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Register16BigEndian.cs" />
- <Compile Include="Register16Factory.cs" />
- <Compile Include="Register16LittleEndian.cs" />
+ <Compile Include="Register16.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Noddybox.Emulation\Noddybox.Emulation.csproj">
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
+{
+ /// <summary>
+ /// Provides a common 8-bit register pattern, which is two 8-bit registers rolled into one.
+ /// While this could be done at runtime using <see cref="BitConverter.IsLittleEndian"/> 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.
+ /// </summary>
+ [StructLayout(LayoutKind.Explicit)]
+ public struct Register16
+ {
+#if TARGET_IS_BIGENDIAN
+
+ /// <summary>
+ /// The 16-bit register.
+ /// </summary>
+ [FieldOffset(0)]
+ public ushort reg;
+
+ /// <summary>
+ /// The high 8-bits of the register.
+ /// </summary>
+ [FieldOffset(0)]
+ public byte high;
+
+ /// <summary>
+ /// The low 8-bits of the register.
+ /// </summary>
+ [FieldOffset(1)]
+ public byte low;
+
+#else
+
+ /// <summary>
+ /// The 16-bit register.
+ /// </summary>
+ [FieldOffset(0)]
+ public ushort reg;
+
+ /// <summary>
+ /// The low 8-bits of the register.
+ /// </summary>
+ [FieldOffset(0)]
+ public byte low;
+
+ /// <summary>
+ /// The high 8-bits of the register.
+ /// </summary>
+ [FieldOffset(1)]
+ public byte high;
+
+#endif
+
+ /// <summary>
+ /// Public constructor. This is provided to stop the compiler complaining when you use the struct as it
+ /// doesn't realise that setting <see cref="reg"/> will also set <see cref="low"/> and <see cref="high"/>.
+ /// </summary>
+ /// <param name="val">The 16-bit value to assign.</param>
+ public Register16(ushort val)
+ {
+ high = 0;
+ low = 0;
+ reg = val;
+ }
+
+ /// <summary>
+ /// Used to verify the compile-time setting at runtime.
+ /// </summary>
+ 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
-{
- /// <summary>
- /// Defines a common 16-bit register, which is two bytes which are separately addressable.
- /// </summary>
- 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
- }
-}