Пример #1
0
        public static void OpenAssembler(CpuType cpuType, string code = "", int startAddress = 0, int blockLength = 0)
        {
            if (_openedWindows.Count == 0)
            {
                DebugWorkspaceManager.GetWorkspace();
            }

            frmAssembler frm = new frmAssembler(cpuType, code, startAddress, blockLength);

            frm.Icon = Properties.Resources.Chip;
            _openedWindows.Add(frm);
            frm.FormClosed += Debugger_FormClosed;
            frm.Show();
        }
Пример #2
0
        public static Form OpenDebugWindow(DebugWindow window)
        {
            Form existingWindow = GetExistingSingleInstanceWindow(window);

            if (existingWindow != null)
            {
                BringToFront(existingWindow);
                return(existingWindow);
            }
            else
            {
                BaseForm frm = null;
                switch (window)
                {
                case DebugWindow.Debugger: frm = new frmDebugger(CpuType.Cpu); frm.Icon = Properties.Resources.Debugger; break;

                case DebugWindow.SpcDebugger: frm = new frmDebugger(CpuType.Spc); frm.Icon = Properties.Resources.SpcDebugger; break;

                case DebugWindow.Sa1Debugger: frm = new frmDebugger(CpuType.Sa1); frm.Icon = Properties.Resources.Sa1Debugger; break;

                case DebugWindow.GsuDebugger: frm = new frmDebugger(CpuType.Gsu); frm.Icon = Properties.Resources.GsuDebugger; break;

                case DebugWindow.TraceLogger: frm = new frmTraceLogger(); frm.Icon = Properties.Resources.LogWindow; break;

                case DebugWindow.MemoryTools: frm = new frmMemoryTools(); frm.Icon = Properties.Resources.CheatCode; break;

                case DebugWindow.TileViewer: frm = new frmTileViewer(); frm.Icon = Properties.Resources.VerticalLayout; break;

                case DebugWindow.TilemapViewer: frm = new frmTilemapViewer(); frm.Icon = Properties.Resources.VideoOptions; break;

                case DebugWindow.PaletteViewer: frm = new frmPaletteViewer(); frm.Icon = Properties.Resources.VideoFilter; break;

                case DebugWindow.SpriteViewer: frm = new frmSpriteViewer(); frm.Icon = Properties.Resources.PerfTracker; break;

                case DebugWindow.EventViewer: frm = new frmEventViewer(); frm.Icon = Properties.Resources.NesEventViewer; break;

                case DebugWindow.ScriptWindow: frm = new frmScript(); frm.Icon = Properties.Resources.Script; break;
                }

                if (_openedWindows.Count == 0)
                {
                    DebugWorkspaceManager.GetWorkspace();
                }

                _openedWindows.Add(frm);
                frm.FormClosed += Debugger_FormClosed;
                frm.Show();
                return(frm);
            }
        }
Пример #3
0
        private void OnNotificationReceived(NotificationEventArgs e)
        {
            switch (e.NotificationType)
            {
            case ConsoleNotificationType.GameLoaded: {
                if (ConfigManager.Config.Debug.Debugger.BreakOnPowerCycleReset)
                {
                    DebugApi.Step(_cpuType, 1, StepType.Step);
                }

                BreakpointManager.SetBreakpoints();

                DebugState state = DebugApi.GetState();
                this.BeginInvoke((MethodInvoker)(() => {
                        //Refresh workspace here as well as frmMain to ensure workspace
                        //is up-to-date no matter which form is notified first.
                        DebugWorkspaceManager.GetWorkspace();

                        bool isPowerCycle = e.Parameter.ToInt32() != 0;
                        if (!isPowerCycle)
                        {
                            DebugWorkspaceManager.AutoImportSymbols();
                        }
                        LabelManager.RefreshLabels();
                        DebugApi.RefreshDisassembly(_cpuType);
                        UpdateDebugger(state, null);
                    }));
                break;
            }

            case ConsoleNotificationType.GameReset:
                if (ConfigManager.Config.Debug.Debugger.BreakOnPowerCycleReset)
                {
                    DebugApi.Step(_cpuType, 1, StepType.PpuStep);
                }
                break;

            case ConsoleNotificationType.PpuFrameDone:
                this.BeginInvoke((MethodInvoker)(() => {
                    UpdateContinueAction();
                }));
                break;

            case ConsoleNotificationType.CodeBreak: {
                BreakEvent evt = (BreakEvent)Marshal.PtrToStructure(e.Parameter, typeof(BreakEvent));
                RefreshDebugger(evt);
                break;
            }
            }
        }
