From f96332b0913a8a365db73a1af3443c0e225a23d8 Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 29 Dec 2011 00:17:13 +0000 Subject: Development check-in. --- Noddybox.Emulation.EightBit/Binary.cs | 63 ++++++++++++++++++++++ Noddybox.Emulation.EightBit/ICpu.cs | 5 +- Noddybox.Emulation.EightBit/IDevice.cs | 5 +- Noddybox.Emulation.EightBit/IMemory.cs | 16 +++--- Noddybox.Emulation.EightBit/IRegister16.cs | 5 +- .../Noddybox.Emulation.EightBit.csproj | 1 + Noddybox.Emulation.EightBit/Register16BigEndian.cs | 5 +- Noddybox.Emulation.EightBit/Register16Factory.cs | 5 +- .../Register16LittleEndian.cs | 5 +- 9 files changed, 98 insertions(+), 12 deletions(-) create mode 100644 Noddybox.Emulation.EightBit/Binary.cs (limited to 'Noddybox.Emulation.EightBit') 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 +{ + /// + /// Provides helpers for shifting smaller values around without casts all over the shop. + /// + public static class Binary + { + /// + /// Shift 8-bits to the left. + /// + /// The byte. + /// How many bits to shift. + /// The shifted value. + public static byte ShiftLeft(byte b, int shift) + { + return (byte)((b << shift) & 0xff); + } + + /// + /// Shift 8-bits to the right. + /// + /// The byte. + /// How many bits to shift. + /// The shifted value. + public static byte ShiftRight(byte b, int shift) + { + return (byte)((b >> shift) & 0xff); + } + + /// + /// Shift 16-bits to the left. + /// + /// The word. + /// How many bits to shift. + /// The shifted value. + public static ushort ShiftLeft(ushort w, int shift) + { + return (ushort)((w << shift) & 0xffff); + } + + /// + /// Shift 16-bits to the right. + /// + /// The word. + /// How many bits to shift. + /// The shifted value. + 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 { /// - /// 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. /// public interface IMemory { @@ -20,14 +24,14 @@ namespace Noddybox.Emulation.EightBit /// Reads a byte at a given address. /// /// The address to read. - /// The value at that address. - byte Read(ushort address); + /// The value at that address in the lower 8-bits. + int Read(int address); /// /// Writes a byte at a given address. /// /// The address to write to. - /// The value to write. - void Write(ushort address, byte value); + /// The value to write. Only the lower 8-bits are taken. + 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 @@ + 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; -- cgit v1.2.3