Example #1
0
        private void btnAddConfig_Click(object sender, EventArgs e)
        {
            string newConfigName = editConfigName.Text;

            var existingConfig = m_Settings.Configuration(newConfigName);

            if (existingConfig != null)
            {
                return;
            }
            ProjectConfig config = new ProjectConfig();

            config.Name    = newConfigName;
            config.Defines = editPreDefines.Text;
            config.DebugStartAddressLabel = editDebugStartAddress.Text;

            foreach (ProjectElement element in m_Project.Elements)
            {
                ProjectElement.PerConfigSettings configSettings    = element.Settings["Default"];
                ProjectElement.PerConfigSettings newConfigSettings = new ProjectElement.PerConfigSettings();

                newConfigSettings.PreBuild    = configSettings.PreBuild;
                newConfigSettings.CustomBuild = configSettings.CustomBuild;
                newConfigSettings.PostBuild   = configSettings.PostBuild;

                element.Settings[newConfigName] = newConfigSettings;
                element.DocumentInfo.DeducedDependency[newConfigName] = new DependencyBuildState();
            }

            m_Settings.Configuration(config.Name, config);
            comboConfiguration.Items.Add(config.Name);
            m_Core.MainForm.mainToolConfig.Items.Add(config.Name);

            Modified = true;
        }
Example #2
0
        private void comboConfig_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selectedConfig = comboConfig.SelectedItem.ToString();

            ProjectElement.PerConfigSettings configSettings = Element.Settings[selectedConfig];

            SelectDebugType(configSettings.DebugFileType);
            editDebugCommand.Text = configSettings.DebugFile;
        }
Example #3
0
        private void editDebugCommand_TextChanged(object sender, EventArgs e)
        {
            string selectedConfig = comboConfig.SelectedItem.ToString();

            ProjectElement.PerConfigSettings configSettings = Element.Settings[selectedConfig];

            if (configSettings.DebugFile != editDebugCommand.Text)
            {
                configSettings.DebugFile = editDebugCommand.Text;
                Element.DocumentInfo.Project.SetModified();
            }
        }
Example #4
0
        private void comboDebugFileType_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selectedConfig = comboConfig.SelectedItem.ToString();

            ProjectElement.PerConfigSettings configSettings = Element.Settings[selectedConfig];

            if ((int)configSettings.DebugFileType != comboDebugFileType.SelectedIndex)
            {
                configSettings.DebugFileType = (C64Studio.Types.CompileTargetType)comboDebugFileType.SelectedIndex;
                Element.DocumentInfo.Project.SetModified();
            }
        }
Example #5
0
        private void comboDebugFileType_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selectedConfig = comboConfig.SelectedItem.ToString();

            ProjectElement.PerConfigSettings configSettings = Element.Settings[selectedConfig];

            var debugType = ((GR.Generic.Tupel <string, CompileTargetType>)comboDebugFileType.SelectedItem).second;

            if (configSettings.DebugFileType != debugType)
            {
                configSettings.DebugFileType = debugType;
                Element.DocumentInfo.Project.SetModified();
            }
        }
Example #6
0
        public PropDebugging(ProjectElement Element, StudioCore Core)
        {
            this.Element = Element;
            this.Core    = Core;
            TopLevel     = false;
            Text         = "Debug";
            InitializeComponent();

            AddType(CompileTargetType.NONE);
            AddType(CompileTargetType.PLAIN);
            AddType(CompileTargetType.PRG);
            AddType(CompileTargetType.T64);
            AddType(CompileTargetType.TAP);
            AddType(CompileTargetType.D64);
            AddType(CompileTargetType.D81);

            if (Element.DocumentInfo.Type == ProjectElement.ElementType.ASM_SOURCE)
            {
                AddType(CompileTargetType.CARTRIDGE_8K_BIN);
                AddType(CompileTargetType.CARTRIDGE_8K_CRT);
                AddType(CompileTargetType.CARTRIDGE_16K_BIN);
                AddType(CompileTargetType.CARTRIDGE_16K_CRT);
                AddType(CompileTargetType.CARTRIDGE_MAGICDESK_BIN);
                AddType(CompileTargetType.CARTRIDGE_MAGICDESK_CRT);
                AddType(CompileTargetType.CARTRIDGE_EASYFLASH_BIN);
                AddType(CompileTargetType.CARTRIDGE_EASYFLASH_CRT);
                AddType(CompileTargetType.CARTRIDGE_RGCD_BIN);
                AddType(CompileTargetType.CARTRIDGE_RGCD_CRT);
            }

            foreach (var configName in Element.DocumentInfo.Project.Settings.GetConfigurationNames())
            {
                comboConfig.Items.Add(configName);
            }
            comboConfig.SelectedItem = Element.DocumentInfo.Project.Settings.CurrentConfig.Name;

            ProjectElement.PerConfigSettings configSettings = Element.Settings[Element.DocumentInfo.Project.Settings.CurrentConfig.Name];

            SelectDebugType(configSettings.DebugFileType);
            editDebugCommand.Text = configSettings.DebugFile;
        }
