-package era.mi.logic.components;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import era.mi.logic.Bit;
-import era.mi.logic.wires.WireArray;
-import era.mi.logic.wires.WireArray.WireArrayInput;
-
-public class TriStateBuffer extends BasicComponent{
- WireArray in, enable;
- WireArrayInput outI;
-
- public TriStateBuffer(int processTime, WireArray in, WireArray out, WireArray enable) {
- super(processTime);
- if(in.length != out.length)
- throw new IllegalArgumentException("Tri-state output must have the same amount of bits as the input. Input: " + in.length + " Output: " + out.length);
- if(enable.length != 1)
- throw new IllegalArgumentException("Tri-state enable must have exactly one bit, not " + enable.length + ".");
- this.in = in;
- in.addObserver(this);
- this.enable = enable;
- enable.addObserver(this);
- outI = out.createInput();
- }
-
- @Override
- protected void compute()
- {
- if(enable.getValue() == Bit.ONE)
- outI.feedSignals(in.getValues());
- else
- outI.clearSignals();
- }
-
- @Override
- public List<WireArray> getAllInputs()
- {
- return Collections.unmodifiableList(Arrays.asList(in, enable));
- }
-
- @Override
- public List<WireArray> getAllOutputs()
- {
- return Collections.unmodifiableList(Arrays.asList(outI.owner));
- }
-
-}
+package era.mi.logic.components;\r
+\r
+import java.util.List;\r
+\r
+import era.mi.logic.Bit;\r
+import era.mi.logic.wires.Wire.WireEnd;\r
+\r
+public class TriStateBuffer extends BasicComponent\r
+{\r
+ WireEnd in, enable;\r
+ WireEnd out;\r
+\r
+ public TriStateBuffer(int processTime, WireEnd in, WireEnd out, WireEnd enable)\r
+ {\r
+ super(processTime);\r
+ if (in.length() != out.length())\r
+ throw new IllegalArgumentException(\r
+ "Tri-state output must have the same amount of bits as the input. Input: " + in.length() + " Output: " + out.length());\r
+ if (enable.length() != 1)\r
+ throw new IllegalArgumentException("Tri-state enable must have exactly one bit, not " + enable.length() + ".");\r
+ this.in = in;\r
+ in.addObserver(this);\r
+ this.enable = enable;\r
+ enable.addObserver(this);\r
+ this.out = out;\r
+ }\r
+\r
+ @Override\r
+ protected void compute()\r
+ {\r
+ if (enable.getValue() == Bit.ONE)\r
+ out.feedSignals(in.getValues());\r
+ else\r
+ out.clearSignals();\r
+ }\r
+\r
+ @Override\r
+ public List<WireEnd> getAllInputs()\r
+ {\r
+ return List.of(in, enable);\r
+ }\r
+\r
+ @Override\r
+ public List<WireEnd> getAllOutputs()\r
+ {\r
+ return List.of(out);\r
+ }\r
+\r
+}\r