From d4e7fabad51c0334ef1776564c87da38ab3c2089 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Sun, 11 Aug 2019 16:48:52 +0200 Subject: [PATCH] Implemented GUIdff4_finewe --- .../am2900/components/GUIdff4_finewe.java | 77 +++++++++++++++++++ .../model/examples/GUIComponentTestbench.java | 10 +-- 2 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIdff4_finewe.java diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIdff4_finewe.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIdff4_finewe.java new file mode 100644 index 00000000..758a9450 --- /dev/null +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIdff4_finewe.java @@ -0,0 +1,77 @@ +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.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.serializing.IndirectGUIComponentCreator; +import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position; + +public class GUIdff4_finewe extends SimpleRectangularHardcodedGUIComponent +{ + public GUIdff4_finewe(ViewModelModifiable model, String name) + { + super(model, name, "D flip flop\n4 bits"); + setSize(35, 100); + addPin(new Pin(this, "C", 1, 0, 5), Usage.INPUT, Position.RIGHT); + addPin(new Pin(this, "_WE1", 1, 0, 15), Usage.INPUT, Position.RIGHT); + addPin(new Pin(this, "_WE2", 1, 0, 25), Usage.INPUT, Position.RIGHT); + addPin(new Pin(this, "_WE3", 1, 0, 35), Usage.INPUT, Position.RIGHT); + addPin(new Pin(this, "_WE4", 1, 0, 45), Usage.INPUT, Position.RIGHT); + addPin(new Pin(this, "_WE", 1, 0, 55), Usage.INPUT, Position.RIGHT); + addPin(new Pin(this, "D1", 1, 0, 65), Usage.INPUT, Position.RIGHT); + addPin(new Pin(this, "D2", 1, 0, 75), Usage.INPUT, Position.RIGHT); + addPin(new Pin(this, "D3", 1, 0, 85), Usage.INPUT, Position.RIGHT); + addPin(new Pin(this, "D4", 1, 0, 95), Usage.INPUT, Position.RIGHT); + addPin(new Pin(this, "Q1", 1, 35, 5), Usage.OUTPUT, Position.LEFT); + addPin(new Pin(this, "Q2", 1, 35, 15), Usage.OUTPUT, Position.LEFT); + addPin(new Pin(this, "Q3", 1, 35, 25), Usage.OUTPUT, Position.LEFT); + addPin(new Pin(this, "Q4", 1, 35, 35), Usage.OUTPUT, Position.LEFT); + } + + @Override + protected Object recalculate(Object lastState, Map readEnds, Map readWriteEnds) + { + Bit[] QC = (Bit[]) lastState; + if (QC == null) + QC = new Bit[] { U, U, U, U, U }; + + Bit CVal = readEnds.get("C").getValue(); + + if (QC[0] == ZERO && CVal == ONE && readEnds.get("_WE").getValue() == ZERO) + for (int i = 1; i < 5; i++) + { + Bit WEiVal = readEnds.get("_WE" + i).getValue(); + if (WEiVal == X || WEiVal == Z) + QC[i] = X; + else if (WEiVal == U) + QC[i] = U; + else if (WEiVal == ZERO) + QC[i] = readEnds.get("D" + i).getValue(); + } + + QC[0] = CVal; + + readWriteEnds.get("Q1").feedSignals(QC[1]); + readWriteEnds.get("Q2").feedSignals(QC[2]); + readWriteEnds.get("Q3").feedSignals(QC[3]); + readWriteEnds.get("Q4").feedSignals(QC[4]); + + return QC; + } + + static + { + IndirectGUIComponentCreator.setComponentSupplier(GUIdff4_finewe.class.getCanonicalName(), (m, p, n) -> new GUIdff4_finewe(m, n)); + } +} \ 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 1c17ac3e..ec395c04 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 @@ -1,11 +1,11 @@ package net.mograsim.logic.model.examples; import java.util.ArrayList; -import java.util.Arrays; import java.util.Comparator; import java.util.List; import net.mograsim.logic.model.SimpleLogicUIStandalone; +import net.mograsim.logic.model.am2900.components.GUIdff4_finewe; import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.logic.model.model.components.GUIComponent; import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay; @@ -14,7 +14,6 @@ import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcod import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent.Usage; import net.mograsim.logic.model.model.wires.GUIWire; import net.mograsim.logic.model.model.wires.Pin; -import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator; public class GUIComponentTestbench { @@ -26,8 +25,8 @@ public class GUIComponentTestbench @SuppressWarnings("unused") // for GUIWires being created public static void createTestbench(ViewModelModifiable model) { - GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "file:components/am2910/GUIAm2910.json", "Am2910"); -// GUIComponent comp = new GUImux4_12(model, "c"); +// GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "file:components/GUIdff4.json", "dff4"); + GUIComponent comp = new GUIdff4_finewe(model, "dff4_finewe"); // 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 @@ -51,9 +50,6 @@ public class GUIComponentTestbench inputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY))); outputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY))); - inputPinNames = Arrays.asList("C", "D", "_RLD", "_CC", "_CCEN", "I", "CI"); - outputPinNames = Arrays.asList("_FULL", "_PL", "_MAP", "_VECT", "Y"); - comp.moveTo(100, 0); for (int i = 0; i < inputPinNames.size(); i++) { -- 2.17.1