Example #7
0
        private void comboBuildEvents_SelectedIndexChanged(object sender, EventArgs e)
        {
            string config = (string)comboConfig.SelectedItem;

            if (string.IsNullOrEmpty(config))
            {
                config = "Default";
            }
            ProjectElement.PerConfigSettings configSetting = Element.Settings[config];

            if (BuildEventDetails != null)
            {
                BuildEventDetails.Close();
                BuildEventDetails = null;
            }

            var buildEvent = ((GR.Generic.Tupel <string, C64Studio.ProjectElement.PerConfigSettings.BuildEvent>)comboBuildEvents.SelectedItem).second;

            switch (buildEvent)
            {
            case ProjectElement.PerConfigSettings.BuildEvent.PRE:
            case ProjectElement.PerConfigSettings.BuildEvent.CUSTOM:
            case ProjectElement.PerConfigSettings.BuildEvent.POST:
                BuildEventDetails = new PropBuildEventScript(Element, Core, configSetting, buildEvent);
                break;

            case ProjectElement.PerConfigSettings.BuildEvent.PRE_BUILD_CHAIN:
                BuildEventDetails = new PropBuildEventBuildChain(Element, Core, configSetting.PreBuildChain, config);
                break;

            case ProjectElement.PerConfigSettings.BuildEvent.POST_BUILD_CHAIN:
                BuildEventDetails = new PropBuildEventBuildChain(Element, Core, configSetting.PostBuildChain, config);
                break;
            }
            BuildEventDetails.Parent   = this;
            BuildEventDetails.Location = new Point(6, 68);
            BuildEventDetails.Visible  = true;

            GR.Image.DPIHandler.ResizeControlsForDPI(BuildEventDetails);
        }
Example #8
0
        public PropDebugging(ProjectElement Element, StudioCore Core)
        {
            this.Element = Element;
            this.Core    = Core;
            TopLevel     = false;
            Text         = "Debug";
            InitializeComponent();

            comboDebugFileType.Items.Add("None");
            comboDebugFileType.Items.Add("Plain");
            comboDebugFileType.Items.Add("PRG (cbm)");
            comboDebugFileType.Items.Add("T64");
            comboDebugFileType.Items.Add("8 KB Cartridge (bin)");
            comboDebugFileType.Items.Add("8 KB Cartridge (crt)");
            comboDebugFileType.Items.Add("16 KB Cartridge (bin)");
            comboDebugFileType.Items.Add("16 KB Cartridge (crt)");
            comboDebugFileType.Items.Add("D64");
            comboDebugFileType.Items.Add("Magic Desk 64 KB Cartridge (bin)");
            comboDebugFileType.Items.Add("Magic Desk 64 KB Cartridge (crt)");
            comboDebugFileType.Items.Add("TAP");
            comboDebugFileType.Items.Add("Easyflash Cartridge (bin)");
            comboDebugFileType.Items.Add("Easyflash Cartridge (crt)");
            comboDebugFileType.Items.Add("RGCD 64 KB Cartridge (bin)");
            comboDebugFileType.Items.Add("RGCD 64 KB Cartridge (crt)");

            foreach (ProjectConfig config in Element.DocumentInfo.Project.Settings.Configs.Values)
            {
                comboConfig.Items.Add(config.Name);
            }
            comboConfig.SelectedItem = Element.DocumentInfo.Project.Settings.CurrentConfig.Name;

            ProjectElement.PerConfigSettings configSettings = Element.Settings[Element.DocumentInfo.Project.Settings.CurrentConfig.Name];

            comboDebugFileType.SelectedIndex = (int)configSettings.DebugFileType;
            editDebugCommand.Text            = configSettings.DebugFile;
        }
