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%2FModelAm2910RegCntr.java;h=baa19bf3fa88dfb8d029fd3d124635a595067f07;hb=e600c87c4bce2f41da6c5087702cab9ddca05221;hp=0c101bb4d4e4ddfe08f385bdcba1ccbc2eb43a5e;hpb=7d05144c25daa53e60fc9ed9fd503546a86567f8;p=Mograsim.git diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java index 0c101bb4..baa19bf3 100644 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java @@ -26,7 +26,7 @@ public class ModelAm2910RegCntr extends SimpleRectangularHardcodedModelComponent setSize(40, 40); addPin(new Pin(model, this, "D", 12, PinUsage.INPUT, 20, 0), Position.BOTTOM); addPin(new Pin(model, this, "_RLD", 1, PinUsage.INPUT, 0, 5), Position.RIGHT); - addPin(new Pin(model, this, "WE", 1, PinUsage.INPUT, 0, 20), Position.RIGHT); + addPin(new Pin(model, this, "LD", 1, PinUsage.INPUT, 0, 20), Position.RIGHT); addPin(new Pin(model, this, "DEC", 1, PinUsage.INPUT, 0, 30), Position.RIGHT); addPin(new Pin(model, this, "C", 1, PinUsage.INPUT, 40, 20), Position.LEFT); addPin(new Pin(model, this, "Y", 12, PinUsage.OUTPUT, 20, 40), Position.TOP); @@ -37,16 +37,11 @@ public class ModelAm2910RegCntr extends SimpleRectangularHardcodedModelComponent @Override public Object recalculate(Object lastState, Map readEnds, Map readWriteEnds) { - Bit[] QC = (Bit[]) lastState; - if (QC == null) - { - QC = new Bit[13]; - Arrays.fill(QC, U); - } + Bit[] QC = castAndInitState(lastState); ReadEnd D = readEnds.get("D"); ReadEnd _RLD = readEnds.get("_RLD"); - ReadEnd WE = readEnds.get("WE"); + ReadEnd LD = readEnds.get("LD"); ReadEnd DEC = readEnds.get("DEC"); ReadEnd C = readEnds.get("C"); ReadWriteEnd Y = readWriteEnds.get("Y"); @@ -57,9 +52,9 @@ public class ModelAm2910RegCntr extends SimpleRectangularHardcodedModelComponent // TODO handle U/X/Z if (oldCVal == ZERO && CVal == ONE) { - if ((DEC.getValue() == ZERO && WE.getValue() == ONE) || _RLD.getValue() == ZERO) + if (LD.getValue() == ONE || _RLD.getValue() == ZERO) System.arraycopy(D.getValues().getBits(), 0, QC, 0, 12); - else if (WE.getValue() == ONE) + else if (DEC.getValue() == ONE) { Bit carry = Bit.ZERO; // TODO extract to helper. This code almost also exists in Modelinc. @@ -80,29 +75,44 @@ public class ModelAm2910RegCntr extends SimpleRectangularHardcodedModelComponent @Override protected Object getHighLevelState(Object state, String stateID) { + Bit[] QC = castAndInitState(state); + switch (stateID) { case "q": - return BitVector.of(Arrays.copyOfRange((Bit[]) state, 0, 12)); + return BitVector.of(Arrays.copyOfRange(QC, 0, 12)); default: - return super.getHighLevelState(state, stateID); + return super.getHighLevelState(QC, stateID); } } @Override protected Object setHighLevelState(Object lastState, String stateID, Object newHighLevelState) { + Bit[] QC = castAndInitState(lastState); + 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; + System.arraycopy(newHighLevelStateCasted.getBits(), 0, QC, 0, 12); + return QC; default: - return super.setHighLevelState(lastState, stateID, newHighLevelState); + return super.setHighLevelState(QC, stateID, newHighLevelState); + } + } + + private static Bit[] castAndInitState(Object lastState) + { + Bit[] QC = (Bit[]) lastState; + if (QC == null) + { + QC = new Bit[13]; + Arrays.fill(QC, U); } + return QC; } static