X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fam2900%2Fcomponents%2FGUIdff12.java;h=03e26d440fe6a8663238701579284374d67149cd;hb=039f31334c661633b71e945aa4332cedb7055526;hp=b4cfb897047f696d951196785f8f8a5dc2042104;hpb=bbe38c55aaa999d025f534245f9207a88643f6e5;p=Mograsim.git diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIdff12.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIdff12.java index b4cfb897..03e26d44 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIdff12.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIdff12.java @@ -8,6 +8,7 @@ import java.util.Arrays; import java.util.Map; import net.mograsim.logic.core.types.Bit; +import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.core.wires.Wire.ReadEnd; import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; import net.mograsim.logic.model.model.ViewModelModifiable; @@ -21,7 +22,7 @@ public class GUIdff12 extends SimpleRectangularHardcodedGUIComponent { public GUIdff12(ViewModelModifiable model, String name) { - super(model, name, "D flip flop\n12 bits"); + super(model, "GUIdff12", name, "D flip flop\n12 bits"); setSize(40, 20); addPin(new Pin(this, "D", 12, PinUsage.INPUT, 20, 20), Position.TOP); addPin(new Pin(this, "C", 1, PinUsage.INPUT, 0, 10), Position.RIGHT); @@ -29,7 +30,7 @@ public class GUIdff12 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) @@ -49,6 +50,34 @@ public class GUIdff12 extends SimpleRectangularHardcodedGUIComponent return QC; } + @Override + protected Object getHighLevelState(Object state, String stateID) + { + switch (stateID) + { + case "q": + return BitVector.of(Arrays.copyOfRange((Bit[]) state, 0, 12)); + 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() != 12) + throw new IllegalArgumentException("Expected BitVector of length 12, not " + newHighLevelStateCasted.length()); + System.arraycopy(newHighLevelStateCasted.getBits(), 0, lastState, 0, 12); + return lastState; + default: + return super.setHighLevelState(lastState, stateID, newHighLevelState); + } + } + static { IndirectGUIComponentCreator.setComponentSupplier(GUIdff12.class.getCanonicalName(), (m, p, n) -> new GUIdff12(m, n));