Implemented GUImux4_12
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 10 Aug 2019 17:46:15 +0000 (19:46 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 10 Aug 2019 17:46:15 +0000 (19:46 +0200)
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUImux4_12.java [new file with mode: 0644]
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java

diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUImux4_12.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUImux4_12.java
new file mode 100644 (file)
index 0000000..af227da
--- /dev/null
@@ -0,0 +1,74 @@
+package net.mograsim.logic.model.am2900.components;
+
+import java.util.Map;
+
+import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.types.BitVector;
+
+import static net.mograsim.logic.core.types.Bit.*;
+import net.mograsim.logic.core.wires.Wire.ReadEnd;
+import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
+import net.mograsim.logic.model.model.ViewModelModifiable;
+import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
+
+public class GUImux4_12 extends SimpleRectangularHardcodedGUIComponent
+{
+       public GUImux4_12(ViewModelModifiable model, String name)
+       {
+               super(model, name, "4-way MUX\n12 bit");
+               setSize(80, 40);
+               addPin(new Pin(this, "SA", 1, 0, 5), Usage.INPUT, Position.RIGHT);
+               addPin(new Pin(this, "SB", 1, 0, 15), Usage.INPUT, Position.RIGHT);
+               addPin(new Pin(this, "SC", 1, 0, 25), Usage.INPUT, Position.RIGHT);
+               addPin(new Pin(this, "SD", 1, 0, 35), Usage.INPUT, Position.RIGHT);
+               addPin(new Pin(this, "A", 12, 10, 0), Usage.INPUT, Position.BOTTOM);
+               addPin(new Pin(this, "B", 12, 30, 0), Usage.INPUT, Position.BOTTOM);
+               addPin(new Pin(this, "C", 12, 50, 0), Usage.INPUT, Position.BOTTOM);
+               addPin(new Pin(this, "D", 12, 70, 0), Usage.INPUT, Position.BOTTOM);
+               addPin(new Pin(this, "Y", 12, 40, 40), Usage.OUTPUT, Position.TOP);
+       }
+
+       @Override
+       protected Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
+       {
+               Bit SAVal = readEnds.get("SA").getValue();
+               Bit SBVal = readEnds.get("SB").getValue();
+               Bit SCVal = readEnds.get("SC").getValue();
+               Bit SDVal = readEnds.get("SD").getValue();
+               BitVector YVal;
+               if (SAVal == X || SBVal == X || SCVal == X || SDVal == X)
+                       YVal = BitVector.of(X, 12);
+               else if (SAVal == U || SBVal == U || SCVal == U || SDVal == U)
+                       YVal = BitVector.of(U, 12);
+               else if (SAVal == Z || SBVal == Z || SCVal == Z || SDVal == Z)
+                       YVal = BitVector.of(X, 12);
+               else
+               {
+                       YVal = null;
+                       if (SAVal == ONE)
+                               YVal = readEnds.get("A").getValues();
+                       if (SBVal == ONE)
+                               if (YVal != null)
+                                       YVal = BitVector.of(X, 12);
+                               else
+                                       YVal = readEnds.get("B").getValues();
+                       if (SCVal == ONE)
+                               if (YVal != null)
+                                       YVal = BitVector.of(X, 12);
+                               else
+                                       YVal = readEnds.get("C").getValues();
+                       if (SDVal == ONE)
+                               if (YVal != null)
+                                       YVal = BitVector.of(X, 12);
+                               else
+                                       YVal = readEnds.get("D").getValues();
+                       if (YVal == null)
+                               YVal = BitVector.of(ZERO, 12);
+               }
+
+               readWriteEnds.get("Y").feedSignals(YVal);
+               return null;
+       }
+}
\ No newline at end of file
index 59682ba..eade266 100644 (file)
@@ -5,7 +5,7 @@ import java.util.Comparator;
 import java.util.List;
 
 import net.mograsim.logic.model.SimpleLogicUIStandalone;
-import net.mograsim.logic.model.am2900.components.GUIdff12;
+import net.mograsim.logic.model.am2900.components.GUImux4_12;
 import net.mograsim.logic.model.model.ViewModelModifiable;
 import net.mograsim.logic.model.model.components.GUIComponent;
 import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay;
@@ -26,7 +26,7 @@ public class GUIComponentTestbench
        public static void createTestbench(ViewModelModifiable model)
        {
 //             GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901", "Am2901");
-               GUIComponent comp = new GUIdff12(model, "c");
+               GUIComponent comp = new GUImux4_12(model, "c");
 
                // guess which pins are outputs and which are inputs
                // TODO this code exists four times... but it seems too "hacky" to put it in a helper class