-package era.mi.logic.components;
-
-import era.mi.logic.wires.WireArray;
-import era.mi.logic.wires.WireArray.WireArrayInput;
-
-/**
- * Models a multiplexer. Takes an arbitrary amount of input {@link WireArray}s, one of which,
- * as determined by select, is put through to the output.
- * @author Fabian Stemmler
- *
- */
-public class Mux extends BasicComponent
-{
- private WireArray select;
- private WireArrayInput outI;
- private WireArray[] inputs;
- private final int outputSize;
- /**
- * Input {@link WireArray}s and out must be of uniform length
- * @param out Must be of uniform length with all inputs.
- * @param select Indexes the input array which is to be mapped to the output. Must have enough bits
- * to index all inputs.
- * @param inputs One of these inputs is mapped to the output, depending on the select bits
- */
- public Mux(int processTime, WireArray out, WireArray select, WireArray... inputs)
- {
- super(processTime);
- outputSize = out.length;
-
- this.inputs = inputs.clone();
- for(int i = 0; i < this.inputs.length; i++)
- {
- if(inputs[i].length != outputSize)
- throw new IllegalArgumentException("All MUX wire arrays must be of uniform length!");
- inputs[i].addObserver(this);
- }
-
- this.select = select;
- select.addObserver(this);
-
- int maxInputs = 1 << select.length;
- if(this.inputs.length > maxInputs)
- throw new IllegalArgumentException("There are more inputs ("
- + this.inputs.length + ") to the MUX than supported by "
- + select.length + " select bits (" + maxInputs + ").");
-
- outI = out.createInput();
- }
-
- public WireArray getOut()
- {
- return outI.owner;
- }
-
- public WireArray getSelect()
- {
- return select;
- }
-
- @Override
- public void compute() {
- int selectValue;
- if(!select.hasNumericValue() || (selectValue = (int) select.getUnsignedValue()) >= inputs.length)
- {
- outI.clearSignals();
- return;
- }
-
- WireArray active = inputs[selectValue];
- outI.feedSignals(active.getValues());
- }
-}
+package era.mi.logic.components;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import era.mi.logic.wires.WireArray;\r
+import era.mi.logic.wires.WireArray.WireArrayInput;\r
+\r
+/**\r
+ * Models a multiplexer. Takes an arbitrary amount of input {@link WireArray}s, one of which, as determined by select, is put through to the\r
+ * output.\r
+ * \r
+ * @author Fabian Stemmler\r
+ *\r
+ */\r
+public class Mux extends BasicComponent {\r
+ private WireArray select;\r
+ private WireArrayInput outI;\r
+ private WireArray[] inputs;\r
+ private final int outputSize;\r
+\r
+ /**\r
+ * Input {@link WireArray}s and out must be of uniform length\r
+ * \r
+ * @param out Must be of uniform length with all inputs.\r
+ * @param select Indexes the input array which is to be mapped to the output. Must have enough bits to index all inputs.\r
+ * @param inputs One of these inputs is mapped to the output, depending on the select bits\r
+ */\r
+ public Mux(int processTime, WireArray out, WireArray select, WireArray... inputs) {\r
+ super(processTime);\r
+ outputSize = out.length;\r
+\r
+ this.inputs = inputs.clone();\r
+ for (int i = 0; i < this.inputs.length; i++) {\r
+ if (inputs[i].length != outputSize)\r
+ throw new IllegalArgumentException("All MUX wire arrays must be of uniform length!");\r
+ inputs[i].addObserver(this);\r
+ }\r
+\r
+ this.select = select;\r
+ select.addObserver(this);\r
+\r
+ int maxInputs = 1 << select.length;\r
+ if (this.inputs.length > maxInputs)\r
+ throw new IllegalArgumentException("There are more inputs (" + this.inputs.length + ") to the MUX than supported by "\r
+ + select.length + " select bits (" + maxInputs + ").");\r
+\r
+ outI = out.createInput();\r
+ }\r
+\r
+ public WireArray getOut() {\r
+ return outI.owner;\r
+ }\r
+\r
+ public WireArray getSelect() {\r
+ return select;\r
+ }\r
+\r
+ @Override\r
+ public void compute() {\r
+ int selectValue;\r
+ if (!select.hasNumericValue() || (selectValue = (int) select.getUnsignedValue()) >= inputs.length) {\r
+ outI.clearSignals();\r
+ return;\r
+ }\r
+\r
+ WireArray active = inputs[selectValue];\r
+ outI.feedSignals(active.getValues());\r
+ }\r
+\r
+ @Override\r
+ public List<WireArray> getAllInputs() {\r
+ ArrayList<WireArray> wires = new ArrayList<WireArray>(Arrays.asList(inputs));\r
+ wires.add(select);\r
+ return Collections.unmodifiableList(wires);\r
+ }\r
+\r
+ @Override\r
+ public List<WireArray> getAllOutputs() {\r
+ return Collections.unmodifiableList(Arrays.asList(outI.owner));\r
+ }\r
+}\r