Пример #1
0
        public void ScrollToLineNumber(int lineNumber, bool scrollToTop = false)
        {
            AddressTypeInfo addressInfo = new AddressTypeInfo();

            InteropEmu.DebugGetAbsoluteAddressAndType((uint)lineNumber, addressInfo);
            ScrollToAddress(addressInfo, scrollToTop);
        }
Пример #2
0
 private void mnuEditLabel_Click(object sender, EventArgs e)
 {
     if (UpdateContextMenu(_lastLocation))
     {
         if (_lastClickedAddress >= 0)
         {
             AddressTypeInfo info = new AddressTypeInfo();
             InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)_lastClickedAddress, info);
             if (info.Address >= 0)
             {
                 ctrlLabelList.EditLabel((UInt32)info.Address, info.Type);
             }
         }
         else if (_lastClickedLabel != null)
         {
             ctrlLabelList.EditLabel(_lastClickedLabel.Address, _lastClickedLabel.AddressType);
         }
         else if (_lastClickedSymbol != null)
         {
             AddressTypeInfo info = Viewer.SymbolProvider.GetSymbolAddressInfo(_lastClickedSymbol);
             if (info != null && info.Address >= 0)
             {
                 ctrlLabelList.EditLabel((UInt32)info.Address, info.Type);
             }
         }
     }
 }
Пример #3
0
        private void mnuViewInMemoryType_Click(object sender, EventArgs e)
        {
            AddressTypeInfo addressInfo = new AddressTypeInfo();

            InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)SelectionStartAddress, addressInfo);
            if (addressInfo.Address >= 0 && (addressInfo.Type == AddressType.PrgRom || addressInfo.Type == AddressType.WorkRam || addressInfo.Type == AddressType.SaveRam))
            {
                MemoryViewer.ShowAddress(addressInfo.Address, addressInfo.Type.ToMemoryType());
            }
        }
Пример #4
0
        public static CodeLabel GetLabel(UInt16 relativeAddress)
        {
            AddressTypeInfo info = new AddressTypeInfo();

            InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)relativeAddress, ref info);
            if (info.Address >= 0)
            {
                return(GetLabel((UInt32)info.Address, info.Type));
            }
            return(null);
        }
Пример #5
0
 private void mnuEditLabel_Click(object sender, EventArgs e)
 {
     if (UpdateContextMenu(_lastLocation))
     {
         AddressTypeInfo info = new AddressTypeInfo();
         InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)_lastClickedAddress, ref info);
         if (info.Address >= 0)
         {
             ctrlLabelList.EditLabel((UInt32)info.Address, info.Type);
         }
     }
 }
Пример #6
0
        private void mnuEditLabel_Click(object sender, EventArgs e)
        {
            UInt32 address = (UInt32)ctrlHexBox.SelectionStart;

            if (this._memoryType == DebugMemoryType.CpuMemory)
            {
                AddressTypeInfo info = new AddressTypeInfo();
                InteropEmu.DebugGetAbsoluteAddressAndType(address, info);
                ctrlLabelList.EditLabel((UInt32)info.Address, info.Type);
            }
            else
            {
                ctrlLabelList.EditLabel(address, GetAddressType().Value);
            }
        }
Пример #7
0
        public void DisplayAddressTooltip(string word, UInt32 address)
        {
            byte   byteValue = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, address);
            UInt16 wordValue = (UInt16)(byteValue | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, address + 1) << 8));

            var values = new Dictionary <string, string>()
            {
                { "Address", "$" + address.ToString("X4") },
                { "Value", $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" }
            };

            AddressTypeInfo addressInfo = new AddressTypeInfo();

            InteropEmu.DebugGetAbsoluteAddressAndType(address, addressInfo);
            this.ShowTooltip(word, values, -1, addressInfo);
        }
Пример #8
0
        private bool CurrentFileContainsAddress(int cpuAddress)
        {
            if (CurrentFile == null)
            {
                return(false);
            }

            AddressTypeInfo addressInfo = new AddressTypeInfo();

            InteropEmu.DebugGetAbsoluteAddressAndType((uint)cpuAddress, addressInfo);
            if (addressInfo.Address >= 0 && addressInfo.Type == AddressType.PrgRom)
            {
                LineInfo line = _symbolProvider.GetSourceCodeLineInfo(addressInfo.Address);
                return(CurrentFile.ID == line?.FileID);
            }
            return(false);
        }
