1 package net.mograsim.logic.model.am2900.components.am2910;
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.ZERO;
7 import java.util.Arrays;
10 import net.mograsim.logic.core.types.Bit;
11 import net.mograsim.logic.core.wires.Wire.ReadEnd;
12 import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
13 import net.mograsim.logic.model.model.ViewModelModifiable;
14 import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent;
15 import net.mograsim.logic.model.model.wires.Pin;
16 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
17 import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
19 public class GUIAm2910RegCntr extends SimpleRectangularHardcodedGUIComponent
21 public GUIAm2910RegCntr(ViewModelModifiable model, String name)
23 super(model, name, "Register/\nCounter");
25 addPin(new Pin(this, "D", 12, 20, 0), Usage.INPUT, Position.BOTTOM);
26 addPin(new Pin(this, "_RLD", 1, 0, 5), Usage.INPUT, Position.RIGHT);
27 addPin(new Pin(this, "WE", 1, 0, 20), Usage.INPUT, Position.RIGHT);
28 addPin(new Pin(this, "DEC", 1, 0, 30), Usage.INPUT, Position.RIGHT);
29 addPin(new Pin(this, "C", 1, 40, 20), Usage.INPUT, Position.LEFT);
30 addPin(new Pin(this, "Y", 12, 20, 40), Usage.OUTPUT, Position.TOP);
34 protected Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
36 Bit[] QC = (Bit[]) lastState;
43 ReadEnd D = readEnds.get("D");
44 ReadEnd _RLD = readEnds.get("_RLD");
45 ReadEnd WE = readEnds.get("WE");
46 ReadEnd DEC = readEnds.get("DEC");
47 ReadEnd C = readEnds.get("C");
48 ReadWriteEnd Y = readWriteEnds.get("Y");
51 Bit CVal = C.getValue();
54 if (oldCVal == ZERO && CVal == ONE)
56 if ((DEC.getValue() == ZERO && WE.getValue() == ONE) || _RLD.getValue() == ZERO)
57 System.arraycopy(D.getValues().getBits(), 0, QC, 0, 12);
58 else if (WE.getValue() == ONE)
61 // TODO extract to helper. This code almost also exists in GUIinc12.
62 // TODO maybe invert loop direction
63 for (int i = 11; i >= 0; i--)
66 QC[i] = a.xnor(carry);
72 Y.feedSignals(Arrays.copyOfRange(QC, 0, 12));
79 IndirectGUIComponentCreator.setComponentSupplier(GUIAm2910RegCntr.class.getCanonicalName(),
80 (m, p, n) -> new GUIAm2910RegCntr(m, n));