Ejemplo n.º 1
0
        public void Prepare(long firstByteIndex, long lastByteIndex)
        {
            int visibleByteCount = (int)(lastByteIndex - firstByteIndex + 1);

            if (_highlightBreakpoints)
            {
                Breakpoint[] breakpoints = BreakpointManager.Breakpoints.ToArray();
                _breakpointTypes = new BreakpointType[visibleByteCount];

                for (int i = 0; i < visibleByteCount; i++)
                {
                    int byteIndex = i + (int)firstByteIndex;
                    foreach (Breakpoint bp in breakpoints)
                    {
                        if (bp.Enabled && bp.IsCpuBreakpoint && bp.Matches(byteIndex, _memoryType))
                        {
                            _breakpointTypes[i] = bp.BreakOnExec ? BreakpointType.Execute : (bp.BreakOnWrite ? BreakpointType.WriteRam : BreakpointType.ReadRam);
                            break;
                        }
                    }
                }
            }
            else
            {
                _breakpointTypes = null;
            }

            _readStamps  = InteropEmu.DebugGetMemoryAccessStamps((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType, MemoryOperationType.Read);
            _writeStamps = InteropEmu.DebugGetMemoryAccessStamps((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType, MemoryOperationType.Write);
            _execStamps  = InteropEmu.DebugGetMemoryAccessStamps((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType, MemoryOperationType.Exec);
            if (_memoryType == DebugMemoryType.CpuMemory)
            {
                _freezeState = InteropEmu.DebugGetFreezeState((UInt16)firstByteIndex, (UInt16)visibleByteCount);
            }

            _readCounts  = InteropEmu.DebugGetMemoryAccessCounts((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType, MemoryOperationType.Read);
            _writeCounts = InteropEmu.DebugGetMemoryAccessCounts((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType, MemoryOperationType.Write);
            _execCounts  = InteropEmu.DebugGetMemoryAccessCounts((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType, MemoryOperationType.Exec);

            _cdlData = null;
            if (_highlightDmcDataBytes || _highlightDataBytes || _highlightCodeBytes)
            {
                switch (_memoryType)
                {
                case DebugMemoryType.ChrRom:
                case DebugMemoryType.PpuMemory:
                case DebugMemoryType.CpuMemory:
                case DebugMemoryType.PrgRom:
                    _cdlData = InteropEmu.DebugGetCdlData((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType);
                    break;
                }
            }

            _hasLabel = new bool[visibleByteCount];
            if (_highlightLabelledBytes)
            {
                if (_memoryType == DebugMemoryType.CpuMemory)
                {
                    for (long i = 0; i < _hasLabel.Length; i++)
                    {
                        _hasLabel[i] = (
                            !string.IsNullOrWhiteSpace(LabelManager.GetLabel((UInt16)(i + firstByteIndex))?.Label) ||
                            !string.IsNullOrWhiteSpace(LabelManager.GetLabel((uint)(i + firstByteIndex), AddressType.Register)?.Label)
                            );
                    }
                }
                else if (_memoryType == DebugMemoryType.PrgRom || _memoryType == DebugMemoryType.WorkRam || _memoryType == DebugMemoryType.SaveRam)
                {
                    for (long i = 0; i < _hasLabel.Length; i++)
                    {
                        _hasLabel[i] = !string.IsNullOrWhiteSpace(LabelManager.GetLabel((uint)(firstByteIndex + i), _memoryType.ToAddressType())?.Label);
                    }
                }
            }

            InteropEmu.DebugGetState(ref _state);
        }
Ejemplo n.º 2
0
        private void ctrlHexViewer_ByteMouseHover(int address, Point position)
        {
            if (address < 0 || !mnuShowLabelInfoOnMouseOver.Checked)
            {
                if (_tooltip != null)
                {
                    _tooltip.Close();
                    _lastLabelTooltip     = null;
                    _lastLabelArrayOffset = -1;
                    _lastTooltipAddress   = -1;
                }
                return;
            }

            if (_lastTooltipAddress == address)
            {
                return;
            }

            _lastTooltipAddress = address;

            CodeLabel label       = null;
            int       arrayOffset = 0;

            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)
                    {
                        arrayOffset = info.Address - (int)label.Address;
                    }
                    else
                    {
                        label = LabelManager.GetLabel((UInt32)address, AddressType.Register);
                    }
                }
                break;

            case DebugMemoryType.InternalRam:
            case DebugMemoryType.WorkRam:
            case DebugMemoryType.SaveRam:
            case DebugMemoryType.PrgRom:
                label = LabelManager.GetLabel((UInt32)address, _memoryType.ToAddressType());
                if (label != null)
                {
                    arrayOffset = address - (int)label.Address;
                }
                break;
            }

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

                    Dictionary <string, string> values = new Dictionary <string, string>();
                    if (!string.IsNullOrWhiteSpace(label.Label))
                    {
                        values["Label"] = label.Label;
                        if (label.Length > 1)
                        {
                            values["Label"] += "+" + arrayOffset.ToString();
                        }
                    }
                    values["Address"]      = "$" + (label.Address + arrayOffset).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;
                    _lastLabelArrayOffset = arrayOffset;
                }
            }
            else
            {
                if (_tooltip != null)
                {
                    _tooltip.Close();
                    _lastLabelTooltip     = null;
                    _lastLabelArrayOffset = -1;
                    _lastTooltipAddress   = -1;
                }
            }
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        public void Prepare(long firstByteIndex, long lastByteIndex)
        {
            int visibleByteCount = (int)(lastByteIndex - firstByteIndex + 1);

            if (_highlightBreakpoints)
            {
                Breakpoint[] breakpoints = BreakpointManager.Breakpoints.ToArray();
                _breakpointTypes = new BreakpointType[visibleByteCount];

                for (int i = 0; i < visibleByteCount; i++)
                {
                    int byteIndex = i + (int)firstByteIndex;
                    foreach (Breakpoint bp in breakpoints)
                    {
                        if (bp.Enabled && bp.IsCpuBreakpoint && bp.Matches(byteIndex, _memoryType))
                        {
                            _breakpointTypes[i] = bp.BreakOnExec ? BreakpointType.Execute : (bp.BreakOnWrite ? BreakpointType.WriteRam : BreakpointType.ReadRam);
                            break;
                        }
                    }
                }
            }
            else
            {
                _breakpointTypes = null;
            }

            _counts = InteropEmu.DebugGetMemoryAccessCounts((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType);
            if (_memoryType == DebugMemoryType.CpuMemory)
            {
                _freezeState = InteropEmu.DebugGetFreezeState((UInt16)firstByteIndex, (UInt16)visibleByteCount);
            }

            _cdlData = null;
            if (_highlightDmcDataBytes || _highlightDataBytes || _highlightCodeBytes)
            {
                switch (_memoryType)
                {
                case DebugMemoryType.ChrRom:
                case DebugMemoryType.PpuMemory:
                case DebugMemoryType.CpuMemory:
                case DebugMemoryType.PrgRom:
                    _cdlData = InteropEmu.DebugGetCdlData((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType);
                    break;
                }
            }

            _hasLabel = new ByteLabelState[visibleByteCount];
            if (_highlightLabelledBytes)
            {
                if (_memoryType == DebugMemoryType.CpuMemory)
                {
                    for (long i = 0; i < _hasLabel.Length; i++)
                    {
                        UInt16    addr  = (UInt16)(i + firstByteIndex);
                        CodeLabel label = LabelManager.GetLabel(addr);
                        if (label == null)
                        {
                            label = LabelManager.GetLabel(addr, AddressType.Register);
                        }

                        if (label != null && !string.IsNullOrWhiteSpace(label.Label))
                        {
                            if (label.Length > 1)
                            {
                                int relAddress = label.GetRelativeAddress();
                                _hasLabel[i] = relAddress == addr ? ByteLabelState.LabelFirstByte : ByteLabelState.LabelExtraByte;
                            }
                            else
                            {
                                _hasLabel[i] = ByteLabelState.LabelFirstByte;
                            }
                        }
                    }
                }
                else if (_memoryType == DebugMemoryType.PrgRom || _memoryType == DebugMemoryType.WorkRam || _memoryType == DebugMemoryType.SaveRam)
                {
                    for (long i = 0; i < _hasLabel.Length; i++)
                    {
                        UInt32    addr  = (UInt32)(i + firstByteIndex);
                        CodeLabel label = LabelManager.GetLabel(addr, _memoryType.ToAddressType());
                        if (label != null && !string.IsNullOrWhiteSpace(label.Label))
                        {
                            _hasLabel[i] = label.Length == 1 || label.Address == addr ? ByteLabelState.LabelFirstByte : ByteLabelState.LabelExtraByte;
                        }
                    }
                }
            }

            InteropEmu.DebugGetState(ref _state);
        }