From e79e655d3b678ecb35a1bc7a58e13918698da9a3 Mon Sep 17 00:00:00 2001 From: Sour Date: Thu, 12 Sep 2024 17:11:56 +0900 Subject: [PATCH] Debugger: Event Viewer - Added missing address/value for some event types (marked breakpoints, etc.) --- Core/Debugger/BaseEventManager.h | 11 +++---- Core/GBA/Debugger/GbaEventManager.cpp | 1 + Core/Gameboy/Debugger/GbEventManager.cpp | 1 + Core/NES/Debugger/NesEventManager.cpp | 9 +++--- Core/PCE/Debugger/PceEventManager.cpp | 1 + Core/SMS/Debugger/SmsEventManager.cpp | 9 +++--- Core/SNES/Debugger/SnesEventManager.cpp | 1 + .../ViewModels/EventViewerViewModel.cs | 14 ++++----- .../Windows/EventViewerWindow.axaml.cs | 30 +++++++++---------- UI/Interop/DebugApi.cs | 11 +++---- 10 files changed, 47 insertions(+), 41 deletions(-) diff --git a/Core/Debugger/BaseEventManager.h b/Core/Debugger/BaseEventManager.h index bc0c35a8f..4eaa2cb68 100644 --- a/Core/Debugger/BaseEventManager.h +++ b/Core/Debugger/BaseEventManager.h @@ -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 diff --git a/Core/GBA/Debugger/GbaEventManager.cpp b/Core/GBA/Debugger/GbaEventManager.cpp index cd9145db1..3a3a21299 100644 --- a/Core/GBA/Debugger/GbaEventManager.cpp +++ b/Core/GBA/Debugger/GbaEventManager.cpp @@ -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; diff --git a/Core/Gameboy/Debugger/GbEventManager.cpp b/Core/Gameboy/Debugger/GbEventManager.cpp index d4c01ebad..0c36d348a 100644 --- a/Core/Gameboy/Debugger/GbEventManager.cpp +++ b/Core/Gameboy/Debugger/GbEventManager.cpp @@ -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; diff --git a/Core/NES/Debugger/NesEventManager.cpp b/Core/NES/Debugger/NesEventManager.cpp index 395523d4d..33f9cfe28 100644 --- a/Core/NES/Debugger/NesEventManager.cpp +++ b/Core/NES/Debugger/NesEventManager.cpp @@ -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; @@ -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; @@ -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; } } diff --git a/Core/PCE/Debugger/PceEventManager.cpp b/Core/PCE/Debugger/PceEventManager.cpp index 266bab251..a08b55e15 100644 --- a/Core/PCE/Debugger/PceEventManager.cpp +++ b/Core/PCE/Debugger/PceEventManager.cpp @@ -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(); diff --git a/Core/SMS/Debugger/SmsEventManager.cpp b/Core/SMS/Debugger/SmsEventManager.cpp index 40fe07f43..16d76550d 100644 --- a/Core/SMS/Debugger/SmsEventManager.cpp +++ b/Core/SMS/Debugger/SmsEventManager.cpp @@ -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(); @@ -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; @@ -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; @@ -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; } diff --git a/Core/SNES/Debugger/SnesEventManager.cpp b/Core/SNES/Debugger/SnesEventManager.cpp index 5995d4b2e..c85007b84 100644 --- a/Core/SNES/Debugger/SnesEventManager.cpp +++ b/Core/SNES/Debugger/SnesEventManager.cpp @@ -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(); diff --git a/UI/Debugger/ViewModels/EventViewerViewModel.cs b/UI/Debugger/ViewModels/EventViewerViewModel.cs index d8ceca745..00fe3d99f 100644 --- a/UI/Debugger/ViewModels/EventViewerViewModel.cs +++ b/UI/Debugger/ViewModels/EventViewerViewModel.cs @@ -195,10 +195,10 @@ private List 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); } @@ -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; @@ -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() }); @@ -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); diff --git a/UI/Debugger/Windows/EventViewerWindow.axaml.cs b/UI/Debugger/Windows/EventViewerWindow.axaml.cs index 83ceb75d6..89d4fd4eb 100644 --- a/UI/Debugger/Windows/EventViewerWindow.axaml.cs +++ b/UI/Debugger/Windows/EventViewerWindow.axaml.cs @@ -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); diff --git a/UI/Interop/DebugApi.cs b/UI/Interop/DebugApi.cs index e24f3e4ea..c8cd3b9fd 100644 --- a/UI/Interop/DebugApi.cs +++ b/UI/Interop/DebugApi.cs @@ -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