Пример #4
0
        public frmProfiler()
        {
            InitializeComponent();

            if (!DesignMode)
            {
                DebugWorkspaceManager.AutoLoadDbgFiles(true);

                ctrlProfiler.RefreshData();
                tmrRefresh.Start();

                RestoreLocation(ConfigManager.Config.DebugInfo.ProfilerLocation, ConfigManager.Config.DebugInfo.ProfilerSize);
            }
        }
Пример #5
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!this.DesignMode)
            {
                this.mnuRefreshOnBreak.Checked        = ConfigManager.Config.DebugInfo.EventViewerRefreshOnBreak;
                this.chkShowPpuRegisterWrites.Checked = ConfigManager.Config.DebugInfo.EventViewerShowPpuRegisterWrites;
                this.chkShowPpuRegisterReads.Checked  = ConfigManager.Config.DebugInfo.EventViewerShowPpuRegisterReads;
                this.chkShowIrq.Checked                  = ConfigManager.Config.DebugInfo.EventViewerShowIrq;
                this.chkShowNmi.Checked                  = ConfigManager.Config.DebugInfo.EventViewerShowNmi;
                this.chkShowSpriteZero.Checked           = ConfigManager.Config.DebugInfo.EventViewerShowSpriteZeroHit;
                this.chkShowMapperRegisterWrites.Checked = ConfigManager.Config.DebugInfo.EventViewerShowMapperRegisterWrites;
                this.chkShowMapperRegisterReads.Checked  = ConfigManager.Config.DebugInfo.EventViewerShowMapperRegisterReads;
                this.chkBreakpoints.Checked              = ConfigManager.Config.DebugInfo.EventViewerShowMarkedBreakpoints;
                this.chkShowPreviousFrameEvents.Checked  = ConfigManager.Config.DebugInfo.EventViewerShowPreviousFrameEvents;

                string toggleViewTooltip = "Toggle Compact/Normal View";
                if (ConfigManager.Config.DebugInfo.Shortcuts.PpuViewer_ToggleView != Keys.None)
                {
                    toggleViewTooltip += " (" + DebuggerShortcutsConfig.GetShortcutDisplay(ConfigManager.Config.DebugInfo.Shortcuts.PpuViewer_ToggleView) + ")";
                }
                this.toolTip.SetToolTip(this.btnToggleView, toggleViewTooltip);

                string toggleZoomTooltip = "Toggle 2x Zoom";
                if (ConfigManager.Config.DebugInfo.Shortcuts.PpuViewer_ToggleZoom != Keys.None)
                {
                    toggleZoomTooltip += " (" + DebuggerShortcutsConfig.GetShortcutDisplay(ConfigManager.Config.DebugInfo.Shortcuts.PpuViewer_ToggleZoom) + ")";
                }
                this.toolTip.SetToolTip(this.chkToggleZoom, toggleZoomTooltip);

                _previousPictureSize = ctrlEventViewerPpuView.Size;

                this.GetData();
                this.RefreshViewer();

                DebugWorkspaceManager.GetWorkspace();

                if (!ConfigManager.Config.DebugInfo.EventViewerLocation.IsEmpty)
                {
                    this.StartPosition = FormStartPosition.Manual;
                    this.Location      = ConfigManager.Config.DebugInfo.EventViewerLocation;
                }

                this._notifListener = new InteropEmu.NotificationListener(ConfigManager.Config.DebugInfo.DebugConsoleId);
                this._notifListener.OnNotification += this._notifListener_OnNotification;
            }
        }
Пример #6
0
        public static Form OpenDebugWindow(DebugWindow window)
        {
            Form existingWindow = GetExistingSingleInstanceWindow(window);

            if (existingWindow != null)
            {
                existingWindow.BringToFront();
                if (existingWindow.WindowState == FormWindowState.Minimized)
                {
                    //Unminimize window if it was minimized
                    existingWindow.WindowState = FormWindowState.Normal;
                }
                existingWindow.Focus();
                return(existingWindow);
            }
            else
            {
                BaseForm frm = null;
                switch (window)
                {
                case DebugWindow.Debugger: frm = new frmDebugger(CpuType.Cpu); frm.Icon = Properties.Resources.Debugger; break;

                case DebugWindow.SpcDebugger: frm = new frmDebugger(CpuType.Spc); frm.Icon = Properties.Resources.SpcDebugger; break;

                case DebugWindow.TraceLogger: frm = new frmTraceLogger(); frm.Icon = Properties.Resources.LogWindow; break;

                case DebugWindow.MemoryTools: frm = new frmMemoryTools(); frm.Icon = Properties.Resources.CheatCode; break;

                case DebugWindow.TileViewer: frm = new frmTileViewer(); frm.Icon = Properties.Resources.VerticalLayout; break;

                case DebugWindow.TilemapViewer: frm = new frmTilemapViewer(); frm.Icon = Properties.Resources.VideoOptions; break;

                case DebugWindow.PaletteViewer: frm = new frmPaletteViewer(); frm.Icon = Properties.Resources.VideoFilter; break;

                case DebugWindow.EventViewer: frm = new frmEventViewer(); frm.Icon = Properties.Resources.NesEventViewer; break;
                }

                if (_openedWindows.Count == 0)
                {
                    DebugWorkspaceManager.GetWorkspace();
                }

                _openedWindows.Add(frm);
                frm.FormClosed += Debugger_FormClosed;
                frm.Show();
                return(frm);
            }
        }
