diff --git a/Core/Debugger/BaseEventManager.cpp b/Core/Debugger/BaseEventManager.cpp index 6e856565..46da7c63 100644 --- a/Core/Debugger/BaseEventManager.cpp +++ b/Core/Debugger/BaseEventManager.cpp @@ -79,3 +79,69 @@ void BaseEventManager::ClearFrameEvents() _prevDebugEvents = _debugEvents; _debugEvents.clear(); } + +void BaseEventManager::GetDisplayBuffer(uint32_t* buffer, uint32_t bufferSize) +{ + auto lock = _lock.AcquireSafe(); + FrameInfo size = GetDisplayBufferSize(); + if(_snapshotScanline < 0 || bufferSize < size.Width * size.Height * sizeof(uint32_t)) { + return; + } + + //Clear buffer + for(uint32_t i = 0; i < size.Width * size.Height; i++) { + buffer[i] = 0xFF555555; + } + + //Draw output screen + DrawScreen(buffer); + + //Draw events, current scanline/dot, etc. + DrawEvents(buffer, size); +} + +void BaseEventManager::DrawLine(uint32_t* buffer, FrameInfo size, uint32_t color, uint32_t row) +{ + uint32_t offset = row * 2 * size.Width; + for(int i = 0; i < size.Width; i++) { + buffer[offset + i] = color; + buffer[offset + size.Width + i] = color; + } +} + +void BaseEventManager::DrawEvent(DebugEventInfo& evt, bool drawBackground, uint32_t* buffer) +{ + EventViewerCategoryCfg evtCfg = GetEventConfig(evt); + uint32_t color = evtCfg.Color; + + int32_t y = evt.Scanline; + int32_t x = evt.Cycle; + ConvertScanlineCycleToRowColumn(x, y); + + DrawDot(x, y, color, drawBackground, buffer); +} + +void BaseEventManager::DrawEvents(uint32_t* buffer, FrameInfo size) +{ + if(_snapshotScanline != 0 || _snapshotCycle != 0) { + DrawLine(buffer, size, 0xFFFFFF55, _snapshotScanline); + } + + FilterEvents(); + for(DebugEventInfo& evt : _sentEvents) { + DrawEvent(evt, true, buffer); + } + for(DebugEventInfo& evt : _sentEvents) { + DrawEvent(evt, false, buffer); + } + + //Draw dot over current pixel + if(_snapshotScanline != 0 || _snapshotCycle != 0) { + int32_t y = _snapshotScanline + _snapshotScanlineOffset; + int32_t x = _snapshotCycle; + ConvertScanlineCycleToRowColumn(x, y); + + DrawDot(x, y, 0xFF990099, true, buffer); + DrawDot(x, y, 0xFFFF00FF, false, buffer); + } +} \ No newline at end of file diff --git a/Core/Debugger/BaseEventManager.h b/Core/Debugger/BaseEventManager.h index f2fcd226..aa56802a 100644 --- a/Core/Debugger/BaseEventManager.h +++ b/Core/Debugger/BaseEventManager.h @@ -46,6 +46,7 @@ protected: vector _snapshotCurrentFrame; vector _snapshotPrevFrame; int16_t _snapshotScanline = -1; + int16_t _snapshotScanlineOffset = 0; uint16_t _snapshotCycle = 0; SimpleLock _lock; @@ -55,6 +56,13 @@ protected: void DrawDot(uint32_t x, uint32_t y, uint32_t color, bool drawBackground, uint32_t* buffer); virtual int GetScanlineOffset() { return 0; } + void DrawLine(uint32_t* buffer, FrameInfo size, uint32_t color, uint32_t row); + void DrawEvents(uint32_t* buffer, FrameInfo size); + + virtual void ConvertScanlineCycleToRowColumn(int32_t& x, int32_t& y) = 0; + virtual void DrawScreen(uint32_t* buffer) = 0; + void DrawEvent(DebugEventInfo& evt, bool drawBackground, uint32_t* buffer); + public: virtual ~BaseEventManager() {} @@ -71,6 +79,7 @@ public: virtual uint32_t TakeEventSnapshot() = 0; virtual FrameInfo GetDisplayBufferSize() = 0; - virtual void GetDisplayBuffer(uint32_t* buffer, uint32_t bufferSize) = 0; virtual DebugEventInfo GetEvent(uint16_t scanline, uint16_t cycle) = 0; + + void GetDisplayBuffer(uint32_t* buffer, uint32_t bufferSize); }; diff --git a/Core/Gameboy/Debugger/GbEventManager.cpp b/Core/Gameboy/Debugger/GbEventManager.cpp index d04062d4..1958a601 100644 --- a/Core/Gameboy/Debugger/GbEventManager.cpp +++ b/Core/Gameboy/Debugger/GbEventManager.cpp @@ -115,14 +115,10 @@ EventViewerCategoryCfg GbEventManager::GetEventConfig(DebugEventInfo& evt) } } -void GbEventManager::DrawEvent(DebugEventInfo& evt, bool drawBackground, uint32_t* buffer) +void GbEventManager::ConvertScanlineCycleToRowColumn(int32_t& x, int32_t& y) { - EventViewerCategoryCfg evtCfg = GetEventConfig(evt); - uint32_t color = evtCfg.Color; - uint32_t y = std::min(evt.Scanline * 2, _scanlineCount * 2); - uint32_t x = evt.Cycle * 2; - - DrawDot(x, y, color, drawBackground, buffer); + y *= 2; + x *= 2; } uint32_t GbEventManager::TakeEventSnapshot() @@ -158,14 +154,8 @@ FrameInfo GbEventManager::GetDisplayBufferSize() return size; } -void GbEventManager::GetDisplayBuffer(uint32_t* buffer, uint32_t bufferSize) +void GbEventManager::DrawScreen(uint32_t* buffer) { - auto lock = _lock.AcquireSafe(); - FrameInfo size = GetDisplayBufferSize(); - if(_snapshotScanline < 0 || bufferSize < size.Width * size.Height * sizeof(uint32_t)) { - return; - } - uint16_t *src = _ppuBuffer; for(uint32_t y = 0, len = GbEventManager::ScreenHeight*2; y < len; y++) { for(uint32_t x = 0; x < GbEventManager::ScanlineWidth; x++) { @@ -173,21 +163,4 @@ void GbEventManager::GetDisplayBuffer(uint32_t* buffer, uint32_t bufferSize) buffer[y*GbEventManager::ScanlineWidth + x] = SnesDefaultVideoFilter::ToArgb(src[srcOffset]); } } - - constexpr uint32_t currentScanlineColor = 0xFFFFFF55; - uint32_t scanlineOffset = _snapshotScanline * 2 * GbEventManager::ScanlineWidth; - if(_snapshotScanline != 0) { - for(int i = 0; i < GbEventManager::ScanlineWidth; i++) { - buffer[scanlineOffset + i] = currentScanlineColor; - buffer[scanlineOffset + GbEventManager::ScanlineWidth + i] = currentScanlineColor; - } - } - - FilterEvents(); - for(DebugEventInfo &evt : _sentEvents) { - DrawEvent(evt, true, buffer); - } - for(DebugEventInfo &evt : _sentEvents) { - DrawEvent(evt, false, buffer); - } } diff --git a/Core/Gameboy/Debugger/GbEventManager.h b/Core/Gameboy/Debugger/GbEventManager.h index df75f2d4..db1fbd6c 100644 --- a/Core/Gameboy/Debugger/GbEventManager.h +++ b/Core/Gameboy/Debugger/GbEventManager.h @@ -47,10 +47,10 @@ private: uint32_t _scanlineCount = GbEventManager::ScreenHeight; uint16_t* _ppuBuffer = nullptr; - void DrawEvent(DebugEventInfo& evt, bool drawBackground, uint32_t* buffer); - protected: bool ShowPreviousFrameEvents() override; + void ConvertScanlineCycleToRowColumn(int32_t& x, int32_t& y) override; + void DrawScreen(uint32_t* buffer) override; public: GbEventManager(Debugger* debugger, GbCpu* cpu, GbPpu* ppu); @@ -62,7 +62,6 @@ public: EventViewerCategoryCfg GetEventConfig(DebugEventInfo& evt); uint32_t TakeEventSnapshot(); - void GetDisplayBuffer(uint32_t* buffer, uint32_t bufferSize); DebugEventInfo GetEvent(uint16_t y, uint16_t x); FrameInfo GetDisplayBufferSize() override; diff --git a/Core/NES/Debugger/NesEventManager.cpp b/Core/NES/Debugger/NesEventManager.cpp index d9d90920..64c4ff1d 100644 --- a/Core/NES/Debugger/NesEventManager.cpp +++ b/Core/NES/Debugger/NesEventManager.cpp @@ -18,6 +18,7 @@ NesEventManager::NesEventManager(Debugger *debugger, NesConsole* console) _cpu = console->GetCpu(); _ppu = console->GetPpu(); _mapper = console->GetMapper(); + _snapshotScanlineOffset = -1; NesDefaultVideoFilter::GetFullPalette(_palette, console->GetNesConfig(), _ppu->GetPpuModel()); @@ -180,18 +181,10 @@ EventViewerCategoryCfg NesEventManager::GetEventConfig(DebugEventInfo& evt) return {}; } -void NesEventManager::DrawEvent(DebugEventInfo &evt, bool drawBackground, uint32_t *buffer) +void NesEventManager::ConvertScanlineCycleToRowColumn(int32_t& x, int32_t& y) { - EventViewerCategoryCfg eventCfg = GetEventConfig(evt); - uint32_t color = eventCfg.Color; - - if(!eventCfg.Visible) { - return; - } - - uint32_t y = std::min((evt.Scanline + 1) * 2, _scanlineCount * 2); - uint32_t x = evt.Cycle * 2; - DrawDot(x, y, color, drawBackground, buffer); + y = (y + 1) * 2; + x = x * 2; } uint32_t NesEventManager::TakeEventSnapshot() @@ -226,19 +219,8 @@ FrameInfo NesEventManager::GetDisplayBufferSize() return size; } -void NesEventManager::GetDisplayBuffer(uint32_t *buffer, uint32_t bufferSize) +void NesEventManager::DrawScreen(uint32_t *buffer) { - auto lock = _lock.AcquireSafe(); - - FrameInfo size = GetDisplayBufferSize(); - if(_snapshotScanline < 0 || bufferSize < size.Width * size.Height * sizeof(uint32_t)) { - return; - } - - for(uint32_t i = 0; i < size.Width*size.Height; i++) { - buffer[i] = 0xFF555555; - } - uint16_t *src = _ppuBuffer; for(uint32_t y = 0, len = NesConstants::ScreenHeight*2; y < len; y++) { int rowOffset = (y + 2) * NesConstants::CyclesPerLine * 2; @@ -252,29 +234,6 @@ void NesEventManager::GetDisplayBuffer(uint32_t *buffer, uint32_t bufferSize) if(_config.ShowNtscBorders) { DrawNtscBorders(buffer); } - - constexpr uint32_t currentScanlineColor = 0xFFFFFF55; - uint32_t scanlineOffset = _snapshotScanline * 2 * NesConstants::CyclesPerLine * 2; - for(int i = 0; i < NesConstants::CyclesPerLine * 2; i++) { - if(_snapshotScanline != 0) { - buffer[scanlineOffset + i] = currentScanlineColor; - buffer[scanlineOffset + NesConstants::CyclesPerLine * 2 + i] = currentScanlineColor; - } - } - - FilterEvents(); - for(DebugEventInfo &evt : _sentEvents) { - DrawEvent(evt, true, buffer); - } - for(DebugEventInfo &evt : _sentEvents) { - DrawEvent(evt, false, buffer); - } - - //Draw dot over current pixel - if(_snapshotScanline != 0 || _snapshotCycle != 0) { - DrawDot(_snapshotCycle * 2, _snapshotScanline * 2, 0xFF990099, true, buffer); - DrawDot(_snapshotCycle * 2, _snapshotScanline * 2, 0xFFFF00FF, false, buffer); - } } void NesEventManager::DrawPixel(uint32_t *buffer, int32_t x, uint32_t y, uint32_t color) diff --git a/Core/NES/Debugger/NesEventManager.h b/Core/NES/Debugger/NesEventManager.h index b83c1b11..9f45939e 100644 --- a/Core/NES/Debugger/NesEventManager.h +++ b/Core/NES/Debugger/NesEventManager.h @@ -59,11 +59,13 @@ private: uint32_t _scanlineCount = 262; uint16_t *_ppuBuffer = nullptr; - void DrawEvent(DebugEventInfo &evt, bool drawBackground, uint32_t *buffer); void DrawNtscBorders(uint32_t *buffer); void DrawPixel(uint32_t *buffer, int32_t x, uint32_t y, uint32_t color); protected: + void ConvertScanlineCycleToRowColumn(int32_t& x, int32_t& y) override; + void DrawScreen(uint32_t* buffer) override; + bool ShowPreviousFrameEvents() override; int GetScanlineOffset() override { return 1; } @@ -81,7 +83,6 @@ public: uint32_t TakeEventSnapshot(); FrameInfo GetDisplayBufferSize() override; - void GetDisplayBuffer(uint32_t* buffer, uint32_t bufferSize) override; DebugEventInfo GetEvent(uint16_t y, uint16_t x) override; diff --git a/Core/SNES/Debugger/SnesEventManager.cpp b/Core/SNES/Debugger/SnesEventManager.cpp index b0082539..4ed62aad 100644 --- a/Core/SNES/Debugger/SnesEventManager.cpp +++ b/Core/SNES/Debugger/SnesEventManager.cpp @@ -151,15 +151,10 @@ EventViewerCategoryCfg SnesEventManager::GetEventConfig(DebugEventInfo& evt) } } -void SnesEventManager::DrawEvent(DebugEventInfo &evt, bool drawBackground, uint32_t *buffer) +void SnesEventManager::ConvertScanlineCycleToRowColumn(int32_t& x, int32_t& y) { - EventViewerCategoryCfg eventCfg = GetEventConfig(evt); - uint32_t color = eventCfg.Color; - - uint32_t y = std::min(evt.Scanline * 2, _scanlineCount * 2); - uint32_t x = evt.Cycle / 2; - - DrawDot(x, y, color, drawBackground, buffer); + y *= 2; + x /= 2; } uint32_t SnesEventManager::TakeEventSnapshot() @@ -199,19 +194,8 @@ FrameInfo SnesEventManager::GetDisplayBufferSize() return size; } -void SnesEventManager::GetDisplayBuffer(uint32_t *buffer, uint32_t bufferSize) +void SnesEventManager::DrawScreen(uint32_t *buffer) { - auto lock = _lock.AcquireSafe(); - - FrameInfo size = GetDisplayBufferSize(); - if(_snapshotScanline < 0 || bufferSize < size.Width * size.Height * sizeof(uint32_t)) { - return; - } - - for(uint32_t i = 0; i < size.Width*size.Height; i++) { - buffer[i] = 0xFF555555; - } - //Skip the first 7 blank lines in the buffer when overscan mode is off uint16_t *src = _ppuBuffer + (_overscanMode ? 0 : (_useHighResOutput ? (512 * 14) : (256 * 7))); @@ -221,25 +205,4 @@ void SnesEventManager::GetDisplayBuffer(uint32_t *buffer, uint32_t bufferSize) buffer[(y + 2)*SnesEventManager::ScanlineWidth + x + 22*2] = SnesDefaultVideoFilter::ToArgb(src[srcOffset]); } } - - constexpr uint32_t nmiColor = 0xFF55FFFF; - constexpr uint32_t currentScanlineColor = 0xFFFFFF55; - int nmiScanline = (_overscanMode ? 240 : 225) * 2 * SnesEventManager::ScanlineWidth; - uint32_t scanlineOffset = _snapshotScanline * 2 * SnesEventManager::ScanlineWidth; - for(int i = 0; i < SnesEventManager::ScanlineWidth; i++) { - buffer[nmiScanline + i] = nmiColor; - buffer[nmiScanline + SnesEventManager::ScanlineWidth + i] = nmiColor; - if(_snapshotScanline != 0) { - buffer[scanlineOffset + i] = currentScanlineColor; - buffer[scanlineOffset + SnesEventManager::ScanlineWidth + i] = currentScanlineColor; - } - } - - FilterEvents(); - for(DebugEventInfo &evt : _sentEvents) { - DrawEvent(evt, true, buffer); - } - for(DebugEventInfo &evt : _sentEvents) { - DrawEvent(evt, false, buffer); - } } diff --git a/Core/SNES/Debugger/SnesEventManager.h b/Core/SNES/Debugger/SnesEventManager.h index c13a3b4d..bb643073 100644 --- a/Core/SNES/Debugger/SnesEventManager.h +++ b/Core/SNES/Debugger/SnesEventManager.h @@ -58,9 +58,9 @@ private: uint32_t _scanlineCount = 262; uint16_t *_ppuBuffer = nullptr; - void DrawEvent(DebugEventInfo& evt, bool drawBackground, uint32_t* buffer); - protected: + void ConvertScanlineCycleToRowColumn(int32_t& x, int32_t& y) override; + void DrawScreen(uint32_t* buffer) override; bool ShowPreviousFrameEvents() override; public: @@ -73,8 +73,7 @@ public: EventViewerCategoryCfg GetEventConfig(DebugEventInfo& evt); uint32_t TakeEventSnapshot(); - FrameInfo GetDisplayBufferSize(); - void GetDisplayBuffer(uint32_t *buffer, uint32_t bufferSize); + FrameInfo GetDisplayBufferSize() override; DebugEventInfo GetEvent(uint16_t y, uint16_t x); void SetConfiguration(BaseEventViewerConfig& config) override; diff --git a/NewUI/Interop/DebugApi.cs b/NewUI/Interop/DebugApi.cs index 7adc0f28..00e4bb10 100644 --- a/NewUI/Interop/DebugApi.cs +++ b/NewUI/Interop/DebugApi.cs @@ -584,7 +584,7 @@ namespace Mesen.Interop public Int16 Scanline; public UInt16 Cycle; public Int16 BreakpointId; - public byte DmaChannel; + public sbyte DmaChannel; public DmaChannelConfig DmaChannelInfo; public EventFlags Flags; public MemoryOperationInfo TargetMemory;