diff --git a/EightBit/IMemory.cs b/EightBit/IMemory.cs
new file mode 100644
index 0000000..92eac32
--- /dev/null
+++ b/EightBit/IMemory.cs
@@ -0,0 +1,26 @@
+//
+// Copyright (c) Adrian Conlon. All rights reserved.
+//
+
+namespace EightBit
+{
+ public interface IMemory
+ {
+ abstract int Size
+ {
+ get;
+ }
+
+ byte Peek(ushort address);
+
+ void Poke(ushort address, byte value);
+
+ ref byte Reference(ushort address);
+
+ int Load(FileStream file, int writeOffset = 0, int readOffset = 0, int limit = -1);
+
+ int Load(string path, int writeOffset = 0, int readOffset = 0, int limit = -1);
+
+ int Load(byte[] from, int writeOffset = 0, int readOffset = 0, int limit = -1);
+ }
+}
diff --git a/EightBit/Memory.cs b/EightBit/Memory.cs
deleted file mode 100644
index 30c32ee..0000000
--- a/EightBit/Memory.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Copyright (c) Adrian Conlon. All rights reserved.
-//
-
-namespace EightBit
-{
- public abstract class Memory
- {
- public abstract int Size
- {
- get;
- }
-
- public abstract byte Peek(ushort address);
-
- public virtual ref byte Reference(ushort address) => throw new NotImplementedException();
-
- public abstract int Load(FileStream file, int writeOffset = 0, int readOffset = 0, int limit = -1);
-
- public abstract int Load(string path, int writeOffset = 0, int readOffset = 0, int limit = -1);
-
- public abstract int Load(byte[] from, int writeOffset = 0, int readOffset = 0, int limit = -1);
-
- protected abstract void Poke(ushort address, byte value);
- }
-}
diff --git a/EightBit/MemoryMapping.cs b/EightBit/MemoryMapping.cs
index 92931d6..85f94cd 100644
--- a/EightBit/MemoryMapping.cs
+++ b/EightBit/MemoryMapping.cs
@@ -6,7 +6,7 @@ namespace EightBit
{
public sealed class MemoryMapping
{
- public MemoryMapping(Memory memory, ushort begin, ushort mask, AccessLevel access)
+ public MemoryMapping(IMemory memory, ushort begin, ushort mask, AccessLevel access)
{
this._memory = memory;
this._begin = begin;
@@ -20,18 +20,18 @@ namespace EightBit
}
}
- public MemoryMapping(Memory memory, ushort begin, Mask mask, AccessLevel access)
+ public MemoryMapping(IMemory memory, ushort begin, Mask mask, AccessLevel access)
: this(memory, begin, (ushort)mask, access)
{
}
private readonly ushort[] _offsets = new ushort[ushort.MaxValue + 1];
- private readonly Memory _memory;
+ private readonly IMemory _memory;
private readonly ushort _begin;
private readonly ushort _mask;
private readonly AccessLevel _access;
- public Memory Memory => this._memory;
+ public IMemory Memory => this._memory;
public ushort Begin => this._begin;
diff --git a/EightBit/Ram.cs b/EightBit/Ram.cs
index 2b4e7a5..1d3b9ca 100644
--- a/EightBit/Ram.cs
+++ b/EightBit/Ram.cs
@@ -12,7 +12,5 @@ namespace EightBit
}
public sealed override ref byte Reference(ushort address) => ref this.Bytes()[address];
-
- public new void Poke(ushort address, byte value) => base.Poke(address, value);
}
}
diff --git a/EightBit/Rom.cs b/EightBit/Rom.cs
index 097a21a..7fec674 100644
--- a/EightBit/Rom.cs
+++ b/EightBit/Rom.cs
@@ -6,11 +6,11 @@ namespace EightBit
{
using System.Diagnostics;
- public class Rom(int size = 0) : Memory
+ public class Rom(int size = 0) : IMemory
{
private byte[] _bytes = new byte[size];
- public override int Size => this._bytes.Length;
+ public int Size => this._bytes.Length;
public static int Load(Stream file, ref byte[] output, int writeOffset = 0, int readOffset = 0, int limit = -1, int maximumSize = -1)
{
@@ -54,19 +54,19 @@ namespace EightBit
return Load(file, ref output, writeOffset, readOffset, limit, maximumSize);
}
- public override int Load(FileStream file, int writeOffset = 0, int readOffset = 0, int limit = -1)
+ public int Load(FileStream file, int writeOffset = 0, int readOffset = 0, int limit = -1)
{
var maximumSize = this.Size - writeOffset;
return Load(file, ref this.Bytes(), writeOffset, readOffset, limit, maximumSize);
}
- public override int Load(string path, int writeOffset = 0, int readOffset = 0, int limit = -1)
+ public int Load(string path, int writeOffset = 0, int readOffset = 0, int limit = -1)
{
var maximumSize = this.Size - writeOffset;
return Load(path, ref this.Bytes(), writeOffset, readOffset, limit, maximumSize);
}
- public override int Load(byte[] from, int writeOffset = 0, int readOffset = 0, int limit = -1)
+ public int Load(byte[] from, int writeOffset = 0, int readOffset = 0, int limit = -1)
{
ArgumentNullException.ThrowIfNull(from);
@@ -88,10 +88,12 @@ namespace EightBit
return limit;
}
- public override byte Peek(ushort address) => this.Bytes()[address];
+ public byte Peek(ushort address) => this.Bytes()[address];
+
+ public void Poke(ushort address, byte value) => this.Bytes()[address] = value;
+
+ public virtual ref byte Reference(ushort address) => throw new NotImplementedException();
protected ref byte[] Bytes() => ref this._bytes;
-
- protected override void Poke(ushort address, byte value) => this.Bytes()[address] = value;
}
}
diff --git a/EightBit/UnusedMemory.cs b/EightBit/UnusedMemory.cs
index 04e2c19..d00dccf 100644
--- a/EightBit/UnusedMemory.cs
+++ b/EightBit/UnusedMemory.cs
@@ -4,21 +4,23 @@
namespace EightBit
{
- public class UnusedMemory(int size, byte unchanging) : Memory
+ public class UnusedMemory(int size, byte unchanging) : IMemory
{
private readonly int _size = size;
private readonly byte _unchanging = unchanging;
- public override int Size => this._size;
+ public int Size => this._size;
- public override int Load(FileStream file, int writeOffset = 0, int readOffset = 0, int limit = -1) => throw new NotImplementedException();
+ public int Load(FileStream file, int writeOffset = 0, int readOffset = 0, int limit = -1) => throw new NotImplementedException();
- public override int Load(string path, int writeOffset = 0, int readOffset = 0, int limit = -1) => throw new NotImplementedException();
+ public int Load(string path, int writeOffset = 0, int readOffset = 0, int limit = -1) => throw new NotImplementedException();
- public override int Load(byte[] from, int writeOffset = 0, int readOffset = 0, int limit = -1) => throw new NotImplementedException();
+ public int Load(byte[] from, int writeOffset = 0, int readOffset = 0, int limit = -1) => throw new NotImplementedException();
- public override byte Peek(ushort address) => this._unchanging;
+ public byte Peek(ushort address) => this._unchanging;
- protected override void Poke(ushort address, byte value) => throw new NotImplementedException();
+ public void Poke(ushort address, byte value) => throw new NotImplementedException();
+
+ public ref byte Reference(ushort address) => throw new NotImplementedException();
}
}