Exemplo n.º 1
0
        public static void DeleteLabel(CodeLabel label, bool raiseEvent)
        {
            bool needEvent = false;

            _labels.Remove(label);
            for (UInt32 i = label.Address; i < label.Address + label.Length; i++)
            {
                UInt64 key = GetKey(i, label.MemoryType);
                if (_labelsByKey.ContainsKey(key))
                {
                    _reverseLookup.Remove(_labelsByKey[key].Label);
                }

                if (_labelsByKey.Remove(key))
                {
                    DebugApi.SetLabel(i, label.MemoryType, string.Empty, string.Empty);
                    if (raiseEvent)
                    {
                        needEvent = true;
                    }
                }
            }

            if (needEvent)
            {
                ProcessLabelUpdate();
                RefreshDisassembly(label);
            }
        }
Exemplo 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, SnesMemoryType.PrgRom) == null) {
         *                      labelsToAdd.Add(new CodeLabel() { Flags = CodeLabelFlags.AutoJumpLabel, Address = (uint)i, SnesMemoryType = SnesMemoryType.PrgRom, Label = "L" + i.ToString("X4"), Comment = "" });
         *              }
         *      }
         *      if(labelsToAdd.Count > 0) {
         *              LabelManager.SetLabels(labelsToAdd, true);
         *      }
         * }*/

        private static void RefreshDisassembly(CodeLabel label)
        {
            if (label.MemoryType.ToCpuType() == CpuType.Spc)
            {
                DebugApi.RefreshDisassembly(CpuType.Spc);
            }
            else
            {
                DebugApi.RefreshDisassembly(CpuType.Cpu);
                DebugApi.RefreshDisassembly(CpuType.Sa1);
            }
        }
Exemplo n.º 3
0
        public static bool SetLabel(CodeLabel label, bool raiseEvent)
        {
            if (_reverseLookup.ContainsKey(label.Label))
            {
                //Another identical label exists, we need to remove it
                DeleteLabel(_reverseLookup[label.Label], false);
            }

            string comment = label.Comment;

            for (UInt32 i = label.Address; i < label.Address + label.Length; i++)
            {
                UInt64    key = GetKey(i, label.MemoryType);
                CodeLabel existingLabel;
                if (_labelsByKey.TryGetValue(key, out existingLabel))
                {
                    DeleteLabel(existingLabel, false);
                    _reverseLookup.Remove(existingLabel.Label);
                }

                _labelsByKey[key] = label;

                if (label.Length == 1)
                {
                    DebugApi.SetLabel(i, label.MemoryType, label.Label, comment.Replace(Environment.NewLine, "\n"));
                }
                else
                {
                    DebugApi.SetLabel(i, label.MemoryType, label.Label + "+" + (i - label.Address).ToString(), comment.Replace(Environment.NewLine, "\n"));

                    //Only set the comment on the first byte of multi-byte comments
                    comment = "";
                }
            }

            _labels.Add(label);
            if (label.Label.Length > 0)
            {
                _reverseLookup[label.Label] = label;
            }

            if (raiseEvent)
            {
                ProcessLabelUpdate();
                RefreshDisassembly(label);
            }

            return(true);
        }
Exemplo n.º 4
0
        public static CodeLabel FromString(string data)
        {
            string[] rowData = data.Split(_separatar, 4);
            if (rowData.Length < 3)
            {
                //Invalid row
                return(null);
            }

            SnesMemoryType type;

            switch (rowData[0])
            {
            case "REG": type = SnesMemoryType.Register; break;

            case "PRG": type = SnesMemoryType.PrgRom; break;

            case "SAVE": type = SnesMemoryType.SaveRam; break;

            case "WORK": type = SnesMemoryType.WorkRam; break;

            case "IRAM": type = SnesMemoryType.Sa1InternalRam; break;

            case "SPCRAM": type = SnesMemoryType.SpcRam; break;

            case "SPCROM": type = SnesMemoryType.SpcRom; break;

            case "PSRAM": type = SnesMemoryType.BsxPsRam; break;

            case "MPACK": type = SnesMemoryType.BsxMemoryPack; break;

            case "DSPPRG": type = SnesMemoryType.DspProgramRom; break;

            case "GBPRG": type = SnesMemoryType.GbPrgRom; break;

            case "GBWRAM": type = SnesMemoryType.GbWorkRam; break;

            case "GBSRAM": type = SnesMemoryType.GbCartRam; break;

            case "GBHRAM": type = SnesMemoryType.GbHighRam; break;

            case "GBBOOT": type = SnesMemoryType.GbBootRom; break;

            case "GBREG": type = SnesMemoryType.GameboyMemory; break;

            default: return(null);
            }

            string addressString = rowData[1];
            uint   address       = 0;
            uint   length        = 1;

            if (addressString.Contains("-"))
            {
                uint     addressEnd;
                string[] addressStartEnd = addressString.Split('-');
                if (UInt32.TryParse(addressStartEnd[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out address) &&
                    UInt32.TryParse(addressStartEnd[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out addressEnd))
                {
                    if (addressEnd > address)
                    {
                        length = addressEnd - address + 1;
                    }
                    else
                    {
                        //Invalid label (start < end)
                        return(null);
                    }
                }
                else
                {
                    //Invalid label (can't parse)
                    return(null);
                }
            }
            else
            {
                if (!UInt32.TryParse(rowData[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out address))
                {
                    //Invalid label (can't parse)
                    return(null);
                }
                length = 1;
            }

            string labelName = rowData[2];

            if (!string.IsNullOrEmpty(labelName) && !LabelManager.LabelRegex.IsMatch(labelName))
            {
                //Reject labels that don't respect the label naming restrictions
                return(null);
            }

            CodeLabel codeLabel;

            codeLabel            = new CodeLabel();
            codeLabel.Address    = address;
            codeLabel.MemoryType = type;
            codeLabel.Label      = labelName;
            codeLabel.Length     = length;
            codeLabel.Comment    = "";

            if (rowData.Length > 3)
            {
                codeLabel.Comment = rowData[3].Replace("\\n", "\n");
            }

            return(codeLabel);
        }