Exemple #1
0
        private bool UpdateContextMenu(Point mouseLocation)
        {
            _lastLocation = mouseLocation;

            UpdateContextMenuItemVisibility(true);

            mnuSwitchView.Text = SourceView ? "Switch to Disassembly View" : "Switch to Source View";

            string word = Viewer.CodeViewer.GetWordUnderLocation(mouseLocation);

            Ld65DbgImporter.SymbolInfo symbol = null;
            CodeLabel codeLabel = null;

            if (!word.StartsWith("$"))
            {
                codeLabel = LabelManager.GetLabel(word);

                if (Viewer.SymbolProvider != null)
                {
                    int rangeStart, rangeEnd;
                    if (Viewer.CodeViewer.GetNoteRangeAtLocation(mouseLocation.Y, out rangeStart, out rangeEnd))
                    {
                        symbol = Viewer.SymbolProvider.GetSymbol(word, rangeStart, rangeEnd);
                        if (symbol?.SegmentID == null)
                        {
                            symbol = null;
                        }
                    }
                }
            }

            if (word.StartsWith("$") || codeLabel != null || symbol != null)
            {
                //Cursor is on a numeric value or label
                _lastWord = word;

                if (word.StartsWith("$"))
                {
                    //CPU Address
                    _lastClickedAddress = Int32.Parse(word.Substring(1), NumberStyles.AllowHexSpecifier);
                    _newWatchValue      = "[$" + _lastClickedAddress.ToString("X") + "]";
                }
                else if (symbol != null)
                {
                    //Symbol
                    AddressTypeInfo addressInfo = (AddressTypeInfo)Viewer.SymbolProvider.GetSymbolAddressInfo(symbol);
                    _lastClickedAddress = (Int32)InteropEmu.DebugGetRelativeAddress((uint)addressInfo.Address, addressInfo.Type);
                    bool matchingLabelExists = codeLabel != null && codeLabel.Label == symbol.Name;
                    _newWatchValue = matchingLabelExists ? $"[{word}]" : $"[${_lastClickedAddress.ToString("X2")}]";
                }
                else if (codeLabel != null)
                {
                    //Label
                    _lastClickedAddress = (Int32)InteropEmu.DebugGetRelativeAddress(codeLabel.Address, codeLabel.AddressType);
                    _newWatchValue      = "[" + word + "]";
                }

                mnuGoToLocation.Enabled = true;
                mnuGoToLocation.Text    = $"Go to Location ({word})";

                mnuShowInSplitView.Enabled = true;
                mnuShowInSplitView.Text    = $"Show in Split View ({word})";

                mnuAddToWatch.Enabled = true;
                mnuAddToWatch.Text    = $"Add to Watch ({word})";

                mnuFindOccurrences.Enabled = true;
                mnuFindOccurrences.Text    = $"Find Occurrences ({word})";

                mnuEditLabel.Enabled = true;
                mnuEditLabel.Text    = $"Edit Label ({word})";

                mnuEditInMemoryViewer.Enabled = true;
                mnuEditInMemoryViewer.Text    = $"Edit in Memory Viewer ({word})";

                return(true);
            }
            else
            {
                mnuGoToLocation.Enabled       = false;
                mnuGoToLocation.Text          = "Go to Location";
                mnuShowInSplitView.Enabled    = false;
                mnuShowInSplitView.Text       = "Show in Split View";
                mnuAddToWatch.Enabled         = false;
                mnuAddToWatch.Text            = "Add to Watch";
                mnuFindOccurrences.Enabled    = false;
                mnuFindOccurrences.Text       = "Find Occurrences";
                mnuEditLabel.Enabled          = false;
                mnuEditLabel.Text             = "Edit Label";
                mnuEditInMemoryViewer.Enabled = false;
                mnuEditInMemoryViewer.Text    = $"Edit in Memory Viewer";

                if (mouseLocation.X < Viewer.CodeViewer.CodeMargin)
                {
                    _lastClickedAddress = Viewer.CodeViewer.GetLineNumberAtPosition(mouseLocation.Y);
                }
                else
                {
                    _lastClickedAddress = Viewer.CodeViewer.LastSelectedLine;
                }

                if (_lastClickedAddress >= 0)
                {
                    //Cursor is in the margin, over an address label
                    string address = $"${_lastClickedAddress.ToString("X4")}";
                    _newWatchValue = $"[{address}]";
                    _lastWord      = address;

                    mnuShowInSplitView.Enabled    = true;
                    mnuShowInSplitView.Text       = $"Show in Split View ({address})";
                    mnuAddToWatch.Enabled         = true;
                    mnuAddToWatch.Text            = $"Add to Watch ({address})";
                    mnuFindOccurrences.Enabled    = true;
                    mnuFindOccurrences.Text       = $"Find Occurrences ({address})";
                    mnuEditLabel.Enabled          = true;
                    mnuEditLabel.Text             = $"Edit Label ({address})";
                    mnuEditInMemoryViewer.Enabled = true;
                    mnuEditInMemoryViewer.Text    = $"Edit in Memory Viewer ({address})";
                    return(true);
                }

                return(false);
            }
        }
