Added MSB first versions of parse() and toString()
[Mograsim.git] / net.mograsim.logic.ui.am2900 / test / net / mograsim / logic / ui / am2900 / TestableAm2901Impl.java
index a6eb791..1862ae3 100644 (file)
@@ -62,7 +62,7 @@ public class TestableAm2901Impl implements TestableAm2901
                        timeline.executeNext();
                        if (!timeline.hasNext())
                        {
-                               System.out.println("run() took " + eventCounter + " events");
+//                             System.out.println("run() took " + eventCounter + " events");
                                return Result.SUCCESS;
                        }
                }
@@ -114,6 +114,7 @@ public class TestableAm2901Impl implements TestableAm2901
                for (String id : am2901.getOutputPinNames())
                {
                        GUIBitDisplay bd = new GUIBitDisplay(viewModel);
+//                     bd.addRedrawListener(() -> System.out.println(id + " " + bd.getBitDisplay().getDisplayedValue()));
                        new GUIWire(viewModel, am2901.getPin(id), bd.getInputPin());
                        idDisplayMap.put(id, bd);
                }
@@ -127,8 +128,6 @@ public class TestableAm2901Impl implements TestableAm2901
                        setField(entry.getKey().replaceAll("\\+|=", "_"), entry.getValue().getManualSwitch());
                for (var entry : idDisplayMap.entrySet())
                        setField(entry.getKey().replaceAll("\\+|=", "_"), entry.getValue().getBitDisplay());
-               // Switch Clock off first
-               C.switchOff();
 
                // Debug code
                HashSet<GUIWire> wiresIncludingSubmodels = new HashSet<>();
@@ -146,7 +145,6 @@ public class TestableAm2901Impl implements TestableAm2901
                {
                        if (debugWires)
                        {
-                               System.out.println(w);
                                wireDebugChangeSet.add(w.toString());
                        }
                }));
@@ -183,21 +181,21 @@ public class TestableAm2901Impl implements TestableAm2901
        @Override
        public void setReg_A(String val_4_bit)
        {
-               var bits = BitVector.parse(val_4_bit);
-               A3.setToValueOf(bits.getBit(0));
-               A2.setToValueOf(bits.getBit(1));
-               A1.setToValueOf(bits.getBit(2));
-               A0.setToValueOf(bits.getBit(3));
+               var bits = BitVector.parseMSBFirst(val_4_bit);
+               A3.setToValueOf(bits.getBit(3));
+               A2.setToValueOf(bits.getBit(2));
+               A1.setToValueOf(bits.getBit(1));
+               A0.setToValueOf(bits.getBit(0));
        }
 
        @Override
        public void setReg_B(String val_4_bit)
        {
-               var bits = BitVector.parse(val_4_bit);
-               B3.setToValueOf(bits.getBit(0));
-               B2.setToValueOf(bits.getBit(1));
-               B1.setToValueOf(bits.getBit(2));
-               B0.setToValueOf(bits.getBit(3));
+               var bits = BitVector.parseMSBFirst(val_4_bit);
+               B3.setToValueOf(bits.getBit(3));
+               B2.setToValueOf(bits.getBit(2));
+               B1.setToValueOf(bits.getBit(1));
+               B0.setToValueOf(bits.getBit(0));
        }
 
        @Override
@@ -215,11 +213,11 @@ public class TestableAm2901Impl implements TestableAm2901
        @Override
        public void setD(String val_4_bit)
        {
-               var bits = BitVector.parse(val_4_bit);
-               D4.setToValueOf(bits.getBit(0));
-               D3.setToValueOf(bits.getBit(1));
-               D2.setToValueOf(bits.getBit(2));
-               D1.setToValueOf(bits.getBit(3));
+               var bits = BitVector.parseMSBFirst(val_4_bit);
+               D4.setToValueOf(bits.getBit(3));
+               D3.setToValueOf(bits.getBit(2));
+               D2.setToValueOf(bits.getBit(1));
+               D1.setToValueOf(bits.getBit(0));
        }
 
        @Override
@@ -247,9 +245,9 @@ public class TestableAm2901Impl implements TestableAm2901
        }
 
        @Override
-       public void toogleClock()
+       public void clockOn(boolean isClockOn)
        {
-               C.toggle();
+               C.setState(isClockOn);
        }
 
        @Override
@@ -319,7 +317,7 @@ public class TestableAm2901Impl implements TestableAm2901
                var y2 = Y3.getDisplayedValue();
                var y1 = Y2.getDisplayedValue();
                var y0 = Y1.getDisplayedValue();
-               return y3.concat(y2).concat(y1).concat(y0).toString();
+               return y0.concat(y1).concat(y2).concat(y3).toBitStringMSBFirst();
        }
 
        private void setField(String name, Object value)
@@ -347,4 +345,23 @@ public class TestableAm2901Impl implements TestableAm2901
                }
                return mutator.toBitVector();
        }
+
+       @Override
+       public void setDirectly(Register r, String val_4_bit)
+       {
+               am2901.setHighLevelState(regToStateID(r), BitVector.parseMSBFirst(val_4_bit));
+       }
+
+       @Override
+       public String getDirectly(Register r)
+       {
+               return ((BitVector) am2901.getHighLevelState(regToStateID(r))).toBitStringMSBFirst();
+       }
+
+       private static String regToStateID(Register r)
+       {
+               if (r == Register.Q)
+                       return "qreg.q";
+               return "regs.c" + r.toBitString() + ".q";
+       }
 }