From: Daniel Kirschten Date: Sat, 10 Aug 2019 17:30:49 +0000 (+0200) Subject: Implemented GUIinc12; fixed GUIAm2910RegCntr X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=21ac3fe55f8c1b16eacec748a422172b2fb638ba;p=Mograsim.git Implemented GUIinc12; fixed GUIAm2910RegCntr --- diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIinc12.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIinc12.java new file mode 100644 index 00000000..20925444 --- /dev/null +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIinc12.java @@ -0,0 +1,72 @@ +package net.mograsim.logic.model.am2900.components; + +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.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.Wire.ReadEnd; +import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; +import net.mograsim.logic.model.model.ViewModelModifiable; +import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent; +import net.mograsim.logic.model.model.wires.Pin; +import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position; + +public class GUIinc12 extends SimpleRectangularHardcodedGUIComponent +{ + public GUIinc12(ViewModelModifiable model, String name) + { + super(model, name, "Incrementer"); + setSize(40, 20); + addPin(new Pin(this, "A", 12, 20, 20), Usage.INPUT, Position.TOP); + addPin(new Pin(this, "CI", 1, 40, 10), Usage.INPUT, Position.LEFT); + addPin(new Pin(this, "Y", 12, 20, 0), Usage.OUTPUT, Position.BOTTOM); + } + + @Override + protected 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 GUIAM2910RegCntr. + // TODO maybe invert loop direction + for (int i = 11; i >= 0; i--) + { + Bit a = ABits[i]; + Bit z; + if (a.isBinary() && carry.isBinary()) + { + boolean aBool = a == ONE; + boolean carryBool = carry == ONE; + z = aBool ^ carryBool ? ONE : ZERO; + carry = aBool && carryBool ? ONE : ZERO; + } else + { + carry = carry.join(a); + z = carry; + } + YBits[i] = z; + } + } + readWriteEnds.get("Y").feedSignals(YBits); + return null; + } + +} \ No newline at end of file diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910RegCntr.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910RegCntr.java index ec900c08..3db7b9d7 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910RegCntr.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910RegCntr.java @@ -49,13 +49,17 @@ public class GUIAm2910RegCntr extends SimpleRectangularHardcodedGUIComponent Bit oldCVal = QC[12]; Bit CVal = C.getValue(); - if (oldCVal == ZERO && CVal == ONE && _RLD.getValue() == ZERO && RWE.getValue() == ONE) + // TODO handle U/X/Z + if (oldCVal == ZERO && CVal == ONE) { - if (RDEC.getValue() == ONE) + if ((RDEC.getValue() == ZERO && RWE.getValue() == ONE) || _RLD.getValue() == ZERO) + System.arraycopy(D.getValues().getBits(), 0, QC, 0, 12); + else if (RWE.getValue() == ONE) { Bit carry = Bit.ZERO; + // TODO extract to helper. This code almost also exists in GUIinc12. // TODO maybe invert loop direction - for (int i = 12; i >= 0; i--) + for (int i = 11; i >= 0; i--) { Bit a = QC[i]; Bit z; @@ -72,8 +76,7 @@ public class GUIAm2910RegCntr extends SimpleRectangularHardcodedGUIComponent } QC[i] = z; } - } else - System.arraycopy(D.getValues().getBits(), 0, QC, 0, 12); + } } QC[12] = CVal; Y.feedSignals(Arrays.copyOfRange(QC, 0, 12)); diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java index 0f0f73c9..05934ae1 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java @@ -5,7 +5,7 @@ import java.util.Comparator; import java.util.List; import net.mograsim.logic.model.SimpleLogicUIStandalone; -import net.mograsim.logic.model.am2900.components.am2910.GUIAm2910SP; +import net.mograsim.logic.model.am2900.components.GUIinc12; import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.logic.model.model.components.GUIComponent; import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay; @@ -26,7 +26,7 @@ public class GUIComponentTestbench public static void createTestbench(ViewModelModifiable model) { // GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901", "Am2901"); - GUIComponent comp = new GUIAm2910SP(model, "c"); + GUIComponent comp = new GUIinc12(model, "c"); // guess which pins are outputs and which are inputs // TODO this code exists four times... but it seems too "hacky" to put it in a helper class