Restructured high level state access
[Mograsim.git] / net.mograsim.logic.ui.am2900 / src / net / mograsim / logic / ui / model / components / mi / nandbased / GUIram4.java
index 419836b..c34c50c 100644 (file)
@@ -1,6 +1,7 @@
 package net.mograsim.logic.ui.model.components.mi.nandbased;
 
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
+import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent;
 import net.mograsim.logic.ui.model.wires.GUIWire;
@@ -9,6 +10,11 @@ import net.mograsim.logic.ui.model.wires.WireCrossPoint;
 
 public class GUIram4 extends SimpleRectangularSubmodelComponent
 {
+       private GUIram2 cell00;
+       private GUIram2 cell01;
+       private GUIram2 cell10;
+       private GUIram2 cell11;
+
        public GUIram4(ViewModelModifiable model)
        {
                super(model, 1, "GUIram4");
@@ -47,10 +53,10 @@ public class GUIram4 extends SimpleRectangularSubmodelComponent
                GUIdemux2   demuxA   = new GUIdemux2  (submodelModifiable);
                GUIdemux2   demuxB   = new GUIdemux2  (submodelModifiable);
                GUIand41    weAndB   = new GUIand41   (submodelModifiable);
-               GUIram2     cell00   = new GUIram2    (submodelModifiable);
-               GUIram2     cell01   = new GUIram2    (submodelModifiable);
-               GUIram2     cell10   = new GUIram2    (submodelModifiable);
-               GUIram2     cell11   = new GUIram2    (submodelModifiable);
+                 cell00   = new GUIram2    (submodelModifiable);
+                 cell01   = new GUIram2    (submodelModifiable);
+                 cell10   = new GUIram2    (submodelModifiable);
+                 cell11   = new GUIram2    (submodelModifiable);
                GUIand41    andB00   = new GUIand41   (submodelModifiable);
                GUIandor414 andorB01 = new GUIandor414(submodelModifiable);
                GUIandor414 andorB10 = new GUIandor414(submodelModifiable);
@@ -279,5 +285,111 @@ public class GUIram4 extends SimpleRectangularSubmodelComponent
                new GUIWire(submodelModifiable, andorA11.getPin("Y3"), QA3                           , new Point(200, 760), new Point(200, 890), new Point(320, 890), new Point(320, 250));
                new GUIWire(submodelModifiable, andorA11.getPin("Y4"), QA4                           , new Point(195, 770), new Point(195, 895), new Point(325, 895), new Point(325, 350));
                //@formatter:on
+
+               addHighLevelStateSubcomponentID("c00", cell00);
+               addHighLevelStateSubcomponentID("c10", cell01);
+               addHighLevelStateSubcomponentID("c01", cell10);
+               addHighLevelStateSubcomponentID("c11", cell11);
+               addAtomicHighLevelStateID("q");
+       }
+
+       @Override
+       public void setAtomicHighLevelState(String stateID, Object newState)
+       {
+               switch (stateID)
+               {
+               case "q":
+                       BitVector newStateCasted = (BitVector) newState;
+                       setHighLevelState("c00.q", newStateCasted.subVector(0, 16));
+                       setHighLevelState("c01.q", newStateCasted.subVector(16, 32));
+                       setHighLevelState("c11.q", newStateCasted.subVector(32, 48));
+                       setHighLevelState("c11.q", newStateCasted.subVector(48, 64));
+                       break;
+               default:
+                       // should not happen because we tell SubmodelComponent to only allow these state IDs.
+                       throw new IllegalStateException("Illegal atomic state ID: " + stateID);
+               }
+       }
+
+       @Override
+       protected void setSubcomponentHighLevelState(String subcomponentID, String subcomponentHighLevelStateID, Object newState)
+       {
+               switch (subcomponentID)
+               {
+               case "c0000":
+               case "c0001":
+               case "c0010":
+               case "c0011":
+                       cell00.setHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID, newState);
+                       break;
+               case "c1000":
+               case "c1001":
+               case "c1010":
+               case "c1011":
+                       cell01.setHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID, newState);
+                       break;
+               case "c0100":
+               case "c0101":
+               case "c0110":
+               case "c0111":
+                       cell10.setHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID, newState);
+                       break;
+               case "c1100":
+               case "c1101":
+               case "c1110":
+               case "c1111":
+                       cell11.setHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID, newState);
+                       break;
+               default:
+                       super.setSubcomponentHighLevelState(subcomponentID, subcomponentHighLevelStateID, newState);
+                       break;
+               }
+       }
+
+       @Override
+       public Object getAtomicHighLevelState(String stateID)
+       {
+               switch (stateID)
+               {
+               case "q":
+                       BitVector q00 = (BitVector) getHighLevelState("c00.q");
+                       BitVector q01 = (BitVector) getHighLevelState("c01.q");
+                       BitVector q10 = (BitVector) getHighLevelState("c10.q");
+                       BitVector q11 = (BitVector) getHighLevelState("c11.q");
+                       return q00.concat(q01).concat(q10).concat(q11);
+               default:
+                       // should not happen because we tell SubmodelComponent to only allow these state IDs.
+                       throw new IllegalStateException("Illegal atomic state ID: " + stateID);
+               }
+       }
+
+       @Override
+       protected Object getSubcomponentHighLevelState(String subcomponentID, String subcomponentHighLevelStateID)
+       {
+               switch (subcomponentID)
+               {
+               case "c0000":
+               case "c0001":
+               case "c0010":
+               case "c0011":
+                       return cell00.getHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID);
+               case "c0100":
+               case "c0101":
+               case "c0110":
+               case "c0111":
+                       return cell01.getHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID);
+               case "c1000":
+               case "c1001":
+               case "c1010":
+               case "c1011":
+                       return cell10.getHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID);
+               case "c1100":
+               case "c1101":
+               case "c1110":
+               case "c1111":
+                       return cell11.getHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID);
+               default:
+                       return super.getSubcomponentHighLevelState(subcomponentID, subcomponentHighLevelStateID);
+               }
        }
 }
\ No newline at end of file