Files
ZXSpectrum48K/Core/Memory/MemoryBus.cs

47 lines
1.3 KiB
C#

using System;
using Core.Interfaces;
namespace Core.Memory
{
public class MemoryBus : IMemory
{
// The flat 64KB memory space
private readonly byte[] _memory = new byte[0x10000];
public byte Read(ushort address)
{
return _memory[address];
}
public void Write(ushort address, byte value)
{
/* ZX Spectrum 48K Memory Map:
* 0x0000 - 0x3FFF: ROM (16KB) -> Cannot write here!
* 0x4000 - 0x57FF: Display File (Screen Pixels)
* 0x5800 - 0x5AFF: Color Attributes
* 0x5B00 - 0xFFFF: General Purpose RAM
*/
if (address < 0x4000)
{
// Attempted to write to the ROM area.
// We simply ignore the write command, just like real hardware.
return;
}
_memory[address] = value;
}
// Helper method to load the original Sinclair ROM file
public void LoadRom(byte[] romData)
{
if (romData.Length > 0x4000)
{
throw new ArgumentException("ROM file exceeds the 16KB capacity of Bank 0.");
}
// Copy the ROM data into the very beginning of the memory array
Array.Copy(romData, 0, _memory, 0, romData.Length);
}
}
}