X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Fviews%2FSimulationView.java;h=179843b943e6c6092823d5dde2dab3f26078a542;hb=029314dfb6b557d178164db7c3ada9e7691d086d;hp=f81fb4b0423506905912edc018096c00c3f2739f;hpb=39a9cc869cbf3e1c7fc3a61ea6552d5d078e1d66;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java index f81fb4b0..179843b9 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java @@ -1,5 +1,11 @@ package net.mograsim.plugin.views; +import static net.mograsim.logic.model.preferences.RenderPreferences.DRAG_BUTTON; +import static net.mograsim.logic.model.preferences.RenderPreferences.ZOOM_BUTTON; +import static net.mograsim.plugin.preferences.PluginPreferences.SIMULATION_SPEED_PRECISION; + +import java.math.BigDecimal; +import java.math.MathContext; import java.util.HashSet; import java.util.Optional; import java.util.Set; @@ -26,16 +32,18 @@ import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInpu import net.mograsim.logic.core.LogicObserver; import net.mograsim.logic.core.components.CoreClock; import net.mograsim.logic.model.LogicUICanvas; +import net.mograsim.logic.model.modeladapter.CoreModelParameters; +import net.mograsim.logic.model.preferences.RenderPreferences; import net.mograsim.machine.Machine; import net.mograsim.machine.Memory.MemoryCellModifiedListener; import net.mograsim.machine.mi.AssignableMicroInstructionMemory; +import net.mograsim.plugin.MograsimActivator; import net.mograsim.plugin.launch.MachineDebugContextListener; import net.mograsim.plugin.launch.MachineDebugTarget; import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.mi.ActiveInstructionPreviewContentProvider; import net.mograsim.plugin.tables.mi.InstructionTable; import net.mograsim.plugin.util.OverlappingFillLayout; -import net.mograsim.preferences.Preferences; public class SimulationView extends ViewPart { @@ -47,6 +55,7 @@ public class SimulationView extends ViewPart private Button sbseButton; private Scale simSpeedScale; private DoubleInput simSpeedInput; + private Label simSpeedDescription; private Composite contextDependentControlsParent; private Composite canvasParent; private InstructionTable instPreview; @@ -66,6 +75,7 @@ public class SimulationView extends ViewPart controlsToDisableWhenNoMachinePresent = new HashSet<>(); memCellListener = a -> instPreview.refresh(); // TODO use Step Over instead + // TODO this should not be managed by the Simulation View clockObserver = o -> { if (((CoreClock) o).isOn()) @@ -119,7 +129,7 @@ public class SimulationView extends ViewPart { Composite c = new Composite(parent, SWT.NONE); c.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - c.setLayout(new GridLayout(7, false)); + c.setLayout(new GridLayout(8, false)); sbseButton = new Button(c, SWT.CHECK); controlsToDisableWhenNoMachinePresent.add(sbseButton); @@ -133,7 +143,7 @@ public class SimulationView extends ViewPart else cl.deregisterObserver(clockObserver); }); - sbseButton.setSelection(false); + sbseButton.setSelection(true); Label simSpeedLabel = new Label(c, SWT.NONE); controlsToDisableWhenNoMachinePresent.add(simSpeedLabel); @@ -153,7 +163,8 @@ public class SimulationView extends ViewPart simSpeedInput = new DoubleInput(c, SWT.NONE); controlsToDisableWhenNoMachinePresent.add(simSpeedInput); - simSpeedInput.setPrecision(Preferences.current().getInt("net.mograsim.plugin.core.simspeedprecision")); + // TODO add a listener + simSpeedInput.setPrecision(MograsimActivator.instance().getPluginPrefs().getInt(SIMULATION_SPEED_PRECISION)); simSpeedInput.addChangeListener(speed -> { if (speed != 0) @@ -162,14 +173,43 @@ public class SimulationView extends ViewPart debugTarget.setExecutionSpeed(Math.pow(10, -simSpeedInput.getPrecision())); }); + simSpeedDescription = new Label(c, SWT.NONE); + simSpeedDescription.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + c.layout(); } + private String describeSimSpeed(double speed) + { + CoreModelParameters coreModelParameters = debugTarget.getMachine().getCoreModelParameters(); + // TODO hardcoding this seems not optimal + int ticksPerSecond = 1000000; + + double simulTicksPerRealSecond = speed * ticksPerSecond; + + // TODO internationalize + StringBuilder sb = new StringBuilder(); + sb.append("Per second: "); + sb.append(formatNSignificantDigits(4, simulTicksPerRealSecond / coreModelParameters.wireTravelTime)); + sb.append(" wire travel times; "); + sb.append(formatNSignificantDigits(4, simulTicksPerRealSecond / coreModelParameters.gateProcessTime)); + sb.append(" gate process times; "); + sb.append(formatNSignificantDigits(4, simulTicksPerRealSecond / debugTarget.getMachine().getClock().getDelta() / 2)); + sb.append(" clock cycles"); + return sb.toString(); + } + + private static String formatNSignificantDigits(int digits, double d) + { + return new BigDecimal(d, new MathContext(digits)).toPlainString(); + } + private void speedFactorChanged(double speed) { simSpeedInput.setValue(speed); int closestScalePos = (int) Math.round(Math.log(speed) / SIM_SPEED_SCALE_STEP_FACTOR_LOG + SIM_SPEED_SCALE_STEPS); simSpeedScale.setSelection(Math.min(Math.max(closestScalePos, 0), SIM_SPEED_SCALE_STEPS)); + simSpeedDescription.setText(describeSimSpeed(speed)); } private void addInstructionPreviewControlWidgets(Composite parent) @@ -220,11 +260,14 @@ public class SimulationView extends ViewPart Machine machine = debugTarget.getMachine(); - canvas = new LogicUICanvas(canvasParent, SWT.NONE, machine.getModel()); + RenderPreferences renderPrefs = MograsimActivator.instance().getRenderPrefs(); + canvas = new LogicUICanvas(canvasParent, SWT.NONE, machine.getModel(), renderPrefs); canvas.addListener(SWT.MouseDown, e -> canvas.setFocus()); ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(canvas); - userInput.buttonDrag = Preferences.current().getInt("net.mograsim.logic.model.button.drag"); - userInput.buttonZoom = Preferences.current().getInt("net.mograsim.logic.model.button.zoom"); + // TODO add a listener + userInput.buttonDrag = renderPrefs.getInt(DRAG_BUTTON); + // TODO add a listener + userInput.buttonZoom = renderPrefs.getInt(ZOOM_BUTTON); userInput.enableUserInput(); if (zoom > 0) { @@ -241,6 +284,9 @@ public class SimulationView extends ViewPart // update preview contentProvider.setMachine(machine); + // enable SBSE + machine.getClock().registerObserver(clockObserver); + // initialize executer debugTarget.addExecutionSpeedListener(executionSpeedListener); speedFactorChanged(debugTarget.getExecutionSpeed()); @@ -261,7 +307,7 @@ public class SimulationView extends ViewPart debugTarget.getMachine().getMicroInstructionMemory().deregisterCellModifiedListener(memCellListener); debugTarget.getMachine().getClock().deregisterObserver(clockObserver); if (sbseButton != null && !sbseButton.isDisposed()) - sbseButton.setSelection(false); + sbseButton.setSelection(true); } }