Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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;
            }
        }