From 97761fb820e53b41f0cc021bf50fdca4da0c79c8 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Wed, 11 Sep 2019 15:16:16 +0200 Subject: [PATCH] Made Modelinc12 generic --- .../logic/model/am2900/components/Am2900.json | 13 ++++----- .../am2900/components/am2910/Am2910.json | 13 ++++----- .../{Modelinc12.java => Modelinc.java} | 27 +++++++++++++------ .../components/am2910/ModelAm2910RegCntr.java | 2 +- .../am2900/standardComponentIDMapping.json | 2 +- 5 files changed, 35 insertions(+), 22 deletions(-) rename net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/{Modelinc12.java => Modelinc.java} (67%) diff --git a/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/Am2900.json b/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/Am2900.json index 7afc8a7a..81891382 100644 --- a/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/Am2900.json +++ b/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/Am2900.json @@ -494,12 +494,13 @@ } }, { - "id": "inc12", - "name": "inc12#0", + "id": "inc", + "name": "inc#0", "pos": { "x": 245.0, "y": 525.0 - } + }, + "params": 12 }, { "id": "mux1_12", @@ -925,7 +926,7 @@ }, { "pin1": { - "compName": "inc12#0", + "compName": "inc#0", "pinName": "Y" }, "pin2": { @@ -937,7 +938,7 @@ }, { "pin1": { - "compName": "inc12#0", + "compName": "inc#0", "pinName": "A" }, "pin2": { @@ -961,7 +962,7 @@ }, { "pin1": { - "compName": "inc12#0", + "compName": "inc#0", "pinName": "CI" }, "pin2": { diff --git a/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/am2910/Am2910.json b/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/am2910/Am2910.json index 55256c7e..04a629fd 100644 --- a/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/am2910/Am2910.json +++ b/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/am2910/Am2910.json @@ -285,12 +285,13 @@ } }, { - "id": "inc12", - "name": "inc12#0", + "id": "inc", + "name": "inc#0", "pos": { "x": 240.0, "y": 140.0 - } + }, + "params": 12 }, { "id": "nor12", @@ -494,7 +495,7 @@ "pinName": "" }, "pin2": { - "compName": "inc12#0", + "compName": "inc#0", "pinName": "A" }, "name": "unnamedWire#18", @@ -834,7 +835,7 @@ }, { "pin1": { - "compName": "inc12#0", + "compName": "inc#0", "pinName": "Y" }, "pin2": { @@ -858,7 +859,7 @@ }, { "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/Modelinc12.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc.java similarity index 67% rename from net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc12.java rename to net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc.java index 05d2eee5..981c8488 100644 --- 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/Modelinc.java @@ -15,18 +15,22 @@ 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 Modelinc12 extends SimpleRectangularHardcodedModelComponent +public class Modelinc extends SimpleRectangularHardcodedModelComponent { - public Modelinc12(LogicModelModifiable model, String name) + private final int logicWidth; + + public Modelinc(LogicModelModifiable model, String name, int logicWidth) { - super(model, "inc12", name, "Incrementer", false); + super(model, "inc", name, "Incrementer", false); + this.logicWidth = logicWidth; setSize(40, 20); - addPin(new Pin(model, this, "A", 12, PinUsage.INPUT, 20, 20), Position.TOP); + 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", 12, PinUsage.OUTPUT, 20, 0), Position.BOTTOM); + addPin(new Pin(model, this, "Y", logicWidth, PinUsage.OUTPUT, 20, 0), Position.BOTTOM); init(); } @@ -36,7 +40,7 @@ public class Modelinc12 extends SimpleRectangularHardcodedModelComponent { Bit[] ABits = readEnds.get("A").getValues().getBits(); Bit CIVal = readEnds.get("CI").getValue(); - Bit[] YBits = new Bit[12]; + Bit[] YBits = new Bit[logicWidth]; if (CIVal == X) Arrays.fill(YBits, X); else if (CIVal == U) @@ -49,7 +53,7 @@ public class Modelinc12 extends SimpleRectangularHardcodedModelComponent { Bit carry = Bit.ONE; // TODO extract to helper. This code almost also exists in ModelAm2910RegCntr. - for (int i = 11; i >= 0; i--) + for (int i = logicWidth - 1; i >= 0; i--) { Bit a = ABits[i]; YBits[i] = a.xor(carry); @@ -60,8 +64,15 @@ public class Modelinc12 extends SimpleRectangularHardcodedModelComponent return null; } + @Override + public Integer getParamsForSerializing(IdentifyParams idParams) + { + return logicWidth; + } + static { - IndirectModelComponentCreator.setComponentSupplier(Modelinc12.class.getCanonicalName(), (m, p, n) -> new Modelinc12(m, n)); + 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/am2910/ModelAm2910RegCntr.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java index 05ebf456..0c101bb4 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/ModelAm2910RegCntr.java @@ -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]; diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/standardComponentIDMapping.json b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/standardComponentIDMapping.json index 6ab00c44..02f9aacf 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/standardComponentIDMapping.json +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/standardComponentIDMapping.json @@ -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", -- 2.17.1