readPort method

  1. @protected
LogicValue readPort(
  1. List<LogicValue> storage, {
  2. required bool? enable,
  3. required int? address,
})

Reads a combinationally addressed register file the way hardware does.

Implementation

@protected
LogicValue readPort(
  List<LogicValue> storage, {
  required bool? enable,
  required int? address,
}) {
  final width = storage.first.width;
  if (enable == false) {
    return LogicValue.filled(width, LogicValue.zero);
  }
  if (enable == null || address == null) {
    return LogicValue.filled(width, LogicValue.x);
  }
  return address < storage.length
      ? storage[address]
      : LogicValue.filled(width, LogicValue.zero);
}