diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-04 00:58:48 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-04 00:58:48 +1000 |
| commit | 86452af2d48e2d1883dbfd67316e371f2a593bfe (patch) | |
| tree | ed9ffb784ea016ce3da63fc7ee45ac73e30bac94 /Chip/RamDevice.cs | |
Initial commit
Diffstat (limited to 'Chip/RamDevice.cs')
| -rw-r--r-- | Chip/RamDevice.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Chip/RamDevice.cs b/Chip/RamDevice.cs new file mode 100644 index 0000000..6811d22 --- /dev/null +++ b/Chip/RamDevice.cs @@ -0,0 +1,49 @@ +namespace Q1Emu.Chip; + +using System; +using System.Runtime.CompilerServices; + +public class RamDevice : BusDevice +{ + public u8[] Memory; + + public RamDevice(u16 start, u16 size) : base(start, (u16) (start + size)) + { + this.Memory = new u8[size]; + } + + public override void Reset() + { + this.Memory = new u8[this.AddressableEnd - this.AddressableStart]; + } + + public override void Clock() + { + // No clocking needed for RAM + } + + public override u8 Read(u16 address) + { + u16 relativeAddress = this.GetRelativeAddress(address); + return this.Memory[relativeAddress]; + } + + public override void Write(u16 address, u8 value) + { + u16 relativeAddress = this.GetRelativeAddress(address); + this.Memory[relativeAddress] = value; + } + + public override ref8 ReadSeq(u16 address, u16 length) + { + u16 relativeAddress = this.GetRelativeAddress(address); + // Console.WriteLine($"{address:X4} {relativeAddress:X4} {length:X4}"); + return new ref8(this.Memory, relativeAddress, length); + } + + public override void WriteSeq(u16 address, u16 length, ref8 value) + { + ref8 destination = this.ReadSeq(address, length); + value.CopyTo(destination); + } +}
\ No newline at end of file |