Пример #7
0
        private static void ImportLabelFile(string path)
        {
            string ext = Path.GetExtension(path).ToLower();

            if (ext == ".msl")
            {
                DebugWorkspaceManager.ImportMslFile(path);
            }
            else if (ext == ".sym" || ext == ".tass")
            {
                DebugWorkspaceManager.ImportSymFile(path);
            }
            else
            {
                DebugWorkspaceManager.ImportDbgFile(path);
            }
        }
Пример #8
0
        private void InitTblMappings()
        {
            DebugWorkspace workspace = DebugWorkspaceManager.GetWorkspace();

            if (workspace.TblMappings != null && workspace.TblMappings.Count > 0)
            {
                var tblDict = TblLoader.ToDictionary(workspace.TblMappings.ToArray());
                if (tblDict != null)
                {
                    this.ctrlHexViewer.ByteCharConverter = new TblByteCharConverter(tblDict);
                }
            }
            else
            {
                this.ctrlHexViewer.ByteCharConverter = null;
            }
        }
Пример #9
0
        private void RefreshData()
        {
            if (DebugWorkspaceManager.GetWorkspace() != this._previousWorkspace)
            {
                this.InitTblMappings();
                _previousWorkspace = DebugWorkspaceManager.GetWorkspace();
            }

            if (this.tabMain.SelectedTab == this.tpgAccessCounters)
            {
                this.ctrlMemoryAccessCounters.RefreshData();
            }
            else if (this.tabMain.SelectedTab == this.tpgMemoryViewer)
            {
                this.UpdateByteColorProvider();
                this.ctrlHexViewer.SetData(InteropEmu.DebugGetMemoryState(this._memoryType));
            }
        }
Пример #10
0
        public frmProfiler()
        {
            InitializeComponent();

            if (!DesignMode)
            {
                DebugWorkspaceManager.AutoLoadDbgFiles(true);

                ctrlProfiler.RefreshData();
                tmrRefresh.Start();

                if (!ConfigManager.Config.DebugInfo.ProfilerSize.IsEmpty)
                {
                    this.StartPosition = FormStartPosition.Manual;
                    this.Size          = ConfigManager.Config.DebugInfo.ProfilerSize;
                    this.Location      = ConfigManager.Config.DebugInfo.ProfilerLocation;
                }
            }
        }
Пример #11
0
        private void UpdateDebuggerFlags()
        {
            DebuggerFlags flags = mnuPpuPartialDraw.Checked ? DebuggerFlags.PpuPartialDraw : DebuggerFlags.None;

            if (mnuShowEffectiveAddresses.Checked)
            {
                flags |= DebuggerFlags.ShowEffectiveAddresses;
            }
            if (mnuDisplayOpCodesInLowerCase.Checked)
            {
                flags |= DebuggerFlags.DisplayOpCodesInLowerCase;
            }

            if (mnuDisassembleVerifiedData.Checked)
            {
                flags |= DebuggerFlags.DisassembleVerifiedData;
            }
            if (mnuDisassembleUnidentifiedData.Checked)
            {
                flags |= DebuggerFlags.DisassembleUnidentifiedData;
            }
            if (mnuShowVerifiedData.Checked)
            {
                flags |= DebuggerFlags.ShowVerifiedData;
            }
            if (mnuShowUnidentifiedData.Checked)
            {
                flags |= DebuggerFlags.ShowUnidentifiedData;
            }

            if (mnuBreakOnUnofficialOpcodes.Checked)
            {
                flags |= DebuggerFlags.BreakOnUnofficialOpCode;
            }
            if (mnuBreakOnBrk.Checked)
            {
                flags |= DebuggerFlags.BreakOnBrk;
            }

            DebugWorkspaceManager.SetFlags(flags);
            InteropEmu.SetFlag(EmulationFlags.DebuggerWindowEnabled, true);
        }
