/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyMemoryBank" /> class. /// </summary> /// <param name="memoryBankConfig">The memory bank configuration.</param> /// <exception cref="MemoryConfigStateException"></exception> public ReadOnlyMemoryBank(IMemoryBankConfig memoryBankConfig) { if (memoryBankConfig.InitialState == null || memoryBankConfig.Length != memoryBankConfig.InitialState.Length) { throw new MemoryConfigStateException(memoryBankConfig.Address, memoryBankConfig.Length, memoryBankConfig.InitialState?.Length ?? 0); } _memory = new byte[memoryBankConfig.Length]; Array.Copy(memoryBankConfig.InitialState, 0, _memory, 0, memoryBankConfig.InitialState.Length); Type = memoryBankConfig.Type; Address = memoryBankConfig.Address; Length = memoryBankConfig.Length; }
/// <summary> /// Initializes a new instance of the <see cref="ArrayBackedMemoryBank"/> class. /// </summary> /// <param name="memoryBankConfig">The memory bank configuration.</param> /// <exception cref="MemoryConfigStateException"></exception> public ArrayBackedMemoryBank(IMemoryBankConfig memoryBankConfig) { Memory = new byte[memoryBankConfig.Length]; Type = memoryBankConfig.Type; Address = memoryBankConfig.Address; Length = memoryBankConfig.Length; if (memoryBankConfig.InitialState == null) { return; } if (memoryBankConfig.Length != memoryBankConfig.InitialState.Length) { throw new MemoryConfigStateException(memoryBankConfig.Address, memoryBankConfig.Length, memoryBankConfig.InitialState.Length); } Array.Copy(memoryBankConfig.InitialState, 0, Memory, 0, memoryBankConfig.InitialState.Length); }
/// <summary> /// Initializes a new instance of the <see cref="NullMemoryBank" /> class. /// </summary> /// <param name="memoryBankConfig">The memory bank configuration.</param> public NullMemoryBank(IMemoryBankConfig memoryBankConfig) { Type = memoryBankConfig.Type; Address = memoryBankConfig.Address; Length = memoryBankConfig.Length; }