private void mnuEditInMemoryViewer_Click(object sender, EventArgs e) { if (_destination != null) { DebugWindowManager.OpenMemoryViewer(_destination); } }
void ProcessBreakEvent(BreakEvent evt, DebugState state, int activeAddress) { if (ConfigManager.Config.Debug.Debugger.BringToFrontOnBreak) { Breakpoint bp = BreakpointManager.GetBreakpointById(evt.BreakpointId); if (bp?.CpuType == _cpuType || evt.Source > BreakSource.PpuStep) { DebugWindowManager.BringToFront(this); } } UpdateContinueAction(); UpdateDebugger(state, activeAddress); if (evt.Source == BreakSource.Breakpoint || evt.Source > BreakSource.PpuStep) { string message = ResourceHelper.GetEnumText(evt.Source); if (evt.Source == BreakSource.Breakpoint) { message += ": " + ResourceHelper.GetEnumText(evt.Operation.Type) + " ($" + evt.Operation.Address.ToString("X4") + ":$" + evt.Operation.Value.ToString("X2") + ")"; } ctrlDisassemblyView.SetMessage(new TextboxMessageInfo() { Message = message }); } }
private void mnuEditInMemoryViewer_Click(object sender, EventArgs e) { if (UpdateContextMenu(_previousLocation)) { DebugWindowManager.OpenMemoryViewer(_lastClickedAddress); } }
private void btnOk_Click(object sender, EventArgs e) { List <string> warningMessages = new List <string>(); if (_hasParsingErrors) { warningMessages.Add("Warning: The code contains parsing errors - lines with errors will be ignored."); } if (_isEditMode) { if (SizeExceeded) { warningMessages.Add("Warning: The new code exceeds the original code's length." + Environment.NewLine + "Applying this modification will overwrite other portions of the code and potentially cause problems."); } if (NeedRtiRtsWarning) { warningMessages.Add("Warning: The code originally contained an RTI/RTS instruction and it no longer does - this will probably cause problems."); } } else { warningMessages.Add($"Warning: The contents currently mapped to CPU memory addresses ${_startAddress.ToString("X4")} to ${(_startAddress+ctrlHexBox.ByteProvider.Length).ToString("X4")} will be overridden."); } if (warningMessages.Count == 0 || MessageBox.Show(string.Join(Environment.NewLine + Environment.NewLine, warningMessages.ToArray()) + Environment.NewLine + Environment.NewLine + "OK?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK) { WaitUntilBreak(); byte lastByte = ctrlHexBox.ByteProvider.ReadByte(ctrlHexBox.ByteProvider.Length - 1); bool endsWithRtiRts = lastByte == 0x40 || lastByte == 0x60; int byteGap = (int)(_blockLength - ctrlHexBox.ByteProvider.Length); List <byte> bytes = new List <byte>(((StaticByteProvider)ctrlHexBox.ByteProvider).Bytes); if (byteGap > 0) { //Pad data with NOPs as needed int insertPoint = endsWithRtiRts ? bytes.Count - 1 : bytes.Count; for (int i = 0; i < byteGap; i++) { bytes.Insert(insertPoint, 0xEA); //0xEA = NOP } } InteropEmu.DebugSetMemoryValues(DebugMemoryType.CpuMemory, (UInt32)_startAddress, bytes.ToArray()); frmDebugger debugger = DebugWindowManager.GetDebugger(); if (debugger != null) { debugger.UpdateDebugger(false); } else { InteropEmu.DebugRun(); } this.DialogResult = DialogResult.OK; this.Close(); } }
private void mnuViewInDisassembly_Click(object sender, EventArgs e) { frmDebugger debugger = DebugWindowManager.GetDebugger(); if (_destination != null && debugger != null) { debugger.GoToDestination(_destination); } }
private void btnOk_Click(object sender, EventArgs e) { List <string> warningMessages = new List <string>(); if (_hasParsingErrors) { warningMessages.Add("Warning: The code contains parsing errors - lines with errors will be ignored."); } if (_isEditMode) { if (SizeExceeded) { warningMessages.Add("Warning: The new code exceeds the original code's length." + Environment.NewLine + "Applying this modification will overwrite other portions of the code and potentially cause problems."); } } else { warningMessages.Add($"Warning: The contents currently mapped to CPU memory addresses ${_startAddress.ToString("X6")} to ${(_startAddress+ctrlHexBox.ByteProvider.Length).ToString("X6")} will be overridden."); } if (warningMessages.Count == 0 || MessageBox.Show(string.Join(Environment.NewLine + Environment.NewLine, warningMessages.ToArray()) + Environment.NewLine + Environment.NewLine + "OK?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK) { List <byte> bytes = new List <byte>(((StaticByteProvider)ctrlHexBox.ByteProvider).Bytes); int byteGap = (int)(_blockLength - ctrlHexBox.ByteProvider.Length); for (int i = 0; i < byteGap; i++) { //Pad data with NOPs as needed bytes.Add(0xEA); } DebugApi.SetMemoryValues(SnesMemoryType.CpuMemory, (UInt32)_startAddress, bytes.ToArray(), bytes.Count); AddressInfo absStart = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = _startAddress, Type = SnesMemoryType.CpuMemory }); AddressInfo absEnd = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = _startAddress + bytes.Count, Type = SnesMemoryType.CpuMemory }); if (absStart.Type == SnesMemoryType.PrgRom && absEnd.Type == SnesMemoryType.PrgRom && (absEnd.Address - absStart.Address) == bytes.Count) { DebugApi.MarkBytesAs((uint)absStart.Address, (uint)absEnd.Address, CdlFlags.Code); } frmDebugger debugger = DebugWindowManager.OpenDebugger(CpuType.Cpu); if (debugger != null) { debugger.RefreshDisassembly(); } this.DialogResult = DialogResult.OK; this.Close(); } }
private void mnuEditInMemoryViewer_Click(object sender, EventArgs e) { if (lstWatch.SelectedItems.Count != 1) { return; } if (_selectedAddress >= 0) { DebugWindowManager.OpenMemoryViewer(_selectedAddress, DebugMemoryType.CpuMemory); } else if (_selectedLabel != null) { DebugWindowManager.OpenMemoryViewer((int)_selectedLabel.Address, _selectedLabel.AddressType.ToMemoryType()); } }
private void MarkSelectionAs(int start, int end, CdlPrgFlags type) { if (_memoryType == DebugMemoryType.CpuMemory) { start = InteropEmu.DebugGetAbsoluteAddress((UInt32)start); end = InteropEmu.DebugGetAbsoluteAddress((UInt32)end); } if (start >= 0 && end >= 0 && start <= end) { InteropEmu.DebugMarkPrgBytesAs((UInt32)start, (UInt32)end, type); frmDebugger debugger = DebugWindowManager.GetDebugger(); if (debugger != null) { debugger.UpdateDebugger(false, false); } } }
private void MarkSelectionAs(CdlPrgFlags type) { int startAddress, endAddress; string range; GetSelectedAddressRange(out startAddress, out endAddress, out range); if (startAddress >= 0 && endAddress >= 0 && startAddress <= endAddress) { InteropEmu.DebugMarkPrgBytesAs((UInt32)startAddress, (UInt32)endAddress, type); frmDebugger debugger = DebugWindowManager.GetDebugger(); if (debugger != null) { debugger.UpdateDebugger(false); } } }
private void mnuEditInMemoryViewer_Click(object sender, EventArgs e) { if (lstWatch.SelectedItems.Count != 1) { return; } if (_selectedAddress >= 0) { DebugWindowManager.OpenMemoryViewer(new AddressInfo() { Address = _selectedAddress, Type = _cpuType.ToMemoryType() }); } else if (_selectedLabel != null) { DebugWindowManager.OpenMemoryViewer(_selectedLabel.GetAbsoluteAddress()); } }
private void txtTraceLog_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { string suffix = ""; string word = txtTraceLog.GetWordUnderLocation(e.Location); if (word.StartsWith("$")) { _destination = new GoToDestination() { CpuAddress = Int32.Parse(word.Substring(1), System.Globalization.NumberStyles.AllowHexSpecifier) }; suffix += " (" + word + ")"; } else { CodeLabel label = LabelManager.GetLabel(word); if (label != null) { _destination = new GoToDestination() { Label = label }; suffix += " (" + label.Label + ")"; } else { //Use the current row's address _destination = new GoToDestination() { CpuAddress = txtTraceLog.CurrentLine, }; suffix += " ($" + txtTraceLog.CurrentLine.ToString("X4") + ")"; } } mnuViewInDisassembly.Enabled = DebugWindowManager.GetDebugger() != null; mnuEditInMemoryViewer.Enabled = true; mnuEditInMemoryViewer.Text = "Edit in Memory Viewer" + suffix; mnuViewInDisassembly.Text = "View in Disassembly" + suffix; } }
private void mnuViewInDisassembly_Click(object sender, EventArgs e) { if (lstWatch.SelectedItems.Count != 1) { return; } if (_selectedAddress >= 0) { DebugWindowManager.OpenDebugger(_cpuType).GoToAddress(_selectedAddress); } else if (_selectedLabel != null) { AddressInfo relAddress = _selectedLabel.GetRelativeAddress(_cpuType); if (relAddress.Address >= 0) { DebugWindowManager.OpenDebugger(_cpuType).GoToAddress(relAddress.Address); } } }
private void mnuViewInDisassembly_Click(object sender, EventArgs e) { if (lstWatch.SelectedItems.Count != 1) { return; } if (_selectedAddress >= 0) { DebugWindowManager.GetDebugger().ScrollToAddress(_selectedAddress); } else if (_selectedLabel != null) { int relAddress = _selectedLabel.GetRelativeAddress(); if (relAddress >= 0) { DebugWindowManager.GetDebugger().ScrollToAddress(relAddress); } } }
public void SelectChrTile(int tileIndex, int paletteIndex, bool allowOpenWindow) { if (_isCompact && allowOpenWindow) { //If in compact mode, don't move to the CHR tab, open or use another window instead frmPpuViewer otherPpuViewer = null; foreach (BaseForm frm in DebugWindowManager.GetWindows()) { if (frm != this && frm is frmPpuViewer && (!((frmPpuViewer)frm)._isCompact || ((frmPpuViewer)frm)._selectedTab == ((frmPpuViewer)frm).tpgChrViewer)) { //If a window exists and is either not in compact mode, or in compact mode and showing the CHR viewer, use it otherPpuViewer = frm as frmPpuViewer; break; } } if (otherPpuViewer == null) { //Open up a new viewer, in compact mode otherPpuViewer = DebugWindowManager.OpenPpuViewer(PpuViewerMode.ChrViewer); otherPpuViewer.SelectChrTile(tileIndex, paletteIndex, false); } else { //Reuse an existing viewer that's not in compact mode otherPpuViewer.SelectChrTile(tileIndex, paletteIndex, false); otherPpuViewer.BringToFront(); } } else { if (!InteropEmu.DebugIsExecutionStopped() || ConfigManager.Config.DebugInfo.PpuRefreshOnBreak) { //Only change the palette if execution is not stopped (or if we're configured to refresh the viewer on break/pause) //Otherwise, the CHR viewer will refresh its data (and it might not match the data we loaded at the specified scanline/cycle anymore) ctrlChrViewer.SelectedPaletteIndex = paletteIndex; } ctrlChrViewer.SelectedTileIndex = tileIndex; tabMain.SelectTab(tpgChrViewer); _selectedTab = tpgChrViewer; } }
private void mnuTraceLogger_Click(object sender, EventArgs e) { DebugWindowManager.OpenDebugWindow(DebugWindow.TraceLogger); }
private void ctrlHexViewer_InitializeContextMenu(object sender, EventArgs evt) { HexBox hexBox = (HexBox)sender; var mnuEditLabel = new ToolStripMenuItem(); mnuEditLabel.Click += (s, e) => { UInt32 address = (UInt32)hexBox.SelectionStart; if (this._memoryType == DebugMemoryType.CpuMemory) { AddressTypeInfo info = new AddressTypeInfo(); InteropEmu.DebugGetAbsoluteAddressAndType(address, ref info); ctrlLabelList.EditLabel((UInt32)info.Address, info.Type); } else { ctrlLabelList.EditLabel(address, GetAddressType().Value); } }; var mnuEditBreakpoint = new ToolStripMenuItem(); mnuEditBreakpoint.Click += (s, e) => { UInt32 startAddress = (UInt32)hexBox.SelectionStart; UInt32 endAddress = (UInt32)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); BreakpointAddressType addressType = startAddress == endAddress ? BreakpointAddressType.SingleAddress : BreakpointAddressType.AddressRange; Breakpoint bp = BreakpointManager.GetMatchingBreakpoint(startAddress, endAddress, this._memoryType == DebugMemoryType.PpuMemory); if (bp == null) { bp = new Breakpoint() { Address = startAddress, StartAddress = startAddress, EndAddress = endAddress, AddressType = addressType, IsAbsoluteAddress = false }; if (this._memoryType == DebugMemoryType.CpuMemory) { bp.BreakOnWrite = bp.BreakOnRead = true; } else { bp.BreakOnWriteVram = bp.BreakOnReadVram = true; } } BreakpointManager.EditBreakpoint(bp); }; var mnuAddWatch = new ToolStripMenuItem(); mnuAddWatch.Click += (s, e) => { UInt32 startAddress = (UInt32)hexBox.SelectionStart; UInt32 endAddress = (UInt32)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); string[] toAdd = Enumerable.Range((int)startAddress, (int)(endAddress - startAddress + 1)).Select((num) => $"[${num.ToString("X4")}]").ToArray(); WatchManager.AddWatch(toAdd); }; var mnuMarkSelectionAs = new ToolStripMenuItem(); var mnuMarkAsCode = new ToolStripMenuItem(); mnuMarkAsCode.Text = "Verified Code"; mnuMarkAsCode.Click += (s, e) => { int startAddress = (int)hexBox.SelectionStart; int endAddress = (int)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); this.MarkSelectionAs(startAddress, endAddress, CdlPrgFlags.Code); }; var mnuMarkAsData = new ToolStripMenuItem(); mnuMarkAsData.Text = "Verified Data"; mnuMarkAsData.Click += (s, e) => { int startAddress = (int)hexBox.SelectionStart; int endAddress = (int)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); this.MarkSelectionAs(startAddress, endAddress, CdlPrgFlags.Data); }; var mnuMarkAsUnidentifiedData = new ToolStripMenuItem(); mnuMarkAsUnidentifiedData.Text = "Unidentified Code/Data"; mnuMarkAsUnidentifiedData.Click += (s, e) => { int startAddress = (int)hexBox.SelectionStart; int endAddress = (int)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); this.MarkSelectionAs(startAddress, endAddress, CdlPrgFlags.None); }; mnuMarkSelectionAs.DropDownItems.Add(mnuMarkAsCode); mnuMarkSelectionAs.DropDownItems.Add(mnuMarkAsData); mnuMarkSelectionAs.DropDownItems.Add(mnuMarkAsUnidentifiedData); var mnuFreeze = new ToolStripMenuItem(); mnuFreeze.Click += (s, e) => { UInt32 startAddress = (UInt32)hexBox.SelectionStart; UInt32 endAddress = (UInt32)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); for (UInt32 i = startAddress; i <= endAddress; i++) { InteropEmu.DebugSetFreezeState((UInt16)i, (bool)mnuFreeze.Tag); } }; hexBox.ContextMenuStrip.Opening += (s, e) => { UInt32 startAddress = (UInt32)hexBox.SelectionStart; UInt32 endAddress = (UInt32)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); string address = "$" + startAddress.ToString("X4"); string addressRange; if (startAddress != endAddress) { addressRange = "$" + startAddress.ToString("X4") + "-$" + endAddress.ToString("X4"); } else { addressRange = address; } mnuEditLabel.Text = $"Edit Label ({address})"; mnuEditBreakpoint.Text = $"Edit Breakpoint ({addressRange})"; mnuAddWatch.Text = $"Add to Watch ({addressRange})"; if (this._memoryType == DebugMemoryType.CpuMemory) { bool[] freezeState = InteropEmu.DebugGetFreezeState((UInt16)startAddress, (UInt16)(endAddress - startAddress + 1)); if (freezeState.All((frozen) => frozen)) { mnuFreeze.Text = $"Unfreeze ({addressRange})"; mnuFreeze.Tag = false; } else { mnuFreeze.Text = $"Freeze ({addressRange})"; mnuFreeze.Tag = true; } } else { mnuFreeze.Text = $"Freeze"; mnuFreeze.Tag = false; } if (this._memoryType == DebugMemoryType.CpuMemory) { int absStart = InteropEmu.DebugGetAbsoluteAddress(startAddress); int absEnd = InteropEmu.DebugGetAbsoluteAddress(endAddress); if (absStart >= 0 && absEnd >= 0 && absStart <= absEnd) { mnuMarkSelectionAs.Text = "Mark selection as... (" + addressRange + ")"; mnuMarkSelectionAs.Enabled = true; } else { mnuMarkSelectionAs.Text = "Mark selection as..."; mnuMarkSelectionAs.Enabled = false; } } else if (this._memoryType == DebugMemoryType.PrgRom) { mnuMarkSelectionAs.Text = "Mark selection as... (" + addressRange + ")"; mnuMarkSelectionAs.Enabled = true; } else { mnuMarkSelectionAs.Text = "Mark selection as..."; mnuMarkSelectionAs.Enabled = false; } bool disableEditLabel = false; if (this._memoryType == DebugMemoryType.CpuMemory) { AddressTypeInfo info = new AddressTypeInfo(); InteropEmu.DebugGetAbsoluteAddressAndType(startAddress, ref info); disableEditLabel = info.Address == -1; } mnuEditLabel.Enabled = !disableEditLabel && (this._memoryType == DebugMemoryType.CpuMemory || this.GetAddressType().HasValue); mnuEditBreakpoint.Enabled = (this._memoryType == DebugMemoryType.CpuMemory || this._memoryType == DebugMemoryType.PpuMemory) && DebugWindowManager.GetDebugger() != null; mnuAddWatch.Enabled = this._memoryType == DebugMemoryType.CpuMemory; mnuFreeze.Enabled = this._memoryType == DebugMemoryType.CpuMemory; }; hexBox.ContextMenuStrip.Items.Insert(0, new ToolStripSeparator()); hexBox.ContextMenuStrip.Items.Insert(0, mnuFreeze); hexBox.ContextMenuStrip.Items.Insert(0, mnuEditLabel); hexBox.ContextMenuStrip.Items.Insert(0, mnuEditBreakpoint); hexBox.ContextMenuStrip.Items.Insert(0, mnuAddWatch); hexBox.ContextMenuStrip.Items.Insert(0, new ToolStripSeparator()); hexBox.ContextMenuStrip.Items.Insert(0, mnuMarkSelectionAs); }
private void mnuNewScript_Click(object sender, EventArgs e) { DebugWindowManager.OpenScriptWindow(true); }
protected override void OnFormClosed(FormClosedEventArgs e) { base.OnFormClosed(e); DebugWindowManager.CleanupDebugger(); }
private void mnuScriptWindow_Click(object sender, EventArgs e) { DebugWindowManager.OpenDebugWindow(DebugWindow.ScriptWindow); }
private void mnuNewScript_Click(object sender, EventArgs e) { frmScript frm = DebugWindowManager.OpenDebugWindow(DebugWindow.ScriptWindow) as frmScript; frm.LoadBuiltInScript(""); }
private void ctrlDebuggerCode_OnEditCode(AssemblerEventArgs args) { DebugWindowManager.OpenAssembler(args.Code, args.StartAddress, args.BlockLength); }
private void mnuApuViewer_Click(object sender, EventArgs e) { DebugWindowManager.OpenDebugWindow(DebugWindow.ApuViewer); }