First OpCode Decoding attempt

This commit is contained in:
2026-06-06 01:49:33 +01:00
parent 3498961aae
commit 806fecaffa
7 changed files with 289 additions and 18 deletions

View File

@@ -0,0 +1,49 @@
using System;
using ParsonsMegadrive.Core.Interfaces;
namespace ParsonsMegaDrive.Core.Memory
{
public class MdMemoryBus : IMemoryBus
{
// For testing, we'll just give it a flat 16MB array to represent the whole address space.
// Later, we will map this properly to ROM (0x000000), Work RAM (0xFF0000), etc.
private readonly byte[] _memory = new byte[16 * 1024 * 1024];
public byte Read8(uint address)
{
return _memory[address & 0xFFFFFF]; // 24-bit address mask
}
public void Write8(uint address, byte value)
{
_memory[address & 0xFFFFFF] = value;
}
public ushort Read16(uint address)
{
// BIG-ENDIAN: High byte comes first!
byte high = Read8(address);
byte low = Read8(address + 1);
return (ushort)((high << 8) | low);
}
public void Write16(uint address, ushort value)
{
Write8(address, (byte)(value >> 8)); // High byte
Write8(address + 1, (byte)(value & 0xFF)); // Low byte
}
public uint Read32(uint address)
{
ushort highWord = Read16(address);
ushort lowWord = Read16(address + 2);
return (uint)((highWord << 16) | lowWord);
}
public void Write32(uint address, uint value)
{
Write16(address, (ushort)(value >> 16));
Write16(address + 2, (ushort)(value & 0xFFFF));
}
}
}