Add Z80 CPU skeleton, RegisterPair struct, and MemoryBus implementation

This commit is contained in:
Marc Parsons
2026-04-08 16:34:49 +01:00
parent 81912da3cb
commit ea828aad2d
9 changed files with 211 additions and 31 deletions

47
Core/Memory/MemoryBus.cs Normal file
View File

@@ -0,0 +1,47 @@
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);
}
}
}