Skip to content

Commit

Permalink
Debugger: Event Viewer - Added missing address/value for some event t…
Browse files Browse the repository at this point in the history
…ypes (marked breakpoints, etc.)
  • Loading branch information
SourMesen committed Sep 12, 2024
1 parent e6c372e commit e79e655
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 41 deletions.
11 changes: 6 additions & 5 deletions Core/Debugger/BaseEventManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

enum class EventFlags
{
PreviousFrame = 1,
RegFirstWrite = 2,
RegSecondWrite = 4,
WithTargetMemory = 8,
SmsVdpPaletteWrite = 16
PreviousFrame = 1 << 0,
RegFirstWrite = 1 << 1,
RegSecondWrite = 1 << 2,
WithTargetMemory = 1 << 3,
SmsVdpPaletteWrite = 1 << 4,
ReadWriteOp = 1 << 5,
};

struct DebugEventInfo
Expand Down
1 change: 1 addition & 0 deletions Core/GBA/Debugger/GbaEventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void GbaEventManager::AddEvent(DebugEventType type, MemoryOperationInfo& operati
uint16_t cycle = _ppu->GetCycle();
uint16_t scanline = _ppu->GetScanline();
evt.Type = type;
evt.Flags = (uint32_t)EventFlags::ReadWriteOp;
evt.Operation = operation;
evt.Scanline = scanline;
evt.Cycle = cycle;
Expand Down
1 change: 1 addition & 0 deletions Core/Gameboy/Debugger/GbEventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void GbEventManager::AddEvent(DebugEventType type, MemoryOperationInfo& operatio
{
DebugEventInfo evt = {};
evt.Type = type;
evt.Flags = (uint32_t)EventFlags::ReadWriteOp;
evt.Operation = operation;
evt.Scanline = _ppu->GetState().Scanline;
evt.Cycle = _ppu->GetState().Cycle;
Expand Down
9 changes: 5 additions & 4 deletions Core/NES/Debugger/NesEventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void NesEventManager::AddEvent(DebugEventType type, MemoryOperationInfo& operati
evt.BreakpointId = breakpointId;
evt.ProgramCounter = _debugger->GetProgramCounter(CpuType::Nes, true);
evt.DmaChannel = -1;
evt.Flags = (uint32_t)EventFlags::ReadWriteOp;

uint32_t addr = operation.Address;
bool isWrite = operation.Type == MemoryOperationType::Write || operation.Type == MemoryOperationType::DmaWrite || operation.Type == MemoryOperationType::DummyWrite;
Expand All @@ -55,16 +56,16 @@ void NesEventManager::AddEvent(DebugEventType type, MemoryOperationInfo& operati
evt.TargetMemory.MemType = MemoryType::NesSpriteRam;
evt.TargetMemory.Address = state.SpriteRamAddr;
evt.TargetMemory.Value = operation.Value;
evt.Flags = (uint32_t)EventFlags::WithTargetMemory;
evt.Flags |= (uint32_t)EventFlags::WithTargetMemory;
break;

case 5:
case 6:
//2005/2006 PPU register writes, mark as 2nd write when needed
if(state.WriteToggle) {
evt.Flags = (uint32_t)EventFlags::RegSecondWrite;
evt.Flags |= (uint32_t)EventFlags::RegSecondWrite;
} else {
evt.Flags = (uint32_t)EventFlags::RegFirstWrite;
evt.Flags |= (uint32_t)EventFlags::RegFirstWrite;
}
break;

Expand All @@ -74,7 +75,7 @@ void NesEventManager::AddEvent(DebugEventType type, MemoryOperationInfo& operati
evt.TargetMemory.MemType = MemoryType::NesPpuMemory;
evt.TargetMemory.Address = state.BusAddress;
evt.TargetMemory.Value = operation.Value;
evt.Flags = (uint32_t)EventFlags::WithTargetMemory;
evt.Flags |= (uint32_t)EventFlags::WithTargetMemory;
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions Core/PCE/Debugger/PceEventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void PceEventManager::AddEvent(DebugEventType type, MemoryOperationInfo &operati
{
DebugEventInfo evt = {};
evt.Type = type;
evt.Flags = (uint32_t)EventFlags::ReadWriteOp;
evt.Operation = operation;
evt.Scanline = (int16_t)_vdc->GetScanline();
evt.Cycle = _vdc->GetHClock();
Expand Down
9 changes: 5 additions & 4 deletions Core/SMS/Debugger/SmsEventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void SmsEventManager::AddEvent(DebugEventType type, MemoryOperationInfo& operati
{
DebugEventInfo evt = {};
evt.Type = type;
evt.Flags = (uint32_t)EventFlags::ReadWriteOp;
evt.Operation = operation;
evt.Scanline = _vdp->GetScanline();
evt.Cycle = _vdp->GetCycle();
Expand All @@ -39,7 +40,7 @@ void SmsEventManager::AddEvent(DebugEventType type, MemoryOperationInfo& operati
switch(evt.Operation.Address & 0xC1) {
case 0x80:
if(_vdp->GetState().CodeReg == 3) {
evt.Flags = (uint32_t)EventFlags::SmsVdpPaletteWrite | (uint32_t)EventFlags::WithTargetMemory;
evt.Flags |= (uint32_t)EventFlags::SmsVdpPaletteWrite | (uint32_t)EventFlags::WithTargetMemory;
evt.TargetMemory.MemType = MemoryType::SmsPaletteRam;
evt.TargetMemory.Type = operation.Type;
evt.TargetMemory.Value = operation.Value;
Expand All @@ -50,7 +51,7 @@ void SmsEventManager::AddEvent(DebugEventType type, MemoryOperationInfo& operati
evt.TargetMemory.Address = _vdp->GetState().AddressReg & 0x1F;
}
} else {
evt.Flags = (uint32_t)EventFlags::WithTargetMemory;
evt.Flags |= (uint32_t)EventFlags::WithTargetMemory;
evt.TargetMemory.MemType = MemoryType::SmsVideoRam;
evt.TargetMemory.Value = operation.Value;
evt.TargetMemory.Type = operation.Type;
Expand All @@ -60,13 +61,13 @@ void SmsEventManager::AddEvent(DebugEventType type, MemoryOperationInfo& operati

case 0x81:
if(_vdp->GetState().ControlPortMsbToggle) {
evt.Flags = (uint32_t)EventFlags::RegSecondWrite;
evt.Flags |= (uint32_t)EventFlags::RegSecondWrite;
if((evt.Operation.Value >> 6) == 2) {
//Value written to the register
evt.RegisterId = _vdp->GetState().AddressReg & 0xFF;
}
} else {
evt.Flags = (uint32_t)EventFlags::RegFirstWrite;
evt.Flags |= (uint32_t)EventFlags::RegFirstWrite;
}
break;
}
Expand Down
1 change: 1 addition & 0 deletions Core/SNES/Debugger/SnesEventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void SnesEventManager::AddEvent(DebugEventType type, MemoryOperationInfo &operat
{
DebugEventInfo evt = {};
evt.Type = type;
evt.Flags = (uint32_t)EventFlags::ReadWriteOp;
evt.Operation = operation;
evt.Scanline = (int16_t)_ppu->GetScanline();
evt.Cycle = _memoryManager->GetHClock();
Expand Down
14 changes: 7 additions & 7 deletions UI/Debugger/ViewModels/EventViewerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ private List<ContextMenuAction> GetContextMenuActions()
},
new ContextMenuAction() {
ActionType = ActionType.ToggleBreakpoint,
IsEnabled = () => SelectedEvent != null && SelectedEvent?.Type == DebugEventType.Register,
HintText = () => (SelectedEvent != null && SelectedEvent?.Type == DebugEventType.Register ? $"Address - ${SelectedEvent.Value.Operation.Address:X4}" : ""),
IsEnabled = () => SelectedEvent?.Flags.HasFlag(EventFlags.ReadWriteOp) == true,
HintText = () => SelectedEvent?.Flags.HasFlag(EventFlags.ReadWriteOp) == true ? $"Address - ${SelectedEvent.Value.Operation.Address:X4}" : "",
OnClick = () => {
if(SelectedEvent != null && SelectedEvent?.Type == DebugEventType.Register) {
if(SelectedEvent?.Flags.HasFlag(EventFlags.ReadWriteOp) == true) {
int addr = (int)SelectedEvent.Value.Operation.Address;
BreakpointManager.ToggleBreakpoint(new AddressInfo() { Address = addr, Type = CpuType.ToMemoryType() }, CpuType, false);
}
Expand Down Expand Up @@ -426,7 +426,6 @@ public static string GetEventDetails(CpuType cpuType, DebugEventInfo evt, bool s
bpInfo += "Type: " + bp.ToReadableType();
bpInfo += singleLine ? " - " : Environment.NewLine;
bpInfo += "Addresses: " + bp.GetAddressString(true);
bpInfo += singleLine ? " - " : Environment.NewLine;
if(bp.Condition.Length > 0) {
bpInfo += singleLine ? " - " : Environment.NewLine;
bpInfo += "Condition: " + bp.Condition;
Expand Down Expand Up @@ -542,7 +541,8 @@ private void UpdateFields()
Scanline = evt.Scanline.ToString();
Cycle = evt.Cycle.ToString();
string address = "";
if(evt.Type == DebugEventType.Register) {
bool isReadWriteOp = evt.Flags.HasFlag(EventFlags.ReadWriteOp);
if(isReadWriteOp) {
address += "$" + evt.Operation.Address.ToString("X4");

CodeLabel? label = LabelManager.GetLabel(new AddressInfo() { Address = (int)evt.Operation.Address, Type = _cpuType.ToMemoryType() });
Expand All @@ -561,9 +561,9 @@ private void UpdateFields()
}

Address = address;
Value = evt.Type == DebugEventType.Register ? "$" + evt.Operation.Value.ToString("X2") : "";
Value = isReadWriteOp ? "$" + evt.Operation.Value.ToString("X2") : "";
Type = ResourceHelper.GetEnumText(evt.Type);
if(evt.Type == DebugEventType.Register) {
if(isReadWriteOp) {
Type += evt.Operation.Type.IsWrite() ? " (W)" : " (R)";
}
Details = EventViewerViewModel.GetEventDetails(_cpuType, evt, true);
Expand Down
30 changes: 14 additions & 16 deletions UI/Debugger/Windows/EventViewerWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,21 @@ private TooltipEntries GetTooltipData(DebugEventInfo evt)

entries.AddSeparator("AddressValueSeparator");

switch(evt.Type) {
case DebugEventType.Register:
bool isWrite = evt.Operation.Type == MemoryOperationType.Write || evt.Operation.Type == MemoryOperationType.DmaWrite;
bool isDma = evt.Operation.Type == MemoryOperationType.DmaWrite || evt.Operation.Type == MemoryOperationType.DmaRead;

CodeLabel? label = LabelManager.GetLabel(new AddressInfo() { Address = (int)evt.Operation.Address, Type = _model.CpuType.ToMemoryType() });
string registerText = "$" + evt.Operation.Address.ToString("X4");
if(label != null) {
registerText = label.Label + " (" + registerText + ")";
}
if(evt.RegisterId >= 0) {
registerText += $" ({evt.GetRegisterName()} - ${evt.RegisterId:X2})";
}
if(evt.Flags.HasFlag(EventFlags.ReadWriteOp)) {
bool isWrite = evt.Operation.Type == MemoryOperationType.Write || evt.Operation.Type == MemoryOperationType.DmaWrite;
bool isDma = evt.Operation.Type == MemoryOperationType.DmaWrite || evt.Operation.Type == MemoryOperationType.DmaRead;

CodeLabel? label = LabelManager.GetLabel(new AddressInfo() { Address = (int)evt.Operation.Address, Type = _model.CpuType.ToMemoryType() });
string registerText = "$" + evt.Operation.Address.ToString("X4");
if(label != null) {
registerText = label.Label + " (" + registerText + ")";
}
if(evt.RegisterId >= 0) {
registerText += $" ({evt.GetRegisterName()} - ${evt.RegisterId:X2})";
}

entries.AddEntry("Register", registerText + (isWrite ? " (Write)" : " (Read)") + (isDma ? " (DMA)" : ""));
entries.AddEntry("Value", "$" + evt.Operation.Value.ToString("X2"));
break;
entries.AddEntry(evt.Type == DebugEventType.Register ? "Register" : "Address", registerText + (isWrite ? " (Write)" : " (Read)") + (isDma ? " (DMA)" : ""));
entries.AddEntry("Value", "$" + evt.Operation.Value.ToString("X2"));
}

string details = EventViewerViewModel.GetEventDetails(_model.CpuType, evt, false);
Expand Down
11 changes: 6 additions & 5 deletions UI/Interop/DebugApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,12 @@ public struct DmaChannelConfig

public enum EventFlags
{
PreviousFrame = 1,
RegFirstWrite = 2,
RegSecondWrite = 4,
HasTargetMemory = 8,
SmsVdpPaletteWrite = 16
PreviousFrame = 1 << 0,
RegFirstWrite = 1 << 1,
RegSecondWrite = 1 << 2,
HasTargetMemory = 1 << 3,
SmsVdpPaletteWrite = 1 << 4,
ReadWriteOp = 1 << 5,
}

public record struct DebugEventInfo
Expand Down

0 comments on commit e79e655

Please sign in to comment.