projects
/
Mograsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Reformatted everything. Eclipse built-in Linewrapping/Comments 140 chars
[Mograsim.git]
/
era.mi
/
src
/
era
/
mi
/
logic
/
components
/
Mux.java
diff --git
a/era.mi/src/era/mi/logic/components/Mux.java
b/era.mi/src/era/mi/logic/components/Mux.java
index
4e09f92
..
db01eb0
100644
(file)
--- a/
era.mi/src/era/mi/logic/components/Mux.java
+++ b/
era.mi/src/era/mi/logic/components/Mux.java
@@
-9,83
+9,76
@@
import era.mi.logic.wires.WireArray;
import era.mi.logic.wires.WireArray.WireArrayInput;
/**
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.
+ * 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
*
*/
* @author Fabian Stemmler
*
*/
-public class Mux extends BasicComponent
-{
+public class Mux extends BasicComponent {
private WireArray select;
private WireArrayInput outI;
private WireArray[] inputs;
private final int outputSize;
private WireArray select;
private WireArrayInput outI;
private WireArray[] inputs;
private final int outputSize;
+
/**
* Input {@link WireArray}s and out must be of uniform length
/**
* 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
*/
* @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, WireArray out, WireArray select, WireArray... inputs) {
super(processTime);
outputSize = out.length;
super(processTime);
outputSize = out.length;
-
+
this.inputs = inputs.clone();
this.inputs = inputs.clone();
- for(int i = 0; i < this.inputs.length; i++)
- {
- if(inputs[i].length != outputSize)
+ 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);
}
throw new IllegalArgumentException("All MUX wire arrays must be of uniform length!");
inputs[i].addObserver(this);
}
-
+
this.select = select;
select.addObserver(this);
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 "
+ 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();
}
outI = out.createInput();
}
-
- public WireArray getOut()
- {
+
+ public WireArray getOut() {
return outI.owner;
}
return outI.owner;
}
- public WireArray getSelect()
- {
+ public WireArray getSelect() {
return select;
}
@Override
public void compute() {
int selectValue;
return select;
}
@Override
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;
}
outI.clearSignals();
return;
}
-
+
WireArray active = inputs[selectValue];
outI.feedSignals(active.getValues());
}
@Override
WireArray active = inputs[selectValue];
outI.feedSignals(active.getValues());
}
@Override
- public List<WireArray> getAllInputs()
- {
+ public List<WireArray> getAllInputs() {
ArrayList<WireArray> wires = new ArrayList<WireArray>(Arrays.asList(inputs));
wires.add(select);
return Collections.unmodifiableList(wires);
}
@Override
ArrayList<WireArray> wires = new ArrayList<WireArray>(Arrays.asList(inputs));
wires.add(select);
return Collections.unmodifiableList(wires);
}
@Override
- public List<WireArray> getAllOutputs()
- {
+ public List<WireArray> getAllOutputs() {
return Collections.unmodifiableList(Arrays.asList(outI.owner));
}
}
return Collections.unmodifiableList(Arrays.asList(outI.owner));
}
}