public static bool SetLabel(UInt32 address, AddressType type, string label, string comment, bool raiseEvent = true, CodeLabelFlags flags = CodeLabelFlags.None) { if (_reverseLookup.ContainsKey(label)) { //Another identical label exists, we need to remove it CodeLabel existingLabel = _reverseLookup[label]; DeleteLabel(existingLabel.Address, existingLabel.AddressType, false); } UInt32 key = GetKey(address, type); if (_labels.ContainsKey(key)) { _reverseLookup.Remove(_labels[key].Label); } _labels[key] = new CodeLabel() { Address = address, AddressType = type, Label = label, Comment = comment, Flags = flags }; if (label.Length > 0) { _reverseLookup[label] = _labels[key]; } InteropEmu.DebugSetLabel(address, type, label, comment.Replace(Environment.NewLine, "\n")); if (raiseEvent) { OnLabelUpdated?.Invoke(null, null); } return(true); }
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]*$"))); }
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(""); } }
public static void Import(string path, bool silent = false) { List <CodeLabel> labels = new List <CodeLabel>(1000); int errorCount = 0; foreach (string row in File.ReadAllLines(path, Encoding.UTF8)) { CodeLabel label = CodeLabel.FromString(row); if (label == null) { errorCount++; } else { labels.Add(label); } } LabelManager.SetLabels(labels); if (!silent) { string message = $"Import completed with {labels.Count} labels imported"; if (errorCount > 0) { message += $" and {errorCount} error(s)"; } MessageBox.Show(message, "Mesen-S", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static bool SetLabel(UInt32 address, AddressType type, string label, string comment, bool raiseEvent = true) { string key = GetKey(address, type); if (_labels.ContainsKey(key)) { _reverseLookup.Remove(_labels[key].Label); } _labels[key] = new CodeLabel() { Address = address, AddressType = type, Label = label, Comment = comment }; if (label.Length > 0) { _reverseLookup[label] = _labels[key]; } InteropEmu.DebugSetLabel(address, type, label, comment.Replace(Environment.NewLine, "\n")); if (raiseEvent) { OnLabelUpdated?.Invoke(null, null); } return(true); }
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; } } } } }
public frmEditComment(CodeLabel label, CodeLabel originalLabel = null) { InitializeComponent(); _originalLabel = originalLabel; Entity = label; AddBinding("Comment", txtComment); }
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++) { UInt32 key = GetKey(i, label.AddressType); if (_labelsByKey.ContainsKey(key)) { _reverseLookup.Remove(_labelsByKey[key].Label); } if (_labelsByKey.Remove(key)) { InteropEmu.DebugSetLabel(i, label.AddressType, string.Empty, string.Empty); if (raiseEvent) { needEvent = true; } } } if (needEvent) { OnLabelUpdated?.Invoke(null, null); } }
private CodeLabel CreateLabel(Int32 address, bool isRamLabel) { CodeLabel label = null; if (isRamLabel) { if (address < 0x2000) { if (!_ramLabels.TryGetValue(address, out label)) { label = new CodeLabel() { Address = (UInt32)address, AddressType = AddressType.InternalRam, Comment = string.Empty, Label = string.Empty }; _ramLabels[address] = label; } } else if (address >= _workRamStart && address <= _workRamEnd) { int labelAddress = address - _workRamStart; if (!_workRamLabels.TryGetValue(labelAddress, out label)) { label = new CodeLabel() { Address = (UInt32)labelAddress, AddressType = AddressType.WorkRam, Comment = string.Empty, Label = string.Empty }; _workRamLabels[labelAddress] = label; } } else if (address >= _saveRamStart && address <= _saveRamEnd) { int labelAddress = address - _saveRamStart; if (!_saveRamLabels.TryGetValue(labelAddress, out label)) { label = new CodeLabel() { Address = (UInt32)labelAddress, AddressType = AddressType.SaveRam, Comment = string.Empty, Label = string.Empty }; _saveRamLabels[labelAddress] = label; } } } else { if (!_romLabels.TryGetValue(address, out label)) { label = new CodeLabel() { Address = (UInt32)address, AddressType = AddressType.PrgRom, Comment = string.Empty, Label = string.Empty }; _romLabels[address] = label; } } return(label); }
public static void Import(string path, bool silent = false) { //This only works reliably for NROM games with 32kb PRG DebugState state = new DebugState(); InteropEmu.DebugGetState(ref state); bool hasLargePrg = state.Cartridge.PrgRomSize != 0x8000; if (!silent && hasLargePrg) { if (MessageBox.Show($"Warning: Due to .fns file format limitations, imported labels are not reliable for games that have more than 32kb of PRG ROM.\n\nAre you sure you want to import these labels?", "Mesen", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return; } } Dictionary <UInt32, CodeLabel> labels = new Dictionary <uint, CodeLabel>(); char[] separator = new char[1] { '=' }; foreach (string row in File.ReadAllLines(path, Encoding.UTF8)) { string[] rowData = row.Split(separator); if (rowData.Length < 2) { //Invalid row continue; } uint address; if (UInt32.TryParse(rowData[1].Trim().Substring(1), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out address)) { CodeLabel codeLabel; if (!labels.TryGetValue(address, out codeLabel)) { codeLabel = new CodeLabel(); codeLabel.Address = hasLargePrg ? address : (address - 0x8000); codeLabel.AddressType = hasLargePrg ? AddressType.Register : AddressType.PrgRom; codeLabel.Label = ""; codeLabel.Comment = ""; labels[address] = codeLabel; } codeLabel.Label = rowData[0].Trim(); } } LabelManager.SetLabels(labels.Values); if (!silent) { MessageBox.Show($"Import completed with {labels.Values.Count} labels imported.", "Mesen", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static void Import(string path, bool silent = false) { List <CodeLabel> labels = new List <CodeLabel>(1000); int errorCount = 0; foreach (string row in File.ReadAllLines(path, Encoding.UTF8)) { string lineData = row.Trim(); int splitIndex = lineData.IndexOf(' '); UInt32 address; if (!UInt32.TryParse(lineData.Substring(0, splitIndex), NumberStyles.HexNumber, null, out address)) { errorCount++; continue; } AddressInfo absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)address, Type = SnesMemoryType.CpuMemory }); if (absAddress.Address >= 0) { CodeLabel label = new CodeLabel(); label.Address = (UInt32)absAddress.Address; label.MemoryType = absAddress.Type; label.Comment = ""; string labelName = lineData.Substring(splitIndex + 1).Replace('.', '_'); if (string.IsNullOrEmpty(labelName) || !LabelManager.LabelRegex.IsMatch(labelName)) { errorCount++; } else { label.Label = labelName; labels.Add(label); } } } LabelManager.SetLabels(labels); if (!silent) { string message = $"Import completed with {labels.Count} labels imported"; if (errorCount > 0) { message += $" and {errorCount} error(s)"; } MessageBox.Show(message, "Mesen-S", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static bool SetLabel(UInt32 address, AddressType type, string label, string comment, bool raiseEvent = true, CodeLabelFlags flags = CodeLabelFlags.None, UInt32 labelLength = 1) { if (_reverseLookup.ContainsKey(label)) { //Another identical label exists, we need to remove it CodeLabel existingLabel = _reverseLookup[label]; DeleteLabel(existingLabel, false); } CodeLabel newLabel = new CodeLabel() { Address = address, AddressType = type, Label = label, Comment = comment, Flags = flags, Length = labelLength }; for (UInt32 i = address; i < address + labelLength; i++) { UInt32 key = GetKey(i, type); CodeLabel existingLabel; if (_labelsByKey.TryGetValue(key, out existingLabel)) { DeleteLabel(existingLabel, false); _reverseLookup.Remove(existingLabel.Label); } _labelsByKey[key] = newLabel; if (labelLength == 1) { InteropEmu.DebugSetLabel(i, type, label, comment.Replace(Environment.NewLine, "\n")); } else { InteropEmu.DebugSetLabel(i, type, label + "+" + (i - address).ToString(), comment.Replace(Environment.NewLine, "\n")); //Only set the comment on the first byte of multi-byte comments comment = ""; } } _labels.Add(newLabel); if (label.Length > 0) { _reverseLookup[label] = newLabel; } if (raiseEvent) { OnLabelUpdated?.Invoke(null, null); } return(true); }
public frmEditLabel(CodeLabel label, CodeLabel originalLabel = null) { InitializeComponent(); _originalLabel = originalLabel; Entity = label; AddBinding("AddressType", cboRegion); AddBinding("Address", txtAddress); AddBinding("Label", txtLabel); AddBinding("Comment", txtComment); }
private CodeLabel CreateLabel(Int32 address, AddressType addressType, UInt32 length) { CodeLabel label = null; if (addressType == AddressType.InternalRam) { if (!_ramLabels.TryGetValue(address, out label)) { label = new CodeLabel() { Address = (UInt32)address, AddressType = AddressType.InternalRam, Comment = string.Empty, Label = string.Empty, Length = length }; _ramLabels[address] = label; } } else if (addressType == AddressType.WorkRam) { if (!_workRamLabels.TryGetValue(address, out label)) { label = new CodeLabel() { Address = (UInt32)address, AddressType = AddressType.WorkRam, Comment = string.Empty, Label = string.Empty, Length = length }; _workRamLabels[address] = label; } } else if (addressType == AddressType.SaveRam) { if (!_saveRamLabels.TryGetValue(address, out label)) { label = new CodeLabel() { Address = (UInt32)address, AddressType = AddressType.SaveRam, Comment = string.Empty, Label = string.Empty, Length = length }; _saveRamLabels[address] = label; } } else { if (!_romLabels.TryGetValue(address, out label)) { label = new CodeLabel() { Address = (UInt32)address, AddressType = AddressType.PrgRom, Comment = string.Empty, Label = string.Empty, Length = length }; _romLabels[address] = label; } } return(label); }
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]*$"))); }
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; } }
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))); }
public frmEditLabel(CodeLabel label, CodeLabel originalLabel = null) { InitializeComponent(); _originalLabel = originalLabel; Entity = label; _maxPrgRomAddress = Math.Max(0, InteropEmu.DebugGetMemorySize(DebugMemoryType.PrgRom) - 1); _maxWorkRamAddress = Math.Max(0, InteropEmu.DebugGetMemorySize(DebugMemoryType.WorkRam) - 1); _maxSaveRamAddress = Math.Max(0, InteropEmu.DebugGetMemorySize(DebugMemoryType.SaveRam) - 1); AddBinding("AddressType", cboRegion); AddBinding("Address", txtAddress); AddBinding("Label", txtLabel); AddBinding("Comment", txtComment); }
private void LoadLabels() { foreach (KeyValuePair <int, SymbolInfo> kvp in _symbols) { try { SymbolInfo symbol = kvp.Value; if (symbol.SegmentID == null) { continue; } if (_segments.ContainsKey(symbol.SegmentID.Value)) { SegmentInfo segment = _segments[symbol.SegmentID.Value]; int count = 2; string orgSymbolName = symbol.Name; if (!LabelManager.LabelRegex.IsMatch(orgSymbolName)) { //ignore labels that don't respect the label naming restrictions continue; } string newName = symbol.Name; while (!_usedLabels.Add(newName)) { //Ensure labels are unique newName = orgSymbolName + "_" + count.ToString(); count++; } AddressTypeInfo addressInfo = GetSymbolAddressInfo(symbol); if (symbol.Address != null && symbol.Address >= 0) { CodeLabel label = this.CreateLabel(addressInfo.Address, addressInfo.Type, (uint)GetSymbolSize(symbol)); if (label != null) { label.Label = newName; } } } } catch { _errorCount++; } } }
private void LoadLabels() { foreach (KeyValuePair <int, SymbolInfo> kvp in _symbols) { try { SymbolInfo symbol = kvp.Value; if (symbol.SegmentID == null) { continue; } if (_segments.ContainsKey(symbol.SegmentID.Value)) { SegmentInfo segment = _segments[symbol.SegmentID.Value]; int count = 2; string orgSymbolName = symbol.Name; string newName = symbol.Name; while (!_usedLabels.Add(newName)) { //Ensure labels are unique newName = orgSymbolName + "_" + count.ToString(); count++; } int address = GetSymbolAddressInfo(symbol).Value.Address; if (segment.IsRam) { _ramLabels[address] = new CodeLabel() { Label = newName, Address = (UInt32)address, AddressType = AddressType.InternalRam, Comment = string.Empty }; } else { _romLabels[address] = new CodeLabel() { Label = newName, Address = (UInt32)address, AddressType = AddressType.PrgRom, Comment = string.Empty }; } } } catch { _errorCount++; } } }
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); }
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; } }
private void DisplayLabelTooltip(string word, CodeLabel label) { Int32 relativeAddress = InteropEmu.DebugGetRelativeAddress(label.Address, label.AddressType); byte byteValue = relativeAddress >= 0 ? InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress) : (byte)0; UInt16 wordValue = relativeAddress >= 0 ? (UInt16)(byteValue | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0; var values = new Dictionary <string, string>() { { "Label", label.Label }, { "Address", "$" + InteropEmu.DebugGetRelativeAddress(label.Address, label.AddressType).ToString("X4") }, { "Value", (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a") }, }; if (!string.IsNullOrWhiteSpace(label.Comment)) { values["Comment"] = label.Comment; } ShowTooltip(word, values); }
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); } }
public frmEditLabel(CodeLabel label) { InitializeComponent(); _originalLabel = label; Entity = label.Clone(); AddBinding(nameof(CodeLabel.MemoryType), cboType); AddBinding(nameof(CodeLabel.Address), txtAddress); AddBinding(nameof(CodeLabel.Label), txtLabel); AddBinding(nameof(CodeLabel.Comment), txtComment); AddBinding(nameof(CodeLabel.Length), nudLength); CpuType cpuType = label.MemoryType.ToCpuType(); cboType.Items.Clear(); if (cpuType == CpuType.Cpu) { if (DebugApi.GetMemorySize(SnesMemoryType.PrgRom) > 0) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.PrgRom)); } if (DebugApi.GetMemorySize(SnesMemoryType.WorkRam) > 0) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.WorkRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.SaveRam) > 0) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SaveRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.Sa1InternalRam) > 0) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Sa1InternalRam)); } cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Register)); } else if (cpuType == CpuType.Spc) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcRam)); cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcRom)); } }
private void LoadLabels() { foreach (KeyValuePair <int, SymbolInfo> kvp in _symbols) { try { SymbolInfo symbol = kvp.Value; if (_segments.ContainsKey(symbol.SegmentID)) { SegmentInfo segment = _segments[symbol.SegmentID]; int count = 2; string orgSymbolName = symbol.Name; while (!_usedLabels.Add(symbol.Name)) { //Ensure labels are unique symbol.Name = orgSymbolName + "_" + count.ToString(); count++; } if (segment.IsRam) { int address = symbol.Address; _ramLabels[address] = new CodeLabel() { Label = symbol.Name, Address = (UInt32)address, AddressType = AddressType.InternalRam, Comment = string.Empty }; } else { int address = symbol.Address - segment.Start + segment.FileOffset - iNesHeaderSize; _romLabels[address] = new CodeLabel() { Label = symbol.Name, Address = (UInt32)address, AddressType = AddressType.PrgRom, Comment = string.Empty }; } } } catch { _errorCount++; } } }
private void LoadLabels() { foreach (KeyValuePair <int, SymbolInfo> kvp in _symbols) { try { SymbolInfo symbol = kvp.Value; if (symbol.SegmentID == null) { continue; } if (_segments.ContainsKey(symbol.SegmentID.Value)) { SegmentInfo segment = _segments[symbol.SegmentID.Value]; int count = 2; string orgSymbolName = symbol.Name; string newName = symbol.Name; while (!_usedLabels.Add(newName)) { //Ensure labels are unique newName = orgSymbolName + "_" + count.ToString(); count++; } AddressTypeInfo addressInfo = GetSymbolAddressInfo(symbol); if (symbol.Address != null) { int address = addressInfo.Address; CodeLabel label = this.CreateLabel(addressInfo.Address, addressInfo.Type); if (label != null) { label.Label = newName; } } } } catch { _errorCount++; } } }
private void DisplayLabelTooltip(string word, CodeLabel label, int?arrayIndex = null) { int relativeAddress = InteropEmu.DebugGetRelativeAddress((uint)(label.Address + (arrayIndex ?? 0)), label.AddressType); byte byteValue = relativeAddress >= 0 ? InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress) : (byte)0; UInt16 wordValue = relativeAddress >= 0 ? (UInt16)(byteValue | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0; var values = new Dictionary <string, string>() { { "Label", label.Label + (arrayIndex != null ? $"+{arrayIndex.Value}" : "") }, { "Address", "$" + relativeAddress.ToString("X4") }, { "Value", (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a") }, }; if (!string.IsNullOrWhiteSpace(label.Comment)) { values["Comment"] = label.Comment; } ShowTooltip(word, values, -1, new AddressTypeInfo() { Address = (int)label.Address, Type = label.AddressType }); }
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(); } } }
private void LoadComments() { foreach (KeyValuePair <int, LineInfo> kvp in _lines) { try { LineInfo line = kvp.Value; if (line.SpanID == null) { continue; } SpanInfo span = _spans[line.SpanID.Value]; SegmentInfo segment = _segments[span.SegmentID]; if (_files[line.FileID].Data == null) { //File was not found. if (_filesNotFound.Add(_files[line.FileID].Name)) { _errorCount++; } continue; } string ext = Path.GetExtension(_files[line.FileID].Name).ToLower(); bool isAsm = ext != ".c" && ext != ".h"; string comment = ""; for (int i = line.LineNumber; i >= 0; i--) { string sourceCodeLine = _files[line.FileID].Data[i]; if (sourceCodeLine.Trim().Length == 0) { //Ignore empty lines continue; } Regex regex; if (i == line.LineNumber) { regex = isAsm ? _asmFirstLineRegex : _cFirstLineRegex; } else { regex = isAsm ? _asmPreviousLinesRegex : _cPreviousLinesRegex; } Match match = regex.Match(sourceCodeLine); if (match.Success) { string matchedComment = match.Groups[1].Value.Replace("\t", " "); if (string.IsNullOrWhiteSpace(comment)) { comment = matchedComment; } else { comment = matchedComment + Environment.NewLine + comment; } } else if (i != line.LineNumber) { break; } } if (comment.Length > 0) { CodeLabel label; if (segment.IsRam) { int address = span.Offset + segment.Start; if (!_ramLabels.TryGetValue(address, out label)) { label = new CodeLabel() { Address = (UInt32)address, AddressType = AddressType.InternalRam, Label = string.Empty }; _ramLabels[span.Offset] = label; } } else { int address = span.Offset + segment.FileOffset - iNesHeaderSize; if (!_romLabels.TryGetValue(address, out label)) { label = new CodeLabel() { Address = (UInt32)address, AddressType = AddressType.PrgRom, Label = string.Empty }; _romLabels[span.Offset] = label; } } label.Comment = comment; } } catch { _errorCount++; } } }