Пример #12
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!this.DesignMode)
            {
                this.GetData();
                this.RefreshViewer();

                DebugWorkspaceManager.GetWorkspace();

                if (!ConfigManager.Config.DebugInfo.EventViewerSize.IsEmpty)
                {
                    this.Size = ConfigManager.Config.DebugInfo.EventViewerSize;
                }

                this._notifListener = new InteropEmu.NotificationListener();
                this._notifListener.OnNotification += this._notifListener_OnNotification;
            }
        }
Пример #13
0
        private void mnuLoadTblFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.SetFilter("TBL files (*.tbl)|*.tbl");
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string[] fileContents = File.ReadAllLines(ofd.FileName);
                var      tblDict      = TblLoader.ToDictionary(fileContents);
                if (tblDict == null)
                {
                    MessageBox.Show("Could not load TBL file.  The file selected file appears to be invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    DebugWorkspaceManager.GetWorkspace().TblMappings = new List <string>(fileContents);
                    this.ctrlHexViewer.ByteCharConverter = new TblByteCharConverter(tblDict);
                    this.mnuShowCharacters.Checked       = true;
                }
            }
        }
Пример #14
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);
            UpdateConfig();
            ConfigManager.Config.DebugInfo.RamFontFamily        = ctrlHexViewer.BaseFont.FontFamily.Name;
            ConfigManager.Config.DebugInfo.RamFontStyle         = ctrlHexViewer.BaseFont.Style;
            ConfigManager.Config.DebugInfo.RamFontSize          = ctrlHexViewer.BaseFont.Size;
            ConfigManager.Config.DebugInfo.MemoryViewerSize     = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Size : this.Size;
            ConfigManager.Config.DebugInfo.MemoryViewerLocation = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Location : this.Location;
            ConfigManager.Config.DebugInfo.RamMemoryType        = cboMemoryType.GetEnumValue <DebugMemoryType>();
            ConfigManager.ApplyChanges();
            DebugWorkspaceManager.SaveWorkspace();

            if (this._notifListener != null)
            {
                this._notifListener.Dispose();
                this._notifListener = null;
            }

            _formClosed = true;
        }
Пример #15
0
 private void mnuResetTblMappings_Click(object sender, EventArgs e)
 {
     DebugWorkspaceManager.GetWorkspace().TblMappings = null;
     this.ctrlHexViewer.ByteCharConverter = null;
 }
Пример #16
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            DebugWorkspaceManager.AutoLoadDbgFiles(true);

            this._selectedTab = this.tabMain.SelectedTab;

            DebugInfo config = ConfigManager.Config.DebugInfo;

            this.mnuAutoRefresh.Checked             = config.RamAutoRefresh;
            this.mnuHighDensityMode.Checked         = config.RamHighDensityTextMode;
            this.mnuByteEditingMode.Checked         = config.RamByteEditingMode;
            this.mnuEnablePerByteNavigation.Checked = config.RamEnablePerByteNavigation;
            UpdateRefreshSpeedMenu();

            this.mnuIgnoreRedundantWrites.Checked = config.RamIgnoreRedundantWrites;
            this.UpdateFlags();

            this.mnuShowCharacters.Checked           = config.RamShowCharacters;
            this.mnuShowLabelInfoOnMouseOver.Checked = config.RamShowLabelInfo;

            this.ctrlHexViewer.TextZoom = config.RamTextZoom;
            this.ctrlHexViewer.BaseFont = new Font(config.RamFontFamily, config.RamFontSize, config.RamFontStyle);

            this.ctrlMemoryAccessCounters.BaseFont = new Font(config.RamFontFamily, config.RamFontSize, config.RamFontStyle);
            this.ctrlMemoryAccessCounters.TextZoom = config.RamTextZoom;

            this.mnuHighlightExecution.Checked = config.RamHighlightExecution;
            this.mnuHightlightReads.Checked    = config.RamHighlightReads;
            this.mnuHighlightWrites.Checked    = config.RamHighlightWrites;
            this.mnuHideUnusedBytes.Checked    = config.RamHideUnusedBytes;
            this.mnuHideReadBytes.Checked      = config.RamHideReadBytes;
            this.mnuHideWrittenBytes.Checked   = config.RamHideWrittenBytes;
            this.mnuHideExecutedBytes.Checked  = config.RamHideExecutedBytes;

            this.mnuHighlightLabelledBytes.Checked = config.RamHighlightLabelledBytes;
            this.mnuHighlightBreakpoints.Checked   = config.RamHighlightBreakpoints;
            this.mnuHighlightChrDrawnBytes.Checked = config.RamHighlightChrDrawnBytes;
            this.mnuHighlightChrReadBytes.Checked  = config.RamHighlightChrReadBytes;
            this.mnuHighlightCodeBytes.Checked     = config.RamHighlightCodeBytes;
            this.mnuHighlightDataBytes.Checked     = config.RamHighlightDataBytes;
            this.mnuHighlightDmcDataBytes.Checked  = config.RamHighlightDmcDataBytes;

            this.UpdateFadeOptions();

            this.InitTblMappings();

            this.ctrlHexViewer.StringViewVisible = mnuShowCharacters.Checked;
            this.ctrlHexViewer.MemoryViewer      = this;

            UpdateImportButton();
            InitMemoryTypeDropdown(true);

            _notifListener = new InteropEmu.NotificationListener(ConfigManager.Config.DebugInfo.DebugConsoleId);
            _notifListener.OnNotification += _notifListener_OnNotification;

            this.mnuShowCharacters.CheckedChanged        += this.mnuShowCharacters_CheckedChanged;
            this.mnuIgnoreRedundantWrites.CheckedChanged += mnuIgnoreRedundantWrites_CheckedChanged;

            if (!ConfigManager.Config.DebugInfo.MemoryViewerSize.IsEmpty)
            {
                this.StartPosition = FormStartPosition.Manual;
                this.Size          = ConfigManager.Config.DebugInfo.MemoryViewerSize;
                this.Location      = ConfigManager.Config.DebugInfo.MemoryViewerLocation;
            }

            this.InitShortcuts();
        }
