Exemplo n.º 1
0
        protected override bool ValidateInput()
        {
            UpdateObject();

            UInt32      address     = ((CodeLabel)Entity).Address;
            AddressType type        = ((CodeLabel)Entity).AddressType;
            CodeLabel   sameLabel   = LabelManager.GetLabel(txtLabel.Text);
            CodeLabel   sameAddress = LabelManager.GetLabel(address, type);

            int maxAddress = GetMaxAddress(type);

            if (maxAddress <= 0)
            {
                lblRange.Text = "(unavailable)";
            }
            else
            {
                lblRange.Text = "($0000 - $" + maxAddress.ToString("X4") + ")";
            }

            return
                (address <= maxAddress &&
                 (sameLabel == null || sameLabel == _originalLabel) &&
                 (sameAddress == null || sameAddress == _originalLabel) &&
                 (_originalLabel != null || txtLabel.Text.Length > 0 || txtComment.Text.Length > 0) &&
                 !txtComment.Text.Contains('\x1') &&
                 (txtLabel.Text.Length == 0 || Regex.IsMatch(txtLabel.Text, "^[@_a-zA-Z]+[@_a-zA-Z0-9]*$")));
        }
Exemplo n.º 2
0
        public string GetAddressLabel()
        {
            UInt32 address = AddressType == BreakpointAddressType.SingleAddress ? this.Address : this.StartAddress;

            if (IsCpuBreakpoint)
            {
                CodeLabel label;
                if (this.IsAbsoluteAddress)
                {
                    label = LabelManager.GetLabel(address, this.MemoryType);
                }
                else
                {
                    label = LabelManager.GetLabel(new AddressInfo()
                    {
                        Address = (int)address, Type = this.MemoryType
                    });
                }
                if (label != null)
                {
                    return(label.Label);
                }
            }
            return(string.Empty);
        }
Exemplo n.º 3
0
 public string GetEffectiveAddressString(string format)
 {
     if (EffectiveAddress >= 0)
     {
         AddressInfo relAddress = new AddressInfo()
         {
             Address = EffectiveAddress, Type = _cpuType == CpuType.Spc ? SnesMemoryType.SpcMemory : SnesMemoryType.CpuMemory
         };
         CodeLabel label = LabelManager.GetLabel(relAddress);
         if (label != null)
         {
             if (label.Length > 1)
             {
                 int gap = DebugApi.GetAbsoluteAddress(relAddress).Address - label.GetAbsoluteAddress().Address;
                 if (gap > 0)
                 {
                     return("[" + label.Label + "+" + gap.ToString() + "]");
                 }
             }
             return("[" + label.Label + "]");
         }
         else
         {
             return("[$" + EffectiveAddress.ToString(format) + "]");
         }
     }
     else
     {
         return("");
     }
 }
