1 package era.mi.logic.components;
\r
3 import java.util.List;
\r
5 import era.mi.logic.types.Bit;
\r
6 import era.mi.logic.wires.Wire.WireEnd;
\r
8 public class TriStateBuffer extends BasicComponent
\r
13 public TriStateBuffer(int processTime, WireEnd in, WireEnd out, WireEnd enable)
\r
16 if (in.length() != out.length())
\r
17 throw new IllegalArgumentException(
\r
18 "Tri-state output must have the same amount of bits as the input. Input: " + in.length() + " Output: " + out.length());
\r
19 if (enable.length() != 1)
\r
20 throw new IllegalArgumentException("Tri-state enable must have exactly one bit, not " + enable.length() + ".");
\r
22 in.addObserver(this);
\r
23 this.enable = enable;
\r
24 enable.addObserver(this);
\r
29 protected void compute()
\r
31 if (enable.getValue() == Bit.ONE)
\r
32 out.feedSignals(in.getValues());
\r
38 public List<WireEnd> getAllInputs()
\r
40 return List.of(in, enable);
\r
44 public List<WireEnd> getAllOutputs()
\r
46 return List.of(out);
\r