Пример #17
0
        private void OnNotificationReceived(NotificationEventArgs e)
        {
            switch (e.NotificationType)
            {
            case ConsoleNotificationType.GameLoaded: {
                if (_cpuType == CpuType.Sa1)
                {
                    CoprocessorType coprocessor = EmuApi.GetRomInfo().CoprocessorType;
                    if (coprocessor != CoprocessorType.SA1)
                    {
                        this.Invoke((MethodInvoker)(() => {
                                this.Close();
                            }));
                        return;
                    }
                }

                if (ConfigManager.Config.Debug.Debugger.BreakOnPowerCycleReset)
                {
                    DebugApi.Step(_cpuType, 1, StepType.PpuStep);
                }

                BreakpointManager.SetBreakpoints();

                DebugState state = DebugApi.GetState();
                this.BeginInvoke((MethodInvoker)(() => {
                        DebugWorkspaceManager.ImportDbgFile();
                        LabelManager.RefreshLabels();
                        DebugApi.RefreshDisassembly(_cpuType);
                        UpdateDebugger(state, null);
                    }));
                break;
            }

            case ConsoleNotificationType.GameReset:
                if (ConfigManager.Config.Debug.Debugger.BreakOnPowerCycleReset)
                {
                    DebugApi.Step(_cpuType, 1, StepType.PpuStep);
                }
                break;

            case ConsoleNotificationType.PpuFrameDone:
                this.BeginInvoke((MethodInvoker)(() => {
                    UpdateContinueAction();
                }));
                break;

            case ConsoleNotificationType.CodeBreak: {
                BreakEvent evt   = (BreakEvent)Marshal.PtrToStructure(e.Parameter, typeof(BreakEvent));
                DebugState state = DebugApi.GetState();
                int        activeAddress;
                switch (_cpuType)
                {
                case CpuType.Cpu: activeAddress = (int)((state.Cpu.K << 16) | state.Cpu.PC); break;

                case CpuType.Spc: activeAddress = (int)state.Spc.PC; break;

                case CpuType.Sa1: activeAddress = (int)((state.Sa1.K << 16) | state.Sa1.PC); break;

                case CpuType.Gsu: activeAddress = (int)((state.Gsu.ProgramBank << 16) | state.Gsu.R[15]); break;

                default: throw new Exception("Unsupported cpu type");
                }

                this.BeginInvoke((MethodInvoker)(() => {
                        ProcessBreakEvent(evt, state, activeAddress);

                        if (_firstBreak && !ConfigManager.Config.Debug.Debugger.BreakOnOpen)
                        {
                            DebugApi.ResumeExecution();
                        }
                        _firstBreak = false;
                    }));
                break;
            }
            }
        }