Exemplo n.º 4
0
        private void UpdateActions()
        {
            mnuEditInMemoryViewer.Enabled = false;
            mnuViewInDisassembly.Enabled  = false;

            if (lstWatch.SelectedItems.Count == 1)
            {
                Match match = _watchAddressOrLabel.Match(lstWatch.SelectedItems[0].Text);
                if (match.Success)
                {
                    string address = match.Groups[3].Value;

                    if (address[0] >= '0' && address[0] <= '9' || address[0] == '$')
                    {
                        //CPU Address
                        _selectedAddress = Int32.Parse(address[0] == '$' ? address.Substring(1) : address, address[0] == '$' ? NumberStyles.AllowHexSpecifier : NumberStyles.None);
                        _selectedLabel   = null;
                        mnuEditInMemoryViewer.Enabled = true;
                        mnuViewInDisassembly.Enabled  = true;
                    }
                    else
                    {
                        //Label
                        _selectedAddress = -1;
                        _selectedLabel   = LabelManager.GetLabel(address);
                        if (_selectedLabel != null)
                        {
                            mnuEditInMemoryViewer.Enabled = true;
                            mnuViewInDisassembly.Enabled  = true;
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void UpdateActions()
        {
            mnuHexDisplay.Checked       = ConfigManager.Config.Debug.Debugger.WatchFormat == WatchFormatStyle.Hex;
            mnuDecimalDisplay.Checked   = ConfigManager.Config.Debug.Debugger.WatchFormat == WatchFormatStyle.Signed;
            mnuBinaryDisplay.Checked    = ConfigManager.Config.Debug.Debugger.WatchFormat == WatchFormatStyle.Binary;
            mnuRowDisplayFormat.Enabled = lstWatch.SelectedItems.Count > 0;
            mnuRemoveWatch.Enabled      = lstWatch.SelectedItems.Count >= 1;

            mnuEditInMemoryViewer.Enabled = false;
            mnuViewInDisassembly.Enabled  = false;
            mnuMoveUp.Enabled             = false;
            mnuMoveDown.Enabled           = false;

            if (lstWatch.SelectedItems.Count == 1)
            {
                Match match = _watchAddressOrLabel.Match(lstWatch.SelectedItems[0].Text);
                if (match.Success)
                {
                    string address = match.Groups[3].Value;

                    if (address[0] >= '0' && address[0] <= '9' || address[0] == '$')
                    {
                        //CPU Address
                        bool   isHex      = address[0] == '$';
                        string addrString = isHex ? address.Substring(1) : address;
                        if (!Int32.TryParse(addrString, isHex ? NumberStyles.AllowHexSpecifier : NumberStyles.None, null, out _selectedAddress))
                        {
                            _selectedAddress = -1;
                        }
                        _selectedLabel = null;
                        mnuEditInMemoryViewer.Enabled = true;
                        mnuViewInDisassembly.Enabled  = true;
                    }
                    else
                    {
                        //Label
                        _selectedAddress = -1;
                        _selectedLabel   = LabelManager.GetLabel(address);
                        if (_selectedLabel != null)
                        {
                            mnuEditInMemoryViewer.Enabled = true;
                            mnuViewInDisassembly.Enabled  = true;
                        }
                    }
                }

                mnuMoveUp.Enabled   = lstWatch.SelectedIndices[0] > 0 && lstWatch.SelectedIndices[0] < lstWatch.Items.Count - 1;
                mnuMoveDown.Enabled = lstWatch.SelectedIndices[0] < lstWatch.Items.Count - 2;
            }
        }
Exemplo n.º 6
0
        protected override bool ValidateInput()
        {
            UpdateObject();

            CodeLabel sameLabel   = LabelManager.GetLabel(txtLabel.Text);
            CodeLabel sameAddress = LabelManager.GetLabel(((CodeLabel)Entity).Address, ((CodeLabel)Entity).AddressType);

            return
                ((sameLabel == null || sameLabel == _originalLabel) &&
                 (sameAddress == null || sameAddress == _originalLabel) &&
                 (_originalLabel != null || txtLabel.Text.Length > 0 || txtComment.Text.Length > 0) &&
                 !txtComment.Text.Contains('\x1') &&
                 (txtLabel.Text.Length == 0 || Regex.IsMatch(txtLabel.Text, "^[@_a-zA-Z]+[@_a-zA-Z0-9]*$")));
        }
Exemplo n.º 7
0
        protected override bool ValidateInput()
        {
            UpdateObject();

            UInt32         address    = ((CodeLabel)Entity).Address;
            UInt32         length     = ((CodeLabel)Entity).Length;
            SnesMemoryType type       = ((CodeLabel)Entity).MemoryType;
            CodeLabel      sameLabel  = LabelManager.GetLabel(txtLabel.Text);
            int            maxAddress = DebugApi.GetMemorySize(type) - 1;

            if (maxAddress <= 0)
            {
                lblRange.Text = "(unavailable)";
            }
            else
            {
                lblRange.Text = "(Max: $" + maxAddress.ToString("X4") + ")";
            }

            for (UInt32 i = 0; i < length; i++)
            {
                CodeLabel sameAddress = LabelManager.GetLabel(address + i, type);
                if (sameAddress != null)
                {
                    if (_originalLabel == null)
                    {
                        //A label already exists and we're not editing an existing label, so we can't add it
                        return(false);
                    }
                    else
                    {
                        if (sameAddress.Label != _originalLabel.Label && !sameAddress.Label.StartsWith(_originalLabel.Label + "+"))
                        {
                            //A label already exists, we're trying to edit an existing label, but the existing label
                            //and the label we're editing aren't the same label.  Can't override an existing label with a different one.
                            return(false);
                        }
                    }
                }
            }

            return
                (length >= 1 && length <= 65536 &&
                 address + (length - 1) <= maxAddress &&
                 (sameLabel == null || sameLabel == _originalLabel) &&
                 (txtLabel.Text.Length > 0 || txtComment.Text.Length > 0) &&
                 !txtComment.Text.Contains('\x1') &&
                 (txtLabel.Text.Length == 0 || LabelManager.LabelRegex.IsMatch(txtLabel.Text)));
        }
Exemplo n.º 8
0
        private static string ProcessArrayDisplaySyntax(bool useHex, ref bool forceHasChanged, Match match)
        {
            string newValue;
            int    address;

            if (match.Groups[2].Value.Length > 0)
            {
                address = int.Parse(match.Groups[2].Value.Substring(1), System.Globalization.NumberStyles.HexNumber);
            }
            else if (match.Groups[3].Value.Length > 0)
            {
                address = int.Parse(match.Groups[3].Value);
            }
            else
            {
                CodeLabel label = LabelManager.GetLabel(match.Groups[4].Value);
                if (label == null)
                {
                    forceHasChanged = true;
                    return("<invalid label>");
                }
                address = label.GetRelativeAddress();
            }
            int elemCount = int.Parse(match.Groups[5].Value);

            if (address >= 0)
            {
                List <string> values = new List <string>(elemCount);
                for (int j = address, end = address + elemCount; j < end; j++)
                {
                    int memValue = InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (uint)j);
                    values.Add(useHex ? memValue.ToString("X2") : memValue.ToString());
                }
                newValue = string.Join(" ", values);
            }
            else
            {
                newValue        = "<label out of scope>";
                forceHasChanged = true;
            }

            return(newValue);
        }
Exemplo n.º 9
0
        public static void CreateAutomaticJumpLabels()
        {
            byte[]           cdlData     = InteropEmu.DebugGetPrgCdlData();
            List <CodeLabel> labelsToAdd = new List <CodeLabel>();

            for (int i = 0; i < cdlData.Length; i++)
            {
                if ((cdlData[i] & (byte)(CdlPrgFlags.JumpTarget | CdlPrgFlags.SubEntryPoint)) != 0)
                {
                    CodeLabel existingLabel = LabelManager.GetLabel((uint)i, AddressType.PrgRom);
                    if (existingLabel == null)
                    {
                        labelsToAdd.Add(new CodeLabel()
                        {
                            Flags       = CodeLabelFlags.AutoJumpLabel,
                            Address     = (uint)i,
                            AddressType = AddressType.PrgRom,
                            Label       = ((cdlData[i] & (byte)CdlPrgFlags.SubEntryPoint) == 0 ? "L" : "F") + i.ToString("X4"),
                            Comment     = ""
                        });
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(existingLabel.Label))
                        {
                            //A comment exists for this address, add the label to it, but keep the comment and don't mark it as a auto-label
                            labelsToAdd.Add(new CodeLabel()
                            {
                                Address     = (uint)i,
                                AddressType = AddressType.PrgRom,
                                Label       = ((cdlData[i] & (byte)CdlPrgFlags.SubEntryPoint) == 0 ? "L" : "F") + i.ToString("X4"),
                                Comment     = existingLabel.Comment
                            });
                        }
                    }
                }
            }

            if (labelsToAdd.Count > 0)
            {
                LabelManager.SetLabels(labelsToAdd, true);
            }
        }
        private void txtTraceLog_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                string suffix = "";
                string word   = txtTraceLog.GetWordUnderLocation(e.Location);
                if (word.StartsWith("$"))
                {
                    _destination = new GoToDestination()
                    {
                        CpuAddress = Int32.Parse(word.Substring(1), System.Globalization.NumberStyles.AllowHexSpecifier)
                    };
                    suffix += " (" + word + ")";
                }
                else
                {
                    CodeLabel label = LabelManager.GetLabel(word);
                    if (label != null)
                    {
                        _destination = new GoToDestination()
                        {
                            Label = label
                        };
                        suffix += " (" + label.Label + ")";
                    }
                    else
                    {
                        //Use the current row's address
                        _destination = new GoToDestination()
                        {
                            CpuAddress = txtTraceLog.CurrentLine,
                        };
                        suffix += " ($" + txtTraceLog.CurrentLine.ToString("X4") + ")";
                    }
                }

                mnuViewInDisassembly.Enabled  = DebugWindowManager.GetDebugger() != null;
                mnuEditInMemoryViewer.Enabled = true;

                mnuEditInMemoryViewer.Text = "Edit in Memory Viewer" + suffix;
                mnuViewInDisassembly.Text  = "View in Disassembly" + suffix;
            }
        }
Exemplo n.º 11
0
        public static void CreateAutomaticJumpLabels()
        {
            bool[]           jumpTargets = InteropEmu.DebugGetJumpTargets();
            List <CodeLabel> labelsToAdd = new List <CodeLabel>();

            for (int i = 0; i < jumpTargets.Length; i++)
            {
                if (jumpTargets[i] && LabelManager.GetLabel((uint)i, AddressType.PrgRom) == null)
                {
                    labelsToAdd.Add(new CodeLabel()
                    {
                        Flags = CodeLabelFlags.AutoJumpLabel, Address = (uint)i, AddressType = AddressType.PrgRom, Label = "L" + i.ToString("X4"), Comment = ""
                    });
                }
            }
            if (labelsToAdd.Count > 0)
            {
                LabelManager.SetLabels(labelsToAdd, true);
            }
        }
Exemplo n.º 12
0
        public static void CreateAutomaticJumpLabels()
        {
            byte[]           cdlData     = InteropEmu.DebugGetPrgCdlData();
            List <CodeLabel> labelsToAdd = new List <CodeLabel>();

            for (int i = 0; i < cdlData.Length; i++)
            {
                if ((cdlData[i] & (byte)CdlPrgFlags.JumpTarget) != 0 && LabelManager.GetLabel((uint)i, AddressType.PrgRom) == null)
                {
                    labelsToAdd.Add(new CodeLabel()
                    {
                        Flags = CodeLabelFlags.AutoJumpLabel, Address = (uint)i, AddressType = AddressType.PrgRom, Label = "L" + i.ToString("X4"), Comment = ""
                    });
                }
            }
            if (labelsToAdd.Count > 0)
            {
                LabelManager.SetLabels(labelsToAdd, true);
            }
        }
Exemplo n.º 13
0
        public string GetAddressLabel()
        {
            UInt32 address = AddressType == BreakpointAddressType.SingleAddress ? this.Address : this.StartAddress;

            if (IsCpuBreakpoint)
            {
                CodeLabel label;
                if (this.IsAbsoluteAddress)
                {
                    label = LabelManager.GetLabel(address, GUI.AddressType.PrgRom);
                }
                else
                {
                    label = LabelManager.GetLabel((UInt16)address);
                }
                if (label != null)
                {
                    return(label.Label);
                }
            }
            return(string.Empty);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        private void picPicture_MouseMove(object sender, MouseEventArgs e)
        {
            Point pos = GetCycleScanline(e.Location);

            if (_lastPos == pos)
            {
                return;
            }

            EventViewerDisplayOptions options = ConfigManager.Config.Debug.EventViewer.GetInteropOptions();
            DebugEventInfo            evt     = DebugApi.GetEventViewerEvent((UInt16)pos.Y, (UInt16)pos.X, options);

            if (evt.ProgramCounter == 0xFFFFFFFF)
            {
                ResetTooltip();
                UpdateOverlay(e.Location);
                return;
            }

            Dictionary <string, string> values = new Dictionary <string, string>()
            {
                { "Type", ResourceHelper.GetEnumText(evt.Type) },
                { "Scanline", evt.Scanline.ToString() },
                { "Cycle", evt.Cycle.ToString() },
                { "PC", "$" + evt.ProgramCounter.ToString("X6") },
            };

            switch (evt.Type)
            {
            case DebugEventType.Register:
                bool isWrite = evt.Operation.Type == MemoryOperationType.Write || evt.Operation.Type == MemoryOperationType.DmaWrite;
                bool isDma   = evt.Operation.Type == MemoryOperationType.DmaWrite || evt.Operation.Type == MemoryOperationType.DmaRead;

                CodeLabel label = LabelManager.GetLabel(new AddressInfo()
                {
                    Address = (int)evt.Operation.Address, Type = SnesMemoryType.CpuMemory
                });
                string registerText = "$" + evt.Operation.Address.ToString("X4");
                if (label != null)
                {
                    registerText = label.Label + " (" + registerText + ")";
                }

                values["Register"] = registerText + (isWrite ? " (Write)" : " (Read)") + (isDma ? " (DMA)" : "");
                values["Value"]    = "$" + evt.Operation.Value.ToString("X2");

                if (isDma)
                {
                    bool indirectHdma = false;
                    values["Channel"] = evt.DmaChannel.ToString();
                    if (evt.DmaChannelInfo.InterruptedByHdma != 0)
                    {
                        indirectHdma           = evt.DmaChannelInfo.HdmaIndirectAddressing != 0;
                        values["Channel"]     += indirectHdma ? " (Indirect HDMA)" : " (HDMA)";
                        values["Line Counter"] = "$" + evt.DmaChannelInfo.HdmaLineCounterAndRepeat.ToString("X2");
                    }
                    values["Mode"] = evt.DmaChannelInfo.TransferMode.ToString();

                    int aBusAddress;
                    if (indirectHdma)
                    {
                        aBusAddress = (evt.DmaChannelInfo.SrcBank << 16) | evt.DmaChannelInfo.TransferSize;
                    }
                    else
                    {
                        aBusAddress = (evt.DmaChannelInfo.SrcBank << 16) | evt.DmaChannelInfo.SrcAddress;
                    }

                    if (evt.DmaChannelInfo.InvertDirection == 0)
                    {
                        values["Transfer"] = "$" + aBusAddress.ToString("X4") + " -> $" + evt.DmaChannelInfo.DestAddress.ToString("X2");
                    }
                    else
                    {
                        values["Transfer"] = "$" + aBusAddress.ToString("X4") + " <- $" + evt.DmaChannelInfo.DestAddress.ToString("X2");
                    }
                }
                break;

            case DebugEventType.Breakpoint:
                //TODO

                /*ReadOnlyCollection<Breakpoint> breakpoints = BreakpointManager.Breakpoints;
                 * if(debugEvent.BreakpointId >= 0 && debugEvent.BreakpointId < breakpoints.Count) {
                 *      Breakpoint bp = breakpoints[debugEvent.BreakpointId];
                 *      values["BP Type"] = bp.ToReadableType();
                 *      values["BP Addresses"] = bp.GetAddressString(true);
                 *      if(bp.Condition.Length > 0) {
                 *              values["BP Condition"] = bp.Condition;
                 *      }
                 * }*/
                break;
            }

            UpdateOverlay(new Point((int)(evt.Cycle * 2 * this.ImageScale), (int)(evt.Scanline * 2 * this.ImageScale)));

            Form  parentForm = this.FindForm();
            Point location   = parentForm.PointToClient(this.PointToScreen(new Point(e.Location.X - picViewer.ScrollOffsets.X, e.Location.Y - picViewer.ScrollOffsets.Y)));

            BaseForm.GetPopupTooltip(parentForm).SetTooltip(location, values);
        }
Exemplo n.º 16
0
        public void Prepare(long firstByteIndex, long lastByteIndex)
        {
            int visibleByteCount = (int)(lastByteIndex - firstByteIndex + 1);

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

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

            _counters = DebugApi.GetMemoryAccessCounts((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType);

            _cdlData = null;
            if (_highlightDataBytes || _highlightCodeBytes)
            {
                switch (_memoryType)
                {
                case SnesMemoryType.CpuMemory:
                case SnesMemoryType.Sa1Memory:
                case SnesMemoryType.Cx4Memory:
                case SnesMemoryType.GsuMemory:
                case SnesMemoryType.GameboyMemory:
                case SnesMemoryType.PrgRom:
                case SnesMemoryType.GbPrgRom:
                    _cdlData = DebugApi.GetCdlData((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType);
                    break;
                }
            }

            _hasLabel = new bool[visibleByteCount];
            if (_highlightLabelledBytes)
            {
                if (_memoryType <= SnesMemoryType.SpcMemory)
                {
                    AddressInfo addr = new AddressInfo();
                    addr.Type = _memoryType;
                    for (long i = 0; i < _hasLabel.Length; i++)
                    {
                        addr.Address = (int)(firstByteIndex + i);
                        _hasLabel[i] = !string.IsNullOrWhiteSpace(LabelManager.GetLabel(addr)?.Label);
                    }
                }
                else if (_memoryType == SnesMemoryType.PrgRom || _memoryType == SnesMemoryType.WorkRam || _memoryType == SnesMemoryType.SaveRam)
                {
                    for (long i = 0; i < _hasLabel.Length; i++)
                    {
                        _hasLabel[i] = !string.IsNullOrWhiteSpace(LabelManager.GetLabel((uint)(firstByteIndex + i), _memoryType)?.Label);
                    }
                }
            }

            _state = DebugApi.GetState();
        }
Exemplo n.º 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();
                }
            }
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
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;
                }
            }
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
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;
            }
        }
