X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FMux.java;h=d6307f9a9354346b74dc982bb662b9465c7f8c9a;hb=18cf2f85ed378005aa93c8b88fe5fa055a108fad;hp=4e09f9251db7d5ea68f28b8b3bc1b336d44067dc;hpb=bcf8d773c7a836c2ee17e17a49c296ebf31d2777;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 4e09f925..d6307f9a 100644 --- a/era.mi/src/era/mi/logic/components/Mux.java +++ b/era.mi/src/era/mi/logic/components/Mux.java @@ -6,52 +6,53 @@ import java.util.Collections; import java.util.List; import era.mi.logic.wires.WireArray; -import era.mi.logic.wires.WireArray.WireArrayInput; +import era.mi.logic.wires.WireArray.WireArrayEnd; /** - * 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. + * 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 WireArrayEnd 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 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++) + 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); } - + 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 " + 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; @@ -63,14 +64,15 @@ public class Mux extends BasicComponent } @Override - public void compute() { + public void compute() + { int selectValue; - if(!select.hasNumericValue() || (selectValue = (int) select.getUnsignedValue()) >= inputs.length) + if (!select.hasNumericValue() || (selectValue = (int) select.getUnsignedValue()) >= inputs.length) { outI.clearSignals(); return; } - + WireArray active = inputs[selectValue]; outI.feedSignals(active.getValues()); }