Fixed a bug in Am2900; created dlatch8/80; relayouted some components
[Mograsim.git] / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / am2900 / components / Modelsel4_12.java
1 package net.mograsim.logic.model.am2900.components;
2
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;
8
9 import java.util.Map;
10
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;
21
22 public class Modelsel4_12 extends SimpleRectangularHardcodedModelComponent
23 {
24         public Modelsel4_12(LogicModelModifiable model, String name)
25         {
26                 super(model, "sel4_12", name, "4-way SEL\n12 bit", false);
27                 setSize(80, 40);
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);
37
38                 init();
39         }
40
41         @Override
42         public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
43         {
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();
48                 BitVector YVal;
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);
55                 else
56                 {
57                         YVal = null;
58                         if (SAVal == ONE)
59                                 YVal = readEnds.get("A").getValues();
60                         if (SBVal == ONE)
61                                 if (YVal != null)
62                                         YVal = BitVector.of(X, 12);
63                                 else
64                                         YVal = readEnds.get("B").getValues();
65                         if (SCVal == ONE)
66                                 if (YVal != null)
67                                         YVal = BitVector.of(X, 12);
68                                 else
69                                         YVal = readEnds.get("C").getValues();
70                         if (SDVal == ONE)
71                                 if (YVal != null)
72                                         YVal = BitVector.of(X, 12);
73                                 else
74                                         YVal = readEnds.get("D").getValues();
75                         if (YVal == null)
76                                 YVal = BitVector.of(ZERO, 12);
77                 }
78
79                 readWriteEnds.get("Y").feedSignals(YVal);
80                 return null;
81         }
82
83         static
84         {
85                 IndirectModelComponentCreator.setComponentSupplier(Modelsel4_12.class.getCanonicalName(), (m, p, n) -> new Modelsel4_12(m, n));
86         }
87 }