Implemented the Am2910RegCntr gate-based
[Mograsim.git] / plugins / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / am2900 / components / am2910 / ModelAm2910RegCntr.java
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
deleted file mode 100644 (file)
index d7b32f0..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-package net.mograsim.logic.model.am2900.components.am2910;
-
-import static net.mograsim.logic.core.types.Bit.ONE;
-import static net.mograsim.logic.core.types.Bit.U;
-import static net.mograsim.logic.core.types.Bit.ZERO;
-
-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.CoreWire.ReadEnd;
-import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
-import net.mograsim.logic.model.model.LogicModelModifiable;
-import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedModelComponent;
-import net.mograsim.logic.model.model.wires.Pin;
-import net.mograsim.logic.model.model.wires.PinUsage;
-import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
-import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
-
-public class ModelAm2910RegCntr extends SimpleRectangularHardcodedModelComponent
-{
-       public ModelAm2910RegCntr(LogicModelModifiable model, String name)
-       {
-               super(model, "Am2910RegCntr", name, "Register/\nCounter", false);
-               setSize(40, 40);
-               addPin(new Pin(model, this, "D", 12, PinUsage.INPUT, 20, 0), Position.BOTTOM);
-               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);
-
-               init();
-       }
-
-       @Override
-       public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
-       {
-               Bit[] QC = castAndInitState(lastState);
-
-               ReadEnd D = readEnds.get("D");
-               ReadEnd LD = readEnds.get("LD");
-               ReadEnd DEC = readEnds.get("DEC");
-               ReadEnd C = readEnds.get("C");
-               ReadWriteEnd Y = readWriteEnds.get("Y");
-
-               Bit oldCVal = QC[12];
-               Bit CVal = C.getValue();
-
-               // TODO handle U/X/Z
-               if (oldCVal == ZERO && CVal == ONE)
-               {
-//                     if (LD.getValue() == ONE || _RLD.getValue() == ZERO)
-                       if (LD.getValue() == ONE)
-                               System.arraycopy(D.getValues().getBits(), 0, QC, 0, 12);
-                       else if (DEC.getValue() == ONE)
-                       {
-                               Bit carry = Bit.ZERO;
-                               // TODO extract to helper. This code almost also exists in Modelinc.
-                               for (int i = 11; i >= 0; i--)
-                               {
-                                       Bit a = QC[i];
-                                       QC[i] = a.xnor(carry);
-                                       carry = a.or(carry);
-                               }
-                       }
-               }
-               QC[12] = CVal;
-               Y.feedSignals(Arrays.copyOfRange(QC, 0, 12));
-
-               return QC;
-       }
-
-       @Override
-       protected Object getHighLevelState(Object state, String stateID)
-       {
-               Bit[] QC = castAndInitState(state);
-
-               switch (stateID)
-               {
-               case "q":
-                       return BitVector.of(Arrays.copyOfRange(QC, 0, 12));
-               default:
-                       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, QC, 0, 12);
-                       return QC;
-               default:
-                       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
-       {
-               IndirectModelComponentCreator.setComponentSupplier(ModelAm2910RegCntr.class.getCanonicalName(),
-                               (m, p, n) -> new ModelAm2910RegCntr(m, n));
-       }
-}
\ No newline at end of file