Пример #9
0
        public bool Matches(int relativeAddress)
        {
            if (this.IsCpuBreakpoint)
            {
                if (this.IsAbsoluteAddress)
                {
                    AddressTypeInfo addressTypeInfo = new AddressTypeInfo();
                    InteropEmu.DebugGetAbsoluteAddressAndType((uint)relativeAddress, ref addressTypeInfo);

                    return(addressTypeInfo.Type == GUI.AddressType.PrgRom && addressTypeInfo.Address == this.Address);
                }
                else
                {
                    return(relativeAddress == this.Address);
                }
            }
            return(false);
        }
Пример #10
0
        private void mnuEditLabel_Click(object sender, EventArgs e)
        {
            if (UpdateContextMenu(_lastLocation))
            {
                if (_lastClickedAddress >= 0)
                {
                    //get selected adress of debugger text window
                    int    startAddress, endAddress;
                    string rangeString;
                    GetSelectedAddressRange(out startAddress, out endAddress, out rangeString);

                    AddressTypeInfo info = new AddressTypeInfo();
                    InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)_lastClickedAddress, info);
                    if (info.Address >= 0)
                    {
                        ctrlLabelList.EditLabel((UInt32)info.Address, info.Type);
                        //if that is the same as the address we just edited, restore selected line
                        if (startAddress == info.Address)
                        {
                            GoToDestination(new GoToDestination()
                            {
                                AddressInfo = info
                            });
                        }
                    }
                    else
                    {
                        ctrlLabelList.EditLabel((UInt32)_lastClickedAddress, AddressType.Register);
                    }
                }
                else if (_lastClickedLabel != null)
                {
                    ctrlLabelList.EditLabel(_lastClickedLabel.Address, _lastClickedLabel.AddressType);
                }
                else if (_lastClickedSymbol != null)
                {
                    AddressTypeInfo info = Viewer.SymbolProvider.GetSymbolAddressInfo(_lastClickedSymbol);
                    if (info != null && info.Address >= 0)
                    {
                        ctrlLabelList.EditLabel((UInt32)info.Address, info.Type);
                    }
                }
            }
        }
Пример #11
0
        private void ctrlCodeViewer_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Location.X > this.ctrlCodeViewer.CodeMargin / 2 && e.Location.X < this.ctrlCodeViewer.CodeMargin)
            {
                int relativeAddress = ctrlCodeViewer.GetLineNumberAtPosition(e.Y);
                if (relativeAddress >= 0)
                {
                    AddressTypeInfo info = new AddressTypeInfo();
                    InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)relativeAddress, ref info);

                    if (info.Address >= 0)
                    {
                        ctrlLabelList.EditLabel((UInt32)info.Address, info.Type);
                    }
                }
            }
            else if (UpdateContextMenu(e.Location) && mnuGoToLocation.Enabled)
            {
                GoToLocation();
            }
        }
Пример #12
0
 private void mnuAddBreakpoint_Click(object sender, EventArgs e)
 {
     if (lstLabels.SelectedIndices.Count > 0)
     {
         CodeLabel label = (CodeLabel)GetSelectedItem().SubItems[1].Tag;
         if (label.AddressType == AddressType.InternalRam || label.AddressType == AddressType.Register)
         {
             AddressTypeInfo info = new AddressTypeInfo();
             InteropEmu.DebugGetAbsoluteAddressAndType(label.Address, info);
             if (BreakpointManager.GetMatchingBreakpoint((Int32)label.Address, info) == null)
             {
                 BreakpointManager.AddBreakpoint(new Breakpoint()
                 {
                     MemoryType   = DebugMemoryType.CpuMemory,
                     BreakOnExec  = true,
                     BreakOnRead  = true,
                     BreakOnWrite = true,
                     Address      = label.Address,
                     StartAddress = label.Address,
                     EndAddress   = label.Address,
                     AddressType  = BreakpointAddressType.SingleAddress
                 });
             }
         }
         else
         {
             BreakpointManager.AddBreakpoint(new Breakpoint()
             {
                 MemoryType   = DebugMemoryType.PrgRom,
                 BreakOnExec  = true,
                 BreakOnRead  = true,
                 BreakOnWrite = false,
                 Address      = label.Address,
                 StartAddress = label.Address,
                 EndAddress   = label.Address,
                 AddressType  = BreakpointAddressType.SingleAddress
             });
         }
     }
 }
