Corrected incorrect correction of bit order
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / LogicUICanvas.java
index 4bc4f67..8e01a16 100644 (file)
@@ -100,13 +100,15 @@ public class LogicUICanvas extends ZoomableCanvas
                radioBit.setText("Single bit");
                Button radioBitVector = new Button(radioGroup, SWT.RADIO);
                radioBitVector.setText("Bitvector");
-               new Label(debugShell, SWT.NONE).setText("Value string representation: ");
+               new Label(debugShell, SWT.NONE).setText("Value string representation: \n(Bit vectors: MSBit...LSBit)");
                Text valueText = new Text(debugShell, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
                valueText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
                Button send = new Button(debugShell, SWT.PUSH);
-               Text lastError = new Text(debugShell, SWT.READ_ONLY);
-               lastError.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
                send.setText("Send!");
+               Button get = new Button(debugShell, SWT.PUSH);
+               get.setText("Get!");
+               Text output = new Text(debugShell, SWT.READ_ONLY);
+               output.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
                Listener sendAction = e ->
                {
                        try
@@ -119,20 +121,35 @@ public class LogicUICanvas extends ZoomableCanvas
                                if (radioBit.getSelection())
                                        value = Bit.parse(valueString);
                                else if (radioBitVector.getSelection())
-                                       value = BitVector.parse(valueString);
+                                       value = BitVector.parse(new StringBuilder(valueString).reverse().toString());
                                else
                                        throw new RuntimeException("No value type selected");
                                target.setHighLevelState(stateIDText.getText(), value);
-                               lastError.setText("Success!");
+                               output.setText("Success!");
                        }
                        catch (Exception x)
                        {
-                               lastError.setText(x.getMessage());
+                               output.setText(x.getClass().getSimpleName() + (x.getMessage() == null ? "" : ": " + x.getMessage()));
+                       }
+               };
+               Listener getAction = e ->
+               {
+                       try
+                       {
+                               if (componentSelector.getSelectionIndex() >= componentsByItemIndex.size())
+                                       throw new RuntimeException("No valid component selected");
+                               output.setText("Success! Value: \r\n"
+                                               + componentsByItemIndex.get(componentSelector.getSelectionIndex()).getHighLevelState(stateIDText.getText()));
+                       }
+                       catch (Exception x)
+                       {
+                               output.setText(x.getClass().getSimpleName() + (x.getMessage() == null ? "" : ": " + x.getMessage()));
                        }
                };
-               stateIDText.addListener(SWT.DefaultSelection, sendAction);
-               valueText.addListener(SWT.DefaultSelection, sendAction);
                send.addListener(SWT.Selection, sendAction);
+               valueText.addListener(SWT.DefaultSelection, sendAction);
+               get.addListener(SWT.Selection, getAction);
+               stateIDText.addListener(SWT.DefaultSelection, getAction);
                debugShell.open();
        }