/// <summary> /// Writes a single byte at the specified address. /// </summary> /// <param name="address">The address where to start writing the data.</param> /// <param name="data">The single byte to write.</param> public void Write(int address, byte data) { DeviceMemoryRange deviceMemoryRange = GetDeviceMemoryRangeByAddress(address); int deviceAddress = CalculateDeviceAddress(deviceMemoryRange, address); deviceMemoryRange.Device.Write(deviceAddress, data); }
/// <summary> /// Reads a single byte from the specified address. /// </summary> /// <param name="address">The address where to start reading the data.</param> public byte Read(int address) { DeviceMemoryRange deviceMemoryRange = GetDeviceMemoryRangeByAddress(address); int deviceAddress = CalculateDeviceAddress(deviceMemoryRange, address); return(deviceMemoryRange.Device.Read(deviceAddress)); }
/// <summary> /// Calculates the relative device address from the specified device mapping and the specified absolute address. /// </summary> /// <param name="deviceMemoryRange">The memory mapping of the device.</param> /// <param name="address">The absolute address to be converted to an device address.</param> /// <returns>The relative device address.</returns> private int CalculateDeviceAddress(DeviceMemoryRange deviceMemoryRange, int address) { return(address - deviceMemoryRange.Range.From); }