X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.logic.model.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fam2900%2Fcomponents%2Fam2910%2FModelAm2910SP.java;h=d9d1a60eacb3818ec25ed75c9513019cdf84c4d5;hb=ee699a26797fe00e442e41d980d501807a7e092f;hp=a99fe0d5cc23d6e30982ead0f02361581e648dba;hpb=b1249d69d59c5f9606cd3c453ac877c6307ba609;p=Mograsim.git diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910SP.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910SP.java index a99fe0d5..d9d1a60e 100644 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910SP.java +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910SP.java @@ -37,13 +37,7 @@ public class ModelAm2910SP extends SimpleRectangularHardcodedModelComponent @Override public Object recalculate(Object lastState, Map readEnds, Map readWriteEnds) { - BitAndInt SPC = (BitAndInt) lastState; - if (SPC == null) - { - SPC = new BitAndInt(); - SPC.bit = U; - SPC.i = -2; - } + BitAndInt SPC = castAndInitState(lastState); int SP = SPC.i; Bit STKI0Val = readEnds.get("STKI0").getValue(); @@ -77,18 +71,22 @@ public class ModelAm2910SP extends SimpleRectangularHardcodedModelComponent @Override protected Object getHighLevelState(Object state, String stateID) { + BitAndInt SPC = castAndInitState(state); + switch (stateID) { case "q": - return getAsBitVector(((BitAndInt) state).i); + return getAsBitVector(SPC.i); default: - return super.getHighLevelState(state, stateID); + return super.getHighLevelState(SPC, stateID); } } @Override protected Object setHighLevelState(Object lastState, String stateID, Object newHighLevelState) { + BitAndInt SPC = castAndInitState(lastState); + switch (stateID) { case "q": @@ -102,11 +100,23 @@ public class ModelAm2910SP extends SimpleRectangularHardcodedModelComponent 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; + SPC.i = i; + return SPC; default: - return super.setHighLevelState(lastState, stateID, newHighLevelState); + return super.setHighLevelState(SPC, stateID, newHighLevelState); + } + } + + private static BitAndInt castAndInitState(Object lastState) + { + BitAndInt SPC = (BitAndInt) lastState; + if (SPC == null) + { + SPC = new BitAndInt(); + SPC.bit = U; + SPC.i = -2; } + return SPC; } private static class BitAndInt