Skip to content

Commit

Permalink
Debugger: Source View - Improve active row behavior when multiple mir…
Browse files Browse the repository at this point in the history
…rors exist

+ Automatically move to current address when clicking on the source view tab (so that the active row is shown after manually loading a symbol file, etc.)
  • Loading branch information
SourMesen committed Dec 7, 2024
1 parent 614e61a commit e52fa70
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Core/PCE/PceConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ AddressInfo PceConsole::GetAbsoluteAddress(AddressInfo& relAddress)

AddressInfo PceConsole::GetRelativeAddress(AddressInfo& absAddress, CpuType cpuType)
{
return _memoryManager->GetRelativeAddress(absAddress);
return _memoryManager->GetRelativeAddress(absAddress, _cpu->GetState().PC);
}

PceVideoState PceConsole::GetVideoState()
Expand Down
12 changes: 9 additions & 3 deletions Core/PCE/PceMemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,18 @@ AddressInfo PceMemoryManager::GetAbsoluteAddress(uint32_t relAddr)
return { (int32_t)absAddr, _bankMemType[bank] };
}

AddressInfo PceMemoryManager::GetRelativeAddress(AddressInfo absAddr)
AddressInfo PceMemoryManager::GetRelativeAddress(AddressInfo absAddr, uint16_t pc)
{
//Start with the bank that the CPU is executing from
//This is to favor any mirror that exists in the current bank
//instead of always picking the first mirror, when mirrors exist.
int startBank = pc >> 13;

for(int i = 0; i < 8; i++) {
AddressInfo bankStart = GetAbsoluteAddress(i * 0x2000);
int bank = (startBank + i) & 0x07;
AddressInfo bankStart = GetAbsoluteAddress(bank * 0x2000);
if(bankStart.Type == absAddr.Type && bankStart.Address == (absAddr.Address & ~0x1FFF)) {
return { (i << 13) | (absAddr.Address & 0x1FFF), MemoryType::PceMemory };
return { (bank << 13) | (absAddr.Address & 0x1FFF), MemoryType::PceMemory };
}
}

Expand Down
2 changes: 1 addition & 1 deletion Core/PCE/PceMemoryManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class PceMemoryManager final : public ISerializable
uint8_t GetMprValue(uint8_t regSelect);

AddressInfo GetAbsoluteAddress(uint32_t relAddr);
AddressInfo GetRelativeAddress(AddressInfo absAddr);
AddressInfo GetRelativeAddress(AddressInfo absAddr, uint16_t pc);

void SetIrqSource(PceIrqSource source) { _state.ActiveIrqs |= (int)source; }
__forceinline uint8_t GetPendingIrqs() { return (_state.ActiveIrqs & ~_state.DisabledIrqs); }
Expand Down
15 changes: 14 additions & 1 deletion UI/Debugger/Disassembly/SourceViewStyleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@ public SourceViewStyleProvider(CpuType cpuType, SourceViewViewModel model) : bas

public override bool IsLineActive(CodeLineData line, int lineIndex)
{
return _model.ActiveAddress.HasValue && _model.ActiveAddress.Value == line.Address;
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;
}
}
}

return false;
}

public override bool IsLineFocused(CodeLineData line, int lineIndex)
Expand Down
1 change: 1 addition & 0 deletions UI/Debugger/ViewModels/DebuggerWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private void UpdateSourceViewState()
ISymbolProvider? provider = DebugWorkspaceManager.SymbolProvider;
if(provider != null) {
SourceView = new SourceViewViewModel(this, provider, CpuType);
SourceView.SetActiveAddress(Disassembly.ActiveAddress);
DockFactory.SourceViewTool.Model = SourceView;
if(!IsToolVisible(DockFactory.SourceViewTool)) {
if(DockFactory.SourceViewTool.Owner is IDock dock && IsDockVisible(dock)) {
Expand Down
4 changes: 4 additions & 0 deletions UI/Debugger/Views/SourceViewView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
}

_model?.SetViewer(_viewer);
if(_model?.ActiveAddress != null) {
//Go to active address when clicking on the source view tab
_model?.GoToRelativeAddress(_model.ActiveAddress.Value, true);
}
FocusViewer();
}

Expand Down

0 comments on commit e52fa70

Please sign in to comment.