Implemented the Am2910RegCntr gate-based
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sun, 12 Apr 2020 22:45:05 +0000 (00:45 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sun, 12 Apr 2020 22:45:05 +0000 (00:45 +0200)
plugins/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/am2910/Am2910RegCntr.json [new file with mode: 0644]
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java [deleted file]
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/standardComponentIDMapping.json
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ModelComponentTestbench.java

diff --git a/plugins/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/am2910/Am2910RegCntr.json b/plugins/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/am2910/Am2910RegCntr.json
new file mode 100644 (file)
index 0000000..12f6e0d
--- /dev/null
@@ -0,0 +1,374 @@
+{
+  "width": 25.0,
+  "height": 25.0,
+  "interfacePins": [
+    {
+      "location": {
+        "x": 10.0,
+        "y": 0.0
+      },
+      "name": "C",
+      "logicWidth": 1,
+      "usage": "INPUT"
+    },
+    {
+      "location": {
+        "x": 0.0,
+        "y": 10.0
+      },
+      "name": "D",
+      "logicWidth": 12,
+      "usage": "INPUT"
+    },
+    {
+      "location": {
+        "x": 0.0,
+        "y": 20.0
+      },
+      "name": "DEC",
+      "logicWidth": 1,
+      "usage": "INPUT"
+    },
+    {
+      "location": {
+        "x": 0.0,
+        "y": 5.0
+      },
+      "name": "LD",
+      "logicWidth": 1,
+      "usage": "INPUT"
+    },
+    {
+      "location": {
+        "x": 25.0,
+        "y": 5.0
+      },
+      "name": "Y",
+      "logicWidth": 12,
+      "usage": "OUTPUT"
+    }
+  ],
+  "innerScale": 0.2,
+  "submodel": {
+    "components": [
+      {
+        "id": "WireCrossPoint",
+        "name": "WireCrossPoint#0",
+        "pos": {
+          "x": 114.0,
+          "y": 29.0
+        },
+        "params": 12
+      },
+      {
+        "id": "dec12",
+        "name": "dec12#0",
+        "pos": {
+          "x": 70.0,
+          "y": 65.0
+        }
+      },
+      {
+        "id": "dff12",
+        "name": "dff12#0",
+        "pos": {
+          "x": 70.0,
+          "y": 10.0
+        }
+      },
+      {
+        "id": "mux1_12",
+        "name": "mux1_12#0",
+        "pos": {
+          "x": 10.0,
+          "y": 20.0
+        }
+      }
+    ],
+    "wires": [
+      {
+        "pin1": {
+          "compName": "_submodelinterface",
+          "pinName": "DEC"
+        },
+        "pin2": {
+          "compName": "dec12#0",
+          "pinName": "CI"
+        },
+        "name": "unnamedWire#0",
+        "path": [
+          {
+            "x": 5.0,
+            "y": 100.0
+          },
+          {
+            "x": 5.0,
+            "y": 105.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "dff12#0",
+          "pinName": "C"
+        },
+        "pin2": {
+          "compName": "_submodelinterface",
+          "pinName": "C"
+        },
+        "name": "unnamedWire#1",
+        "path": [
+          {
+            "x": 50.0,
+            "y": 15.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "dff12#0",
+          "pinName": "Q"
+        },
+        "pin2": {
+          "compName": "WireCrossPoint#0",
+          "pinName": ""
+        },
+        "name": "unnamedWire#2",
+        "path": []
+      },
+      {
+        "pin1": {
+          "compName": "WireCrossPoint#0",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "_submodelinterface",
+          "pinName": "Y"
+        },
+        "name": "unnamedWire#3",
+        "path": [
+          {
+            "x": 115.0,
+            "y": 25.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "WireCrossPoint#0",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "dec12#0",
+          "pinName": "A"
+        },
+        "name": "unnamedWire#4",
+        "path": [
+          {
+            "x": 115.0,
+            "y": 55.0
+          },
+          {
+            "x": 65.0,
+            "y": 55.0
+          },
+          {
+            "x": 65.0,
+            "y": 85.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "_submodelinterface",
+          "pinName": "LD"
+        },
+        "pin2": {
+          "compName": "mux1_12#0",
+          "pinName": "S"
+        },
+        "name": "unnamedWire#5",
+        "path": []
+      },
+      {
+        "pin1": {
+          "compName": "_submodelinterface",
+          "pinName": "D"
+        },
+        "pin2": {
+          "compName": "mux1_12#0",
+          "pinName": "I1"
+        },
+        "name": "unnamedWire#6",
+        "path": [
+          {
+            "x": 5.0,
+            "y": 50.0
+          },
+          {
+            "x": 5.0,
+            "y": 80.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "dec12#0",
+          "pinName": "Y"
+        },
+        "pin2": {
+          "compName": "mux1_12#0",
+          "pinName": "I0"
+        },
+        "name": "unnamedWire#7",
+        "path": [
+          {
+            "x": 120.0,
+            "y": 85.0
+          },
+          {
+            "x": 120.0,
+            "y": 5.0
+          },
+          {
+            "x": 5.0,
+            "y": 5.0
+          },
+          {
+            "x": 5.0,
+            "y": 40.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "mux1_12#0",
+          "pinName": "Y"
+        },
+        "pin2": {
+          "compName": "dff12#0",
+          "pinName": "D"
+        },
+        "name": "unnamedWire#8",
+        "path": [
+          {
+            "x": 65.0,
+            "y": 50.0
+          },
+          {
+            "x": 65.0,
+            "y": 30.0
+          }
+        ]
+      }
+    ],
+    "version": "0.1.1"
+  },
+  "symbolRendererSnippetID": "simpleRectangularLike",
+  "symbolRendererParams": {
+    "centerText": "Register/\nCounter",
+    "centerTextHeight": 5.0,
+    "horizontalComponentCenter": 12.5,
+    "pinLabelHeight": 3.5,
+    "pinLabelMargin": 0.5
+  },
+  "outlineRendererSnippetID": "default",
+  "highLevelStateHandlerSnippetID": "standard",
+  "highLevelStateHandlerParams": {
+    "subcomponentHighLevelStates": {},
+    "atomicHighLevelStates": {
+      "q": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q"
+        }
+      },
+      "q1": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q1"
+        }
+      },
+      "q2": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q2"
+        }
+      },
+      "q3": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q3"
+        }
+      },
+      "q4": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q4"
+        }
+      },
+      "q5": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q5"
+        }
+      },
+      "q6": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q6"
+        }
+      },
+      "q7": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q7"
+        }
+      },
+      "q8": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q8"
+        }
+      },
+      "q9": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q9"
+        }
+      },
+      "q10": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q10"
+        }
+      },
+      "q11": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q11"
+        }
+      },
+      "q12": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff12#0",
+          "subStateID": "q12"
+        }
+      }
+    }
+  },
+  "version": "0.1.5"
+}
\ No newline at end of file
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
index b6e79d2..0cdec6f 100644 (file)
@@ -3,7 +3,6 @@
   "Am2900MicroInstructionMemory": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.ModelAm2900MicroInstructionMemory",
   "Am2904RegCTInstrDecode": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2904.ModelAm2904RegCTInstrDecode",
   "Am2904ShiftInstrDecode": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2904.ModelAm2904ShiftInstrDecode",
-  "Am2910RegCntr": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2910.ModelAm2910RegCntr",
   "Am2910SP": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2910.ModelAm2910SP",
   "ram5_12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelram5_12",
 
@@ -19,6 +18,7 @@
   "Am2904": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2904/Am2904.json",
   "Am2910": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2910/Am2910.json",
   "Am2910InstrPLA": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2910/Am2910InstrPLA.json",
+  "Am2910RegCntr": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2910/Am2910RegCntr.json",
   "Am2904MSR": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2904/Am2904MSR.json",
   "Am2904muSR": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2904/Am2904muSR.json",
   "Am2904TestLogic": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2904/Am2904TestLogic.json",
index d9cd6aa..cd44fd3 100644 (file)
@@ -27,7 +27,7 @@ public class ModelComponentTestbench
        {
                Am2900Loader.setup();
 //             ModelComponent comp = new StrictAm2900MachineDefinition().createNew(model).getAm2900();
-               ModelComponent comp = IndirectModelComponentCreator.createComponent(model, "dec12");
+               ModelComponent comp = IndirectModelComponentCreator.createComponent(model, "Am2910RegCntr");
 
                List<String> inputPinNames = new ArrayList<>();
                List<String> outputPinNames = new ArrayList<>();