From 9b34381259d5e6cb46bd3834712311cd60317506 Mon Sep 17 00:00:00 2001 From: Christian Femers Date: Mon, 2 Sep 2019 09:39:30 +0200 Subject: [PATCH] Maybe needs review: fixed bug in ManualSwitch concerning the input The problem was, that the method getInputValues() did not really return the current input values, but the last ones that already reached the wire. This means that different value ranges could not be combined, since the method already returned the some time ago successfully inputed values. This could also cause Problems with setState, since this method used to compare the argument against the values inputed on the wire, but not some feedSignals call that is sill due in the Timeline. Therefore a value change might be discarded although it might actually change the values again (back): new: 1010 --- (still in Timeline: 0000) --- already set: 1010 The old method would not have noticed this and ignored the new values. It is possible, that there are more bugs like this in logic core. --- .../net/mograsim/logic/core/components/ManualSwitch.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java index 40f0005a..fa31f0c6 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java @@ -22,12 +22,14 @@ public class ManualSwitch extends Component implements LogicObservable { private Collection observers; private ReadWriteEnd output; + private BitVector inputValues; public ManualSwitch(Timeline timeline, ReadWriteEnd output) { super(timeline); observers = new ArrayList<>(); this.output = output; + this.inputValues = output.getInputValues(); } public void switchFullOn() @@ -57,8 +59,9 @@ public class ManualSwitch extends Component implements LogicObservable { if (bits.length() != output.width()) throw new IllegalArgumentException("Incorrect bit vector length"); - if (bits.equals(output.getInputValues())) + if (bits.equals(inputValues)) return; + inputValues = bits; output.feedSignals(bits); notifyObservers(); } @@ -70,7 +73,7 @@ public class ManualSwitch extends Component implements LogicObservable public BitVector getValues() { - return output.getInputValues(); + return inputValues; } @Override -- 2.17.1