Timeline now passed via constructor
[Mograsim.git] / era.mi / src / era / mi / logic / components / Mux.java
index 6003723..818a175 100644 (file)
@@ -5,11 +5,13 @@ import java.util.Arrays;
 import java.util.Collections;\r
 import java.util.List;\r
 \r
-import era.mi.logic.wires.WireArray;\r
-import era.mi.logic.wires.WireArray.WireArrayEnd;\r
+import era.mi.logic.timeline.Timeline;\r
+import era.mi.logic.wires.Wire;\r
+import era.mi.logic.wires.Wire.ReadEnd;\r
+import era.mi.logic.wires.Wire.ReadWriteEnd;\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
+ * Models a multiplexer. Takes an arbitrary amount of input {@link Wire}s, one of which, as determined by select, is put through to the\r
  * output.\r
  * \r
  * @author Fabian Stemmler\r
@@ -17,27 +19,27 @@ import era.mi.logic.wires.WireArray.WireArrayEnd;
  */\r
 public class Mux extends BasicComponent\r
 {\r
-       private WireArray select;\r
-       private WireArrayEnd outI;\r
-       private WireArray[] inputs;\r
+       private ReadEnd select;\r
+       private ReadWriteEnd out;\r
+       private ReadEnd[] inputs;\r
        private final int outputSize;\r
 \r
        /**\r
-        * Input {@link WireArray}s and out must be of uniform length\r
+        * Input {@link Wire}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
+       public Mux(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd select, ReadEnd... inputs)\r
        {\r
-               super(processTime);\r
-               outputSize = out.length;\r
+               super(timeline, processTime);\r
+               outputSize = out.length();\r
 \r
                this.inputs = inputs.clone();\r
                for (int i = 0; i < this.inputs.length; i++)\r
                {\r
-                       if (inputs[i].length != outputSize)\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
@@ -45,20 +47,20 @@ public class Mux extends BasicComponent
                this.select = select;\r
                select.addObserver(this);\r
 \r
-               int maxInputs = 1 << select.length;\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
+                                       + select.length() + " select bits (" + maxInputs + ").");\r
 \r
-               outI = out.createInput();\r
+               this.out = out;\r
        }\r
 \r
-       public WireArray getOut()\r
+       public ReadEnd getOut()\r
        {\r
-               return outI.owner;\r
+               return out;\r
        }\r
 \r
-       public WireArray getSelect()\r
+       public ReadEnd getSelect()\r
        {\r
                return select;\r
        }\r
@@ -69,25 +71,25 @@ public class Mux extends BasicComponent
                int selectValue;\r
                if (!select.hasNumericValue() || (selectValue = (int) select.getUnsignedValue()) >= inputs.length)\r
                {\r
-                       outI.clearSignals();\r
+                       out.clearSignals();\r
                        return;\r
                }\r
 \r
-               WireArray active = inputs[selectValue];\r
-               outI.feedSignals(active.getValues());\r
+               ReadEnd active = inputs[selectValue];\r
+               out.feedSignals(active.getValues());\r
        }\r
 \r
        @Override\r
-       public List<WireArray> getAllInputs()\r
+       public List<ReadEnd> getAllInputs()\r
        {\r
-               ArrayList<WireArray> wires = new ArrayList<WireArray>(Arrays.asList(inputs));\r
+               ArrayList<ReadEnd> wires = new ArrayList<ReadEnd>(Arrays.asList(inputs));\r
                wires.add(select);\r
                return Collections.unmodifiableList(wires);\r
        }\r
 \r
        @Override\r
-       public List<WireArray> getAllOutputs()\r
+       public List<ReadWriteEnd> getAllOutputs()\r
        {\r
-               return Collections.unmodifiableList(Arrays.asList(outI.owner));\r
+               return List.of(out);\r
        }\r
 }\r