Пример #13
0
        private void ShowTooltip(string word, Dictionary <string, string> values, int address)
        {
            if (_hoverLastWord != word || _codeTooltip == null)
            {
                if (!_preventCloseTooltip && _codeTooltip != null)
                {
                    _codeTooltip.Close();
                    _codeTooltip = null;
                }

                if (ConfigManager.Config.DebugInfo.ShowOpCodeTooltips && frmOpCodeTooltip.IsOpCode(word))
                {
                    _codeTooltip = new frmOpCodeTooltip(word);
                }
                else
                {
                    bool isPrgRom = false;
                    if (address >= 0 && ConfigManager.Config.DebugInfo.ShowCodePreview)
                    {
                        AddressTypeInfo addressInfo = new AddressTypeInfo();
                        InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)address, ref addressInfo);
                        isPrgRom = addressInfo.Type == AddressType.PrgRom;
                    }

                    _codeTooltip = new frmCodeTooltip(values, isPrgRom ? address : -1, isPrgRom ? _code : null);
                }
                _codeTooltip.Left = Cursor.Position.X + 10;
                _codeTooltip.Top  = Cursor.Position.Y + 10;
                _codeTooltip.Show(this);
            }
            _codeTooltip.Left = Cursor.Position.X + 10;
            _codeTooltip.Top  = Cursor.Position.Y + 10;

            _preventCloseTooltip = true;
            _hoverLastWord       = word;
        }
Пример #14
0
        private void ctrlCodeViewer_MouseMove(object sender, MouseEventArgs e)
        {
            //Always enable to allow F2 shortcut
            mnuEditLabel.Enabled = true;

            if (e.Location.X < this.ctrlCodeViewer.CodeMargin / 4)
            {
                this.ctrlCodeViewer.ContextMenuStrip = contextMenuMargin;
            }
            else
            {
                this.ctrlCodeViewer.ContextMenuStrip = contextMenuCode;
            }

            if (_previousLocation != e.Location)
            {
                if (!_preventCloseTooltip && _codeTooltip != null)
                {
                    _codeTooltip.Close();
                    _codeTooltip = null;
                }
                _preventCloseTooltip = false;

                string word = GetWordUnderLocation(e.Location);
                if (word.StartsWith("$"))
                {
                    try {
                        UInt32 address = UInt32.Parse(word.Substring(1), System.Globalization.NumberStyles.AllowHexSpecifier);

                        AddressTypeInfo info = new AddressTypeInfo();
                        InteropEmu.DebugGetAbsoluteAddressAndType(address, ref info);

                        if (info.Address >= 0)
                        {
                            CodeLabel label = LabelManager.GetLabel((UInt32)info.Address, info.Type);
                            if (label == null)
                            {
                                DisplayAddressTooltip(word, address);
                            }
                            else
                            {
                                DisplayLabelTooltip(word, label);
                            }
                        }
                        else
                        {
                            DisplayAddressTooltip(word, address);
                        }
                    } catch { }
                }
                else
                {
                    CodeLabel label = LabelManager.GetLabel(word);

                    if (label != null)
                    {
                        DisplayLabelTooltip(word, label);
                    }
                }
                _previousLocation = e.Location;
            }
        }
Пример #15
0
        private void UpdateActionAvailability()
        {
            UInt32 startAddress = (UInt32)SelectionStartAddress;
            UInt32 endAddress   = (UInt32)SelectionEndAddress;

            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})";
            mnuAddToWatch.Text     = $"Add to Watch ({addressRange})";

            if (this._memoryType == DebugMemoryType.CpuMemory)
            {
                bool[] freezeState = InteropEmu.DebugGetFreezeState((UInt16)startAddress, (UInt16)(endAddress - startAddress + 1));
                mnuFreeze.Enabled   = !freezeState.All((frozen) => frozen);
                mnuUnfreeze.Enabled = freezeState.Any((frozen) => frozen);
                mnuFreeze.Text      = $"Freeze ({addressRange})";
                mnuUnfreeze.Text    = $"Unfreeze ({addressRange})";
            }
            else
            {
                mnuFreeze.Text      = $"Freeze";
                mnuUnfreeze.Text    = $"Unfreeze";
                mnuFreeze.Enabled   = false;
                mnuUnfreeze.Enabled = 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 = DebugWindowManager.GetDebugger() != null && (
                this._memoryType == DebugMemoryType.CpuMemory ||
                this._memoryType == DebugMemoryType.PpuMemory ||
                this._memoryType == DebugMemoryType.PrgRom ||
                this._memoryType == DebugMemoryType.WorkRam ||
                this._memoryType == DebugMemoryType.SaveRam ||
                this._memoryType == DebugMemoryType.ChrRam ||
                this._memoryType == DebugMemoryType.ChrRom ||
                this._memoryType == DebugMemoryType.PaletteMemory
                );

            mnuAddToWatch.Enabled = this._memoryType == DebugMemoryType.CpuMemory;

            mnuCopy.Enabled      = ctrlHexBox.CanCopy();
            mnuPaste.Enabled     = ctrlHexBox.CanPaste();
            mnuSelectAll.Enabled = ctrlHexBox.CanSelectAll();
            mnuUndo.Enabled      = InteropEmu.DebugHasUndoHistory();
        }