Exemple #2
0
        private bool UpdateContextMenu(Point mouseLocation)
        {
            _lastLocation = mouseLocation;

            UpdateContextMenuItemVisibility(contextMenu.Items);

            mnuSwitchView.Text = IsSourceView ? "Switch to Disassembly View" : "Switch to Source View";

            string word = Viewer.CodeViewer.GetWordUnderLocation(mouseLocation);

            Ld65DbgImporter.SymbolInfo symbol = null;
            CodeLabel codeLabel = null;

            if (!word.StartsWith("$"))
            {
                Match arrayMatch = CodeTooltipManager.LabelArrayFormat.Match(word);
                if (arrayMatch.Success)
                {
                    word = arrayMatch.Groups[1].Value;
                }

                codeLabel = LabelManager.GetLabel(word);

                if (Viewer.SymbolProvider != null && IsSourceView)
                {
                    int rangeStart, rangeEnd;
                    if (Viewer.CodeViewer.GetNoteRangeAtLocation(mouseLocation.Y, out rangeStart, out rangeEnd))
                    {
                        symbol = Viewer.SymbolProvider.GetSymbol(word, rangeStart, rangeEnd);
                    }
                }
            }

            if (word.StartsWith("$") || codeLabel != null || symbol != null)
            {
                //Cursor is on a numeric value or label
                _lastWord = word;

                if (word.StartsWith("$"))
                {
                    //CPU Address
                    _lastClickedAddress = Int32.Parse(word.Substring(1), NumberStyles.AllowHexSpecifier);
                    _lastClickedSymbol  = null;
                    _lastClickedLabel   = null;
                    _newWatchValue      = "[$" + _lastClickedAddress.ToString("X") + "]";
                }
                else if (symbol != null)
                {
                    //Symbol
                    _lastClickedAddress = -1;
                    _lastClickedLabel   = null;
                    _lastClickedSymbol  = symbol;
                    _newWatchValue      = "[" + word + "]";
                }
                else if (codeLabel != null)
                {
                    //Label
                    _lastClickedLabel   = codeLabel;
                    _lastClickedAddress = -1;
                    _lastClickedSymbol  = null;
                    _newWatchValue      = "[" + word + "]";
                }

                mnuGoToLocation.Enabled = true;
                mnuGoToLocation.Text    = $"Go to Location ({word})";

                mnuShowInSplitView.Enabled = true;
                mnuShowInSplitView.Text    = $"Show in Split View ({word})";

                mnuAddToWatch.Enabled = true;
                mnuAddToWatch.Text    = $"Add to Watch ({word})";

                mnuFindOccurrences.Enabled = true;
                mnuFindOccurrences.Text    = $"Find Occurrences ({word})";

                mnuEditLabel.Enabled = true;
                mnuEditLabel.Text    = $"Edit Label ({word})";

                mnuEditInMemoryViewer.Enabled = true;
                mnuEditInMemoryViewer.Text    = $"Edit in Memory Viewer ({word})";

                return(true);
            }
            else
            {
                mnuGoToLocation.Enabled       = false;
                mnuGoToLocation.Text          = "Go to Location";
                mnuShowInSplitView.Enabled    = false;
                mnuShowInSplitView.Text       = "Show in Split View";
                mnuAddToWatch.Enabled         = false;
                mnuAddToWatch.Text            = "Add to Watch";
                mnuFindOccurrences.Enabled    = false;
                mnuFindOccurrences.Text       = "Find Occurrences";
                mnuEditLabel.Enabled          = false;
                mnuEditLabel.Text             = "Edit Label";
                mnuEditInMemoryViewer.Enabled = false;
                mnuEditInMemoryViewer.Text    = $"Edit in Memory Viewer";

                _lastClickedLabel  = null;
                _lastClickedSymbol = null;
                if (mouseLocation.X < Viewer.CodeViewer.CodeMargin)
                {
                    _lastClickedAddress = Viewer.CodeViewer.GetLineNumberAtPosition(mouseLocation.Y);
                }
                else
                {
                    _lastClickedAddress = Viewer.CodeViewer.LastSelectedLine;
                }

                if (_lastClickedAddress >= 0)
                {
                    //Cursor is in the margin, over an address label
                    string address = $"${_lastClickedAddress.ToString("X4")}";
                    _newWatchValue = $"[{address}]";
                    _lastWord      = address;

                    mnuShowInSplitView.Enabled    = true;
                    mnuShowInSplitView.Text       = $"Show in Split View ({address})";
                    mnuAddToWatch.Enabled         = true;
                    mnuAddToWatch.Text            = $"Add to Watch ({address})";
                    mnuFindOccurrences.Enabled    = true;
                    mnuFindOccurrences.Text       = $"Find Occurrences ({address})";
                    mnuEditLabel.Enabled          = true;
                    mnuEditLabel.Text             = $"Edit Label ({address})";
                    mnuEditInMemoryViewer.Enabled = true;
                    mnuEditInMemoryViewer.Text    = $"Edit in Memory Viewer ({address})";
                    return(true);
                }

                return(false);
            }
        }