1 package net.mograsim.logic.model.am2900.components;
3 import static net.mograsim.logic.core.types.Bit.ONE;
4 import static net.mograsim.logic.core.types.Bit.U;
5 import static net.mograsim.logic.core.types.Bit.X;
6 import static net.mograsim.logic.core.types.Bit.Z;
7 import static net.mograsim.logic.core.types.Bit.ZERO;
11 import net.mograsim.logic.core.types.Bit;
12 import net.mograsim.logic.core.wires.Wire.ReadEnd;
13 import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
14 import net.mograsim.logic.model.model.ViewModelModifiable;
15 import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent;
16 import net.mograsim.logic.model.model.wires.Pin;
17 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
18 import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
20 public class GUIdff4_finewe extends SimpleRectangularHardcodedGUIComponent
22 public GUIdff4_finewe(ViewModelModifiable model, String name)
24 super(model, name, "D flip flop\n4 bits");
26 addPin(new Pin(this, "C", 1, 0, 5), Usage.INPUT, Position.RIGHT);
27 addPin(new Pin(this, "_WE1", 1, 0, 15), Usage.INPUT, Position.RIGHT);
28 addPin(new Pin(this, "_WE2", 1, 0, 25), Usage.INPUT, Position.RIGHT);
29 addPin(new Pin(this, "_WE3", 1, 0, 35), Usage.INPUT, Position.RIGHT);
30 addPin(new Pin(this, "_WE4", 1, 0, 45), Usage.INPUT, Position.RIGHT);
31 addPin(new Pin(this, "D1", 1, 0, 55), Usage.INPUT, Position.RIGHT);
32 addPin(new Pin(this, "D2", 1, 0, 65), Usage.INPUT, Position.RIGHT);
33 addPin(new Pin(this, "D3", 1, 0, 75), Usage.INPUT, Position.RIGHT);
34 addPin(new Pin(this, "D4", 1, 0, 85), Usage.INPUT, Position.RIGHT);
35 addPin(new Pin(this, "Q1", 1, 35, 5), Usage.OUTPUT, Position.LEFT);
36 addPin(new Pin(this, "Q2", 1, 35, 15), Usage.OUTPUT, Position.LEFT);
37 addPin(new Pin(this, "Q3", 1, 35, 25), Usage.OUTPUT, Position.LEFT);
38 addPin(new Pin(this, "Q4", 1, 35, 35), Usage.OUTPUT, Position.LEFT);
42 protected Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
44 Bit[] QC = (Bit[]) lastState;
46 QC = new Bit[] { U, U, U, U, U };
48 Bit CVal = readEnds.get("C").getValue();
50 if (QC[0] == ZERO && CVal == ONE)
51 for (int i = 1; i < 5; i++)
53 Bit WEiVal = readEnds.get("_WE" + i).getValue();
54 if (WEiVal == X || WEiVal == Z)
58 else if (WEiVal == ZERO)
59 QC[i] = readEnds.get("D" + i).getValue();
64 readWriteEnds.get("Q1").feedSignals(QC[1]);
65 readWriteEnds.get("Q2").feedSignals(QC[2]);
66 readWriteEnds.get("Q3").feedSignals(QC[3]);
67 readWriteEnds.get("Q4").feedSignals(QC[4]);
74 IndirectGUIComponentCreator.setComponentSupplier(GUIdff4_finewe.class.getCanonicalName(), (m, p, n) -> new GUIdff4_finewe(m, n));