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.Wire;
\r
9 import era.mi.logic.wires.Wire.WireEnd;
\r
11 public class TriStateBuffer extends BasicComponent
\r
16 public TriStateBuffer(int processTime, WireEnd in, WireEnd out, WireEnd 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
32 protected void compute()
\r
34 if (enable.getValue() == Bit.ONE)
\r
35 out.feedSignals(in.getValues());
\r
41 public List<WireEnd> getAllInputs()
\r
43 return Collections.unmodifiableList(Arrays.asList(in, enable));
\r
47 public List<WireEnd> getAllOutputs()
\r
49 return Collections.unmodifiableList(Arrays.asList(out));
\r