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.types.BitVector;
13 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
14 import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
15 import net.mograsim.logic.model.model.LogicModelModifiable;
16 import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedModelComponent;
17 import net.mograsim.logic.model.model.wires.Pin;
18 import net.mograsim.logic.model.model.wires.PinUsage;
19 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
20 import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
22 public class Modelsel4_12 extends SimpleRectangularHardcodedModelComponent
24 public Modelsel4_12(LogicModelModifiable model, String name)
26 super(model, "sel4_12", name, "4-way SEL\n12 bit", false);
28 addPin(new Pin(model, this, "SA", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
29 addPin(new Pin(model, this, "SB", 1, PinUsage.INPUT, 0, 15), Position.RIGHT);
30 addPin(new Pin(model, this, "SC", 1, PinUsage.INPUT, 0, 25), Position.RIGHT);
31 addPin(new Pin(model, this, "SD", 1, PinUsage.INPUT, 0, 35), Position.RIGHT);
32 addPin(new Pin(model, this, "A", 12, PinUsage.INPUT, 10, 0), Position.BOTTOM);
33 addPin(new Pin(model, this, "B", 12, PinUsage.INPUT, 30, 0), Position.BOTTOM);
34 addPin(new Pin(model, this, "C", 12, PinUsage.INPUT, 50, 0), Position.BOTTOM);
35 addPin(new Pin(model, this, "D", 12, PinUsage.INPUT, 70, 0), Position.BOTTOM);
36 addPin(new Pin(model, this, "Y", 12, PinUsage.OUTPUT, 40, 40), Position.TOP);
42 public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
44 Bit SAVal = readEnds.get("SA").getValue();
45 Bit SBVal = readEnds.get("SB").getValue();
46 Bit SCVal = readEnds.get("SC").getValue();
47 Bit SDVal = readEnds.get("SD").getValue();
49 if (SAVal == X || SBVal == X || SCVal == X || SDVal == X)
50 YVal = BitVector.of(X, 12);
51 else if (SAVal == U || SBVal == U || SCVal == U || SDVal == U)
52 YVal = BitVector.of(U, 12);
53 else if (SAVal == Z || SBVal == Z || SCVal == Z || SDVal == Z)
54 YVal = BitVector.of(X, 12);
59 YVal = readEnds.get("A").getValues();
62 YVal = BitVector.of(X, 12);
64 YVal = readEnds.get("B").getValues();
67 YVal = BitVector.of(X, 12);
69 YVal = readEnds.get("C").getValues();
72 YVal = BitVector.of(X, 12);
74 YVal = readEnds.get("D").getValues();
76 YVal = BitVector.of(ZERO, 12);
79 readWriteEnds.get("Y").feedSignals(YVal);
85 IndirectModelComponentCreator.setComponentSupplier(Modelsel4_12.class.getCanonicalName(), (m, p, n) -> new Modelsel4_12(m, n));