Revisited some hardcoded components
[Mograsim.git] / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / am2900 / components / am2904 / GUIAm2904ShiftInstrDecode.java
index 51b6da0..dae7ae4 100644 (file)
@@ -9,11 +9,13 @@ import static net.mograsim.logic.core.types.Bit.ZERO;
 import java.util.Map;
 
 import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.types.BitVector;
 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.model.wires.PinUsage;
 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
 import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
 
@@ -23,15 +25,15 @@ public class GUIAm2904ShiftInstrDecode extends SimpleRectangularHardcodedGUIComp
        {
                super(model, name, "Shift \ninstruction\ndecode");
                setSize(60, 80);
-               addPin(new Pin(this, "I", 5, 0, 25), Usage.INPUT, Position.RIGHT);
-               addPin(new Pin(this, "_SE", 1, 0, 55), Usage.INPUT, Position.RIGHT);
+               addPin(new Pin(this, "I", 5, PinUsage.INPUT, 0, 25), Position.RIGHT);
+               addPin(new Pin(this, "_SE", 1, PinUsage.INPUT, 0, 55), Position.RIGHT);
                // SIO0 MUX:
                // 000: 0
                // 001: 1
                // 01x: SIOn
                // 10x: QIOn
                // 11x: MC
-               addPin(new Pin(this, "SIO0_MUX", 3, 60, 5), Usage.OUTPUT, Position.LEFT);
+               addPin(new Pin(this, "SIO0_MUX", 3, PinUsage.OUTPUT, 60, 5), Position.LEFT);
                // SIOn MUX:
                // 000: 0
                // 001: 1
@@ -41,37 +43,37 @@ public class GUIAm2904ShiftInstrDecode extends SimpleRectangularHardcodedGUIComp
                // 101: MN
                // 110: IC
                // 111: IN xor IVOR
-               addPin(new Pin(this, "SIOn_MUX", 3, 60, 15), Usage.OUTPUT, Position.LEFT);
+               addPin(new Pin(this, "SIOn_MUX", 3, PinUsage.OUTPUT, 60, 15), Position.LEFT);
                // QIO0 MUX:
                // 000: 0
                // 001: 1
                // 01x: SIOn
                // 10x: QIOn
                // 11x: MC
-               addPin(new Pin(this, "QIO0_MUX", 3, 60, 25), Usage.OUTPUT, Position.LEFT);
+               addPin(new Pin(this, "QIO0_MUX", 3, PinUsage.OUTPUT, 60, 25), Position.LEFT);
                // QIOn MUX:
                // 000: 0
                // 001: 1
                // 01x: SIO0
                // 10x: QIO0
                // 11x: MN
-               addPin(new Pin(this, "QIOn_MUX", 3, 60, 35), Usage.OUTPUT, Position.LEFT);
-               addPin(new Pin(this, "OEn", 1, 60, 45), Usage.OUTPUT, Position.LEFT);
-               addPin(new Pin(this, "OE0", 1, 60, 55), Usage.OUTPUT, Position.LEFT);
+               addPin(new Pin(this, "QIOn_MUX", 3, PinUsage.OUTPUT, 60, 35), Position.LEFT);
+               addPin(new Pin(this, "OEn", 1, PinUsage.OUTPUT, 60, 45), Position.LEFT);
+               addPin(new Pin(this, "OE0", 1, PinUsage.OUTPUT, 60, 55), Position.LEFT);
                // 00: SIO0
                // 01: QIO0
                // 1x: SIOn
-               addPin(new Pin(this, "MC_MUX", 2, 60, 65), Usage.OUTPUT, Position.LEFT);
-               addPin(new Pin(this, "MC_EN", 1, 60, 75), Usage.OUTPUT, Position.LEFT);
+               addPin(new Pin(this, "MC_MUX", 2, PinUsage.OUTPUT, 60, 65), Position.LEFT);
+               addPin(new Pin(this, "MC_EN", 1, PinUsage.OUTPUT, 60, 75), Position.LEFT);
        }
 
        @Override
-       protected Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
+       public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
        {
                Bit _SE = readEnds.get("_SE").getValue();
-               Bit[] IBits = readEnds.get("I").getValues().getBits();
-               readWriteEnds.get("OEn").feedSignals(IBits[0].not().and(_SE.not()));
-               readWriteEnds.get("OE0").feedSignals(IBits[0].and(_SE.not()));
+               BitVector I = readEnds.get("I").getValues();
+               readWriteEnds.get("OEn").feedSignals(I.getMSBit(0).not().and(_SE.not()));
+               readWriteEnds.get("OE0").feedSignals(I.getMSBit(0).and(_SE.not()));
                if (_SE == Z || _SE == X)
                {
                        readWriteEnds.get("SIO0_MUX").feedSignals(X, X, X);
@@ -101,36 +103,24 @@ public class GUIAm2904ShiftInstrDecode extends SimpleRectangularHardcodedGUIComp
                        readWriteEnds.get("MC_EN").feedSignals(ZERO);
                        return null;
                }
-               // TODO move the following loop to BitVector.
-               int IAsInt = 0;
-               for (int i = 0; i < 5; i++)
-                       switch (IBits[4 - i])
-                       {
-                       case ONE:
-                               IAsInt |= 1 << i;
-                               break;
-                       case U:
-                               readWriteEnds.get("SIO0_MUX").feedSignals(U, U, U);
-                               readWriteEnds.get("SIOn_MUX").feedSignals(U, U, U);
-                               readWriteEnds.get("QIO0_MUX").feedSignals(U, U, U);
-                               readWriteEnds.get("QIOn_MUX").feedSignals(U, U, U);
-                               readWriteEnds.get("MC_MUX").feedSignals(U, U);
-                               readWriteEnds.get("MC_EN").feedSignals(U);
-                               return null;
-                       case X:
-                       case Z:
-                               readWriteEnds.get("SIO0_MUX").feedSignals(X, X, X);
-                               readWriteEnds.get("SIOn_MUX").feedSignals(X, X, X);
-                               readWriteEnds.get("QIO0_MUX").feedSignals(X, X, X);
-                               readWriteEnds.get("QIOn_MUX").feedSignals(X, X, X);
-                               readWriteEnds.get("MC_MUX").feedSignals(X, X);
-                               readWriteEnds.get("MC_EN").feedSignals(X);
-                               return null;
-                       case ZERO:
-                               break;
-                       default:
-                               throw new IllegalArgumentException("Unknown enum constant: " + IBits[i]);
-                       }
+               if (!I.isBinary())
+               {
+                       Bit val = null;
+                       for (Bit b : I.getBits())
+                               if (!b.isBinary())
+                               {
+                                       val = b;
+                                       break;
+                               }
+                       readWriteEnds.get("SIO0_MUX").feedSignals(val, val, val);
+                       readWriteEnds.get("SIOn_MUX").feedSignals(val, val, val);
+                       readWriteEnds.get("QIO0_MUX").feedSignals(val, val, val);
+                       readWriteEnds.get("QIOn_MUX").feedSignals(val, val, val);
+                       readWriteEnds.get("MC_MUX").feedSignals(val, val);
+                       readWriteEnds.get("MC_EN").feedSignals(val);
+                       return null;
+               }
+               int IAsInt = I.getUnsignedValue().intValue();
                if (IAsInt < 16)
                {
                        readWriteEnds.get("SIO0_MUX").feedSignals(X, X, X);