X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FMux.java;h=b7cb674436b38f4545ac3758b4308fb8ca6a9056;hb=b7ce41467a2cbd9f45554982730741810e99feaa;hp=17680969ed0fcdaed521df07967f26c6d3054129;hpb=c18c04011cab0040c2287608eeefc9c3cc4536c2;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/components/Mux.java b/era.mi/src/era/mi/logic/components/Mux.java index 17680969..b7cb6744 100644 --- a/era.mi/src/era/mi/logic/components/Mux.java +++ b/era.mi/src/era/mi/logic/components/Mux.java @@ -5,11 +5,12 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import era.mi.logic.wires.WireArray; -import era.mi.logic.wires.WireArray.WireArrayEnd; +import era.mi.logic.wires.Wire; +import era.mi.logic.wires.Wire.ReadEnd; +import era.mi.logic.wires.Wire.ReadWriteEnd; /** - * Models a multiplexer. Takes an arbitrary amount of input {@link WireArray}s, one of which, as determined by select, is put through to the + * Models a multiplexer. Takes an arbitrary amount of input {@link Wire}s, one of which, as determined by select, is put through to the * output. * * @author Fabian Stemmler @@ -17,27 +18,27 @@ import era.mi.logic.wires.WireArray.WireArrayEnd; */ public class Mux extends BasicComponent { - private WireArray select; - private WireArrayEnd outI; - private WireArray[] inputs; + private ReadEnd select; + private ReadWriteEnd out; + private ReadEnd[] inputs; private final int outputSize; /** - * Input {@link WireArray}s and out must be of uniform length + * Input {@link Wire}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) + public Mux(int processTime, ReadWriteEnd out, ReadEnd select, ReadEnd... inputs) { super(processTime); - outputSize = out.length; + outputSize = out.length(); this.inputs = inputs.clone(); for (int i = 0; i < this.inputs.length; i++) { - if (inputs[i].length != outputSize) + if (inputs[i].length() != outputSize) throw new IllegalArgumentException("All MUX wire arrays must be of uniform length!"); inputs[i].addObserver(this); } @@ -45,20 +46,20 @@ public class Mux extends BasicComponent this.select = select; select.addObserver(this); - int maxInputs = 1 << select.length; + 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 + ")."); + + select.length() + " select bits (" + maxInputs + ")."); - outI = out.createInput(); + this.out = out; } - public WireArray getOut() + public ReadEnd getOut() { - return outI.owner; + return out; } - public WireArray getSelect() + public ReadEnd getSelect() { return select; } @@ -69,25 +70,25 @@ public class Mux extends BasicComponent int selectValue; if (!select.hasNumericValue() || (selectValue = (int) select.getUnsignedValue()) >= inputs.length) { - outI.clearSignals(); + out.clearSignals(); return; } - WireArray active = inputs[selectValue]; - outI.feedSignals(active.getValues()); + ReadEnd active = inputs[selectValue]; + out.feedSignals(active.getValues()); } @Override - public List getAllInputs() + public List getAllInputs() { - ArrayList wires = new ArrayList(Arrays.asList(inputs)); + ArrayList wires = new ArrayList(Arrays.asList(inputs)); wires.add(select); return Collections.unmodifiableList(wires); } @Override - public List getAllOutputs() + public List getAllOutputs() { - return List.of(outI.owner); + return List.of(out); } }