X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fwires%2FWire.java;h=f42447192389529039a42a181861b0dc4975071d;hb=61e725f32f7d78ce8fe416deeec0b0ca1475747f;hp=a1361b0cb5d447914ec4085d1d014049dc789e89;hpb=b9bb4f6396099db98e7cafd86bade4cdd258f9ca;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 a1361b0c..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.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 @@ -556,7 +552,7 @@ public class Wire * @param fromB The first bit of {@link Wire} b to be fused * @param length The amount of bits to fuse */ - private static void fuse(Wire a, Wire b, int fromA, int fromB, int length) + public static void fuse(Wire a, Wire b, int fromA, int fromB, int length) { ReadWriteEnd rA = a.createReadWriteEnd(), rB = b.createReadWriteEnd(); rA.setWriting(false);