Exemplo n.º 22
0
        private bool UpdateContextMenu(Point mouseLocation)
        {
            UpdateContextMenuItemVisibility(true);

            string word = GetWordUnderLocation(mouseLocation);

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

                if (word.StartsWith("$"))
                {
                    _lastClickedAddress = Int32.Parse(word.Substring(1), System.Globalization.NumberStyles.AllowHexSpecifier);
                    _newWatchValue      = "[$" + _lastClickedAddress.ToString("X") + "]";
                }
                else
                {
                    _lastClickedAddress = (Int32)InteropEmu.DebugGetRelativeAddress(LabelManager.GetLabel(word).Address, LabelManager.GetLabel(word).AddressType);
                    _newWatchValue      = "[" + word + "]";
                }

                mnuGoToLocation.Enabled = true;
                mnuGoToLocation.Text    = $"Go to Location ({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})";

                return(true);
            }
            else
            {
                mnuGoToLocation.Enabled    = false;
                mnuGoToLocation.Text       = "Go to Location";
                mnuAddToWatch.Enabled      = false;
                mnuAddToWatch.Text         = "Add to Watch";
                mnuFindOccurrences.Enabled = false;
                mnuFindOccurrences.Text    = "Find Occurrences";
                mnuEditLabel.Enabled       = false;
                mnuEditLabel.Text          = "Edit Label";

                _lastClickedAddress = ctrlCodeViewer.GetLineNumberAtPosition(mouseLocation.Y);
                if (mouseLocation.X < this.ctrlCodeViewer.CodeMargin && _lastClickedAddress >= 0)
                {
                    //Cursor is in the margin, over an address label
                    string address = $"${_lastClickedAddress.ToString("X4")}";
                    _newWatchValue = $"[{address}]";
                    _lastWord      = 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})";

                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 23
