X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fam2900%2Fcomponents%2FGUIdff4_finewe.java;h=8781f1ac4e7f20338cdb4c7d0bebe018b9cdf4e2;hb=0a04a4ed66ecebd4254541c4977599f6052c115a;hp=a96f400f5774f3ba3bacce60239a62cc1f33cd1c;hpb=bbe38c55aaa999d025f534245f9207a88643f6e5;p=Mograsim.git diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIdff4_finewe.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIdff4_finewe.java index a96f400f..8781f1ac 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIdff4_finewe.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIdff4_finewe.java @@ -6,11 +6,13 @@ import static net.mograsim.logic.core.types.Bit.X; import static net.mograsim.logic.core.types.Bit.Z; import static net.mograsim.logic.core.types.Bit.ZERO; +import java.util.Arrays; import java.util.Map; import net.mograsim.logic.core.types.Bit; -import net.mograsim.logic.core.wires.Wire.ReadEnd; -import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; +import net.mograsim.logic.core.types.BitVector; +import net.mograsim.logic.core.wires.CoreWire.ReadEnd; +import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd; import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent; import net.mograsim.logic.model.model.wires.Pin; @@ -22,7 +24,7 @@ public class GUIdff4_finewe extends SimpleRectangularHardcodedGUIComponent { public GUIdff4_finewe(ViewModelModifiable model, String name) { - super(model, name, "D flip flop\n4 bits"); + super(model, "GUIdff4_finewe", name, "D flip flop\n4 bits"); setSize(35, 90); addPin(new Pin(this, "C", 1, PinUsage.INPUT, 0, 5), Position.RIGHT); addPin(new Pin(this, "_WE1", 1, PinUsage.INPUT, 0, 15), Position.RIGHT); @@ -40,7 +42,7 @@ public class GUIdff4_finewe extends SimpleRectangularHardcodedGUIComponent } @Override - protected Object recalculate(Object lastState, Map readEnds, Map readWriteEnds) + public Object recalculate(Object lastState, Map readEnds, Map readWriteEnds) { Bit[] QC = (Bit[]) lastState; if (QC == null) @@ -70,6 +72,34 @@ public class GUIdff4_finewe extends SimpleRectangularHardcodedGUIComponent return QC; } + @Override + protected Object getHighLevelState(Object state, String stateID) + { + switch (stateID) + { + case "q": + return BitVector.of(Arrays.copyOfRange((Bit[]) state, 1, 5)); + default: + return super.getHighLevelState(state, stateID); + } + } + + @Override + protected Object setHighLevelState(Object lastState, String stateID, Object newHighLevelState) + { + switch (stateID) + { + case "q": + BitVector newHighLevelStateCasted = (BitVector) newHighLevelState; + if (newHighLevelStateCasted.length() != 4) + throw new IllegalArgumentException("Expected BitVector of length 4, not " + newHighLevelStateCasted.length()); + System.arraycopy(newHighLevelStateCasted.getBits(), 0, lastState, 1, 4); + return lastState; + default: + return super.setHighLevelState(lastState, stateID, newHighLevelState); + } + } + static { IndirectGUIComponentCreator.setComponentSupplier(GUIdff4_finewe.class.getCanonicalName(), (m, p, n) -> new GUIdff4_finewe(m, n));