summaryrefslogtreecommitdiff
path: root/Noddybox.Emulation.EightBit
diff options
context:
space:
mode:
Diffstat (limited to 'Noddybox.Emulation.EightBit')
-rw-r--r--Noddybox.Emulation.EightBit/ICpu.cs54
-rw-r--r--Noddybox.Emulation.EightBit/IDevice.cs4
-rw-r--r--Noddybox.Emulation.EightBit/IMemory.cs4
-rw-r--r--Noddybox.Emulation.EightBit/IRegister16.cs34
-rw-r--r--Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj11
-rw-r--r--Noddybox.Emulation.EightBit/Register16BigEndian.cs53
-rw-r--r--Noddybox.Emulation.EightBit/Register16Factory.cs31
-rw-r--r--Noddybox.Emulation.EightBit/Register16LittleEndian.cs53
8 files changed, 240 insertions, 4 deletions
diff --git a/Noddybox.Emulation.EightBit/ICpu.cs b/Noddybox.Emulation.EightBit/ICpu.cs
new file mode 100644
index 0000000..139933d
--- /dev/null
+++ b/Noddybox.Emulation.EightBit/ICpu.cs
@@ -0,0 +1,54 @@
+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 an 8-bit CPU.
+ /// </summary>
+ public interface ICpu
+ {
+ /// <summary>
+ /// Initialise the CPU to give it access to memory and devices.
+ /// </summary>
+ /// <param name="memory">The memory to access.</param>
+ /// <param name="device">The devices to access.</param>
+ /// <param name="clock">The clock to use.</param>
+ void Initialise(IMemory memory, IDevice device, Clock clock);
+
+ /// <summary>
+ /// Resets the CPU to its initial state.
+ /// </summary>
+ void Reset();
+
+ /// <summary>
+ /// Runs the next instruction.
+ /// </summary>
+ void Step();
+
+ /// <summary>
+ /// Runs the CPU until the next frame flyback.
+ /// </summary>
+ void Run();
+
+ /// <summary>
+ /// Generates a maskable interrupt to the CPU.
+ /// </summary>
+ /// <param name="value">Optional value from an interrupting device. May be ignored depending on the CPU type.</param>
+ void MaskableInterrupt(byte value);
+
+ /// <summary>
+ /// Generates a non-maskable interrupt to the CPU.
+ /// </summary>
+ /// <param name="value">Optional value from an interrupting device. May be ignored depending on the CPU type.</param>
+ void NonMaskableInterrupt(byte value);
+ }
+}
diff --git a/Noddybox.Emulation.EightBit/IDevice.cs b/Noddybox.Emulation.EightBit/IDevice.cs
index 108adf9..00ef38d 100644
--- a/Noddybox.Emulation.EightBit/IDevice.cs
+++ b/Noddybox.Emulation.EightBit/IDevice.cs
@@ -22,13 +22,13 @@ namespace Noddybox.Emulation.EightBit
/// </summary>
/// <param name="device">The address of the device.</param>
/// <returns>The byte returned from the device.</returns>
- byte Read(UInt16 device);
+ byte Read(ushort device);
/// <summary>
/// Write to a device.
/// </summary>
/// <param name="device">The address of the device.</param>
/// <param name="value">The value to write to the device.</param>
- void Write(UInt16 device, byte value);
+ void Write(ushort device, byte value);
}
}
diff --git a/Noddybox.Emulation.EightBit/IMemory.cs b/Noddybox.Emulation.EightBit/IMemory.cs
index 5131eb0..2c842a5 100644
--- a/Noddybox.Emulation.EightBit/IMemory.cs
+++ b/Noddybox.Emulation.EightBit/IMemory.cs
@@ -21,13 +21,13 @@ namespace Noddybox.Emulation.EightBit
/// </summary>
/// <param name="address">The address to read.</param>
/// <returns>The value at that address.</returns>
- byte Read(UInt16 address);
+ 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.</param>
- void Write(UInt16 address, byte value);
+ void Write(ushort address, byte value);
}
}
diff --git a/Noddybox.Emulation.EightBit/IRegister16.cs b/Noddybox.Emulation.EightBit/IRegister16.cs
new file mode 100644
index 0000000..e3bfc69
--- /dev/null
+++ b/Noddybox.Emulation.EightBit/IRegister16.cs
@@ -0,0 +1,34 @@
+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 316b00b..c7d5924 100644
--- a/Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj
+++ b/Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj
@@ -49,9 +49,20 @@
<Reference Include="mscorlib.extensions" />
</ItemGroup>
<ItemGroup>
+ <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" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Noddybox.Emulation\Noddybox.Emulation.csproj">
+ <Project>{A2478066-4DFD-4042-BF98-963922DC97F8}</Project>
+ <Name>Noddybox.Emulation</Name>
+ </ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
diff --git a/Noddybox.Emulation.EightBit/Register16BigEndian.cs b/Noddybox.Emulation.EightBit/Register16BigEndian.cs
new file mode 100644
index 0000000..8378543
--- /dev/null
+++ b/Noddybox.Emulation.EightBit/Register16BigEndian.cs
@@ -0,0 +1,53 @@
+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
new file mode 100644
index 0000000..fd31fe4
--- /dev/null
+++ b/Noddybox.Emulation.EightBit/Register16Factory.cs
@@ -0,0 +1,31 @@
+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
new file mode 100644
index 0000000..a2cf8a8
--- /dev/null
+++ b/Noddybox.Emulation.EightBit/Register16LittleEndian.cs
@@ -0,0 +1,53 @@
+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
+ }
+}