X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fwires%2FWire.java;h=a14efb08ad884ebdd9b6970b46b68b175b5d6f31;hb=c6ad3a18e8a437d7b131b203267fe2723708641f;hp=fc7d346856deae23397e630282f488116e91dcb8;hpb=2bc7d9114dc95b4a2b75c402f3ed63bf8b4a09b2;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 fc7d3468..a14efb08 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.get()); - } - 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. * @@ -495,7 +491,7 @@ public class Wire continue; mutator.join(wireEnd.inputValues); } - return mutator.get(); + return mutator.toBitVector(); } @Override