0
        private void UpdateResults()
        {
            string searchString = txtSearch.Text.Trim();

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

            searchStrings.Add(searchString.ToLower());
            searchStrings.AddRange(searchString.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            for (int i = 0; i < searchString.Length; i++)
            {
                char ch = searchString[i];
                if (ch >= 'A' && ch <= 'Z')
                {
                    searchString = searchString.Remove(i, 1).Insert(i, " " + (char)(ch + 'a' - 'A'));
                }
            }
            searchStrings.AddRange(searchString.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            searchStrings = searchStrings.Distinct().ToList();

            _resultCount = 0;

            HashSet <int> entryPoints = new HashSet <int>(InteropEmu.DebugGetFunctionEntryPoints());

            byte[] cdlData = InteropEmu.DebugGetPrgCdlData();

            List <SearchResultInfo> searchResults = new List <SearchResultInfo>();

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                if (_symbolProvider != null)
                {
                    if (_showFilesAndConstants)
                    {
                        foreach (Ld65DbgImporter.FileInfo file in _symbolProvider.Files.Values)
                        {
                            if (Contains(file.Name, searchStrings))
                            {
                                searchResults.Add(new SearchResultInfo()
                                {
                                    Caption          = Path.GetFileName(file.Name),
                                    AbsoluteAddress  = -1,
                                    MemoryType       = AddressType.InternalRam,
                                    SearchResultType = SearchResultType.File,
                                    Filename         = file.Name,
                                    FileLineNumber   = 0,
                                    RelativeAddress  = -1,
                                    CodeLabel        = null
                                });
                            }
                        }
                    }

                    foreach (Ld65DbgImporter.SymbolInfo symbol in _symbolProvider.GetSymbols())
                    {
                        if (Contains(symbol.Name, searchStrings))
                        {
                            Ld65DbgImporter.ReferenceInfo def = _symbolProvider.GetSymbolDefinition(symbol);
                            AddressTypeInfo addressInfo       = _symbolProvider.GetSymbolAddressInfo(symbol);
                            int             value             = 0;
                            int             relAddress        = -1;
                            bool            isConstant        = addressInfo == null;
                            if (!_showFilesAndConstants && isConstant)
                            {
                                continue;
                            }

                            if (addressInfo != null)
                            {
                                value      = InteropEmu.DebugGetMemoryValue(addressInfo.Type.ToMemoryType(), (uint)addressInfo.Address);
                                relAddress = InteropEmu.DebugGetRelativeAddress((uint)addressInfo.Address, addressInfo.Type);
                            }
                            else
                            {
                                //For constants, the address field contains the constant's value
                                value = symbol.Address ?? 0;
                            }

                            SearchResultType resultType = SearchResultType.Data;
                            if (addressInfo?.Type == AddressType.PrgRom && entryPoints.Contains(addressInfo.Address))
                            {
                                resultType = SearchResultType.Function;
                            }
                            else if (addressInfo?.Type == AddressType.PrgRom && addressInfo.Address < cdlData.Length && (cdlData[addressInfo.Address] & (byte)CdlPrgFlags.JumpTarget) != 0)
                            {
                                resultType = SearchResultType.JumpTarget;
                            }
                            else if (isConstant)
                            {
                                resultType = SearchResultType.Constant;
                            }

                            searchResults.Add(new SearchResultInfo()
                            {
                                Caption          = symbol.Name,
                                AbsoluteAddress  = addressInfo?.Address ?? -1,
                                MemoryType       = addressInfo?.Type ?? AddressType.InternalRam,
                                SearchResultType = resultType,
                                Value            = value,
                                Filename         = def?.FileName ?? "",
                                FileLineNumber   = def?.LineNumber ?? 0,
                                RelativeAddress  = relAddress,
                                CodeLabel        = LabelManager.GetLabel(symbol.Name)
                            });
                        }
                    }
                }
                else
                {
                    foreach (CodeLabel label in LabelManager.GetLabels())
                    {
                        if (Contains(label.Label, searchStrings))
                        {
                            SearchResultType resultType = SearchResultType.Data;
                            if (label.AddressType == AddressType.PrgRom && entryPoints.Contains((int)label.Address))
                            {
                                resultType = SearchResultType.Function;
                            }
                            else if (label.AddressType == AddressType.PrgRom && label.Address < cdlData.Length && (cdlData[label.Address] & (byte)CdlPrgFlags.JumpTarget) != 0)
                            {
                                resultType = SearchResultType.JumpTarget;
                            }

                            int relativeAddress = label.GetRelativeAddress();

                            searchResults.Add(new SearchResultInfo()
                            {
                                Caption          = label.Label,
                                AbsoluteAddress  = (int)label.Address,
                                Value            = label.GetValue(),
                                MemoryType       = label.AddressType,
                                SearchResultType = resultType,
                                Filename         = "",
                                Disabled         = !_allowOutOfScope && relativeAddress < 0,
                                RelativeAddress  = relativeAddress,
                                CodeLabel        = label
                            });
                        }
                    }
                }
            }

            searchResults.Sort((SearchResultInfo a, SearchResultInfo b) => {
                int comparison = a.Disabled.CompareTo(b.Disabled);

                if (comparison == 0)
                {
                    bool aStartsWithSearch = a.Caption.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase);
                    bool bStartsWithSearch = b.Caption.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase);

                    comparison = bStartsWithSearch.CompareTo(aStartsWithSearch);
                    if (comparison == 0)
                    {
                        comparison = a.Caption.CompareTo(b.Caption);
                    }
                }
                return(comparison);
            });

            _resultCount   = Math.Min(searchResults.Count, MaxResultCount);
            SelectedResult = 0;

            if (searchResults.Count == 0)
            {
                searchResults.Add(new SearchResultInfo()
                {
                    Caption = "No results found.", AbsoluteAddress = -1
                });
                pnlResults.BackColor = SystemColors.ControlLight;
            }
            else
            {
                pnlResults.BackColor = SystemColors.ControlDarkDark;
            }

            if (Program.IsMono)
            {
                pnlResults.Visible = false;
            }
            else
            {
                //Suspend layout causes a crash on Mono
                tlpResults.SuspendLayout();
            }

            for (int i = 0; i < _resultCount; i++)
            {
                _results[i].Initialize(searchResults[i]);
                _results[i].Tag     = searchResults[i];
                _results[i].Visible = true;
            }

            for (int i = searchResults.Count; i < MaxResultCount; i++)
            {
                _results[i].Visible = false;
            }

            pnlResults.VerticalScroll.Value = 0;
            tlpResults.Height = (_results[0].Height + 1) * _resultCount;

            pnlResults.ResumeLayout();
            if (Program.IsMono)
            {
                pnlResults.Visible = true;
                tlpResults.Width   = pnlResults.ClientSize.Width - 17;
            }
            else
            {
                tlpResults.ResumeLayout();
                tlpResults.Width = pnlResults.ClientSize.Width - 1;
            }
        }