Example #9
0
        public bool Load(byte[] ProjectData)
        {
            string currentConfig = "Default";
            string activeElement = "";

            Node     = new System.Windows.Forms.TreeNode();
            Node.Tag = this;

            GR.IO.MemoryReader memIn = new GR.IO.MemoryReader(ProjectData);

            GR.IO.FileChunk chunk = new GR.IO.FileChunk();
            ushort          origDebugStartAddress = 2049;

            while (chunk.ReadFromStream(memIn))
            {
                GR.IO.MemoryReader memChunk = chunk.MemoryReader();
                switch (chunk.Type)
                {
                case Types.FileChunk.PROJECT:
                    // Project Info

                    // Version
                    memChunk.ReadUInt32();
                    Settings.Name         = memChunk.ReadString();
                    Settings.Filename     = memChunk.ReadString();
                    Settings.DebugPort    = memChunk.ReadUInt16();
                    origDebugStartAddress = memChunk.ReadUInt16();
                    Settings.BuildTool    = memChunk.ReadString();
                    Settings.RunTool      = memChunk.ReadString();
                    Settings.MainDocument = memChunk.ReadString();
                    currentConfig         = memChunk.ReadString();
                    activeElement         = memChunk.ReadString();
                    Node.Text             = Settings.Name;
                    break;

                case Types.FileChunk.PROJECT_ELEMENT:
                    // Element Info
                {
                    // Version
                    int version = (int)memChunk.ReadUInt32();

                    ProjectElement.ElementType type = (ProjectElement.ElementType)memChunk.ReadUInt32();

                    //System.Windows.Forms.TreeNode nodeParent = NodeFromHierarchy(

                    ProjectElement element = CreateElement(type, Node);
                    element.Name = memChunk.ReadString();
                    //element.Filename = System.IO.Path.GetFileName( memChunk.ReadString() );
                    element.Filename = memChunk.ReadString();
                    if (element.DocumentInfo.Type == ProjectElement.ElementType.FOLDER)
                    {
                        element.Node.Text = element.Name;
                    }
                    else
                    {
                        element.Node.Text = System.IO.Path.GetFileName(element.Filename);
                    }

                    GR.IO.FileChunk subChunk = new GR.IO.FileChunk();

                    if (!subChunk.ReadFromStream(memChunk))
                    {
                        return(false);
                    }
                    if (subChunk.Type != Types.FileChunk.PROJECT_ELEMENT_DATA)
                    {
                        return(false);
                    }
                    // Element Data
                    element.DocumentInfo.DocumentFilename = element.Filename;
                    if (element.Document != null)
                    {
                        if (!element.Document.ReadFromReader(subChunk.MemoryReader()))
                        {
                            Elements.Remove(element);
                            element.Document.Dispose();
                            element = null;
                        }
                        else
                        {
                            element.Document.SetDocumentFilename(element.Filename);
                        }
                    }
                    element.TargetFilename = memChunk.ReadString();
                    element.TargetType     = (Types.CompileTargetType)memChunk.ReadUInt32();
                    int dependencyCount = memChunk.ReadInt32();
                    for (int i = 0; i < dependencyCount; ++i)
                    {
                        string dependency = memChunk.ReadString();
                        element.ForcedDependency.DependentOnFile.Add(new FileDependency.DependencyInfo(dependency, true, false));
                    }
                    // 3 free strings
                    memChunk.ReadString();
                    memChunk.ReadString();
                    memChunk.ReadString();

                    int perConfigSettingCount = memChunk.ReadInt32();
                    for (int i = 0; i < perConfigSettingCount; ++i)
                    {
                        GR.IO.FileChunk chunkElementPerConfigSetting = new GR.IO.FileChunk();
                        chunkElementPerConfigSetting.ReadFromStream(memChunk);
                        if (chunkElementPerConfigSetting.Type == Types.FileChunk.PROJECT_ELEMENT_PER_CONFIG_SETTING)
                        {
                            ProjectElement.PerConfigSettings perConfigSetting = new ProjectElement.PerConfigSettings();
                            GR.IO.MemoryReader memSubChunk = chunkElementPerConfigSetting.MemoryReader();
                            string             config      = memSubChunk.ReadString();

                            perConfigSetting.PreBuild      = memSubChunk.ReadString();
                            perConfigSetting.CustomBuild   = memSubChunk.ReadString();
                            perConfigSetting.PostBuild     = memSubChunk.ReadString();
                            perConfigSetting.DebugFile     = memSubChunk.ReadString();
                            perConfigSetting.DebugFileType = (C64Studio.Types.CompileTargetType)memSubChunk.ReadInt32();

                            perConfigSetting.PreBuildChain.Active = (memSubChunk.ReadInt32() == 1);
                            int numEntries = memSubChunk.ReadInt32();
                            for (int j = 0; j < numEntries; ++j)
                            {
                                var entry = new BuildChainEntry();

                                entry.ProjectName      = memSubChunk.ReadString();
                                entry.Config           = memSubChunk.ReadString();
                                entry.DocumentFilename = memSubChunk.ReadString();
                                entry.PreDefines       = memSubChunk.ReadString();

                                perConfigSetting.PreBuildChain.Entries.Add(entry);
                            }

                            perConfigSetting.PostBuildChain.Active = (memSubChunk.ReadInt32() == 1);
                            numEntries = memSubChunk.ReadInt32();
                            for (int j = 0; j < numEntries; ++j)
                            {
                                var entry = new BuildChainEntry();

                                entry.ProjectName      = memSubChunk.ReadString();
                                entry.Config           = memSubChunk.ReadString();
                                entry.DocumentFilename = memSubChunk.ReadString();
                                entry.PreDefines       = memSubChunk.ReadString();

                                perConfigSetting.PostBuildChain.Entries.Add(entry);
                            }
                            element.Settings[config] = perConfigSetting;
                        }
                    }

                    element.IsShown       = (memChunk.ReadInt32() != 0);
                    element.AssemblerType = (C64Studio.Types.AssemblerType)memChunk.ReadUInt32();

                    int hierarchyPartCount = memChunk.ReadInt32();
                    for (int i = 0; i < hierarchyPartCount; ++i)
                    {
                        string part = memChunk.ReadString();

                        element.ProjectHierarchy.Add(part);
                    }

                    if (element.ProjectHierarchy.Count > 0)
                    {
                        // node is sub-node, move accordingly
                        System.Windows.Forms.TreeNode parentNode = NodeFromHierarchy(element.ProjectHierarchy);
                        if ((parentNode != null) &&
                            (parentNode != element.Node.Parent))
                        {
                            element.Node.Remove();
                            parentNode.Nodes.Add(element.Node);
                        }
                    }

                    // dependency - include symbols
                    dependencyCount = memChunk.ReadInt32();
                    for (int i = 0; i < dependencyCount; ++i)
                    {
                        element.ForcedDependency.DependentOnFile[i].IncludeSymbols = (memChunk.ReadInt32() != 0);
                    }

                    // code folding entries
                    int numFoldingEntries = memChunk.ReadInt32();
                    element.DocumentInfo.CollapsedFoldingBlocks = new GR.Collections.Set <int>();
                    for (int i = 0; i < numFoldingEntries; ++i)
                    {
                        int collapsedBlockLine = memChunk.ReadInt32();
                        element.DocumentInfo.CollapsedFoldingBlocks.Add(collapsedBlockLine);
                        //Debug.Log( "Get collapsed blocked for " + element.DocumentInfo.FullPath + ", line " + collapsedBlockLine );
                    }

                    // TODO - load other stuff
                    if ((element != null) &&
                        (element.IsShown))
                    {
                        ShowDocument(element);
                        if (element.Document != null)
                        {
                            element.Document.ShowHint = DockState.Document;
                            //element.Document.Show( MainForm.panelMain );
                        }
                    }
                }
                break;

                case Types.FileChunk.PROJECT_ELEMENT_DISPLAY_DATA:
                {
                    string elementFilename = memChunk.ReadString();

                    ProjectElement element = GetElementByFilename(elementFilename);
                    if (element != null)
                    {
                        UInt32 numBytes = memChunk.ReadUInt32();
                        GR.Memory.ByteBuffer displayData = new GR.Memory.ByteBuffer();
                        memChunk.ReadBlock(displayData, numBytes);

                        if (element.Document != null)
                        {
                            element.Document.ApplyDisplayDetails(displayData);
                        }
                    }
                }
                break;

                case Types.FileChunk.PROJECT_CONFIG:
                {
                    ProjectConfig config = new ProjectConfig();

                    config.Load(memChunk);

                    if (string.IsNullOrEmpty(config.DebugStartAddressLabel))
                    {
                        config.DebugStartAddressLabel = origDebugStartAddress.ToString();
                    }

                    Settings.Configs.Add(config.Name, config);
                }
                break;

                case Types.FileChunk.PROJECT_WATCH_ENTRY:
                {
                    WatchEntry watch = new WatchEntry();

                    watch.Load(memChunk);
                    Core.MainForm.AddWatchEntry(watch);
                    //Debug.Log( "loaded watch entry for " + watch.Name );
                }
                break;
                }
            }
            if (Settings.Configs.Count == 0)
            {
                // there must be one config
                ProjectConfig config = new ProjectConfig();

                config.Name = "Default";
                Settings.Configs.Add(config.Name, config);
                Settings.CurrentConfig = config;
            }
            else
            {
                if (Settings.Configs.ContainsKey(currentConfig))
                {
                    Settings.CurrentConfig = Settings.Configs[currentConfig];
                }
                else
                {
                    foreach (ProjectConfig config in Settings.Configs.Values)
                    {
                        Settings.CurrentConfig = config;
                        break;
                    }
                }
            }
            foreach (ProjectElement element in Elements)
            {
                if (element.Settings.Count == 0)
                {
                    foreach (ProjectConfig config in Settings.Configs.Values)
                    {
                        // needs a default setting!
                        element.Settings[config.Name] = new ProjectElement.PerConfigSettings();
                    }
                }
                if ((!string.IsNullOrEmpty(element.Filename)) &&
                    (GR.Path.IsPathEqual(element.Filename, Settings.MainDocument)))
                {
                    Core.MainForm.m_SolutionExplorer.HighlightNode(element.Node);
                }

                Core.MainForm.RaiseApplicationEvent(new C64Studio.Types.ApplicationEvent(C64Studio.Types.ApplicationEvent.Type.DOCUMENT_INFO_CREATED, element.DocumentInfo));
                Core.MainForm.RaiseApplicationEvent(new C64Studio.Types.ApplicationEvent(C64Studio.Types.ApplicationEvent.Type.ELEMENT_CREATED, element));
            }



            if (!String.IsNullOrEmpty(activeElement))
            {
                ProjectElement element = GetElementByFilename(activeElement);
                if ((element != null) &&
                    (element.Document != null))
                {
                    element.Document.Show();
                }
            }
            m_Modified = false;
            return(true);
        }
        public bool DebugCompiledFile(DocumentInfo DocumentToDebug, DocumentInfo DocumentToRun)
        {
            if (DocumentToDebug == null)
            {
                Core.AddToOutput("Debug document not found, this is an internal error!");
                return(false);
            }

            if (DocumentToDebug.Element == null)
            {
                Core.AddToOutput("Debugging " + DocumentToDebug.DocumentFilename + System.Environment.NewLine);
            }
            else
            {
                Core.AddToOutput("Debugging " + DocumentToDebug.Element.Name + System.Environment.NewLine);
            }

            ToolInfo toolRun = Core.DetermineTool(DocumentToRun, true);

            if (toolRun == null)
            {
                System.Windows.Forms.MessageBox.Show("No emulator tool has been configured yet!", "Missing emulator tool");
                Core.AddToOutput("There is no emulator tool configured!");
                return(false);
            }

            SetupDebugger(toolRun);

            if (!Debugger.CheckEmulatorVersion(toolRun))
            {
                return(false);
            }

            DebuggedASMBase      = DocumentToDebug;
            DebugBaseDocumentRun = DocumentToRun;

            Core.MainForm.m_DebugWatch.ReseatWatches(DocumentToDebug.ASMFileInfo);
            Debugger.ClearCaches();
            MemoryViews.ForEach(mv => mv.MarkAllMemoryAsUnknown());
            ReseatBreakpoints(DocumentToDebug.ASMFileInfo);
            AddVirtualBreakpoints(DocumentToDebug.ASMFileInfo);
            Debugger.ClearAllBreakpoints();
            MarkedDocument     = null;
            MarkedDocumentLine = -1;

            if (!Core.Executing.StartProcess(toolRun, DocumentToRun))
            {
                return(false);
            }
            if (!System.IO.Directory.Exists(Core.Executing.RunProcess.StartInfo.WorkingDirectory.Trim(new char[] { '"' })))
            {
                Core.AddToOutput("The determined working directory " + Core.Executing.RunProcess.StartInfo.WorkingDirectory + " does not exist" + System.Environment.NewLine);
                return(false);
            }

            // determine debug target type
            Types.CompileTargetType targetType = C64Studio.Types.CompileTargetType.NONE;
            if (DocumentToRun.Element != null)
            {
                targetType = DocumentToRun.Element.TargetType;
            }

            string fileToRun = "";

            if (DocumentToRun.Element != null)
            {
                fileToRun = DocumentToRun.Element.TargetFilename;
                ProjectElement.PerConfigSettings configSetting = DocumentToRun.Element.Settings[DocumentToRun.Project.Settings.CurrentConfig.Name];
                if (!string.IsNullOrEmpty(configSetting.DebugFile))
                {
                    targetType = configSetting.DebugFileType;
                }
            }

            if (targetType == C64Studio.Types.CompileTargetType.NONE)
            {
                targetType = Core.Compiling.m_LastBuildInfo.TargetType;
            }
            DebugType = targetType;

            string breakPointFile = PrepareAfterStartBreakPoints();
            string command        = toolRun.DebugArguments;

            if (Parser.ASMFileParser.IsCartridge(targetType))
            {
                command = command.Replace("-initbreak 0x$(DebugStartAddressHex) ", "");
            }

            if ((toolRun.PassLabelsToEmulator) &&
                (DebuggedASMBase.ASMFileInfo != null))
            {
                breakPointFile += DebuggedASMBase.ASMFileInfo.LabelsAsFile(EmulatorInfo.LabelFormat(toolRun));
            }

            if (breakPointFile.Length > 0)
            {
                try
                {
                    TempDebuggerStartupFilename = System.IO.Path.GetTempFileName();
                    System.IO.File.WriteAllText(TempDebuggerStartupFilename, breakPointFile);
                    command += " -moncommands \"" + TempDebuggerStartupFilename + "\"";
                }
                catch (System.IO.IOException ioe)
                {
                    System.Windows.Forms.MessageBox.Show(ioe.Message, "Error writing temporary file");
                    Core.AddToOutput("Error writing temporary file");
                    TempDebuggerStartupFilename = "";
                    return(false);
                }
            }

            //ParserASM.CompileTarget != Types.CompileTargetType.NONE ) ? ParserASM.CompileTarget : DocumentToRun.Element.TargetType;

            // need to adjust initial breakpoint address for late added store/load breakpoints?

            InitialBreakpointIsTemporary = true;
            //if ( BreakpointsToAddAfterStartup.Count > 0 )
            {
                // yes
                LateBreakpointOverrideDebugStart = OverrideDebugStart;

                // special start addresses for different run types
                if (Parser.ASMFileParser.IsCartridge(targetType))
                {
                    OverrideDebugStart = Debugger.ConnectedMachine.InitialBreakpointAddressCartridge;
                }
                else
                {
                    // directly after calling load from ram (as VICE does when autostarting a .prg file)
                    // TODO - check with .t64, .tap, .d64
                    OverrideDebugStart = Debugger.ConnectedMachine.InitialBreakpointAddress;
                }
            }
            if ((DocumentToDebug.Project != null) &&
                (LateBreakpointOverrideDebugStart == -1) &&
                (!string.IsNullOrEmpty(DocumentToDebug.Project.Settings.CurrentConfig.DebugStartAddressLabel)))
            {
                int debugStartAddress = -1;
                if (!Core.MainForm.DetermineDebugStartAddress(DocumentToDebug, DocumentToDebug.Project.Settings.CurrentConfig.DebugStartAddressLabel, out debugStartAddress))
                {
                    Core.AddToOutput("Cannot determine value for debug start address from '" + DocumentToDebug.Project.Settings.CurrentConfig.DebugStartAddressLabel + "'" + System.Environment.NewLine);
                    return(false);
                }
                if (debugStartAddress != 0)
                {
                    InitialBreakpointIsTemporary     = false;
                    OverrideDebugStart               = debugStartAddress;
                    LateBreakpointOverrideDebugStart = debugStartAddress;
                }
            }

            if (Core.Settings.TrueDriveEnabled)
            {
                command = toolRun.TrueDriveOnArguments + " " + command;
            }
            else
            {
                command = toolRun.TrueDriveOffArguments + " " + command;
            }

            bool error = false;

            Core.Executing.RunProcess.StartInfo.Arguments = Core.MainForm.FillParameters(command, DocumentToRun, true, out error);
            if (error)
            {
                return(false);
            }

            if (Parser.ASMFileParser.IsCartridge(targetType))
            {
                Core.Executing.RunProcess.StartInfo.Arguments += " " + Core.MainForm.FillParameters(toolRun.CartArguments, DocumentToRun, true, out error);
            }
            else
            {
                Core.Executing.RunProcess.StartInfo.Arguments += " " + Core.MainForm.FillParameters(toolRun.PRGArguments, DocumentToRun, true, out error);
            }
            if (error)
            {
                return(false);
            }

            Core.AddToOutput("Calling " + Core.Executing.RunProcess.StartInfo.FileName + " with " + Core.Executing.RunProcess.StartInfo.Arguments + System.Environment.NewLine);
            Core.Executing.RunProcess.Exited += new EventHandler(Core.MainForm.runProcess_Exited);
            Core.SetStatus("Running...");

            Core.MainForm.SetGUIForWaitOnExternalTool(true);

            if (Core.Executing.RunProcess.Start())
            {
                DateTime current = DateTime.Now;

                // new GTK VICE opens up with console window (yuck) which nicely interferes with WaitForInputIdle -> give it 5 seconds to open main window
                bool waitForInputIdleFailed = false;
                try
                {
                    Core.Executing.RunProcess.WaitForInputIdle(5000);
                }
                catch (Exception ex)
                {
                    Debug.Log("WaitForInputIdle failed: " + ex.ToString());
                    waitForInputIdleFailed = true;
                }

                // only connect with debugger if VICE
                int numConnectionAttempts = 1;
                if ((string.IsNullOrEmpty(Core.Executing.RunProcess.MainWindowTitle)) &&
                    (waitForInputIdleFailed))
                {
                    // assume GTK VICE
                    numConnectionAttempts = 10;
                }
                if (EmulatorInfo.SupportsDebugging(toolRun))
                {
                    //Debug.Log( "Have " + numConnectionAttempts + " attempts" );
                    Core.AddToOutput("Connection attempt ");
                    for (int i = 0; i < numConnectionAttempts; ++i)
                    {
                        //Debug.Log( "attempt" + i );
                        Core.AddToOutput((i + 1).ToString());
                        if (Debugger.ConnectToEmulator(Parser.ASMFileParser.IsCartridge(targetType)))
                        {
                            //Debug.Log( "-succeeded" );
                            Core.AddToOutput(" succeeded" + System.Environment.NewLine);
                            Core.MainForm.m_CurrentActiveTool = toolRun;
                            DebuggedProject        = DocumentToRun.Project;
                            Core.MainForm.AppState = Types.StudioState.DEBUGGING_RUN;
                            Core.MainForm.SetGUIForDebugging(true);
                            break;
                        }
                        // wait a second
                        for (int j = 0; j < 20; ++j)
                        {
                            System.Threading.Thread.Sleep(50);
                            System.Windows.Forms.Application.DoEvents();
                        }
                    }
                    if (Core.MainForm.AppState != Types.StudioState.DEBUGGING_RUN)
                    {
                        Core.AddToOutput("failed " + numConnectionAttempts + " times, giving up" + System.Environment.NewLine);
                        return(false);
                    }
                }
                else
                {
                    Core.MainForm.m_CurrentActiveTool = toolRun;
                    DebuggedProject        = DocumentToRun.Project;
                    Core.MainForm.AppState = Types.StudioState.DEBUGGING_RUN;
                    Core.MainForm.SetGUIForDebugging(true);
                }
            }
            return(true);
        }