コード例 #1
0
        private void mnuViewInDisassembly_Click(object sender, EventArgs e)
        {
            frmDebugger debugger = DebugWindowManager.GetDebugger();

            if (_destination != null && debugger != null)
            {
                debugger.GoToDestination(_destination);
            }
        }
コード例 #2
0
ファイル: frmAssembler.cs プロジェクト: fang2x/Mesen
        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();
            }
        }
コード例 #3
0
ファイル: frmMemoryViewer.cs プロジェクト: McKayJT/Mesen
        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);
                }
            }
        }
コード例 #4
0
ファイル: ctrlDebuggerCode.cs プロジェクト: orbea/Mesen
        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);
                }
            }
        }
コード例 #5
0
        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;
            }
        }
コード例 #6
0
ファイル: ctrlWatch.cs プロジェクト: sdefkk/Mesen
        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);
                }
            }
        }
コード例 #7
0
ファイル: frmMemoryViewer.cs プロジェクト: McKayJT/Mesen
        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);
        }