From 47c123124b44e287fc8c6845637a21eb1fdd262d Mon Sep 17 00:00:00 2001 From: Sour Date: Sat, 7 Dec 2024 21:15:57 +0900 Subject: [PATCH] Debugger: Source View - Improve active line highlight logic for C files Highlight the C line of code if any of the CPU instructions contained inside of it is the current CPU instruction --- .../Disassembly/SourceViewStyleProvider.cs | 15 ++++++++++++--- UI/Debugger/Integration/PceasSymbolImporter.cs | 14 +++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/UI/Debugger/Disassembly/SourceViewStyleProvider.cs b/UI/Debugger/Disassembly/SourceViewStyleProvider.cs index eb8f48c5..ee00a433 100644 --- a/UI/Debugger/Disassembly/SourceViewStyleProvider.cs +++ b/UI/Debugger/Disassembly/SourceViewStyleProvider.cs @@ -19,15 +19,24 @@ public SourceViewStyleProvider(CpuType cpuType, SourceViewViewModel model) : bas public override bool IsLineActive(CodeLineData line, int lineIndex) { + lineIndex += _model.ScrollPosition; + if(_model.ActiveAddress.HasValue && !line.IsAddressHidden) { if(_model.ActiveAddress.Value == line.Address) { return true; } else if(line.AbsoluteAddress.Address > 0) { AddressInfo relActiveAddr = new AddressInfo() { Address = _model.ActiveAddress.Value, Type = _model.CpuType.ToMemoryType() }; AddressInfo absAddr = DebugApi.GetAbsoluteAddress(relActiveAddr); - if(line.AbsoluteAddress.Address == absAddr.Address && line.AbsoluteAddress.Type == absAddr.Type) { - //Relative address doesn't match but the absolute address does - different mirror, mark it as active - return true; + if(absAddr.Address > 0) { + if(line.AbsoluteAddress.Address == absAddr.Address && line.AbsoluteAddress.Type == absAddr.Type) { + //Relative address doesn't match but the absolute address does - different mirror, mark it as active + return true; + } else if(_model.SymbolProvider.GetSourceCodeLineInfo(absAddr)?.LineNumber == lineIndex) { + //Current line number is associated with this address, mark it as active + //This allows C code mappings to display as "active" for each CPU instruction + //that's part of a single line of C code + return true; + } } } } diff --git a/UI/Debugger/Integration/PceasSymbolImporter.cs b/UI/Debugger/Integration/PceasSymbolImporter.cs index 189f977d..aa32680b 100644 --- a/UI/Debugger/Integration/PceasSymbolImporter.cs +++ b/UI/Debugger/Integration/PceasSymbolImporter.cs @@ -328,23 +328,31 @@ public void Import(string path, bool showResult) AddressInfo absAddr = GetLabelAddress(bank, addr); if(absAddr.Address >= 0) { + long lengthFlags = long.Parse(m.Groups[3].Value, System.Globalization.NumberStyles.HexNumber); + int length = (int)(lengthFlags & ~0xC0000000); + if(absAddr.Type == MemoryType.PcePrgRom) { //Build CDL data based on the extra flags present in the mappings - long lengthFlags = long.Parse(m.Groups[3].Value, System.Globalization.NumberStyles.HexNumber); if((lengthFlags & 0x40000000) != 0) { cdlData[absAddr.Address] |= (byte)CdlFlags.SubEntryPoint; } byte cdlFlags = (lengthFlags & 0x80000000) != 0 ? (byte)CdlFlags.Code : (byte)CdlFlags.Data; - for(long j = 0, len = (lengthFlags & ~0xC0000000); j < len; j++) { + for(long j = 0; j < length; j++) { if(absAddr.Address + j < cdlData.Length) { cdlData[absAddr.Address + j] |= cdlFlags; + } else { + break; } } } _addressByLine[_sourceFiles[fileId].Name + "_" + lineNumber.ToString()] = absAddr; - _linesByAddress[absAddr.Type.ToString() + absAddr.Address.ToString()] = new SourceCodeLocation(_sourceFiles[fileId], lineNumber); + SourceCodeLocation loc = new SourceCodeLocation(_sourceFiles[fileId], lineNumber); + for(int j = 0; j < length; j++) { + //Map this line of code to every address it represents + _linesByAddress[absAddr.Type.ToString() + (absAddr.Address + j).ToString()] = loc; + } } } } else {