From: Fabian Stemmler Date: Fri, 21 Jun 2019 13:02:41 +0000 (+0200) Subject: Quickfix for Wire.fuse(...) X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=e6d8e1a6099a1bc26af3851860bfd849543278c3;p=Mograsim.git Quickfix for Wire.fuse(...) The fusion of Wires caused an exception upon updating Wire values, if one of the fused Wires had no inputs, other than the Wire it was fused with. The Connector Component still has this issue. --- diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/tests/ComponentTest.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/tests/ComponentTest.java index a595f056..b80b2f30 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/tests/ComponentTest.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/tests/ComponentTest.java @@ -88,7 +88,7 @@ class ComponentTest } @Test - void fusionTest() + void fusionTest1() { t.reset(); Wire a = new Wire(t, 3, 1), b = new Wire(t, 2, 1), c = new Wire(t, 3, 1), out = new Wire(t, 8, 1); @@ -117,6 +117,17 @@ class ComponentTest assertBitArrayEquals(rC.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO); } + @Test + void fusionTest2() + { + t.reset(); + Wire a = new Wire(t, 3, 1), b = new Wire(t, 3, 1); + Wire.fuse(a, b); + a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.U, Bit.Z); + t.executeAll(); + assertBitArrayEquals(b.getValues(), Bit.ONE, Bit.U, Bit.Z); + } + @Test void triStateBufferTest() { @@ -430,7 +441,7 @@ class ComponentTest TestBitDisplay test = new TestBitDisplay(t, c.createReadOnlyEnd()); TestBitDisplay test2 = new TestBitDisplay(t, a.createReadOnlyEnd()); - LongConsumer print = time -> System.out.format("Time %2d\n a: %s\n b: %s\n c: %s\n", time, a, b, c); + LongConsumer print = time -> System.out.format("Time %2d\n a: %s\n b: %s\n c: %s\n", time, a, b, c); cI.feedSignals(Bit.ONE); test.assertAfterSimulationIs(print, Bit.ONE); 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 04ca9ce3..ec30040d 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 @@ -567,8 +567,11 @@ public class Wire @Override public void update(LogicObservable initiator) { - ReadWriteEnd read = (ReadWriteEnd) initiator; - target.setValues(fromTarget, read.wireValuesExcludingMe().subVector(fromSource, fromSource + length)); + ReadWriteEnd source = (ReadWriteEnd) initiator; + BitVector targetInput = (source.getWire().inputs.size() > 1) + ? source.wireValuesExcludingMe().subVector(fromSource, fromSource + length) + : BitVector.of(Bit.Z, length); + target.setValues(fromTarget, targetInput); } } } \ No newline at end of file