Renamed core components to have the common prefix Core
[Mograsim.git] / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / am2900 / components / am2910 / GUIAm2910RegCntr.java
index 49e4a4c..964637d 100644 (file)
@@ -8,8 +8,9 @@ import java.util.Arrays;
 import java.util.Map;
 
 import 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.core.types.BitVector;
+import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
+import net.mograsim.logic.core.wires.CoreWire.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;
@@ -21,7 +22,7 @@ public class GUIAm2910RegCntr extends SimpleRectangularHardcodedGUIComponent
 {
        public GUIAm2910RegCntr(ViewModelModifiable model, String name)
        {
-               super(model, name, "Register/\nCounter");
+               super(model, "GUIAm2910RegCntr", name, "Register/\nCounter");
                setSize(40, 40);
                addPin(new Pin(this, "D", 12, PinUsage.INPUT, 20, 0), Position.BOTTOM);
                addPin(new Pin(this, "_RLD", 1, PinUsage.INPUT, 0, 5), Position.RIGHT);
@@ -60,7 +61,6 @@ public class GUIAm2910RegCntr extends SimpleRectangularHardcodedGUIComponent
                        {
                                Bit carry = Bit.ZERO;
                                // TODO extract to helper. This code almost also exists in GUIinc12.
-                               // TODO maybe invert loop direction
                                for (int i = 11; i >= 0; i--)
                                {
                                        Bit a = QC[i];
@@ -75,6 +75,34 @@ public class GUIAm2910RegCntr extends SimpleRectangularHardcodedGUIComponent
                return QC;
        }
 
+       @Override
+       protected Object getHighLevelState(Object state, String stateID)
+       {
+               switch (stateID)
+               {
+               case "q":
+                       return BitVector.of(Arrays.copyOfRange((Bit[]) state, 0, 12));
+               default:
+                       return super.getHighLevelState(state, stateID);
+               }
+       }
+
+       @Override
+       protected Object setHighLevelState(Object lastState, String stateID, Object newHighLevelState)
+       {
+               switch (stateID)
+               {
+               case "q":
+                       BitVector newHighLevelStateCasted = (BitVector) newHighLevelState;
+                       if (newHighLevelStateCasted.length() != 12)
+                               throw new IllegalArgumentException("Expected BitVector of length 12, not " + newHighLevelStateCasted.length());
+                       System.arraycopy(newHighLevelStateCasted.getBits(), 0, lastState, 0, 12);
+                       return lastState;
+               default:
+                       return super.setHighLevelState(lastState, stateID, newHighLevelState);
+               }
+       }
+
        static
        {
                IndirectGUIComponentCreator.setComponentSupplier(GUIAm2910RegCntr.class.getCanonicalName(),