Made Modelinc12 generic
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 11 Sep 2019 13:16:16 +0000 (15:16 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 11 Sep 2019 13:16:16 +0000 (15:16 +0200)
net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/Am2900.json
net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/am2910/Am2910.json
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc.java [new file with mode: 0644]
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc12.java [deleted file]
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/standardComponentIDMapping.json

index 7afc8a7..8189138 100644 (file)
         }
       },
       {
-        "id": "inc12",
-        "name": "inc12#0",
+        "id": "inc",
+        "name": "inc#0",
         "pos": {
           "x": 245.0,
           "y": 525.0
-        }
+        },
+        "params": 12
       },
       {
         "id": "mux1_12",
       },
       {
         "pin1": {
-          "compName": "inc12#0",
+          "compName": "inc#0",
           "pinName": "Y"
         },
         "pin2": {
       },
       {
         "pin1": {
-          "compName": "inc12#0",
+          "compName": "inc#0",
           "pinName": "A"
         },
         "pin2": {
       },
       {
         "pin1": {
-          "compName": "inc12#0",
+          "compName": "inc#0",
           "pinName": "CI"
         },
         "pin2": {
index 55256c7..04a629f 100644 (file)
         }
       },
       {
-        "id": "inc12",
-        "name": "inc12#0",
+        "id": "inc",
+        "name": "inc#0",
         "pos": {
           "x": 240.0,
           "y": 140.0
-        }
+        },
+        "params": 12
       },
       {
         "id": "nor12",
           "pinName": ""
         },
         "pin2": {
-          "compName": "inc12#0",
+          "compName": "inc#0",
           "pinName": "A"
         },
         "name": "unnamedWire#18",
       },
       {
         "pin1": {
-          "compName": "inc12#0",
+          "compName": "inc#0",
           "pinName": "Y"
         },
         "pin2": {
       },
       {
         "pin1": {
-          "compName": "inc12#0",
+          "compName": "inc#0",
           "pinName": "CI"
         },
         "pin2": {
diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc.java
new file mode 100644 (file)
index 0000000..981c848
--- /dev/null
@@ -0,0 +1,78 @@
+package net.mograsim.logic.model.am2900.components;
+
+import static net.mograsim.logic.core.types.Bit.U;
+import static net.mograsim.logic.core.types.Bit.X;
+import static net.mograsim.logic.core.types.Bit.Z;
+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.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.IdentifyParams;
+import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
+import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
+
+public class Modelinc extends SimpleRectangularHardcodedModelComponent
+{
+       private final int logicWidth;
+
+       public Modelinc(LogicModelModifiable model, String name, int logicWidth)
+       {
+               super(model, "inc", name, "Incrementer", false);
+               this.logicWidth = logicWidth;
+               setSize(40, 20);
+               addPin(new Pin(model, this, "A", logicWidth, PinUsage.INPUT, 20, 20), Position.TOP);
+               addPin(new Pin(model, this, "CI", 1, PinUsage.INPUT, 40, 10), Position.LEFT);
+               addPin(new Pin(model, this, "Y", logicWidth, PinUsage.OUTPUT, 20, 0), Position.BOTTOM);
+
+               init();
+       }
+
+       @Override
+       public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
+       {
+               Bit[] ABits = readEnds.get("A").getValues().getBits();
+               Bit CIVal = readEnds.get("CI").getValue();
+               Bit[] YBits = new Bit[logicWidth];
+               if (CIVal == X)
+                       Arrays.fill(YBits, X);
+               else if (CIVal == U)
+                       Arrays.fill(YBits, U);
+               else if (CIVal == Z)
+                       Arrays.fill(YBits, X);
+               else if (CIVal == ZERO)
+                       YBits = ABits;
+               else
+               {
+                       Bit carry = Bit.ONE;
+                       // TODO extract to helper. This code almost also exists in ModelAm2910RegCntr.
+                       for (int i = logicWidth - 1; i >= 0; i--)
+                       {
+                               Bit a = ABits[i];
+                               YBits[i] = a.xor(carry);
+                               carry = a.and(carry);
+                       }
+               }
+               readWriteEnds.get("Y").feedSignals(YBits);
+               return null;
+       }
+
+       @Override
+       public Integer getParamsForSerializing(IdentifyParams idParams)
+       {
+               return logicWidth;
+       }
+
+       static
+       {
+               IndirectModelComponentCreator.setComponentSupplier(Modelinc.class.getCanonicalName(),
+                               (m, p, n) -> new Modelinc(m, n, p.getAsInt()));
+       }
+}
\ No newline at end of file
diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc12.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc12.java
deleted file mode 100644 (file)
index 05d2eee..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-package net.mograsim.logic.model.am2900.components;
-
-import static net.mograsim.logic.core.types.Bit.U;
-import static net.mograsim.logic.core.types.Bit.X;
-import static net.mograsim.logic.core.types.Bit.Z;
-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.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 Modelinc12 extends SimpleRectangularHardcodedModelComponent
-{
-       public Modelinc12(LogicModelModifiable model, String name)
-       {
-               super(model, "inc12", name, "Incrementer", false);
-               setSize(40, 20);
-               addPin(new Pin(model, this, "A", 12, PinUsage.INPUT, 20, 20), Position.TOP);
-               addPin(new Pin(model, this, "CI", 1, PinUsage.INPUT, 40, 10), Position.LEFT);
-               addPin(new Pin(model, this, "Y", 12, PinUsage.OUTPUT, 20, 0), Position.BOTTOM);
-
-               init();
-       }
-
-       @Override
-       public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
-       {
-               Bit[] ABits = readEnds.get("A").getValues().getBits();
-               Bit CIVal = readEnds.get("CI").getValue();
-               Bit[] YBits = new Bit[12];
-               if (CIVal == X)
-                       Arrays.fill(YBits, X);
-               else if (CIVal == U)
-                       Arrays.fill(YBits, U);
-               else if (CIVal == Z)
-                       Arrays.fill(YBits, X);
-               else if (CIVal == ZERO)
-                       YBits = ABits;
-               else
-               {
-                       Bit carry = Bit.ONE;
-                       // TODO extract to helper. This code almost also exists in ModelAm2910RegCntr.
-                       for (int i = 11; i >= 0; i--)
-                       {
-                               Bit a = ABits[i];
-                               YBits[i] = a.xor(carry);
-                               carry = a.and(carry);
-                       }
-               }
-               readWriteEnds.get("Y").feedSignals(YBits);
-               return null;
-       }
-
-       static
-       {
-               IndirectModelComponentCreator.setComponentSupplier(Modelinc12.class.getCanonicalName(), (m, p, n) -> new Modelinc12(m, n));
-       }
-}
\ No newline at end of file
index 05ebf45..0c101bb 100644 (file)
@@ -62,7 +62,7 @@ public class ModelAm2910RegCntr extends SimpleRectangularHardcodedModelComponent
                        else if (WE.getValue() == ONE)
                        {
                                Bit carry = Bit.ZERO;
-                               // TODO extract to helper. This code almost also exists in Modelinc12.
+                               // TODO extract to helper. This code almost also exists in Modelinc.
                                for (int i = 11; i >= 0; i--)
                                {
                                        Bit a = QC[i];
index 6ab00c4..02f9aac 100644 (file)
@@ -7,7 +7,7 @@ mograsim version: 0.1.3
   "Am2910SP": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2910.ModelAm2910SP",
   "dff12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modeldff12",
   "dff4_finewe": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modeldff4_finewe",
-  "inc12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelinc12",
+  "inc": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelinc",
   "nor12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelnor12",
   "ram5_12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelram5_12",
   "sel4_12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelsel4_12",