1 package net.mograsim.logic.model.am2900.components;
5 import net.mograsim.logic.core.types.Bit;
6 import net.mograsim.logic.core.types.BitVector;
8 import static net.mograsim.logic.core.types.Bit.*;
9 import net.mograsim.logic.core.wires.Wire.ReadEnd;
10 import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
11 import net.mograsim.logic.model.model.ViewModelModifiable;
12 import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent;
13 import net.mograsim.logic.model.model.wires.Pin;
14 import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
16 public class GUImux4_12 extends SimpleRectangularHardcodedGUIComponent
18 public GUImux4_12(ViewModelModifiable model, String name)
20 super(model, name, "4-way MUX\n12 bit");
22 addPin(new Pin(this, "SA", 1, 0, 5), Usage.INPUT, Position.RIGHT);
23 addPin(new Pin(this, "SB", 1, 0, 15), Usage.INPUT, Position.RIGHT);
24 addPin(new Pin(this, "SC", 1, 0, 25), Usage.INPUT, Position.RIGHT);
25 addPin(new Pin(this, "SD", 1, 0, 35), Usage.INPUT, Position.RIGHT);
26 addPin(new Pin(this, "A", 12, 10, 0), Usage.INPUT, Position.BOTTOM);
27 addPin(new Pin(this, "B", 12, 30, 0), Usage.INPUT, Position.BOTTOM);
28 addPin(new Pin(this, "C", 12, 50, 0), Usage.INPUT, Position.BOTTOM);
29 addPin(new Pin(this, "D", 12, 70, 0), Usage.INPUT, Position.BOTTOM);
30 addPin(new Pin(this, "Y", 12, 40, 40), Usage.OUTPUT, Position.TOP);
34 protected Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
36 Bit SAVal = readEnds.get("SA").getValue();
37 Bit SBVal = readEnds.get("SB").getValue();
38 Bit SCVal = readEnds.get("SC").getValue();
39 Bit SDVal = readEnds.get("SD").getValue();
41 if (SAVal == X || SBVal == X || SCVal == X || SDVal == X)
42 YVal = BitVector.of(X, 12);
43 else if (SAVal == U || SBVal == U || SCVal == U || SDVal == U)
44 YVal = BitVector.of(U, 12);
45 else if (SAVal == Z || SBVal == Z || SCVal == Z || SDVal == Z)
46 YVal = BitVector.of(X, 12);
51 YVal = readEnds.get("A").getValues();
54 YVal = BitVector.of(X, 12);
56 YVal = readEnds.get("B").getValues();
59 YVal = BitVector.of(X, 12);
61 YVal = readEnds.get("C").getValues();
64 YVal = BitVector.of(X, 12);
66 YVal = readEnds.get("D").getValues();
68 YVal = BitVector.of(ZERO, 12);
71 readWriteEnds.get("Y").feedSignals(YVal);