summaryrefslogtreecommitdiff
path: root/Noddybox.Emulation.EightBit
diff options
context:
space:
mode:
Diffstat (limited to 'Noddybox.Emulation.EightBit')
-rw-r--r--Noddybox.Emulation.EightBit/Binary.cs63
-rw-r--r--Noddybox.Emulation.EightBit/ICpu.cs5
-rw-r--r--Noddybox.Emulation.EightBit/IDevice.cs5
-rw-r--r--Noddybox.Emulation.EightBit/IMemory.cs16
-rw-r--r--Noddybox.Emulation.EightBit/IRegister16.cs5
-rw-r--r--Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj1
-rw-r--r--Noddybox.Emulation.EightBit/Register16BigEndian.cs5
-rw-r--r--Noddybox.Emulation.EightBit/Register16Factory.cs5
-rw-r--r--Noddybox.Emulation.EightBit/Register16LittleEndian.cs5
9 files changed, 98 insertions, 12 deletions
diff --git a/Noddybox.Emulation.EightBit/Binary.cs b/Noddybox.Emulation.EightBit/Binary.cs
new file mode 100644
index 0000000..0b1928b
--- /dev/null
+++ b/Noddybox.Emulation.EightBit/Binary.cs
@@ -0,0 +1,63 @@
+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 helpers for shifting smaller values around without casts all over the shop.
+ /// </summary>
+ public static class Binary
+ {
+ /// <summary>
+ /// Shift 8-bits to the left.
+ /// </summary>
+ /// <param name="b">The byte.</param>
+ /// <param name="shift">How many bits to shift.</param>
+ /// <returns>The shifted value.</returns>
+ public static byte ShiftLeft(byte b, int shift)
+ {
+ return (byte)((b << shift) & 0xff);
+ }
+
+ /// <summary>
+ /// Shift 8-bits to the right.
+ /// </summary>
+ /// <param name="b">The byte.</param>
+ /// <param name="shift">How many bits to shift.</param>
+ /// <returns>The shifted value.</returns>
+ public static byte ShiftRight(byte b, int shift)
+ {
+ return (byte)((b >> shift) & 0xff);
+ }
+
+ /// <summary>
+ /// Shift 16-bits to the left.
+ /// </summary>
+ /// <param name="w">The word.</param>
+ /// <param name="shift">How many bits to shift.</param>
+ /// <returns>The shifted value.</returns>
+ public static ushort ShiftLeft(ushort w, int shift)
+ {
+ return (ushort)((w << shift) & 0xffff);
+ }
+
+ /// <summary>
+ /// Shift 16-bits to the right.
+ /// </summary>
+ /// <param name="w">The word.</param>
+ /// <param name="shift">How many bits to shift.</param>
+ /// <returns>The shifted value.</returns>
+ public static ushort ShiftRight(ushort w, int shift)
+ {
+ return (ushort)((w >> shift) & 0xffff);
+ }
+ }
+}
diff --git a/Noddybox.Emulation.EightBit/ICpu.cs b/Noddybox.Emulation.EightBit/ICpu.cs
index 139933d..dc2f811 100644
--- a/Noddybox.Emulation.EightBit/ICpu.cs
+++ b/Noddybox.Emulation.EightBit/ICpu.cs
@@ -1,4 +1,7 @@
-using System;
+//
+// Copyright (c) 2012 Ian Cowburn
+//
+using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
diff --git a/Noddybox.Emulation.EightBit/IDevice.cs b/Noddybox.Emulation.EightBit/IDevice.cs
index 00ef38d..b8d234a 100644
--- a/Noddybox.Emulation.EightBit/IDevice.cs
+++ b/Noddybox.Emulation.EightBit/IDevice.cs
@@ -1,4 +1,7 @@
-using System;
+//
+// Copyright (c) 2012 Ian Cowburn
+//
+using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
diff --git a/Noddybox.Emulation.EightBit/IMemory.cs b/Noddybox.Emulation.EightBit/IMemory.cs
index 2c842a5..ee41500 100644
--- a/Noddybox.Emulation.EightBit/IMemory.cs
+++ b/Noddybox.Emulation.EightBit/IMemory.cs
@@ -1,4 +1,7 @@
-using System;
+//
+// Copyright (c) 2012 Ian Cowburn
+//
+using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
@@ -12,7 +15,8 @@ using System.Windows.Shapes;
namespace Noddybox.Emulation.EightBit
{
/// <summary>
- /// Defines an interface for memory.
+ /// 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.
/// </summary>
public interface IMemory
{
@@ -20,14 +24,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.</returns>
- byte Read(ushort address);
+ /// <returns>The value at that address in the lower 8-bits.</returns>
+ int Read(int 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(ushort address, byte value);
+ /// <param name="value">The value to write. Only the lower 8-bits are taken.</param>
+ void Write(int address, int value);
}
}
diff --git a/Noddybox.Emulation.EightBit/IRegister16.cs b/Noddybox.Emulation.EightBit/IRegister16.cs
index e3bfc69..4356756 100644
--- a/Noddybox.Emulation.EightBit/IRegister16.cs
+++ b/Noddybox.Emulation.EightBit/IRegister16.cs
@@ -1,4 +1,7 @@
-using System;
+//
+// Copyright (c) 2012 Ian Cowburn
+//
+using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
diff --git a/Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj b/Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj
index c7d5924..801adae 100644
--- a/Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj
+++ b/Noddybox.Emulation.EightBit/Noddybox.Emulation.EightBit.csproj
@@ -49,6 +49,7 @@
<Reference Include="mscorlib.extensions" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Binary.cs" />
<Compile Include="ICpu.cs" />
<Compile Include="IDevice.cs" />
<Compile Include="IMemory.cs" />
diff --git a/Noddybox.Emulation.EightBit/Register16BigEndian.cs b/Noddybox.Emulation.EightBit/Register16BigEndian.cs
index 8378543..e7a3780 100644
--- a/Noddybox.Emulation.EightBit/Register16BigEndian.cs
+++ b/Noddybox.Emulation.EightBit/Register16BigEndian.cs
@@ -1,4 +1,7 @@
-using System;
+//
+// Copyright (c) 2012 Ian Cowburn
+//
+using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
diff --git a/Noddybox.Emulation.EightBit/Register16Factory.cs b/Noddybox.Emulation.EightBit/Register16Factory.cs
index fd31fe4..249e668 100644
--- a/Noddybox.Emulation.EightBit/Register16Factory.cs
+++ b/Noddybox.Emulation.EightBit/Register16Factory.cs
@@ -1,4 +1,7 @@
-using System;
+//
+// Copyright (c) 2012 Ian Cowburn
+//
+using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
diff --git a/Noddybox.Emulation.EightBit/Register16LittleEndian.cs b/Noddybox.Emulation.EightBit/Register16LittleEndian.cs
index a2cf8a8..ccecdaf 100644
--- a/Noddybox.Emulation.EightBit/Register16LittleEndian.cs
+++ b/Noddybox.Emulation.EightBit/Register16LittleEndian.cs
@@ -1,4 +1,7 @@
-using System;
+//
+// Copyright (c) 2012 Ian Cowburn
+//
+using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;