X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fwires%2FWire.java;h=f42447192389529039a42a181861b0dc4975071d;hb=61e725f32f7d78ce8fe416deeec0b0ca1475747f;hp=86add6202ee17ab25e356966684fd4bd28e6b1ca;hpb=6a2fce7c0b04020da386277ac1ad99bf1b0dc2eb;p=Mograsim.git diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/wires/Wire.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/wires/Wire.java index 86add620..f4244719 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/wires/Wire.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/wires/Wire.java @@ -51,19 +51,6 @@ public class Wire values = U.toVector(length); } - private void recalculateSingleInput() - { - setNewValues(inputs.get(0).getInputValues()); - } - - private void recalculateMultipleInputs() - { - BitVectorMutator mutator = BitVectorMutator.empty(); - for (ReadWriteEnd wireArrayEnd : inputs) - mutator.join(wireArrayEnd.getInputValues()); - setNewValues(mutator.toBitVector()); - } - private void setNewValues(BitVector newValues) { if (values.equals(newValues)) @@ -75,19 +62,28 @@ public class Wire void recalculate() { - switch (inputs.size()) - { - case 0: + if (inputs.size() == 0) setNewValues(BitVector.of(Bit.U, length)); - break; - case 1: - recalculateSingleInput(); - break; - default: - recalculateMultipleInputs(); + else + { + BitVectorMutator mutator = BitVectorMutator.empty(); + for (ReadWriteEnd wireArrayEnd : inputs) + mutator.join(wireArrayEnd.getInputValues()); + setNewValues(mutator.toBitVector()); } } + /** + * Forces a Wire to take on specific values. If the new values differ from the old ones, the observers of the Wire will be notified. + * WARNING! Use this with care! The preferred way of writing the values is ReadWriteEnd.feedSignals(BitVector) + * + * @param values The values the Wire will have immediately after this method is called + */ + public void forceValues(BitVector values) + { + setNewValues(values); + } + /** * The {@link Wire} is interpreted as an unsigned integer with n bits. *