public void ScrollToAddress(uint address) { if (_inSourceView) { AddressInfo absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)address, Type = SnesMemoryType.CpuMemory }); if (absAddress.Address >= 0) { SourceCodeLocation line = _symbolProvider?.GetSourceCodeLineInfo(absAddress); if (line != null) { foreach (SourceFileInfo fileInfo in cboSourceFile.Items) { if (line.File == fileInfo) { cboSourceFile.SelectedItem = fileInfo; ctrlCode.ScrollToLineIndex(line.LineNumber); return; } } } } ToggleView(); } ctrlCode.ScrollToAddress((int)address); }
private void MarkSelectionAs(CdlFlags type) { if (_memoryType != SnesMemoryType.CpuMemory && _memoryType != SnesMemoryType.PrgRom && _memoryType != SnesMemoryType.GameboyMemory && _memoryType != SnesMemoryType.GbPrgRom) { return; } int start = SelectionStartAddress; int end = SelectionEndAddress; if (_memoryType == SnesMemoryType.CpuMemory || _memoryType == SnesMemoryType.GameboyMemory) { start = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = start, Type = _memoryType }).Address; end = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = end, Type = _memoryType }).Address; } if (start >= 0 && end >= 0 && start <= end) { DebugApi.MarkBytesAs((UInt32)start, (UInt32)end, type); DebugWindowManager.GetDebugger(_memoryType.ToCpuType())?.RefreshDisassembly(); } RefreshData(_memoryType); }
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(""); } }
private void EditInMemoryTools(LocationInfo location) { if (location.Symbol != null) { AddressInfo?address = _symbolProvider.GetSymbolAddressInfo(location.Symbol); if (address.HasValue) { DebugWindowManager.OpenMemoryViewer(address.Value); } } else if (location.Address >= 0) { AddressInfo relAddress = new AddressInfo() { Address = location.Address, Type = _manager.RelativeMemoryType }; AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); if (absAddress.Address >= 0) { DebugWindowManager.OpenMemoryViewer(absAddress); } else { DebugWindowManager.OpenMemoryViewer(relAddress); } } else if (location.Label != null) { DebugWindowManager.OpenMemoryViewer(location.Label.GetAbsoluteAddress()); } }
private void mnuEditLabel_Click(object sender, EventArgs e) { UInt32 address = (UInt32)ctrlHexBox.SelectionStart; SnesMemoryType memType = _memoryType; if (!memType.SupportsLabels()) { AddressInfo relAddress = new AddressInfo() { Address = (int)address, Type = memType }; AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); if (absAddress.Address < 0 || !absAddress.Type.SupportsLabels()) { return; } address = (uint)absAddress.Address; memType = absAddress.Type; } CodeLabel label = LabelManager.GetLabel(address, memType); if (label == null) { label = new CodeLabel() { Address = address, MemoryType = memType }; } ctrlLabelList.EditLabel(label); }
public static CodeLabel GetLabel(AddressInfo relAddress) { AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); if (absAddress.Address >= 0) { return(GetLabel((UInt32)absAddress.Address, absAddress.Type)); } return(null); }
private void btnOk_Click(object sender, EventArgs e) { List <string> warningMessages = new List <string>(); if (_hasParsingErrors) { warningMessages.Add("Warning: The code contains parsing errors - lines with errors will be ignored."); } if (_isEditMode) { if (SizeExceeded) { warningMessages.Add("Warning: The new code exceeds the original code's length." + Environment.NewLine + "Applying this modification will overwrite other portions of the code and potentially cause problems."); } } else { warningMessages.Add($"Warning: The contents currently mapped to CPU memory addresses ${_startAddress.ToString("X6")} to ${(_startAddress+ctrlHexBox.ByteProvider.Length).ToString("X6")} will be overridden."); } if (warningMessages.Count == 0 || MessageBox.Show(string.Join(Environment.NewLine + Environment.NewLine, warningMessages.ToArray()) + Environment.NewLine + Environment.NewLine + "OK?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK) { List <byte> bytes = new List <byte>(((StaticByteProvider)ctrlHexBox.ByteProvider).Bytes); int byteGap = (int)(_blockLength - ctrlHexBox.ByteProvider.Length); for (int i = 0; i < byteGap; i++) { //Pad data with NOPs as needed bytes.Add(0xEA); } DebugApi.SetMemoryValues(SnesMemoryType.CpuMemory, (UInt32)_startAddress, bytes.ToArray(), bytes.Count); AddressInfo absStart = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = _startAddress, Type = SnesMemoryType.CpuMemory }); AddressInfo absEnd = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = _startAddress + bytes.Count, Type = SnesMemoryType.CpuMemory }); if (absStart.Type == SnesMemoryType.PrgRom && absEnd.Type == SnesMemoryType.PrgRom && (absEnd.Address - absStart.Address) == bytes.Count) { DebugApi.MarkBytesAs((uint)absStart.Address, (uint)absEnd.Address, CdlFlags.Code); } frmDebugger debugger = DebugWindowManager.OpenDebugger(CpuType.Cpu); if (debugger != null) { debugger.RefreshDisassembly(); } this.DialogResult = DialogResult.OK; this.Close(); } }
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 int GetLineIndex(uint cpuAddress) { int absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)cpuAddress, Type = SnesMemoryType.CpuMemory }).Address; for (int i = 0; i < _lineCount; i++) { if (_symbolProvider.GetPrgAddress(_file.ID, i) == absAddress) { return(i); } } return(0); }
private SelectedAddressRange GetSelectedAddressRange() { SelectedAddressRange range = GetSelectedRelativeAddressRange(); if (range != null && range.Start.Address >= 0 && range.End.Address >= 0) { return(new SelectedAddressRange() { Start = DebugApi.GetAbsoluteAddress(range.Start), End = DebugApi.GetAbsoluteAddress(range.End), Display = $"${range.Start.Address.ToString("X4")} - ${range.End.Address.ToString("X4")}" }); } return(null); }
private void GetBreakpointLineProperties(LineProperties props, int cpuAddress) { AddressInfo absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = cpuAddress, Type = SnesMemoryType.NecDspMemory }); foreach (Breakpoint breakpoint in BreakpointManager.Breakpoints) { if (breakpoint.Matches((uint)cpuAddress, SnesMemoryType.NecDspMemory, CpuType.NecDsp) || (absAddress.Address >= 0 && breakpoint.Matches((uint)absAddress.Address, absAddress.Type, CpuType.NecDsp))) { SetBreakpointLineProperties(props, breakpoint); return; } } }
public void GetBreakpointLineProperties(LineProperties props, int cpuAddress) { DebuggerInfo config = ConfigManager.Config.Debug.Debugger; AddressInfo absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = cpuAddress, Type = SnesMemoryType.CpuMemory }); foreach (Breakpoint breakpoint in BreakpointManager.Breakpoints) { if (breakpoint.Matches((uint)cpuAddress, SnesMemoryType.CpuMemory, CpuType.Cpu) || (absAddress.Address >= 0 && breakpoint.Matches((uint)absAddress.Address, absAddress.Type, CpuType.Cpu))) { SetBreakpointLineProperties(props, breakpoint); } } }
private void GetRamLabelAddressAndType(int address, out int absoluteAddress, out SnesMemoryType?memoryType) { AddressInfo absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = address, Type = SnesMemoryType.CpuMemory }); absoluteAddress = absAddress.Address; if (absoluteAddress >= 0) { memoryType = absAddress.Type; } else { memoryType = null; } }
public int GetLineIndex(uint cpuAddress) { AddressInfo absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)cpuAddress, Type = SnesMemoryType.CpuMemory }); for (int i = 0; i < _lineCount; i++) { AddressInfo?lineAddr = _symbolProvider.GetLineAddress(_file, i); if (lineAddr != null && lineAddr.Value.Address == absAddress.Address && lineAddr.Value.Type == absAddress.Type) { return(i); } } return(0); }
private void EnableDisableBreakpoint(int address) { if (address >= 0) { AddressInfo relAddress = new AddressInfo() { Address = address, Type = _manager.RelativeMemoryType }; if (!BreakpointManager.EnableDisableBreakpoint(relAddress, _manager.CpuType)) { AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); BreakpointManager.EnableDisableBreakpoint(absAddress, _manager.CpuType); } } }
private void EditLabel(LocationInfo location) { if (location.Symbol != null) { //Don't allow edit label on symbols return; } if (location.Label != null) { using (frmEditLabel frm = new frmEditLabel(location.Label)) { frm.ShowDialog(); } } else if (location.Address >= 0) { AddressInfo relAddress = new AddressInfo() { Address = location.Address, Type = _manager.RelativeMemoryType }; AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); if (absAddress.Address >= 0) { CodeLabel label = LabelManager.GetLabel((uint)absAddress.Address, absAddress.Type); if (label == null) { label = new CodeLabel() { Address = (uint)absAddress.Address, MemoryType = absAddress.Type }; } using (frmEditLabel frm = new frmEditLabel(label)) { frm.ShowDialog(); } } } }
private void UpdateActionAvailability() { UInt32 startAddress = (UInt32)SelectionStartAddress; UInt32 endAddress = (UInt32)SelectionEndAddress; string address = "$" + startAddress.ToString("X4"); string addressRange; if (startAddress != endAddress) { addressRange = "$" + startAddress.ToString("X4") + "-$" + endAddress.ToString("X4"); } else { addressRange = address; } mnuEditLabel.Text = $"Edit Label ({address})"; mnuEditBreakpoint.Text = $"Edit Breakpoint ({addressRange})"; mnuAddToWatch.Text = $"Add to Watch ({addressRange})"; if (_memoryType == SnesMemoryType.CpuMemory || _memoryType == SnesMemoryType.SpcMemory) { AddressInfo relAddress = new AddressInfo() { Address = (int)startAddress, Type = _memoryType }; AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); mnuEditLabel.Enabled = absAddress.Address != -1 && absAddress.Type.SupportsLabels(); mnuAddToWatch.Enabled = _memoryType.SupportsWatch(); } else { mnuEditLabel.Enabled = _memoryType.SupportsLabels(); mnuAddToWatch.Enabled = false; } mnuEditBreakpoint.Enabled = true; }
private void ToggleBreakpoint(int address) { if (address >= 0) { AddressInfo relAddress = new AddressInfo() { Address = address, Type = _manager.RelativeMemoryType }; AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); if (absAddress.Address < 0) { BreakpointManager.ToggleBreakpoint(relAddress, _manager.CpuType); } else { BreakpointManager.ToggleBreakpoint(absAddress, _manager.CpuType); } } }
public static void Import(string path, bool silent = false) { const int prgBankSize = 0x4000; const int wramBankSize = 0x1000; const int sramBankSize = 0x2000; List <CodeLabel> labels = new List <CodeLabel>(1000); int errorCount = 0; foreach (string row in File.ReadAllLines(path, Encoding.UTF8)) { UInt32 address; UInt32 bank; string labelName; if (!GetBankAddressLabel(row, out address, out bank, out labelName)) { errorCount++; continue; } else if (labelName == null) { //Empty line/comment continue; } UInt32 fullAddress = 0; AddressInfo absAddress; if (address <= 0x7FFF) { fullAddress = bank * prgBankSize + (address & (prgBankSize - 1)); absAddress = new AddressInfo() { Address = (int)fullAddress, Type = SnesMemoryType.GbPrgRom }; } else if (address >= 0xA000 && address <= 0xCFFF) { fullAddress = bank * sramBankSize + (address & (sramBankSize - 1)); absAddress = new AddressInfo() { Address = (int)fullAddress, Type = SnesMemoryType.GbCartRam }; } else if (address >= 0xC000 && address <= 0xDFFF) { fullAddress = bank * wramBankSize + (address & (wramBankSize - 1)); absAddress = new AddressInfo() { Address = (int)fullAddress, Type = SnesMemoryType.GbWorkRam }; } else { absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)address, Type = SnesMemoryType.GameboyMemory }); } if (absAddress.Address >= 0) { CodeLabel label = new CodeLabel(); label.Address = (UInt32)absAddress.Address; label.MemoryType = absAddress.Type; label.Comment = ""; label.Label = labelName; labels.Add(label); } else { errorCount++; } } 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 void Import(string path, bool silent) { string basePath = Path.GetDirectoryName(path); string[] lines = File.ReadAllLines(path); Regex labelRegex = new Regex(@"^([0-9a-fA-F]{2}):([0-9a-fA-F]{4}) ([^\s]*)", RegexOptions.Compiled); Regex fileRegex = new Regex(@"^([0-9a-fA-F]{4}) ([0-9a-fA-F]{8}) (.*)", RegexOptions.Compiled); Regex addrRegex = new Regex(@"^([0-9a-fA-F]{2}):([0-9a-fA-F]{4}) ([0-9a-fA-F]{4}):([0-9a-fA-F]{8})", RegexOptions.Compiled); Dictionary <string, CodeLabel> labels = new Dictionary <string, CodeLabel>(); for (int i = 0; i < lines.Length; i++) { string str = lines[i].Trim(); if (str == "[labels]") { for (; i < lines.Length; i++) { if (lines[i].Length > 0) { Match m = labelRegex.Match(lines[i]); if (m.Success) { int bank = Int32.Parse(m.Groups[1].Value, System.Globalization.NumberStyles.HexNumber); int addr = (bank << 16) | Int32.Parse(m.Groups[2].Value, System.Globalization.NumberStyles.HexNumber); string label = m.Groups[3].Value; if (!LabelManager.LabelRegex.IsMatch(label)) { //ignore labels that don't respect the label naming restrictions continue; } AddressInfo relAddr = new AddressInfo() { Address = addr, Type = SnesMemoryType.CpuMemory }; AddressInfo absAddr = DebugApi.GetAbsoluteAddress(relAddr); if (absAddr.Address < 0) { continue; } string orgLabel = label; int j = 1; while (labels.ContainsKey(label)) { label = orgLabel + j.ToString(); j++; } labels[label] = new CodeLabel() { Label = label, Address = (UInt32)absAddr.Address, MemoryType = absAddr.Type, Comment = "", Flags = CodeLabelFlags.None, Length = 1 }; } } else { break; } } } else if (str == "[source files]") { for (; i < lines.Length; i++) { if (lines[i].Length > 0) { Match m = fileRegex.Match(lines[i]); if (m.Success) { int fileId = Int32.Parse(m.Groups[1].Value, System.Globalization.NumberStyles.HexNumber); //int fileCrc = Int32.Parse(m.Groups[2].Value, System.Globalization.NumberStyles.HexNumber); string filePath = m.Groups[3].Value; string fullPath = Path.Combine(basePath, filePath); _sourceFiles[fileId] = new SourceFileInfo() { Name = filePath, Data = File.Exists(fullPath) ? File.ReadAllLines(fullPath) : new string[0] }; } } else { break; } } } else if (str == "[addr-to-line mapping]") { for (; i < lines.Length; i++) { if (lines[i].Length > 0) { Match m = addrRegex.Match(lines[i]); if (m.Success) { int bank = Int32.Parse(m.Groups[1].Value, System.Globalization.NumberStyles.HexNumber); int addr = (bank << 16) | Int32.Parse(m.Groups[2].Value, System.Globalization.NumberStyles.HexNumber); int fileId = Int32.Parse(m.Groups[3].Value, System.Globalization.NumberStyles.HexNumber); int lineNumber = Int32.Parse(m.Groups[4].Value, System.Globalization.NumberStyles.HexNumber); if (lineNumber <= 1) { //Ignore line number 0 and 1, seems like bad data? continue; } AddressInfo absAddr = new AddressInfo() { Address = addr, Type = SnesMemoryType.PrgRom }; _addressByLine[_sourceFiles[fileId].Name + "_" + lineNumber.ToString()] = absAddr; _linesByAddress[absAddr.Type.ToString() + absAddr.Address.ToString()] = new SourceCodeLocation() { File = _sourceFiles[fileId], LineNumber = lineNumber }; } } else { break; } } } } LabelManager.SetLabels(labels.Values, true); }
public LocationInfo GetLocationInfo(string word, int lineIndex) { LocationInfo location = new LocationInfo(); int arraySeparatorIndex = word.IndexOf("+"); if (arraySeparatorIndex >= 0) { int index; if (int.TryParse(word.Substring(arraySeparatorIndex + 1), out index)) { location.ArrayIndex = index; } word = word.Substring(0, arraySeparatorIndex); } if (_provider is SymbolCodeDataProvider && _symbolProvider != null) { int rangeStart, rangeEnd; GetSymbolByteRange(lineIndex, out rangeStart, out rangeEnd); location.Symbol = _symbolProvider.GetSymbol(word, rangeStart, rangeEnd); } location.Label = LabelManager.GetLabel(word); int address; if (location.Label != null) { address = location.Label.GetRelativeAddress(this.CpuType).Address; if (address >= 0) { location.Address = location.Label.GetRelativeAddress(this.CpuType).Address + (location.ArrayIndex ?? 0); } else { location.Address = -1; } } else if (word.StartsWith("$")) { word = word.Replace("$", ""); if (Int32.TryParse(word, System.Globalization.NumberStyles.HexNumber, null, out address)) { location.Address = GetFullAddress(address, word.Length); } } else if (Int32.TryParse(word, out address)) { location.Address = (int)address; } else { location.Address = -1; } if (location.Label == null && location.Address >= 0) { AddressInfo relAddress = new AddressInfo() { Address = location.Address, Type = RelativeMemoryType }; CodeLabel label = LabelManager.GetLabel(relAddress); if (label != null && !string.IsNullOrWhiteSpace(label.Label)) { //ignore comment-only labels location.Label = label; } } if (location.Label != null && location.Address >= 0) { AddressInfo absAddress = location.Label.GetAbsoluteAddress(); AddressInfo absIndexedAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = location.Address, Type = RelativeMemoryType }); if (absIndexedAddress.Address > absAddress.Address) { location.ArrayIndex = absIndexedAddress.Address - absAddress.Address; } } return(location); }
public Dictionary <string, string> GetTooltipData(string word, int lineIndex) { if (_provider.GetCodeLineData(lineIndex).Flags.HasFlag(LineFlags.ShowAsData)) { //Disable tooltips for .db statements return(null); } LocationInfo location = GetLocationInfo(word, lineIndex); if (location.Symbol != null) { AddressInfo?symbolAddress = _symbolProvider.GetSymbolAddressInfo(location.Symbol); if (symbolAddress != null && symbolAddress.Value.Address >= 0) { int relativeAddress = DebugApi.GetRelativeAddress(symbolAddress.Value, this.CpuType).Address; byte byteValue = relativeAddress >= 0 ? DebugApi.GetMemoryValue(this.RelativeMemoryType, (UInt32)relativeAddress) : (byte)0; UInt16 wordValue = relativeAddress >= 0 ? (UInt16)(byteValue | (DebugApi.GetMemoryValue(this.RelativeMemoryType, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0; var values = new Dictionary <string, string>() { { "Symbol", location.Symbol.Name + (location.ArrayIndex != null ? $"+{location.ArrayIndex.Value}" : "") } }; if (relativeAddress >= 0) { values["CPU Address"] = "$" + relativeAddress.ToString("X4"); } else { values["CPU Address"] = "<out of scope>"; } if (symbolAddress.Value.Type == SnesMemoryType.PrgRom) { values["PRG Offset"] = "$" + (symbolAddress.Value.Address + (location.ArrayIndex ?? 0)).ToString("X4"); } values["Value"] = (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a"); return(values); } else { return(new Dictionary <string, string>() { { "Symbol", location.Symbol.Name }, { "Constant", location.Symbol.Address.HasValue ? ("$" + location.Symbol.Address.Value.ToString("X2")) : "<unknown>" } }); } } else if (location.Label != null) { AddressInfo absAddress = location.Label.GetAbsoluteAddress(); int relativeAddress; if (location.Address >= 0) { relativeAddress = location.Address; AddressInfo absIndexedAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = location.Address, Type = RelativeMemoryType }); if (absIndexedAddress.Address > absAddress.Address) { location.ArrayIndex = absIndexedAddress.Address - absAddress.Address; } } else if (absAddress.Type.IsRelativeMemory() || absAddress.Type == SnesMemoryType.Register) { relativeAddress = absAddress.Address; } else { relativeAddress = location.Label.GetRelativeAddress(this.CpuType).Address + (location.ArrayIndex ?? 0); } byte byteValue = relativeAddress >= 0 ? DebugApi.GetMemoryValue(this.RelativeMemoryType, (UInt32)relativeAddress) : (byte)0; UInt16 wordValue = relativeAddress >= 0 ? (UInt16)(byteValue | (DebugApi.GetMemoryValue(this.RelativeMemoryType, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0; var values = new Dictionary <string, string>() { { "Label", location.Label.Label + (location.ArrayIndex != null ? $"+{location.ArrayIndex.Value}" : "") }, { "Address", (relativeAddress >= 0 ? "$" + relativeAddress.ToString("X4") : "n/a") }, { "Value", (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a") }, }; if (!string.IsNullOrWhiteSpace(location.Label.Comment)) { values["Comment"] = location.Label.Comment; } return(values); } else if (location.Address >= 0) { byte byteValue = DebugApi.GetMemoryValue(this.RelativeMemoryType, (uint)location.Address); UInt16 wordValue = (UInt16)(byteValue | (DebugApi.GetMemoryValue(this.RelativeMemoryType, (uint)location.Address + 1) << 8)); return(new Dictionary <string, string>() { { "Address", "$" + location.Address.ToString("X4") }, { "Value", $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" } }); } return(null); }
private void UpdateActionAvailability() { UInt32 startAddress = (UInt32)SelectionStartAddress; UInt32 endAddress = (UInt32)SelectionEndAddress; string address = "$" + startAddress.ToString("X4"); string addressRange; if (startAddress != endAddress) { addressRange = "$" + startAddress.ToString("X4") + "-$" + endAddress.ToString("X4"); } else { addressRange = address; } mnuEditLabel.Text = $"Edit Label ({address})"; mnuEditBreakpoint.Text = $"Edit Breakpoint ({addressRange})"; mnuAddToWatch.Text = $"Add to Watch ({addressRange})"; if (_memoryType.IsRelativeMemory()) { AddressInfo relAddress = new AddressInfo() { Address = (int)startAddress, Type = _memoryType }; AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); mnuEditLabel.Enabled = absAddress.Address != -1 && absAddress.Type.SupportsLabels(); mnuAddToWatch.Enabled = _memoryType.SupportsWatch(); } else { mnuEditLabel.Enabled = _memoryType.SupportsLabels(); mnuAddToWatch.Enabled = false; } if (_memoryType == SnesMemoryType.CpuMemory || _memoryType == SnesMemoryType.GameboyMemory) { AddressInfo start = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)startAddress, Type = _memoryType }); AddressInfo end = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)endAddress, Type = _memoryType }); if (start.Address >= 0 && end.Address >= 0 && start.Address <= end.Address && ((start.Type == SnesMemoryType.PrgRom && end.Type == SnesMemoryType.PrgRom) || (start.Type == SnesMemoryType.GbPrgRom && end.Type == SnesMemoryType.GbPrgRom))) { mnuMarkSelectionAs.Text = "Mark selection as... (" + addressRange + ")"; mnuMarkSelectionAs.Enabled = true; } else { mnuMarkSelectionAs.Text = "Mark selection as..."; mnuMarkSelectionAs.Enabled = false; } } else if (_memoryType == SnesMemoryType.PrgRom || _memoryType == SnesMemoryType.GbPrgRom) { mnuMarkSelectionAs.Text = "Mark selection as... (" + addressRange + ")"; mnuMarkSelectionAs.Enabled = true; } else { mnuMarkSelectionAs.Text = "Mark selection as..."; mnuMarkSelectionAs.Enabled = false; } mnuEditBreakpoint.Enabled = true; }
public static void Import(string path, bool silent = false) { List <CodeLabel> labels = new List <CodeLabel>(1000); List <Breakpoint> breakpoints = new List <Breakpoint>(1000); int errorCount = 0; foreach (string row in File.ReadAllLines(path, Encoding.UTF8)) { string lineData = row.Trim(); if (lineData.StartsWith("<")) { continue; //this is a <command line>: operation and we don't want it } if (lineData.Contains(":=")) { continue; //this is a "variable" we dont' want it } int splitIndex = lineData.IndexOf(' '); string[] parts = lineData.Substring(splitIndex + 1).Split('='); UInt32 address; string value = parts[1].Trim(); NumberStyles type = NumberStyles.Integer; if (value.StartsWith("$")) { type = NumberStyles.HexNumber; value = value.Substring(1); //remove the $ } else if (value.StartsWith("%")) { continue; // Binary values are not labels 99.99999999999999% of the time } if (!UInt32.TryParse(value, type, null, out address)) { errorCount++; continue; } AddressInfo absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)address, Type = SnesMemoryType.CpuMemory }); if (absAddress.Address >= 0) { if (parts[0].Contains("BREAK")) { //we have a break point Breakpoint breakpoint = new Breakpoint(); breakpoint.Address = address; breakpoint.AddressType = BreakpointAddressType.SingleAddress; breakpoint.BreakOnExec = true; breakpoint.CpuType = CpuType.Cpu; breakpoints.Add(breakpoint); } else if (parts[0].Contains("ASSERT_")) { string assert_field = parts[0].Trim().ToLower().Substring(parts[0].IndexOf("ASSERT_") + 7); string cond = string.Empty; if (assert_field == "a8") { cond = "(PS & 32) == 32"; } else if (assert_field == "a16") { cond = "(PS & 32) == 0"; } else if (assert_field == "xy8") { cond = "(PS & 16) == 16"; } else if (assert_field == "xy16") { cond = "(PS & 16) == 0"; } else if (assert_field == "axy8") { cond = "(PS & 48) == 48"; } else if (assert_field == "axy16") { cond = "(PS & 48) == 32"; } else if (assert_field == "jsl") { cond = "jslf == 1"; } else if (assert_field == "jsr") { cond = "jslf == 0"; } else { cond = assert_field.Replace("_0x", "_$"); cond = cond.Replace("_eq_", "=="); cond = cond.Replace("_lt_", "<"); cond = cond.Replace("_lte_", "<="); cond = cond.Replace("_gt_", ">"); cond = cond.Replace("_gte_", ">="); cond = cond.Replace("_ne_", "!="); cond = cond.Replace("_and_", "&&"); cond = cond.Replace("_or_", "||"); cond = cond.Replace("_not_", "!"); cond = cond.Replace("_lbrac_", "("); cond = cond.Replace("_rbrac_", ")"); cond = cond.Replace("_", " "); } Breakpoint breakpoint = new Breakpoint(); breakpoint.Address = address; breakpoint.AddressType = BreakpointAddressType.SingleAddress; breakpoint.BreakOnExec = true; breakpoint.CpuType = CpuType.Cpu; breakpoint.IsAssert = true; breakpoint.Condition = "!(" + cond + ")"; breakpoints.Add(breakpoint); } else if (parts[0].Contains("WATCH_")) { string[] watchParts = parts[0].Trim().ToLower().Split('_'); Breakpoint breakpoint = new Breakpoint(); breakpoint.CpuType = CpuType.Cpu; breakpoint.IsAssert = false; breakpoint.Condition = String.Empty; breakpoint.BreakOnExec = false; int range = 1; for (int i = 1; i < watchParts.Length; ++i) { switch (watchParts[i]) { case "load": case "read": breakpoint.BreakOnRead = true; break; case "store": case "write": breakpoint.BreakOnWrite = true; break; case "readwrite": case "writeread": case "loadstore": case "storeload": breakpoint.BreakOnRead = true; breakpoint.BreakOnWrite = true; break; case "word": range = 2; break; case "long": range = 3; break; } } breakpoint.EndAddress = address - 1; switch (range) { case 1: breakpoint.StartAddress = address - 1; breakpoint.AddressType = BreakpointAddressType.SingleAddress; break; case 2: breakpoint.StartAddress = address - 2; breakpoint.AddressType = BreakpointAddressType.AddressRange; break; case 3: breakpoint.StartAddress = address - 3; breakpoint.AddressType = BreakpointAddressType.AddressRange; break; } breakpoint.Address = breakpoint.StartAddress; breakpoints.Add(breakpoint); } else { CodeLabel label = new CodeLabel(); label.Address = (UInt32)absAddress.Address; label.MemoryType = absAddress.Type; label.Comment = ""; string labelName = parts[0].Trim(); if (string.IsNullOrEmpty(labelName) || !LabelManager.LabelRegex.IsMatch(labelName)) { errorCount++; } else { label.Label = labelName; labels.Add(label); } } } } LabelManager.SetLabels(labels); BreakpointManager.SetBreakpoints(breakpoints); 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); } }
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(); } }