+
+ private static boolean showErrorAndReturnFalse(String message)
+ {
+ StatusManager.getManager().handle(new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, message, null), StatusManager.SHOW);
+ return false;
+ }
+
+ @Override
+ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException
+ {
+ String projName = configuration.getAttribute(PROJECT_ATTR, "");
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projName);
+
+ MachineContext machineContext = ProjectMachineContext.getMachineContextOf(project);
+ MachineDefinition machineDefinition = machineContext.getMachineDefinition().orElseThrow();
+
+ IFile mpmFile = project.getFile(configuration.getAttribute(MPM_FILE_ATTR, ""));
+ Optional<IFile> mpromFile = fileOptional(project, configuration.getAttribute(MPROM_FILE_ATTR, ""));
+ Optional<IFile> memFile = fileOptional(project, configuration.getAttribute(INITIAL_RAM_FILE_ATTR, ""));
+ MachineDebugTarget debugTarget = new MachineDebugTarget(launch, mpmFile, mpromFile, memFile, machineDefinition);
+ // TODO make selectable whether the machine starts paused or not
+ debugTarget.suspend();
+ debugTarget.setExecutionSpeed(1);
+ Machine machine = debugTarget.getMachine();
+ machine.reset();
+
+ // Add the default Mograsim memory block to make it less confusing and more comfortable.
+ DebugPlugin.getDefault().getMemoryBlockManager()
+ .addMemoryBlocks(new IMemoryBlock[] { new MainMemoryBlockExtension(debugTarget, "0", null) });
+ }
+
+ private static Optional<IFile> fileOptional(IProject project, String filename)
+ {
+ if ("".equals(filename))
+ return Optional.empty();
+ return Optional.of(project.getFile(filename));
+ }
+