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.X;
6 import static net.mograsim.logic.core.types.Bit.ZERO;
10 import net.mograsim.logic.core.types.Bit;
11 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
12 import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
13 import net.mograsim.logic.model.model.ViewModelModifiable;
14 import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedModelComponent;
15 import net.mograsim.logic.model.model.wires.Pin;
16 import net.mograsim.logic.model.model.wires.PinUsage;
17 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
18 import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
20 public class ModelAm2910InstrPLA extends SimpleRectangularHardcodedModelComponent
22 public ModelAm2910InstrPLA(ViewModelModifiable model, String name)
24 super(model, "Am2910InstrPLA", name, "Instr.\nPLA");
26 addPin(new Pin(this, "PASS", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
27 addPin(new Pin(this, "I", 4, PinUsage.INPUT, 0, 20), Position.RIGHT);
28 addPin(new Pin(this, "R=0", 1, PinUsage.INPUT, 15, 0), Position.BOTTOM);
29 addPin(new Pin(this, "_PL", 1, PinUsage.OUTPUT, 5, 85), Position.TOP);
30 addPin(new Pin(this, "_MAP", 1, PinUsage.OUTPUT, 15, 85), Position.TOP);
31 addPin(new Pin(this, "_VECT", 1, PinUsage.OUTPUT, 25, 85), Position.TOP);
32 addPin(new Pin(this, "RWE", 1, PinUsage.OUTPUT, 30, 5), Position.LEFT);
33 addPin(new Pin(this, "RDEC", 1, PinUsage.OUTPUT, 30, 15), Position.LEFT);
34 addPin(new Pin(this, "YD", 1, PinUsage.OUTPUT, 30, 25), Position.LEFT);
35 addPin(new Pin(this, "YR", 1, PinUsage.OUTPUT, 30, 35), Position.LEFT);
36 addPin(new Pin(this, "YF", 1, PinUsage.OUTPUT, 30, 45), Position.LEFT);
37 addPin(new Pin(this, "YmuPC", 1, PinUsage.OUTPUT, 30, 55), Position.LEFT);
38 addPin(new Pin(this, "STKI0", 1, PinUsage.OUTPUT, 30, 65), Position.LEFT);
39 addPin(new Pin(this, "STKI1", 1, PinUsage.OUTPUT, 30, 75), Position.LEFT);
43 public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
45 ReadEnd PASS = readEnds.get("PASS");
46 ReadEnd I = readEnds.get("I");
47 ReadEnd Req0 = readEnds.get("R=0");
48 ReadWriteEnd _PL = readWriteEnds.get("_PL");
49 ReadWriteEnd _MAP = readWriteEnds.get("_MAP");
50 ReadWriteEnd _VECT = readWriteEnds.get("_VECT");
51 ReadWriteEnd RWE = readWriteEnds.get("RWE");
52 ReadWriteEnd RDEC = readWriteEnds.get("RDEC");
53 ReadWriteEnd YD = readWriteEnds.get("YD");
54 ReadWriteEnd YR = readWriteEnds.get("YR");
55 ReadWriteEnd YF = readWriteEnds.get("YF");
56 ReadWriteEnd YmuPC = readWriteEnds.get("YmuPC");
57 ReadWriteEnd STKI0 = readWriteEnds.get("STKI0");
58 ReadWriteEnd STKI1 = readWriteEnds.get("STKI1");
60 Bit PASSVal = PASS.getValue();
61 Bit I3Val = I.getValue(3);
62 Bit I2Val = I.getValue(2);
63 Bit I1Val = I.getValue(1);
64 Bit I0Val = I.getValue(0);
65 Bit Req0Val = Req0.getValue();
67 if (!I3Val.isBinary() || !I2Val.isBinary() || !I1Val.isBinary() || !I0Val.isBinary())
68 if ((I3Val == U || I3Val.isBinary()) || (I2Val == U || I2Val.isBinary()) || (I1Val == U || I1Val.isBinary())
69 || (I0Val == U || I0Val.isBinary()))
98 int IAsInt = (I3Val == ONE ? 8 : 0) + (I2Val == ONE ? 4 : 0) + (I1Val == ONE ? 2 : 0) + (I0Val == ONE ? 1 : 0);
104 else if (IAsInt == 6)
108 _PL.feedSignals(_PLVal);
109 _MAP.feedSignals(_MAPVal);
110 _VECT.feedSignals(_VECTVal);
111 if (IAsInt == 8 || IAsInt == 9 || IAsInt == 15)
113 RWE.feedSignals(Req0Val);
114 RDEC.feedSignals(Req0Val);// "forward" X/U/Z
115 } else if (IAsInt == 4)
117 RWE.feedSignals(PASSVal);
118 RDEC.feedSignals(PASSVal == ONE ? ZERO : PASSVal);// "forward" X/U/Z
121 RWE.feedSignals(ZERO);
122 RDEC.feedSignals(ZERO);
124 if (!PASSVal.isBinary())
126 YD.feedSignals(PASSVal);// "forward" X/U/Z
127 YR.feedSignals(PASSVal);// "forward" X/U/Z
128 YF.feedSignals(PASSVal);// "forward" X/U/Z
129 YmuPC.feedSignals(PASSVal);// "forward" X/U/Z
136 switch (IAsInt + (PASSVal == ONE ? 16 : 0))
176 YFVal = Req0Val.not();// "forward" X/U/Z
177 YmuPCVal = Req0Val;// "forward" X/U/Z
181 YDVal = Req0Val.not();// "forward" X/U/Z
182 YmuPCVal = Req0Val;// "forward" X/U/Z
185 YFVal = Req0Val.not();// "forward" X/U/Z
186 YDVal = Req0Val;// "forward" X/U/Z
189 throw new IllegalStateException("shouldn't happen");
191 YD.feedSignals(YDVal);
192 YR.feedSignals(YRVal);
193 YF.feedSignals(YFVal);
194 YmuPC.feedSignals(YmuPCVal);
197 switch (IAsInt + (PASSVal == ONE ? 16 : 0))
247 STKI1Val = Req0Val;// "forward" X/U/Z
248 STKI0Val = Req0Val;// "forward" X/U/Z
251 throw new IllegalStateException("shouldn't happen");
253 STKI0.feedSignals(STKI0Val);
254 STKI1.feedSignals(STKI1Val);
262 IndirectModelComponentCreator.setComponentSupplier(ModelAm2910InstrPLA.class.getCanonicalName(),
263 (m, p, n) -> new ModelAm2910InstrPLA(m, n));