Пример #16
0
        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);
        }
Пример #17
0
        public void ProcessMouseMove(Point location)
        {
            if (_previousLocation != location)
            {
                bool closeExistingPopup = true;

                _previousLocation = location;

                string word = _codeViewer.GetWordUnderLocation(location);
                if (word.StartsWith("$"))
                {
                    try {
                        UInt32 address = UInt32.Parse(word.Substring(1), NumberStyles.AllowHexSpecifier);

                        AddressTypeInfo info = new AddressTypeInfo();
                        InteropEmu.DebugGetAbsoluteAddressAndType(address, info);

                        if (info.Address >= 0)
                        {
                            CodeLabel label = LabelManager.GetLabel((UInt32)info.Address, info.Type);
                            if (label == null)
                            {
                                DisplayAddressTooltip(word, address);
                                closeExistingPopup = false;
                            }
                            else
                            {
                                DisplayLabelTooltip(word, label, 0);
                                closeExistingPopup = false;
                            }
                        }
                        else
                        {
                            DisplayAddressTooltip(word, address);
                            closeExistingPopup = false;
                        }
                    } catch { }
                }
                else
                {
                    Match arrayMatch = LabelArrayFormat.Match(word);
                    int?  arrayIndex = null;
                    if (arrayMatch.Success)
                    {
                        word       = arrayMatch.Groups[1].Value;
                        arrayIndex = Int32.Parse(arrayMatch.Groups[2].Value);
                    }

                    int address = _codeViewer.GetLineNumberAtPosition(location.Y);
                    if (SymbolProvider != null)
                    {
                        int rangeStart, rangeEnd;
                        if (_codeViewer.GetNoteRangeAtLocation(location.Y, out rangeStart, out rangeEnd))
                        {
                            Ld65DbgImporter.SymbolInfo symbol = SymbolProvider.GetSymbol(word, rangeStart, rangeEnd);
                            if (symbol != null)
                            {
                                DisplaySymbolTooltip(symbol, arrayIndex);
                                return;
                            }
                        }
                    }
                    else
                    {
                        CodeLabel label = LabelManager.GetLabel(word);
                        if (label != null)
                        {
                            DisplayLabelTooltip(word, label, arrayIndex);
                            return;
                        }
                    }

                    if (ConfigManager.Config.DebugInfo.ShowOpCodeTooltips && frmOpCodeTooltip.IsOpCode(word))
                    {
                        ShowTooltip(word, null, address, new AddressTypeInfo()
                        {
                            Address = address, Type = AddressType.Register
                        });
                        closeExistingPopup = false;
                    }
                }

                if (closeExistingPopup)
                {
                    this.Close();
                }
            }
        }
