From: Daniel Kirschten Date: Sat, 10 Aug 2019 16:16:38 +0000 (+0200) Subject: Implemented GUIram5_12 X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=c9e5a301f6925386a62e77a84ba4d9b1b6f43aae;p=Mograsim.git Implemented GUIram5_12 --- diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIram5_12.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIram5_12.java new file mode 100644 index 00000000..7dcea022 --- /dev/null +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIram5_12.java @@ -0,0 +1,79 @@ +package net.mograsim.logic.model.am2900.components; + +import static net.mograsim.logic.core.types.Bit.*; + +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.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 GUIram5_12 extends SimpleRectangularHardcodedGUIComponent +{ + public GUIram5_12(ViewModelModifiable model, String name) + { + super(model, name, "RAM\n5 x 12 Bit"); + setSize(40, 40); + addPin(new Pin(this, "A", 3, 10, 0), Usage.INPUT, Position.BOTTOM); + addPin(new Pin(this, "B", 3, 30, 0), Usage.INPUT, Position.BOTTOM); + addPin(new Pin(this, "WE", 1, 0, 5), Usage.INPUT, Position.RIGHT); + addPin(new Pin(this, "C", 1, 0, 15), Usage.INPUT, Position.RIGHT); + addPin(new Pin(this, "Y", 12, 0, 30), Usage.OUTPUT, Position.RIGHT); + addPin(new Pin(this, "D", 12, 20, 40), Usage.INPUT, Position.TOP); + } + + @Override + protected Object recalculate(Object lastState, Map readEnds, Map readWriteEnds) + { + BitVector[] memC = (BitVector[]) lastState; + if (memC == null) + { + memC = new BitVector[6]; + Arrays.fill(memC, 0, 5, BitVector.of(U, 12)); + memC[5] = BitVector.of(U); + } + BitVector CVal = readEnds.get("C").getValues(); + BitVector oldC = memC[5]; + // TODO is the timing right? + if (oldC.getLSBit(0) == ZERO && CVal.getLSBit(0) == ONE && readEnds.get("WE").getValue() == ONE) + { + int BInt = getAsInt(readEnds.get("B").getValues()); + if (BInt == -1 || BInt > 4) + Arrays.fill(memC, BitVector.of(X, 12)); + else if (BInt == -2) + Arrays.fill(memC, BitVector.of(U, 12)); + else + memC[BInt] = readEnds.get("D").getValues(); + } + int AInt = getAsInt(readEnds.get("A").getValues()); + BitVector YVal = AInt == -1 || AInt > 4 ? BitVector.of(X, 12) : AInt == -2 ? BitVector.of(U, 12) : memC[AInt]; + readWriteEnds.get("Y").feedSignals(YVal); + memC[5] = CVal; + return memC; + } + + /** + * -1 means X, -2 means U + */ + private static int getAsInt(BitVector vect) + { + Bit[] bits = vect.getBits(); + for (int i = 0; i < 3; i++) + if (bits[i] == X) + return -1; + for (int i = 0; i < 3; i++) + if (bits[i] == U) + return -2; + for (int i = 0; i < 3; i++) + if (bits[i] == Z) + return -1; + // TODO maybe this is the wrong way around + return (bits[0] == ONE ? 4 : 0) + (bits[1] == ONE ? 2 : 0) + (bits[2] == ONE ? 1 : 0); + } +} \ No newline at end of file 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 f725d5ee..7f42c019 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.GUInor12; +import net.mograsim.logic.model.am2900.components.GUIram5_12; 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 GUInor12(model, "or12"); + GUIComponent comp = new GUIram5_12(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