Made muSR / MSR accessible bit-wise
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sun, 6 Oct 2019 23:30:16 +0000 (01:30 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sun, 6 Oct 2019 23:30:16 +0000 (01:30 +0200)
plugins/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/am2904/Am2904MSR.json
plugins/net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/am2904/Am2904muSR.json
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/Modeldff4_finewe.java

index c3b5fcf..6eba852 100644 (file)
           "delegateTarget": "dff4_finewe#0",
           "subStateID": "q"
         }
+      },
+      "q1": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff4_finewe#0",
+          "subStateID": "q1"
+        }
+      },
+      "q2": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff4_finewe#0",
+          "subStateID": "q2"
+        }
+      },
+      "q3": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff4_finewe#0",
+          "subStateID": "q3"
+        }
+      },
+      "q4": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff4_finewe#0",
+          "subStateID": "q4"
+        }
       }
     }
   },
index 7321c22..6aa0738 100644 (file)
           "delegateTarget": "dff4_finewe#0",
           "subStateID": "q"
         }
+      },
+      "q1": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff4_finewe#0",
+          "subStateID": "q1"
+        }
+      },
+      "q2": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff4_finewe#0",
+          "subStateID": "q2"
+        }
+      },
+      "q3": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff4_finewe#0",
+          "subStateID": "q3"
+        }
+      },
+      "q4": {
+        "id": "delegating",
+        "params": {
+          "delegateTarget": "dff4_finewe#0",
+          "subStateID": "q4"
+        }
       }
     }
   },
index d362a15..6aebcbd 100644 (file)
@@ -46,9 +46,7 @@ public class Modeldff4_finewe extends SimpleRectangularHardcodedModelComponent
        @Override
        public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
        {
-               Bit[] QC = (Bit[]) lastState;
-               if (QC == null)
-                       QC = new Bit[] { U, U, U, U, U };
+               Bit[] QC = castAndInitState(lastState);
 
                Bit CVal = readEnds.get("C").getValue();
 
@@ -77,29 +75,60 @@ public class Modeldff4_finewe extends SimpleRectangularHardcodedModelComponent
        @Override
        protected Object getHighLevelState(Object state, String stateID)
        {
-               switch (stateID)
+               Bit[] QC = castAndInitState(state);
+
+               if ("q".equals(stateID))
+                       return BitVector.of(Arrays.copyOfRange(QC, 1, 5));
+               if (stateID.length() == 2 && stateID.charAt(0) == 'q')
                {
-               case "q":
-                       return state == null ? BitVector.of(U, U, U, U) : BitVector.of(Arrays.copyOfRange((Bit[]) state, 1, 5));
-               default:
-                       return super.getHighLevelState(state, stateID);
+                       char secondChar = stateID.charAt(1);
+                       if (secondChar >= '1' && secondChar <= '4')
+                               return BitVector.of(QC[secondChar - '0']);
                }
+               return super.getHighLevelState(state, stateID);
        }
 
        @Override
        protected Object setHighLevelState(Object lastState, String stateID, Object newHighLevelState)
        {
-               switch (stateID)
+               Bit[] QC = castAndInitState(lastState);
+
+               if ("q".equals(stateID))
                {
-               case "q":
                        BitVector newHighLevelStateCasted = (BitVector) newHighLevelState;
                        if (newHighLevelStateCasted.length() != 4)
                                throw new IllegalArgumentException("Expected BitVector of length 4, not " + newHighLevelStateCasted.length());
-                       System.arraycopy(newHighLevelStateCasted.getBits(), 0, lastState, 1, 4);
-                       return lastState;
-               default:
-                       return super.setHighLevelState(lastState, stateID, newHighLevelState);
+                       System.arraycopy(newHighLevelStateCasted.getBits(), 0, QC, 1, 4);
+                       return QC;
+               }
+               if (stateID.length() == 2 && stateID.charAt(0) == 'q')
+               {
+                       char secondChar = stateID.charAt(1);
+                       if (secondChar >= '1' && secondChar <= '4')
+                       {
+                               Bit newHighLevelStateCasted;
+                               if (newHighLevelState instanceof Bit)
+                                       newHighLevelStateCasted = (Bit) newHighLevelState;
+                               else
+                               {
+                                       BitVector vector = (BitVector) newHighLevelState;
+                                       if (vector.length() != 1)
+                                               throw new IllegalArgumentException("Expected BitVector of length 1, not " + vector.length());
+                                       newHighLevelStateCasted = vector.getMSBit(0);
+                               }
+                               QC[secondChar - '0'] = newHighLevelStateCasted;
+                               return QC;
+                       }
                }
+               return super.setHighLevelState(QC, stateID, newHighLevelState);
+       }
+
+       private static Bit[] castAndInitState(Object state)
+       {
+               Bit[] QC = (Bit[]) state;
+               if (QC == null)
+                       QC = new Bit[] { U, U, U, U, U };
+               return QC;
        }
 
        static