summaryrefslogtreecommitdiff
path: root/Chip/Bus.cs
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-04 00:58:48 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-04 00:58:48 +1000
commit86452af2d48e2d1883dbfd67316e371f2a593bfe (patch)
treeed9ffb784ea016ce3da63fc7ee45ac73e30bac94 /Chip/Bus.cs
Initial commit
Diffstat (limited to 'Chip/Bus.cs')
-rw-r--r--Chip/Bus.cs55
1 files changed, 55 insertions, 0 deletions
diff --git a/Chip/Bus.cs b/Chip/Bus.cs
new file mode 100644
index 0000000..e8cf5ad
--- /dev/null
+++ b/Chip/Bus.cs
@@ -0,0 +1,55 @@
+namespace Q1Emu.Chip;
+
+using System.Collections.Generic;
+using System.Linq;
+
+public class Bus : BusDevice
+{
+ public List<BusDevice> Devices;
+
+ public Bus(u16 addressableStart, u16 addressableEnd) : base(addressableStart, addressableEnd)
+ {
+ this.Devices = [];
+ }
+ private BusDevice? GetDevice(u16 address)
+ {
+ BusDevice? device = this.Devices.FirstOrDefault(x => address >= x.AddressableStart && address < x.AddressableEnd);
+ return device;
+ }
+
+ public override u8 Read(u16 address)
+ {
+ BusDevice? device = GetDevice(address);
+ if (device == null)
+ return 0;
+
+ return device.Read(address);
+ }
+
+ public override void Write(u16 address, u8 value)
+ {
+ BusDevice? device = GetDevice(address);
+ if (device == null)
+ return;
+
+ device.Write(address, value);
+ }
+
+ public override ref8 ReadSeq(u16 address, u16 length)
+ {
+ BusDevice? device = this.GetDevice(address);
+ if (device == null)
+ return [];
+
+ return device.ReadSeq(address, length);
+ }
+
+ public override void WriteSeq(u16 address, u16 length, ref8 value)
+ {
+ BusDevice? device = this.GetDevice(address);
+ if (device == null)
+ return;
+
+ device.WriteSeq(address, length, value);
+ }
+} \ No newline at end of file