Пример #18
0
        private void RefreshLog(bool scrollToBottom)
        {
            if (_refreshRunning)
            {
                return;
            }

            //Make sure labels are up to date
            DebugWorkspaceManager.GetWorkspace();

            _refreshRunning = true;
            SetOptions();
            Task.Run(() => {
                //Update trace log in another thread for performance
                DebugState state = new DebugState();
                InteropEmu.DebugGetState(ref state);
                if (_previousCycleCount != state.CPU.CycleCount)
                {
                    string newTrace     = InteropEmu.DebugGetExecutionTrace((UInt32)_lineCount);
                    _previousCycleCount = state.CPU.CycleCount;
                    _previousTrace      = newTrace;

                    int index            = 0;
                    string line          = null;
                    Func <bool> readLine = () => {
                        if (index < newTrace.Length)
                        {
                            int endOfLineIndex = newTrace.IndexOf('\n', index);
                            line  = newTrace.Substring(index, endOfLineIndex - index);
                            index = endOfLineIndex + 1;
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    };

                    List <int> programCounter = new List <int>(30000);
                    List <string> byteCode    = new List <string>(30000);
                    List <string> lineContent = new List <string>(30000);
                    List <int> indent         = new List <int>(30000);

                    char[] splitter = new char[] { ' ' };
                    while (readLine())
                    {
                        programCounter.Add(Int32.Parse(line.Substring(0, 4), System.Globalization.NumberStyles.HexNumber));
                        byteCode.Add(line.Substring(6, 11));
                        lineContent.Add(line.Substring(19));
                        indent.Add(6);
                    }
                    this.BeginInvoke((Action)(() => {
                        txtTraceLog.ShowContentNotes = chkShowByteCode.Checked;
                        txtTraceLog.ShowSingleContentLineNotes = chkShowByteCode.Checked;

                        txtTraceLog.LineIndentations = indent.ToArray();
                        txtTraceLog.LineNumbers = programCounter.ToArray();
                        txtTraceLog.TextLineNotes = byteCode.ToArray();
                        txtTraceLog.TextLines = lineContent.ToArray();

                        if (scrollToBottom)
                        {
                            txtTraceLog.ScrollToLineIndex(txtTraceLog.LineCount - 1);
                        }
                    }));
                }
                _refreshRunning = false;
            });
        }
Пример #19
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!this.DesignMode)
            {
                _binder.Entity = _config;

                mnuRefreshOnBreak.Checked = _config.EventViewerRefreshOnBreak;

                _binder.AddBinding(nameof(DebugInfo.EventViewerShowPpuWrite2000), chkWrite2000);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowPpuWrite2001), chkWrite2001);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowPpuWrite2003), chkWrite2003);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowPpuWrite2004), chkWrite2004);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowPpuWrite2005), chkWrite2005);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowPpuWrite2006), chkWrite2006);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowPpuWrite2007), chkWrite2007);

                _binder.AddBinding(nameof(DebugInfo.EventViewerShowPpuRead2002), chkRead2002);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowPpuRead2004), chkRead2004);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowPpuRead2007), chkRead2007);

                _binder.AddBinding(nameof(DebugInfo.EventViewerShowIrq), chkShowIrq);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowNmi), chkShowNmi);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowSpriteZeroHit), chkShowSpriteZero);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowMapperRegisterWrites), chkShowMapperRegisterWrites);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowMapperRegisterReads), chkShowMapperRegisterReads);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowDmcDmaReads), chkShowDmcDmaRead);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowMarkedBreakpoints), chkBreakpoints);

                _binder.AddBinding(nameof(DebugInfo.EventViewerPpuRegisterWrite2000Color), picWrite2000);
                _binder.AddBinding(nameof(DebugInfo.EventViewerPpuRegisterWrite2001Color), picWrite2001);
                _binder.AddBinding(nameof(DebugInfo.EventViewerPpuRegisterWrite2003Color), picWrite2003);
                _binder.AddBinding(nameof(DebugInfo.EventViewerPpuRegisterWrite2004Color), picWrite2004);
                _binder.AddBinding(nameof(DebugInfo.EventViewerPpuRegisterWrite2005Color), picWrite2005);
                _binder.AddBinding(nameof(DebugInfo.EventViewerPpuRegisterWrite2006Color), picWrite2006);
                _binder.AddBinding(nameof(DebugInfo.EventViewerPpuRegisterWrite2007Color), picWrite2007);

                _binder.AddBinding(nameof(DebugInfo.EventViewerPpuRegisterRead2002Color), picRead2002);
                _binder.AddBinding(nameof(DebugInfo.EventViewerPpuRegisterRead2004Color), picRead2004);
                _binder.AddBinding(nameof(DebugInfo.EventViewerPpuRegisterRead2007Color), picRead2007);

                _binder.AddBinding(nameof(DebugInfo.EventViewerMapperRegisterWriteColor), picMapperWrite);
                _binder.AddBinding(nameof(DebugInfo.EventViewerMapperRegisterReadColor), picMapperRead);
                _binder.AddBinding(nameof(DebugInfo.EventViewerNmiColor), picNmi);
                _binder.AddBinding(nameof(DebugInfo.EventViewerIrqColor), picIrq);
                _binder.AddBinding(nameof(DebugInfo.EventViewerSpriteZeroHitColor), picSpriteZeroHit);
                _binder.AddBinding(nameof(DebugInfo.EventViewerBreakpointColor), picBreakpoint);
                _binder.AddBinding(nameof(DebugInfo.EventViewerDmcDmaReadColor), picDmcDmaRead);

                _binder.AddBinding(nameof(DebugInfo.EventViewerShowPreviousFrameEvents), chkShowPreviousFrameEvents);
                _binder.AddBinding(nameof(DebugInfo.EventViewerShowNtscBorders), chkShowNtscBorders);

                DebugWorkspaceManager.GetWorkspace();

                RestoreLocation(_config.EventViewerLocation, _config.EventViewerSize);

                mnuAutoRefresh.Checked               = _config.EventViewerAutoRefresh;
                mnuAutoRefreshLow.Click             += (s, evt) => _refreshManager.AutoRefreshSpeed = RefreshSpeed.Low;
                mnuAutoRefreshNormal.Click          += (s, evt) => _refreshManager.AutoRefreshSpeed = RefreshSpeed.Normal;
                mnuAutoRefreshHigh.Click            += (s, evt) => _refreshManager.AutoRefreshSpeed = RefreshSpeed.High;
                mnuAutoRefreshSpeed.DropDownOpening += (s, evt) => UpdateRefreshSpeedMenu();

                this.RefreshData();
                _binder.UpdateUI();
                this.RefreshViewer();

                _refreshManager                  = new WindowRefreshManager(this);
                _refreshManager.AutoRefresh      = _config.EventViewerAutoRefresh;
                _refreshManager.AutoRefreshSpeed = _config.EventViewerAutoRefreshSpeed;

                this._notifListener = new InteropEmu.NotificationListener(_config.DebugConsoleId);
                this._notifListener.OnNotification += this._notifListener_OnNotification;

                InitShortcuts();
            }
        }
        private void RefreshLog(bool scrollToBottom, bool forceUpdate)
        {
            if (_refreshRunning)
            {
                return;
            }

            //Make sure labels are up to date
            DebugWorkspaceManager.GetWorkspace();

            _refreshRunning = true;
            SetOptions();
            Task.Run(() => {
                //Update trace log in another thread for performance
                DebugState state = new DebugState();
                InteropEmu.DebugGetState(ref state);
                if (_previousCycleCount != state.CPU.CycleCount || forceUpdate)
                {
                    string newTrace     = InteropEmu.DebugGetExecutionTrace((UInt32)_lineCount);
                    _previousCycleCount = state.CPU.CycleCount;
                    _previousTrace      = newTrace;

                    int index            = 0;
                    string line          = null;
                    Func <bool> readLine = () => {
                        if (index < newTrace.Length)
                        {
                            int endOfLineIndex = newTrace.IndexOf('\n', index);
                            line  = newTrace.Substring(index, endOfLineIndex - index);
                            index = endOfLineIndex + 1;
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    };

                    List <int> programCounter = new List <int>(30000);
                    List <string> byteCode    = new List <string>(30000);
                    List <string> lineContent = new List <string>(30000);
                    List <int> indent         = new List <int>(30000);

                    bool showByteCode = false;
                    while (readLine())
                    {
                        string[] parts = line.Split('\x1');
                        programCounter.Add(Int32.Parse(parts[0], System.Globalization.NumberStyles.HexNumber));
                        byteCode.Add(parts[1]);

                        string content = parts[2];
                        while (true)
                        {
                            string str = content.TrimStart();
                            if (str.StartsWith(parts[0]))
                            {
                                content = str.Substring(4);
                            }
                            else if (str.StartsWith(parts[1]))
                            {
                                content      = str.Substring(11);
                                showByteCode = true;
                            }
                            else if (str.StartsWith(parts[1].Replace("$", "")))
                            {
                                content      = str.Substring(8);
                                showByteCode = true;
                            }
                            else
                            {
                                break;
                            }
                        }
                        lineContent.Add(content);
                        indent.Add(0);
                    }
                    this.BeginInvoke((Action)(() => {
                        txtTraceLog.ShowContentNotes = showByteCode;
                        txtTraceLog.ShowSingleContentLineNotes = showByteCode;

                        txtTraceLog.LineIndentations = indent.ToArray();
                        txtTraceLog.LineNumbers = programCounter.ToArray();
                        txtTraceLog.TextLineNotes = byteCode.ToArray();
                        txtTraceLog.TextLines = lineContent.ToArray();

                        if (scrollToBottom)
                        {
                            txtTraceLog.ScrollToLineIndex(txtTraceLog.LineCount - 1);
                        }
                    }));
                }
                _refreshRunning = false;
            });
        }
Пример #21
0
        public frmScript(bool forceBlank = false)
        {
            InitializeComponent();
            ThemeHelper.ExcludeFromTheme(txtScriptContent);
            txtScriptContent.ForeColor = Color.Black;

            DebugInfo.ApplyConfig();

            List <string> builtInScripts = new List <string> {
                "DmcCapture.lua", "DrawMode.lua", "Example.lua", "GameBoyMode.lua", "Grid.lua", "LogParallax.lua", "ModifyScreen.lua", "NtscSafeArea.lua", "ReverseMode.lua", "SpriteBox.lua"
            };

            foreach (string script in builtInScripts)
            {
                ToolStripItem item = mnuBuiltInScripts.DropDownItems.Add(script);
                item.Click += (s, e) => {
                    LoadBuiltInScript(item.Text);
                };
            }

            tsToolbar.AddItemsToToolbar(
                mnuOpen, mnuSave, null,
                mnuRun, mnuStop, null,
                mnuBuiltInScripts
                );

            //Make sure labels are loaded
            DebugWorkspaceManager.GetWorkspace();

            DebugInfo config = ConfigManager.Config.DebugInfo;

            _popupMenu           = new AutocompleteMenu(txtScriptContent, this);
            _popupMenu.ImageList = new ImageList();
            _popupMenu.ImageList.Images.Add(Resources.Enum);
            _popupMenu.ImageList.Images.Add(Resources.Function);
            _popupMenu.SelectedColor = Color.LightBlue;
            _popupMenu.SearchPattern = @"[\w\.]";

            List <AutocompleteItem> items = new List <AutocompleteItem>();

            _availableFunctions.Sort((a, b) => {
                int type = a[0].CompareTo(b[0]);
                if (type == 0)
                {
                    return(a[1].CompareTo(b[1]));
                }
                else
                {
                    return(-type);
                }
            });

            foreach (List <string> item in _availableFunctions)
            {
                MethodAutocompleteItem autocompleteItem = new MethodAutocompleteItem(item[1]);
                autocompleteItem.ImageIndex   = item[0] == "func" ? 1 : 0;
                autocompleteItem.ToolTipTitle = item[2];
                if (!string.IsNullOrWhiteSpace(item[3]))
                {
                    autocompleteItem.ToolTipText = "Parameters" + Environment.NewLine + item[3] + Environment.NewLine + Environment.NewLine;
                }
                if (!string.IsNullOrWhiteSpace(item[4]))
                {
                    autocompleteItem.ToolTipText += "Return Value" + Environment.NewLine + item[4] + Environment.NewLine + Environment.NewLine;
                }
                if (!string.IsNullOrWhiteSpace(item[5]))
                {
                    autocompleteItem.ToolTipText += "Description" + Environment.NewLine + item[5] + Environment.NewLine + Environment.NewLine;
                }
                items.Add(autocompleteItem);
            }

            _popupMenu.Items.SetAutocompleteItems(items);

            UpdateRecentScripts();

            mnuTutorialScript.Checked     = config.ScriptStartupBehavior == ScriptStartupBehavior.ShowTutorial;
            mnuBlankWindow.Checked        = config.ScriptStartupBehavior == ScriptStartupBehavior.ShowBlankWindow;
            mnuAutoLoadLastScript.Checked = config.ScriptStartupBehavior == ScriptStartupBehavior.LoadLastScript;

            if (!forceBlank)
            {
                if (mnuAutoLoadLastScript.Checked && mnuRecentScripts.DropDownItems.Count > 0)
                {
                    string scriptToLoad = config.RecentScripts.Where((s) => File.Exists(s)).FirstOrDefault();
                    if (scriptToLoad != null)
                    {
                        LoadScriptFile(scriptToLoad, false);
                    }
                }
                else if (mnuTutorialScript.Checked)
                {
                    LoadBuiltInScript("Example.lua");
                }
            }

            RestoreLocation(config.ScriptWindowLocation, config.ScriptWindowSize);
            mnuSaveBeforeRun.Checked = config.SaveScriptBeforeRun;

            if (config.ScriptCodeWindowHeight >= ctrlSplit.Panel1MinSize)
            {
                if (config.ScriptCodeWindowHeight == Int32.MaxValue)
                {
                    ctrlSplit.CollapsePanel();
                }
                else
                {
                    ctrlSplit.SplitterDistance = config.ScriptCodeWindowHeight;
                }
            }

            txtScriptContent.Font = new Font(config.ScriptFontFamily, config.ScriptFontSize, config.ScriptFontStyle);
            txtScriptContent.Zoom = config.ScriptZoom;
        }