Пример #18
0
        private void UpdateActionAvailability()
        {
            UInt32 startAddress = (UInt32)SelectionStartAddress;
            UInt32 endAddress   = (UInt32)SelectionEndAddress;

            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})";
            mnuAddToWatch.Text     = $"Add to Watch ({addressRange})";

            mnuViewInDisassembly.Text = $"View in disassembly ({address})";

            bool viewInCpuMemoryVisible  = (_memoryType == DebugMemoryType.PrgRom || _memoryType == DebugMemoryType.WorkRam || _memoryType == DebugMemoryType.SaveRam);
            bool viewInMemoryTypeVisible = _memoryType == DebugMemoryType.CpuMemory;

            mnuViewInCpuMemory.Visible   = viewInCpuMemoryVisible;
            mnuViewInMemoryType.Visible  = viewInMemoryTypeVisible;
            mnuViewInDisassembly.Visible = (viewInCpuMemoryVisible || viewInMemoryTypeVisible);
            sepViewActions.Visible       = (viewInCpuMemoryVisible || viewInMemoryTypeVisible);

            if (viewInMemoryTypeVisible)
            {
                frmDebugger     debugger    = DebugWindowManager.GetDebugger();
                AddressTypeInfo addressInfo = new AddressTypeInfo();
                InteropEmu.DebugGetAbsoluteAddressAndType(startAddress, addressInfo);
                mnuViewInMemoryType.Text     = $"View in " + ResourceHelper.GetEnumText(addressInfo.Type) + $" ({address})";
                mnuViewInDisassembly.Enabled = debugger != null;
                bool viewInMemoryTypeEnabled = addressInfo.Address >= 0 && (addressInfo.Type == AddressType.PrgRom || addressInfo.Type == AddressType.WorkRam || addressInfo.Type == AddressType.SaveRam);
                mnuViewInMemoryType.Enabled = viewInMemoryTypeEnabled;
                mnuViewInMemoryType.Visible = viewInMemoryTypeEnabled;
                mnuViewInCpuMemory.Enabled  = false;
            }
            else if (viewInCpuMemoryVisible)
            {
                frmDebugger debugger        = DebugWindowManager.GetDebugger();
                int         relativeAddress = InteropEmu.DebugGetRelativeAddress(startAddress, _memoryType.ToAddressType());
                mnuViewInCpuMemory.Text      = $"View in CPU memory ({address})";
                mnuViewInCpuMemory.Enabled   = relativeAddress >= 0;
                mnuViewInDisassembly.Enabled = debugger != null && relativeAddress >= 0;
                mnuViewInMemoryType.Enabled  = false;
            }
            else
            {
                mnuViewInMemoryType.Enabled  = false;
                mnuViewInCpuMemory.Enabled   = false;
                mnuViewInDisassembly.Enabled = false;
            }

            if (this._memoryType == DebugMemoryType.CpuMemory)
            {
                bool[] freezeState = InteropEmu.DebugGetFreezeState((UInt16)startAddress, (UInt16)(endAddress - startAddress + 1));
                mnuFreeze.Enabled   = !freezeState.All((frozen) => frozen);
                mnuUnfreeze.Enabled = freezeState.Any((frozen) => frozen);
                mnuFreeze.Text      = $"Freeze ({addressRange})";
                mnuUnfreeze.Text    = $"Unfreeze ({addressRange})";
            }
            else
            {
                mnuFreeze.Text      = $"Freeze";
                mnuUnfreeze.Text    = $"Unfreeze";
                mnuFreeze.Enabled   = false;
                mnuUnfreeze.Enabled = 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, info);
                disableEditLabel = info.Address == -1;
            }

            mnuEditLabel.Enabled      = !disableEditLabel && (this._memoryType == DebugMemoryType.CpuMemory || this.GetAddressType().HasValue);
            mnuEditBreakpoint.Enabled = DebugWindowManager.GetDebugger() != null && (
                this._memoryType == DebugMemoryType.CpuMemory ||
                this._memoryType == DebugMemoryType.PpuMemory ||
                this._memoryType == DebugMemoryType.PrgRom ||
                this._memoryType == DebugMemoryType.WorkRam ||
                this._memoryType == DebugMemoryType.SaveRam ||
                this._memoryType == DebugMemoryType.ChrRam ||
                this._memoryType == DebugMemoryType.ChrRom ||
                this._memoryType == DebugMemoryType.PaletteMemory
                );

            mnuAddToWatch.Enabled = this._memoryType == DebugMemoryType.CpuMemory;

            mnuCopy.Enabled      = ctrlHexBox.CanCopy();
            mnuPaste.Enabled     = ctrlHexBox.CanPaste();
            mnuSelectAll.Enabled = ctrlHexBox.CanSelectAll();
            mnuUndo.Enabled      = InteropEmu.DebugHasUndoHistory();
        }
