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/BusDevice.cs | |
Initial commit
Diffstat (limited to 'Chip/BusDevice.cs')
| -rw-r--r-- | Chip/BusDevice.cs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Chip/BusDevice.cs b/Chip/BusDevice.cs new file mode 100644 index 0000000..e1f559c --- /dev/null +++ b/Chip/BusDevice.cs @@ -0,0 +1,50 @@ +namespace Q1Emu.Chip; + +using System.Runtime.CompilerServices; + +public abstract class BusDevice +{ + public BusDevice(u16 addressableStart, u16 addressableEnd) + { + this.AddressableStart = addressableStart; + this.AddressableEnd = addressableEnd; + } + + public Bus Bus { get; set; } + public abstract u8 Read(u16 address); + public abstract void Write(u16 address, u8 value); + + public abstract ref8 ReadSeq(u16 address, u16 length); + public abstract void WriteSeq(u16 address, u16 length, ref8 value); + + public u16 ReadWord(u16 address) + { + ref8 data = this.ReadSeq(address, 2); + u16 value = Make.u16(data); + return value; + } + + public void WriteWord(u16 address, u16 value) + { + ref8 data = Make.ref8(value); + this.WriteSeq(address, 2, data); + } + + public virtual void Clock() { } + public virtual void Reset() { } + + public void AttachToBus(Bus bus) + { + this.Bus = bus; + bus.Devices.Add(this); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected u16 GetRelativeAddress(u16 address) + { + return (u16) (address - this.AddressableStart); + } + + public u16 AddressableStart { get; } + public u16 AddressableEnd { get; } +}
\ No newline at end of file |
