Example #1
0
        private void GetSelectedAddressRange(out int start, out int end, out string range)
        {
            int firstLineOfSelection = Viewer.CodeViewer.SelectionStart;

            while (Viewer.CodeViewer.GetLineNumber(firstLineOfSelection) < 0)
            {
                firstLineOfSelection++;
            }
            int firstLineAfterSelection = Viewer.CodeViewer.SelectionStart + Viewer.CodeViewer.SelectionLength + 1;

            while (Viewer.CodeViewer.GetLineNumber(firstLineAfterSelection) < 0)
            {
                firstLineAfterSelection++;
            }
            start = Viewer.CodeViewer.GetLineNumber(firstLineOfSelection);
            end   = Viewer.CodeViewer.GetLineNumber(firstLineAfterSelection) - 1;

            range = "";
            if (start >= 0 && end >= 0)
            {
                range = $"${start.ToString("X4")} - ${end.ToString("X4")}";
                start = InteropEmu.DebugGetAbsoluteAddress((UInt32)start);
                end   = InteropEmu.DebugGetAbsoluteAddress((UInt32)end);
            }
        }
Example #2
0
        private void HandleNotification(InteropEmu.NotificationEventArgs e)
        {
            switch (e.NotificationType)
            {
            case InteropEmu.ConsoleNotificationType.GameLoaded:
                if (InteropEmu.IsRunning())
                {
                    RefreshBreakpoints();
                }
                GameLoaded();
                if (OnRun != null)
                {
                    OnRun();
                }
                if (OnStatusChange != null)
                {
                    OnStatusChange(EmulatorStatus.Playing);
                }
                EmitDebugData();
                return;

            case InteropEmu.ConsoleNotificationType.CodeBreak:
                var source = (BreakSource)(byte)e.Parameter.ToInt64();
                //if (source == BreakSource.Breakpoint && OnBreak != null)
                if (OnBreak != null)
                {
                    DebugState state = default(DebugState);
                    InteropEmu.DebugGetState(ref state);
                    var address = InteropEmu.DebugGetAbsoluteAddress(state.CPU.DebugPC);
                    OnBreak(address);
                }
                if (OnStatusChange != null)
                {
                    OnStatusChange(EmulatorStatus.Paused);
                }
                EmitDebugData();
                return;

            case InteropEmu.ConsoleNotificationType.PpuFrameDone:
                CountFrame();
                return;
            }

            if (e.NotificationType == InteropEmu.ConsoleNotificationType.PpuFrameDone)
            {
                return;
            }
            if (e.NotificationType == InteropEmu.ConsoleNotificationType.EventViewerDisplayFrame)
            {
                return;
            }

            var status = string.Format("Emulator: {0}", e.NotificationType.ToString());

            _logHandler(new LogData(status, LogType.Normal));
        }
Example #3
0
        private List <StackInfo> GetStackInfo()
        {
            int nmiHandler = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFA) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFB) << 8);
            int irqHandler = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFE) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFF) << 8);

            InteropEmu.DebugGetCallstack(out _absoluteCallstack, out _relativeCallstack);
            DebugState state = new DebugState();

            InteropEmu.DebugGetState(ref state);
            _programCounter = state.CPU.DebugPC;

            int relDestinationAddr = -1, absDestinationAddr = -1;

            List <StackInfo> stack = new List <StackInfo>();

            for (int i = 0, len = _relativeCallstack.Length; i < len; i += 2)
            {
                if (_relativeCallstack[i] == -2)
                {
                    break;
                }

                int relSubEntryAddr = i == 0 ? -1 : _relativeCallstack[i - 1] & 0xFFFF;
                int absSubEntryAddr = i == 0 ? -1 : _absoluteCallstack[i - 1];

                stack.Add(new StackInfo()
                {
                    SubName             = this.GetFunctionName(relSubEntryAddr, absSubEntryAddr, nmiHandler, irqHandler),
                    IsMapped            = (_relativeCallstack[i] & 0x10000) != 0x10000,
                    CurrentRelativeAddr = _relativeCallstack[i] & 0xFFFF,
                    CurrentAbsoluteAddr = _absoluteCallstack[i]
                });

                relDestinationAddr = _relativeCallstack[i + 1] & 0xFFFF;
                absDestinationAddr = _absoluteCallstack[i + 1];
            }

            //Add current location
            stack.Add(new StackInfo()
            {
                SubName             = this.GetFunctionName(relDestinationAddr, absDestinationAddr, nmiHandler, irqHandler),
                IsMapped            = true,
                CurrentRelativeAddr = _programCounter,
                CurrentAbsoluteAddr = InteropEmu.DebugGetAbsoluteAddress((UInt32)_programCounter)
            });

            return(stack);
        }
Example #4
0
        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);
                }
            }
        }
Example #5
0
        private List <StackInfo> GetStackInfo()
        {
            int nmiHandler = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFA) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFB) << 8);
            int irqHandler = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFE) | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, 0xFFFF) << 8);

            _stackFrames = InteropEmu.DebugGetCallstack();
            DebugState state = new DebugState();

            InteropEmu.DebugGetState(ref state);
            _programCounter = state.CPU.DebugPC;

            int relDestinationAddr = -1, absDestinationAddr = -1;

            List <StackInfo> stack = new List <StackInfo>();

            for (int i = 0, len = _stackFrames.Length; i < len; i++)
            {
                int relSubEntryAddr = i == 0 ? -1 : _stackFrames[i - 1].JumpTarget;
                int absSubEntryAddr = i == 0 ? -1 : _stackFrames[i - 1].JumpTargetAbsolute;

                stack.Add(new StackInfo()
                {
                    SubName             = this.GetFunctionName(relSubEntryAddr, absSubEntryAddr, nmiHandler, irqHandler),
                    IsMapped            = _stackFrames[i].JumpSourceAbsolute < 0 ? false : InteropEmu.DebugGetRelativeAddress((uint)_stackFrames[i].JumpSourceAbsolute, AddressType.PrgRom) >= 0,
                    CurrentRelativeAddr = _stackFrames[i].JumpSource,
                    CurrentAbsoluteAddr = _stackFrames[i].JumpSourceAbsolute
                });

                relDestinationAddr = _stackFrames[i].JumpTarget;
                absDestinationAddr = _stackFrames[i].JumpTargetAbsolute;
            }

            //Add current location
            stack.Add(new StackInfo()
            {
                SubName             = this.GetFunctionName(relDestinationAddr, absDestinationAddr, nmiHandler, irqHandler),
                IsMapped            = true,
                CurrentRelativeAddr = _programCounter,
                CurrentAbsoluteAddr = InteropEmu.DebugGetAbsoluteAddress((UInt32)_programCounter)
            });

            return(stack);
        }
Example #6
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();
        }
Example #7
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);
        }
Example #8
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();
        }