Implemented GUIAm2910
[Mograsim.git] / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / am2900 / components / am2910 / GUIAm2910InstrPLA.java
index 20ae560..6e42d2e 100644 (file)
@@ -13,6 +13,7 @@ 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.serializing.IndirectGUIComponentCreator;
 import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
 
 public class GUIAm2910InstrPLA extends SimpleRectangularHardcodedGUIComponent
@@ -22,10 +23,7 @@ public class GUIAm2910InstrPLA extends SimpleRectangularHardcodedGUIComponent
                super(model, name, "Instr.\nPLA");
                setSize(30, 85);
                addPin(new Pin(this, "PASS", 1, 0, 5), Usage.INPUT, Position.RIGHT);
-               addPin(new Pin(this, "I3", 1, 0, 20), Usage.INPUT, Position.RIGHT);
-               addPin(new Pin(this, "I2", 1, 0, 30), Usage.INPUT, Position.RIGHT);
-               addPin(new Pin(this, "I1", 1, 0, 40), Usage.INPUT, Position.RIGHT);
-               addPin(new Pin(this, "I0", 1, 0, 50), Usage.INPUT, Position.RIGHT);
+               addPin(new Pin(this, "I", 4, 0, 20), Usage.INPUT, Position.RIGHT);
                addPin(new Pin(this, "R=0", 1, 15, 0), Usage.INPUT, Position.BOTTOM);
                addPin(new Pin(this, "_PL", 1, 5, 85), Usage.OUTPUT, Position.TOP);
                addPin(new Pin(this, "_MAP", 1, 15, 85), Usage.OUTPUT, Position.TOP);
@@ -41,13 +39,10 @@ public class GUIAm2910InstrPLA extends SimpleRectangularHardcodedGUIComponent
        }
 
        @Override
-       protected void recalculate(Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
+       protected Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
        {
                ReadEnd PASS = readEnds.get("PASS");
-               ReadEnd I3 = readEnds.get("I3");
-               ReadEnd I2 = readEnds.get("I2");
-               ReadEnd I1 = readEnds.get("I1");
-               ReadEnd I0 = readEnds.get("I0");
+               ReadEnd I = readEnds.get("I");
                ReadEnd Req0 = readEnds.get("R=0");
                ReadWriteEnd _PL = readWriteEnds.get("_PL");
                ReadWriteEnd _MAP = readWriteEnds.get("_MAP");
@@ -62,10 +57,10 @@ public class GUIAm2910InstrPLA extends SimpleRectangularHardcodedGUIComponent
                ReadWriteEnd STKI1 = readWriteEnds.get("STKI1");
 
                Bit PASSVal = PASS.getValue();
-               Bit I3Val = I3.getValue();
-               Bit I2Val = I2.getValue();
-               Bit I1Val = I1.getValue();
-               Bit I0Val = I0.getValue();
+               Bit I3Val = I.getValue(3);
+               Bit I2Val = I.getValue(2);
+               Bit I1Val = I.getValue(1);
+               Bit I0Val = I.getValue(0);
                Bit Req0Val = Req0.getValue();
 
                if (!I3Val.isBinary() || !I2Val.isBinary() || !I1Val.isBinary() || !I0Val.isBinary())
@@ -99,24 +94,24 @@ public class GUIAm2910InstrPLA extends SimpleRectangularHardcodedGUIComponent
                        }
                else
                {
-                       int I = (I3Val == ONE ? 8 : 0) + (I2Val == ONE ? 4 : 0) + (I1Val == ONE ? 2 : 0) + (I0Val == ONE ? 1 : 0);
+                       int IAsInt = (I3Val == ONE ? 8 : 0) + (I2Val == ONE ? 4 : 0) + (I1Val == ONE ? 2 : 0) + (I0Val == ONE ? 1 : 0);
                        Bit _PLVal = ONE;
                        Bit _MAPVal = ONE;
                        Bit _VECTVal = ONE;
-                       if (I == 2)
+                       if (IAsInt == 2)
                                _MAPVal = ZERO;
-                       else if (I == 6)
+                       else if (IAsInt == 6)
                                _VECTVal = ZERO;
                        else
                                _PLVal = ZERO;
                        _PL.feedSignals(_PLVal);
                        _MAP.feedSignals(_MAPVal);
                        _VECT.feedSignals(_VECTVal);
-                       if (I == 8 || I == 9 || I == 15)
+                       if (IAsInt == 8 || IAsInt == 9 || IAsInt == 15)
                        {
                                RWE.feedSignals(Req0Val);
                                RDEC.feedSignals(Req0Val);// "forward" X/U/Z
-                       } else if (I == 4)
+                       } else if (IAsInt == 4)
                        {
                                RWE.feedSignals(PASSVal);
                                RDEC.feedSignals(PASSVal == ONE ? ZERO : PASSVal);// "forward" X/U/Z
@@ -137,7 +132,7 @@ public class GUIAm2910InstrPLA extends SimpleRectangularHardcodedGUIComponent
                                Bit YRVal = ZERO;
                                Bit YFVal = ZERO;
                                Bit YmuPCVal = ZERO;
-                               switch (I + (PASSVal == ONE ? 16 : 0))
+                               switch (IAsInt + (PASSVal == ONE ? 16 : 0))
                                {
                                case 0:
                                case 0 + 16:
@@ -198,7 +193,7 @@ public class GUIAm2910InstrPLA extends SimpleRectangularHardcodedGUIComponent
                                YmuPC.feedSignals(YmuPCVal);
                                Bit STKI0Val;
                                Bit STKI1Val;
-                               switch (I + (PASSVal == ONE ? 16 : 0))
+                               switch (IAsInt + (PASSVal == ONE ? 16 : 0))
                                {
                                case 1:
                                case 2:
@@ -258,5 +253,12 @@ public class GUIAm2910InstrPLA extends SimpleRectangularHardcodedGUIComponent
                                STKI1.feedSignals(STKI1Val);
                        }
                }
+               return null;
+       }
+
+       static
+       {
+               IndirectGUIComponentCreator.setComponentSupplier(GUIAm2910InstrPLA.class.getCanonicalName(),
+                               (m, p, n) -> new GUIAm2910InstrPLA(m, n));
        }
 }
\ No newline at end of file