X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fam2900%2Fcomponents%2Fam2910%2FGUIAm2910RegCntr.java;h=00635bf7e36e3eee06f7c83b8d6b89c2d5a3d394;hb=bfd483ea32de08383550ba6903f77c11c33ea36d;hp=3db7b9d77b43da13ba26535254d9c2cfc37b3f1d;hpb=af730951db57d13d0b25671991f5bac36daabb85;p=Mograsim.git diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910RegCntr.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910RegCntr.java index 3db7b9d7..00635bf7 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910RegCntr.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910RegCntr.java @@ -8,11 +8,14 @@ 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; 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; public class GUIAm2910RegCntr extends SimpleRectangularHardcodedGUIComponent @@ -21,16 +24,16 @@ public class GUIAm2910RegCntr extends SimpleRectangularHardcodedGUIComponent { super(model, name, "Register/\nCounter"); setSize(40, 40); - addPin(new Pin(this, "D", 12, 20, 0), Usage.INPUT, Position.BOTTOM); - addPin(new Pin(this, "_RLD", 1, 0, 5), Usage.INPUT, Position.RIGHT); - addPin(new Pin(this, "RWE", 1, 0, 20), Usage.INPUT, Position.RIGHT); - addPin(new Pin(this, "RDEC", 1, 0, 30), Usage.INPUT, Position.RIGHT); - addPin(new Pin(this, "C", 1, 40, 20), Usage.INPUT, Position.LEFT); - addPin(new Pin(this, "Y", 12, 20, 40), Usage.OUTPUT, Position.TOP); + addPin(new Pin(this, "D", 12, PinUsage.INPUT, 20, 0), Position.BOTTOM); + addPin(new Pin(this, "_RLD", 1, PinUsage.INPUT, 0, 5), Position.RIGHT); + addPin(new Pin(this, "WE", 1, PinUsage.INPUT, 0, 20), Position.RIGHT); + addPin(new Pin(this, "DEC", 1, PinUsage.INPUT, 0, 30), Position.RIGHT); + addPin(new Pin(this, "C", 1, PinUsage.INPUT, 40, 20), Position.LEFT); + addPin(new Pin(this, "Y", 12, PinUsage.OUTPUT, 20, 40), Position.TOP); } @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) @@ -41,8 +44,8 @@ public class GUIAm2910RegCntr extends SimpleRectangularHardcodedGUIComponent ReadEnd D = readEnds.get("D"); ReadEnd _RLD = readEnds.get("_RLD"); - ReadEnd RWE = readEnds.get("RWE"); - ReadEnd RDEC = readEnds.get("RDEC"); + ReadEnd WE = readEnds.get("WE"); + ReadEnd DEC = readEnds.get("DEC"); ReadEnd C = readEnds.get("C"); ReadWriteEnd Y = readWriteEnds.get("Y"); @@ -52,29 +55,17 @@ public class GUIAm2910RegCntr extends SimpleRectangularHardcodedGUIComponent // TODO handle U/X/Z if (oldCVal == ZERO && CVal == ONE) { - if ((RDEC.getValue() == ZERO && RWE.getValue() == ONE) || _RLD.getValue() == ZERO) + if ((DEC.getValue() == ZERO && WE.getValue() == ONE) || _RLD.getValue() == ZERO) System.arraycopy(D.getValues().getBits(), 0, QC, 0, 12); - else if (RWE.getValue() == ONE) + else if (WE.getValue() == ONE) { Bit carry = Bit.ZERO; // TODO extract to helper. This code almost also exists in GUIinc12. - // TODO maybe invert loop direction for (int i = 11; i >= 0; i--) { Bit a = QC[i]; - Bit z; - if (a.isBinary() && carry.isBinary()) - { - boolean aBool = a == ONE; - boolean carryBool = carry == ONE; - z = !aBool ^ carryBool ? ONE : ZERO; - carry = aBool || carryBool ? ONE : ZERO; - } else - { - carry = carry.join(a); - z = carry; - } - QC[i] = z; + QC[i] = a.xnor(carry); + carry = a.or(carry); } } } @@ -83,4 +74,38 @@ public class GUIAm2910RegCntr 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(GUIAm2910RegCntr.class.getCanonicalName(), + (m, p, n) -> new GUIAm2910RegCntr(m, n)); + } } \ No newline at end of file