From: Daniel Kirschten Date: Wed, 11 Sep 2019 13:16:16 +0000 (+0200) Subject: Made Modelinc12 generic X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=97761fb820e53b41f0cc021bf50fdca4da0c79c8;p=Mograsim.git Made Modelinc12 generic --- 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/Modelinc.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc.java new file mode 100644 index 00000000..981c8488 --- /dev/null +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc.java @@ -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 readEnds, Map 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 index 05d2eee5..00000000 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modelinc12.java +++ /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 readEnds, Map 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 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",