1 package era.mi.logic.components;
\r
3 import java.util.List;
\r
5 import era.mi.logic.Bit;
\r
6 import era.mi.logic.wires.WireArray;
\r
7 import era.mi.logic.wires.WireArray.WireArrayEnd;
\r
9 public class TriStateBuffer extends BasicComponent
\r
11 WireArray in, enable;
\r
14 public TriStateBuffer(int processTime, WireArray in, WireArray out, WireArray enable)
\r
17 if (in.length != out.length)
\r
18 throw new IllegalArgumentException(
\r
19 "Tri-state output must have the same amount of bits as the input. Input: " + in.length + " Output: " + out.length);
\r
20 if (enable.length != 1)
\r
21 throw new IllegalArgumentException("Tri-state enable must have exactly one bit, not " + enable.length + ".");
\r
23 in.addObserver(this);
\r
24 this.enable = enable;
\r
25 enable.addObserver(this);
\r
26 outI = out.createInput();
\r
30 protected void compute()
\r
32 if (enable.getValue() == Bit.ONE)
\r
33 outI.feedSignals(in.getValues());
\r
35 outI.clearSignals();
\r
39 public List<WireArray> getAllInputs()
\r
41 return List.of(in, enable);
\r
45 public List<WireArray> getAllOutputs()
\r
47 return List.of(outI.owner);
\r