Пример #19
0
        public List <string> GetCode(out int byteLength, ref int startAddress, int endAddress = -1)
        {
            _code.InitAssemblerValues();

            List <string> result = new List <string>();

            byteLength = 0;

            if (endAddress == -1)
            {
                //When no end address is specified, find the start of the function based on startAddress
                int address = InteropEmu.DebugFindSubEntryPoint((UInt16)startAddress);
                if (address != -1)
                {
                    startAddress = address;
                }
            }

            for (int i = startAddress; (i <= endAddress || endAddress == -1) && endAddress < 65536;)
            {
                string code;
                if (_code.CodeContent.TryGetValue(i, out code))
                {
                    code = code.Split('\x2')[0].Trim();

                    if (code.StartsWith("--") || code.StartsWith("__"))
                    {
                        //Stop adding code when we find a new section (new function, data blocks, etc.)
                        break;
                    }

                    AddressTypeInfo info = new AddressTypeInfo();
                    InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)i, info);
                    CodeLabel codeLabel = info.Address >= 0 ? LabelManager.GetLabel((UInt32)info.Address, AddressType.PrgRom) : null;
                    string    comment   = codeLabel?.Comment;
                    string    label     = codeLabel?.Label;

                    bool addPadding = true;
                    if (code.StartsWith("STP*") || code.StartsWith("NOP*"))
                    {
                        //Transform unofficial opcodes that can't be reassembled properly into .byte statements
                        if (comment != null)
                        {
                            comment.Insert(0, code + " - ");
                        }
                        else
                        {
                            comment = code;
                        }
                        code       = ".byte " + string.Join(",", _code.CodeByteCode[i].Split(' '));
                        addPadding = false;
                    }

                    if (!string.IsNullOrWhiteSpace(comment) && comment.Contains("\n"))
                    {
                        result.AddRange(comment.Replace("\r", "").Split('\n').Select(cmt => ";" + cmt));
                        comment = null;
                    }
                    if (!string.IsNullOrWhiteSpace(label))
                    {
                        result.Add(label + ":");
                    }
                    result.Add((addPadding ? "  " : "") + code + (!string.IsNullOrWhiteSpace(comment) ? (" ;" + comment) : ""));

                    int length = _code.CodeByteCode[i].Count(c => c == ' ') + 1;
                    byteLength += length;
                    i          += length;

                    if (endAddress == -1 && (string.Compare(code, "RTI", true) == 0 || string.Compare(code, "RTS", true) == 0))
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }

            result.Add("");
            return(result);
        }
Пример #20
0
        private void ctrlHexViewer_ByteMouseHover(int address, Point position)
        {
            if (address < 0 || !mnuShowLabelInfoOnMouseOver.Checked)
            {
                if (_tooltip != null)
                {
                    _tooltip.Close();
                    _lastLabelTooltip   = null;
                    _lastTooltipAddress = -1;
                }
                return;
            }

            if (_lastTooltipAddress == address)
            {
                return;
            }

            _lastTooltipAddress = address;

            CodeLabel label = null;

            switch (_memoryType)
            {
            case DebugMemoryType.CpuMemory:
                AddressTypeInfo info = new AddressTypeInfo();
                InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)address, info);
                if (info.Address >= 0)
                {
                    label = LabelManager.GetLabel((UInt32)info.Address, info.Type);
                }
                if (label == null)
                {
                    label = LabelManager.GetLabel((UInt32)address, AddressType.Register);
                }
                break;

            case DebugMemoryType.InternalRam:
                label = LabelManager.GetLabel((UInt32)address, AddressType.InternalRam);
                break;

            case DebugMemoryType.WorkRam:
                label = LabelManager.GetLabel((UInt32)address, AddressType.WorkRam);
                break;

            case DebugMemoryType.SaveRam:
                label = LabelManager.GetLabel((UInt32)address, AddressType.SaveRam);
                break;

            case DebugMemoryType.PrgRom:
                label = LabelManager.GetLabel((UInt32)address, AddressType.PrgRom);
                break;
            }

            if (label != null)
            {
                if (_lastLabelTooltip != label)
                {
                    if (_tooltip != null)
                    {
                        _tooltip.Close();
                    }

                    Dictionary <string, string> values = new Dictionary <string, string>();
                    if (!string.IsNullOrWhiteSpace(label.Label))
                    {
                        values["Label"] = label.Label;
                    }
                    values["Address"]      = "$" + label.Address.ToString("X4");
                    values["Address Type"] = label.AddressType.ToString();
                    if (!string.IsNullOrWhiteSpace(label.Comment))
                    {
                        values["Comment"] = label.Comment;
                    }

                    _tooltip             = new frmCodeTooltip(this, values);
                    _tooltip.FormClosed += (s, evt) => { _tooltip = null; };
                    _tooltip.SetFormLocation(new Point(position.X, position.Y), ctrlHexViewer);
                    _lastLabelTooltip = label;
                }
            }
            else
            {
                if (_tooltip != null)
                {
                    _tooltip.Close();
                    _lastLabelTooltip   = null;
                    _lastTooltipAddress = -1;
                }
            }
        }