public void Initialize(IDisassemblyManager manager, BaseStyleProvider styleProvider) { _manager = manager; _styleProvider = styleProvider; _symbolProvider = DebugWorkspaceManager.GetSymbolProvider(); ctrlCode.StyleProvider = _styleProvider; ctrlCode.ShowContentNotes = false; ctrlCode.ShowMemoryValues = true; ctrlCode.ExtendedMarginWidth = manager.ByteCodeSize * 4; ctrlCode.AddressSize = manager.AddressSize; UpdateSourceFileDropdown(); _manager.RefreshCode(_inSourceView ? _symbolProvider : null, _inSourceView ? cboSourceFile.SelectedItem as SourceFileInfo : null); }
public void Import(string path, bool silent = false) { DbgFileStamp = File.GetLastWriteTime(path); string[] fileRows = File.ReadAllLines(path); string basePath = Path.GetDirectoryName(path); DbgPath = basePath; foreach (string row in fileRows) { try { if (LoadLines(row) || LoadSpans(row) || LoadSymbols(row) || LoadCSymbols(row) || LoadScopes(row) || LoadFiles(row, basePath) || LoadSegments(row)) { continue; } } catch { _errorCount++; } } LoadFileData(basePath); BuildCdlData(); foreach (LineInfo line in _lines.Values) { foreach (int spanID in line.SpanIDs) { SpanInfo span; if (_spans.TryGetValue(spanID, out span)) { SegmentInfo segment; if (_segments.TryGetValue(span.SegmentID, out segment) && !segment.IsRam) { for (int i = 0; i < span.Size; i++) { int prgAddress = segment.FileOffset - _headerSize + span.Offset + i; LineInfo existingLine; if (_linesByPrgAddress.TryGetValue(prgAddress, out existingLine) && existingLine.Type == LineType.External) { //Give priority to lines that come from C files continue; } _linesByPrgAddress[prgAddress] = line; if (i == 0 && spanID == line.SpanIDs[0]) { //Mark the first byte of the first span representing this line as the PRG address for this line of code FileInfo file = _files[line.FileID]; _prgAddressByLine[file.ID.ToString() + "_" + line.LineNumber.ToString()] = prgAddress; } } } } } } LoadLabels(); int labelCount = 0; DbgIntegrationConfig config = ConfigManager.Config.Debug.DbgIntegration; if (config.ImportCpuComments || config.ImportSpcComments) { LoadComments(); } List <CodeLabel> labels = new List <CodeLabel>(_romLabels.Count + _ramLabels.Count + _workRamLabels.Count + _saveRamLabels.Count); if (config.ImportCpuPrgRomLabels) { labels.AddRange(_romLabels.Values); labelCount += _romLabels.Count; } if (config.ImportCpuWorkRamLabels) { labels.AddRange(_workRamLabels.Values); labelCount += _workRamLabels.Count; } if (config.ImportCpuSaveRamLabels) { labels.AddRange(_saveRamLabels.Values); labelCount += _saveRamLabels.Count; } if (config.ImportSpcRamLabels) { labels.AddRange(_spcRamLabels.Values); labelCount += _spcRamLabels.Count; } if (ConfigManager.Config.Debug.DbgIntegration.ResetLabelsOnImport) { DebugWorkspaceManager.ResetLabels(); } LabelManager.SetLabels(labels, true); if (!silent) { if (_errorCount > 0) { _errorCount -= _filesNotFound.Count; string message = $"Import completed with {labelCount} labels imported"; if (_errorCount > 0) { message += $"and {_errorCount} errors - please file a bug report and attach the DBG file you tried to import."; } if (_filesNotFound.Count > 0) { message += Environment.NewLine + Environment.NewLine + "The following files could not be found:"; foreach (string file in _filesNotFound) { message += Environment.NewLine + file; } } MessageBox.Show(message, "Mesen", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show($"Import completed with {labelCount} labels imported.", "Mesen", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void OnNotificationReceived(NotificationEventArgs e) { switch (e.NotificationType) { case ConsoleNotificationType.GameLoaded: CheatCodes.ApplyCheats(); this.BeginInvoke((Action)(() => { UpdateDebuggerMenu(); ctrlRecentGames.Visible = false; SaveStateManager.UpdateStateMenu(mnuLoadState, false); SaveStateManager.UpdateStateMenu(mnuSaveState, true); RomInfo romInfo = EmuApi.GetRomInfo(); this.Text = "Mesen-S - " + romInfo.GetRomName(); if (DebugWindowManager.HasOpenedWindow) { DebugWorkspaceManager.GetWorkspace(); } })); break; case ConsoleNotificationType.BeforeEmulationStop: this.Invoke((Action)(() => { DebugWindowManager.CloseAll(); })); break; case ConsoleNotificationType.GameResumed: this.BeginInvoke((Action)(() => { //Ensure mouse is hidden when game is resumed CursorManager.OnMouseMove(ctrlRenderer); })); break; case ConsoleNotificationType.EmulationStopped: this.BeginInvoke((Action)(() => { this.Text = "Mesen-S"; UpdateDebuggerMenu(); ShowGameScreen(GameScreenMode.RecentGames); ResizeRecentGames(); if (_displayManager.ExclusiveFullscreen) { _displayManager.SetFullscreenState(false); } })); break; case ConsoleNotificationType.ResolutionChanged: this.BeginInvoke((Action)(() => { _displayManager.UpdateViewerSize(); })); break; case ConsoleNotificationType.ExecuteShortcut: this.BeginInvoke((Action)(() => { _shortcuts.ExecuteShortcut((EmulatorShortcut)e.Parameter); })); break; case ConsoleNotificationType.MissingFirmware: this.Invoke((Action)(() => { MissingFirmwareMessage msg = (MissingFirmwareMessage)Marshal.PtrToStructure(e.Parameter, typeof(MissingFirmwareMessage)); FirmwareHelper.RequestFirmwareFile(msg); })); break; } }
internal static int Run(string[] args) { ConfigManager.DoNotSaveSettings = true; string romPath; List <string> luaScriptsToLoad; CommandLineHelper.GetRomPathFromCommandLine(CommandLineHelper.PreprocessCommandLineArguments(args, false), out romPath, out luaScriptsToLoad); if (romPath == null) { //No rom specified return(-1); } List <string> lcArgs = CommandLineHelper.PreprocessCommandLineArguments(args, true); int timeout = 100; //100 seconds string timeoutArg = lcArgs.Find(arg => arg.StartsWith("/timeout=")); if (timeoutArg != null) { int timeoutValue; if (Int32.TryParse(timeoutArg.Substring(timeoutArg.IndexOf("=") + 1), out timeoutValue)) { timeout = timeoutValue; } } InteropEmu.InitDll(); ConfigManager.ProcessSwitches(lcArgs); ConfigManager.Config.ApplyConfig(); InteropEmu.SetFlag(EmulationFlags.ConsoleMode, true); InteropEmu.InitializeEmu(ConfigManager.HomeFolder, IntPtr.Zero, IntPtr.Zero, true, true, true); InteropEmu.LoadROM(romPath, string.Empty); DebugWorkspaceManager.GetWorkspace(); foreach (string luaScript in luaScriptsToLoad) { try { string script = File.ReadAllText(luaScript); InteropEmu.DebugLoadScript(luaScript, script); } catch { } } System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); Task.Run(() => { InteropEmu.Run(); }); InteropEmu.SetFlag(EmulationFlags.ForceMaxSpeed, true); sw.Start(); int result = -1; while (sw.ElapsedMilliseconds < timeout * 1000) { System.Threading.Thread.Sleep(100); if (!InteropEmu.IsRunning()) { result = InteropEmu.GetStopCode(); break; } } InteropEmu.Stop(); InteropEmu.Release(); return(result); }