Exemplo n.º 24
0
        private void picPicture_MouseMove(object sender, MouseEventArgs e)
        {
            DebugEventInfo?result = GetEventAtPosition(e.Location);

            if (result == null)
            {
                ResetTooltip();
                UpdateOverlay(e.Location);
                return;
            }

            DebugEventInfo evt    = result.Value;
            Point          newPos = new Point(evt.Cycle, evt.Scanline);

            if (_lastPos == newPos)
            {
                return;
            }

            Dictionary <string, string> values;

            if (this.CpuType == CpuType.Gameboy)
            {
                values = new Dictionary <string, string>()
                {
                    { "Type", ResourceHelper.GetEnumText(evt.Type) },
                    { "Scanline", evt.Scanline.ToString() },
                    { "Cycle", evt.Cycle.ToString() },
                    { "PC", "$" + evt.ProgramCounter.ToString("X4") },
                };
            }
            else
            {
                values = new Dictionary <string, string>()
                {
                    { "Type", ResourceHelper.GetEnumText(evt.Type) },
                    { "Scanline", evt.Scanline.ToString() },
                    { "H-Clock", evt.Cycle.ToString() + " (" + GetCycle(evt.Cycle) + ")" },
                    { "PC", "$" + evt.ProgramCounter.ToString("X6") },
                };
            }

            switch (evt.Type)
            {
            case DebugEventType.Register:
                bool isWrite = evt.Operation.Type == MemoryOperationType.Write || evt.Operation.Type == MemoryOperationType.DmaWrite;
                bool isDma   = evt.Operation.Type == MemoryOperationType.DmaWrite || evt.Operation.Type == MemoryOperationType.DmaRead;

                CodeLabel label = LabelManager.GetLabel(new AddressInfo()
                {
                    Address = (int)evt.Operation.Address, Type = SnesMemoryType.CpuMemory
                });
                string registerText = "$" + evt.Operation.Address.ToString("X4");
                if (label != null)
                {
                    registerText = label.Label + " (" + registerText + ")";
                }

                values["Register"] = registerText + (isWrite ? " (Write)" : " (Read)") + (isDma ? " (DMA)" : "");
                values["Value"]    = "$" + evt.Operation.Value.ToString("X2");

                if (isDma && this.CpuType != CpuType.Gameboy)
                {
                    bool indirectHdma = false;
                    values["Channel"] = (evt.DmaChannel & 0x07).ToString();

                    if ((evt.DmaChannel & ctrlEventViewerPpuView.HdmaChannelFlag) != 0)
                    {
                        indirectHdma           = evt.DmaChannelInfo.HdmaIndirectAddressing;
                        values["Channel"]     += indirectHdma ? " (Indirect HDMA)" : " (HDMA)";
                        values["Line Counter"] = "$" + evt.DmaChannelInfo.HdmaLineCounterAndRepeat.ToString("X2");
                    }

                    values["Mode"] = evt.DmaChannelInfo.TransferMode.ToString();

                    int aBusAddress;
                    if (indirectHdma)
                    {
                        aBusAddress = (evt.DmaChannelInfo.SrcBank << 16) | evt.DmaChannelInfo.TransferSize;
                    }
                    else
                    {
                        aBusAddress = (evt.DmaChannelInfo.SrcBank << 16) | evt.DmaChannelInfo.SrcAddress;
                    }

                    if (!evt.DmaChannelInfo.InvertDirection)
                    {
                        values["Transfer"] = "$" + aBusAddress.ToString("X4") + " -> $" + evt.DmaChannelInfo.DestAddress.ToString("X2");
                    }
                    else
                    {
                        values["Transfer"] = "$" + aBusAddress.ToString("X4") + " <- $" + evt.DmaChannelInfo.DestAddress.ToString("X2");
                    }
                }
                break;

            case DebugEventType.Breakpoint:
                ReadOnlyCollection <Breakpoint> breakpoints = BreakpointManager.Breakpoints;
                if (evt.BreakpointId >= 0 && evt.BreakpointId < breakpoints.Count)
                {
                    Breakpoint bp = breakpoints[evt.BreakpointId];
                    values["CPU Type"]     = ResourceHelper.GetEnumText(bp.CpuType);
                    values["BP Type"]      = bp.ToReadableType();
                    values["BP Addresses"] = bp.GetAddressString(true);
                    if (bp.Condition.Length > 0)
                    {
                        values["BP Condition"] = bp.Condition;
                    }
                }
                break;
            }

            UpdateOverlay(new Point((int)(evt.Cycle / _xRatio * this.ImageScale), (int)(evt.Scanline * 2 * this.ImageScale)));

            Form  parentForm = this.FindForm();
            Point location   = parentForm.PointToClient(Control.MousePosition);

            BaseForm.GetPopupTooltip(parentForm).SetTooltip(location, values);
        }
