1 package era.mi.logic.components;
\r
3 import java.util.Arrays;
\r
4 import java.util.Collections;
\r
5 import java.util.List;
\r
7 import era.mi.logic.Bit;
\r
8 import era.mi.logic.wires.WireArray;
\r
9 import era.mi.logic.wires.WireArray.WireArrayInput;
\r
11 public class TriStateBuffer extends BasicComponent {
\r
12 WireArray in, enable;
\r
13 WireArrayInput outI;
\r
15 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
31 if (enable.getValue() == Bit.ONE)
\r
32 outI.feedSignals(in.getValues());
\r
34 outI.clearSignals();
\r
38 public List<WireArray> getAllInputs() {
\r
39 return Collections.unmodifiableList(Arrays.asList(in, enable));
\r
43 public List<WireArray> getAllOutputs() {
\r
44 return Collections.unmodifiableList(Arrays.asList(outI.owner));
\r