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.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
18 public class GUIAm2910RegCntr extends SimpleRectangularHardcodedGUIComponent
20 public GUIAm2910RegCntr(ViewModelModifiable model, String name)
22 super(model, name, "Register/\nCounter");
24 addPin(new Pin(this, "D", 12, 20, 0), Usage.INPUT, Position.BOTTOM);
25 addPin(new Pin(this, "_RLD", 1, 0, 5), Usage.INPUT, Position.RIGHT);
26 addPin(new Pin(this, "RWE", 1, 0, 20), Usage.INPUT, Position.RIGHT);
27 addPin(new Pin(this, "RDEC", 1, 0, 30), Usage.INPUT, Position.RIGHT);
28 addPin(new Pin(this, "C", 1, 40, 20), Usage.INPUT, Position.LEFT);
29 addPin(new Pin(this, "Y", 12, 20, 40), Usage.OUTPUT, Position.TOP);
33 protected Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
35 Bit[] QC = (Bit[]) lastState;
42 ReadEnd D = readEnds.get("D");
43 ReadEnd _RLD = readEnds.get("_RLD");
44 ReadEnd RWE = readEnds.get("RWE");
45 ReadEnd RDEC = readEnds.get("RDEC");
46 ReadEnd C = readEnds.get("C");
47 ReadWriteEnd Y = readWriteEnds.get("Y");
50 Bit CVal = C.getValue();
52 if (oldCVal == ZERO && CVal == ONE && _RLD.getValue() == ZERO && RWE.getValue() == ONE)
54 if (RDEC.getValue() == ONE)
57 // TODO maybe invert loop direction
58 for (int i = 12; i >= 0; i--)
62 if (a.isBinary() && carry.isBinary())
64 boolean aBool = a == ONE;
65 boolean carryBool = carry == ONE;
66 z = !aBool ^ carryBool ? ONE : ZERO;
67 carry = aBool || carryBool ? ONE : ZERO;
70 carry = carry.join(a);
76 System.arraycopy(D.getValues().getBits(), 0, QC, 0, 12);
79 Y.feedSignals(Arrays.copyOfRange(QC, 0, 12));