X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fam2900%2Fcomponents%2Fam2910%2FGUIAm2910SP.java;h=fb449d25b57e7ea7a57a59c478084d96bc40d819;hb=49633e6eb96305bfa6cbacab46216ff816074fbf;hp=c4b44f3699d793f3fd855888c9ba516b8af0489f;hpb=c9cca272f312bdea6cf661e861508fca2431a9d2;p=Mograsim.git diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910SP.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910SP.java index c4b44f36..fb449d25 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910SP.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910SP.java @@ -14,6 +14,7 @@ import net.mograsim.logic.core.wires.Wire.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; +import net.mograsim.logic.model.model.wires.PinUsage; import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator; import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position; @@ -23,16 +24,16 @@ public class GUIAm2910SP extends SimpleRectangularHardcodedGUIComponent { super(model, name, "Stack\npointer"); setSize(40, 30); - addPin(new Pin(this, "STKI0", 1, 0, 5), Usage.INPUT, Position.RIGHT); - addPin(new Pin(this, "STKI1", 1, 0, 15), Usage.INPUT, Position.RIGHT); - addPin(new Pin(this, "C", 1, 0, 25), Usage.INPUT, Position.RIGHT); - addPin(new Pin(this, "A", 3, 10, 30), Usage.OUTPUT, Position.TOP); - addPin(new Pin(this, "B", 3, 30, 30), Usage.OUTPUT, Position.TOP); - addPin(new Pin(this, "_FULL", 1, 40, 15), Usage.OUTPUT, Position.LEFT); + addPin(new Pin(this, "STKI0", 1, PinUsage.INPUT, 0, 5), Position.RIGHT); + addPin(new Pin(this, "STKI1", 1, PinUsage.INPUT, 0, 15), Position.RIGHT); + addPin(new Pin(this, "C", 1, PinUsage.INPUT, 0, 25), Position.RIGHT); + addPin(new Pin(this, "A", 3, PinUsage.OUTPUT, 10, 30), Position.TOP); + addPin(new Pin(this, "B", 3, PinUsage.OUTPUT, 30, 30), Position.TOP); + addPin(new Pin(this, "_FULL", 1, PinUsage.OUTPUT, 40, 15), Position.LEFT); } @Override - protected Object recalculate(Object lastState, Map readEnds, Map readWriteEnds) + public Object recalculate(Object lastState, Map readEnds, Map readWriteEnds) { BitAndInt SPC = (BitAndInt) lastState; if (SPC == null) @@ -62,7 +63,7 @@ public class GUIAm2910SP extends SimpleRectangularHardcodedGUIComponent else if (STKI0Val == ONE && STKI1Val == ONE) // POP SP = SP <= 0 ? SP : SP - 1; - readWriteEnds.get("A").feedSignals(getAsBitVector(SP == 0 ? 7 : SP - 1)); + readWriteEnds.get("A").feedSignals(getAsBitVector(SP == 0 ? 7 : SP < 0 ? SP : SP - 1)); readWriteEnds.get("B").feedSignals(getAsBitVector(SP == 5 ? 4 : SP)); readWriteEnds.get("_FULL").feedSignals(SP == -2 ? U : SP == -1 ? X : SP == 5 ? ZERO : ONE); @@ -71,6 +72,41 @@ public class GUIAm2910SP extends SimpleRectangularHardcodedGUIComponent return SPC; } + @Override + protected Object getHighLevelState(Object state, String stateID) + { + switch (stateID) + { + case "q": + return getAsBitVector(((BitAndInt) state).i); + default: + return super.getHighLevelState(state, stateID); + } + } + + @Override + protected Object setHighLevelState(Object lastState, String stateID, Object newHighLevelState) + { + switch (stateID) + { + case "q": + int i; + BitVector newHighLevelStateCasted = (BitVector) newHighLevelState; + if (newHighLevelStateCasted.length() != 3) + throw new IllegalArgumentException("Expected BitVector of length 3, not " + newHighLevelStateCasted.length()); + if (newHighLevelStateCasted.isBinary()) + i = newHighLevelStateCasted.getUnsignedValue().intValue(); + else + i = -1;// this makes setting to U impossible + if (i > 5) + throw new IllegalArgumentException("Given value not in range (0-5 incl.): " + i); + ((BitAndInt) lastState).i = i; + return lastState; + default: + return super.setHighLevelState(lastState, stateID, newHighLevelState); + } + } + private static class BitAndInt { Bit bit;