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.WireArrayEnd;
\r
11 public class TriStateBuffer extends BasicComponent
\r
13 WireArray in, enable;
\r
16 public TriStateBuffer(int processTime, WireArray in, WireArray out, WireArray enable)
\r
19 if (in.length != out.length)
\r
20 throw new IllegalArgumentException(
\r
21 "Tri-state output must have the same amount of bits as the input. Input: " + in.length + " Output: " + out.length);
\r
22 if (enable.length != 1)
\r
23 throw new IllegalArgumentException("Tri-state enable must have exactly one bit, not " + enable.length + ".");
\r
25 in.addObserver(this);
\r
26 this.enable = enable;
\r
27 enable.addObserver(this);
\r
28 outI = out.createInput();
\r
32 protected void compute()
\r
34 if (enable.getValue() == Bit.ONE)
\r
35 outI.feedSignals(in.getValues());
\r
37 outI.clearSignals();
\r
41 public List<WireArray> getAllInputs()
\r
43 return Collections.unmodifiableList(Arrays.asList(in, enable));
\r
47 public List<WireArray> getAllOutputs()
\r
49 return Collections.unmodifiableList(Arrays.asList(outI.owner));
\r