Exemplo n.º 25
0
        private void UpdateResults()
        {
            string searchString = txtSearch.Text.Trim();

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

            searchStrings.Add(searchString.ToLower());
            searchStrings.AddRange(searchString.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            for (int i = 0; i < searchString.Length; i++)
            {
                char ch = searchString[i];
                if (ch >= 'A' && ch <= 'Z')
                {
                    searchString = searchString.Remove(i, 1).Insert(i, " " + (char)(ch + 'a' - 'A'));
                }
            }
            searchStrings.AddRange(searchString.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            searchStrings = searchStrings.Distinct().ToList();

            _resultCount = 0;

            int size = DebugApi.GetMemorySize(SnesMemoryType.PrgRom);

            byte[] cdlData = DebugApi.GetCdlData(0, (uint)size, SnesMemoryType.PrgRom);

            List <SearchResultInfo> searchResults = new List <SearchResultInfo>();
            bool isEmptySearch = string.IsNullOrWhiteSpace(searchString);

            if (!isEmptySearch)
            {
                if (_symbolProvider != null)
                {
                    if (_showFilesAndConstants)
                    {
                        foreach (SourceFileInfo file in _symbolProvider.SourceFiles)
                        {
                            if (Contains(file.Name, searchStrings))
                            {
                                searchResults.Add(new SearchResultInfo()
                                {
                                    Caption          = Path.GetFileName(file.Name),
                                    AbsoluteAddress  = null,
                                    SearchResultType = SearchResultType.File,
                                    File             = file,
                                    SourceLocation   = null,
                                    RelativeAddress  = null,
                                    CodeLabel        = null
                                });
                            }
                        }
                    }

                    foreach (SourceSymbol symbol in _symbolProvider.GetSymbols())
                    {
                        if (Contains(symbol.Name, searchStrings))
                        {
                            SourceCodeLocation def         = _symbolProvider.GetSymbolDefinition(symbol);
                            AddressInfo?       addressInfo = _symbolProvider.GetSymbolAddressInfo(symbol);
                            int         value      = 0;
                            AddressInfo?relAddress = null;
                            bool        isConstant = addressInfo == null;
                            if (!_showFilesAndConstants && isConstant)
                            {
                                continue;
                            }

                            if (addressInfo != null)
                            {
                                value      = DebugApi.GetMemoryValue(addressInfo.Value.Type, (uint)addressInfo.Value.Address);
                                relAddress = DebugApi.GetRelativeAddress(addressInfo.Value, CpuType.Cpu);                                 //TODO
                            }
                            else
                            {
                                //For constants, the address field contains the constant's value
                                value = symbol.Address ?? 0;
                            }

                            SearchResultType resultType = SearchResultType.Data;
                            if (isConstant)
                            {
                                resultType = SearchResultType.Constant;
                            }
                            else if (addressInfo?.Type == SnesMemoryType.PrgRom && addressInfo.Value.Address < cdlData.Length)
                            {
                                if ((cdlData[addressInfo.Value.Address] & (byte)CdlFlags.JumpTarget) != 0)
                                {
                                    resultType = SearchResultType.JumpTarget;
                                }
                                else if ((cdlData[addressInfo.Value.Address] & (byte)CdlFlags.SubEntryPoint) != 0)
                                {
                                    resultType = SearchResultType.Function;
                                }
                            }

                            searchResults.Add(new SearchResultInfo()
                            {
                                Caption          = symbol.Name,
                                AbsoluteAddress  = addressInfo,
                                Length           = _symbolProvider.GetSymbolSize(symbol),
                                SearchResultType = resultType,
                                Value            = value,
                                File             = def?.File,
                                SourceLocation   = def,
                                RelativeAddress  = relAddress,
                                CodeLabel        = LabelManager.GetLabel(symbol.Name)
                            });
                        }
                    }
                }
                else
                {
                    foreach (CodeLabel label in LabelManager.GetLabels(CpuType.Cpu))                      //TODO
                    {
                        if (Contains(label.Label, searchStrings))
                        {
                            SearchResultType resultType  = SearchResultType.Data;
                            AddressInfo      addressInfo = label.GetAbsoluteAddress();
                            if (addressInfo.Type == SnesMemoryType.PrgRom && addressInfo.Address < cdlData.Length)
                            {
                                if ((cdlData[addressInfo.Address] & (byte)CdlFlags.JumpTarget) != 0)
                                {
                                    resultType = SearchResultType.JumpTarget;
                                }
                                else if ((cdlData[addressInfo.Address] & (byte)CdlFlags.SubEntryPoint) != 0)
                                {
                                    resultType = SearchResultType.Function;
                                }
                            }

                            AddressInfo relAddress = label.GetRelativeAddress(CpuType.Cpu);                             //TODO
                            searchResults.Add(new SearchResultInfo()
                            {
                                Caption          = label.Label,
                                AbsoluteAddress  = label.GetAbsoluteAddress(),
                                Length           = (int)label.Length,
                                Value            = label.GetValue(),
                                SearchResultType = resultType,
                                File             = null,
                                Disabled         = !_allowOutOfScope && relAddress.Address < 0,
                                RelativeAddress  = relAddress,
                                CodeLabel        = label
                            });
                        }
                    }
                }
            }

            searchResults.Sort((SearchResultInfo a, SearchResultInfo b) => {
                int comparison = a.Disabled.CompareTo(b.Disabled);

                if (comparison == 0)
                {
                    bool aStartsWithSearch = a.Caption.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase);
                    bool bStartsWithSearch = b.Caption.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase);

                    comparison = bStartsWithSearch.CompareTo(aStartsWithSearch);
                    if (comparison == 0)
                    {
                        comparison = a.Caption.CompareTo(b.Caption);
                    }
                }
                return(comparison);
            });

            _resultCount   = Math.Min(searchResults.Count, MaxResultCount);
            SelectedResult = 0;

            lblResultCount.Visible = !isEmptySearch;
            lblResultCount.Text    = searchResults.Count.ToString() + (searchResults.Count == 1 ? " result" : " results");
            if (searchResults.Count > MaxResultCount)
            {
                lblResultCount.Text += " (" + MaxResultCount.ToString() + " shown)";
            }

            if (searchResults.Count == 0 && !isEmptySearch)
            {
                _resultCount++;
                searchResults.Add(new SearchResultInfo()
                {
                    Caption = "No results found."
                });
                pnlResults.BackColor = SystemColors.ControlLight;
            }
            else
            {
                pnlResults.BackColor = SystemColors.ControlDarkDark;
            }

            if (Program.IsMono)
            {
                pnlResults.Visible = false;
            }
            else
            {
                //Suspend layout causes a crash on Mono
                tlpResults.SuspendLayout();
            }

            for (int i = 0; i < _resultCount; i++)
            {
                _results[i].Initialize(searchResults[i]);
                _results[i].Tag     = searchResults[i];
                _results[i].Visible = true;
            }

            for (int i = _resultCount; i < MaxResultCount; i++)
            {
                _results[i].Visible = false;
            }

            pnlResults.VerticalScroll.Value = 0;
            tlpResults.Height = (_results[0].Height + 1) * _resultCount;

            pnlResults.ResumeLayout();
            if (Program.IsMono)
            {
                pnlResults.Visible = true;
                tlpResults.Width   = pnlResults.ClientSize.Width - 17;
            }
            else
            {
                tlpResults.ResumeLayout();
                tlpResults.Width = pnlResults.ClientSize.Width - 1;
            }
        }
