public static void Read(int port, Registers reg, VirtualMachine vm) { if (ReadPorts.ContainsKey(port)) { ReadPorts[port].HandleRead(port, reg, vm); return; } throw new Exception($"Unmapped Port 0x{port.ToString("x")}"); }
public static void ScanDevices() { foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { if (type.GetInterfaces().Contains(typeof(IPortMappedDevice))) { var device = (IPortMappedDevice)Activator.CreateInstance(type); var attrs = type.GetCustomAttributes <PortAttribute>(); foreach (var att in attrs) { if (att.Access == PortAccess.Read) { ReadPorts.Add(att.Address, device); } else { WritePorts.Add(att.Address, device); } } } } }