Exemplo n.º 26
0
        private void ctrlHexViewer_ByteMouseHover(int address, Point position)
        {
            ctrlTooltip tooltip = BaseForm.GetPopupTooltip(this);

            if (address < 0 || !mnuShowLabelInfoOnMouseOver.Checked)
            {
                _lastTooltipAddress = -1;
                tooltip.Hide();
                return;
            }
            else if (_lastTooltipAddress == address)
            {
                return;
            }

            _lastTooltipAddress = address;

            CodeLabel label       = null;
            int       arrayOffset = 0;

            switch (_memoryType)
            {
            case SnesMemoryType.CpuMemory:
            case SnesMemoryType.SpcMemory:
                AddressInfo relAddress = new AddressInfo()
                {
                    Address = address,
                    Type    = _memoryType
                };
                AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress);
                if (absAddress.Address >= 0)
                {
                    label = LabelManager.GetLabel((uint)absAddress.Address, absAddress.Type);
                    if (label != null)
                    {
                        arrayOffset = relAddress.Address - (int)label.Address;
                    }
                }
                break;

            case SnesMemoryType.WorkRam:
            case SnesMemoryType.SaveRam:
            case SnesMemoryType.PrgRom:
            case SnesMemoryType.SpcRam:
            case SnesMemoryType.SpcRom:
                label = LabelManager.GetLabel((uint)address, _memoryType);
                if (label != null)
                {
                    arrayOffset = address - (int)label.Address;
                }
                break;
            }

            if (label != null && !string.IsNullOrWhiteSpace(label.Label))
            {
                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["Type"]    = ResourceHelper.GetEnumText(label.MemoryType);
                if (!string.IsNullOrWhiteSpace(label.Comment))
                {
                    values["Comment"] = label.Comment;
                }

                tooltip.SetTooltip(this.PointToClient(position), values);
            }
            else
            {
                tooltip.Hide();
            }
        }