diff --git a/Core/Debugger.cpp b/Core/Debugger.cpp index ea5c95a5..76754ad5 100644 --- a/Core/Debugger.cpp +++ b/Core/Debugger.cpp @@ -926,11 +926,13 @@ void Debugger::SetPpuViewerScanlineCycle(int32_t scanline, int32_t cycle) _ppuViewerCycle = cycle; } -void Debugger::SetLastFramePpuScroll(uint16_t x, uint16_t y) +void Debugger::SetLastFramePpuScroll(uint16_t addr, uint8_t xScroll, bool updateHorizontalScrollOnly) { if(Debugger::Instance) { - Debugger::Instance->_ppuScrollX = x; - Debugger::Instance->_ppuScrollY = y; + Debugger::Instance->_ppuScrollX = ((addr & 0x1F) << 3) | xScroll | ((addr & 0x400) ? 0x100 : 0); + if(!updateHorizontalScrollOnly) { + Debugger::Instance->_ppuScrollY = (((addr & 0x3E0) >> 2) | ((addr & 0x7000) >> 12)) + ((addr & 0x800) ? 240 : 0); + } } } diff --git a/Core/Debugger.h b/Core/Debugger.h index d0e71003..bd76632a 100644 --- a/Core/Debugger.h +++ b/Core/Debugger.h @@ -196,7 +196,7 @@ public: static void ProcessVramWriteOperation(uint16_t addr, uint8_t &value); static void ProcessPpuCycle(); - static void SetLastFramePpuScroll(uint16_t x, uint16_t y); + static void SetLastFramePpuScroll(uint16_t addr, uint8_t xScroll, bool updateHorizontalScrollOnly); uint32_t GetPpuScroll(); static void ProcessInterrupt(uint16_t cpuAddr, uint16_t destCpuAddr, bool forNmi); diff --git a/Core/PPU.cpp b/Core/PPU.cpp index 0e4e3d46..a19a5000 100644 --- a/Core/PPU.cpp +++ b/Core/PPU.cpp @@ -330,6 +330,9 @@ void PPU::WriteRAM(uint16_t addr, uint8_t value) } else { _state.XScroll = value & 0x07; _state.TmpVideoRamAddr = (_state.TmpVideoRamAddr & ~0x001F) | (value >> 3); + + //Update debugger overlay X scroll only + Debugger::SetLastFramePpuScroll(_state.TmpVideoRamAddr, _state.XScroll, false); } _state.WriteToggle = !_state.WriteToggle; break; @@ -341,6 +344,7 @@ void PPU::WriteRAM(uint16_t addr, uint8_t value) //A 3-cycle delay causes issues with the scanline test. _updateVramAddrDelay = 2; _updateVramAddr = _state.TmpVideoRamAddr; + Debugger::SetLastFramePpuScroll(_updateVramAddr, _state.XScroll, false); } else { _state.TmpVideoRamAddr = (_state.TmpVideoRamAddr & ~0xFF00) | ((value & 0x3F) << 8); } @@ -843,10 +847,7 @@ void PPU::ProcessScanline() _oamCopybuffer = _secondarySpriteRAM[0]; } if(_scanline == -1) { - Debugger::SetLastFramePpuScroll( - ((_state.VideoRamAddr & 0x1F) << 3) | _state.XScroll | ((_state.VideoRamAddr & 0x400) ? 0x100 : 0), - (((_state.VideoRamAddr & 0x3E0) >> 2) | ((_state.VideoRamAddr & 0x7000) >> 12)) + ((_state.VideoRamAddr & 0x800) ? 240 : 0) - ); + Debugger::SetLastFramePpuScroll(_state.VideoRamAddr, _state.XScroll, false); } } else if(_prevRenderingEnabled && (_cycle == 328 || _cycle == 336)) { _state.LowBitShift <<= 8; diff --git a/Core/PPU.h b/Core/PPU.h index c701b8cf..8f3f1c20 100644 --- a/Core/PPU.h +++ b/Core/PPU.h @@ -224,7 +224,7 @@ class PPU : public IMemoryHandler, public Snapshotable { return _secondarySpriteRAM; } - + static uint32_t GetPixelBrightness(uint8_t x, uint8_t y) { //Used by Zapper, gives a rough approximation of the brightness level of the specific pixel diff --git a/GUI.NET/Debugger/Controls/ctrlNametableViewer.cs b/GUI.NET/Debugger/Controls/ctrlNametableViewer.cs index 1eccd120..d9c3127e 100644 --- a/GUI.NET/Debugger/Controls/ctrlNametableViewer.cs +++ b/GUI.NET/Debugger/Controls/ctrlNametableViewer.cs @@ -25,6 +25,8 @@ namespace Mesen.GUI.Debugger.Controls private int _currentPpuAddress = -1; private int _tileX = 0; private int _tileY = 0; + private int _xScroll = 0; + private int _yScroll = 0; private int _nametableIndex = 0; private ctrlChrViewer _chrViewer; @@ -48,6 +50,8 @@ namespace Mesen.GUI.Debugger.Controls public void GetData() { + InteropEmu.DebugGetPpuScroll(out _xScroll, out _yScroll); + for(int i = 0; i < 4; i++) { InteropEmu.DebugGetNametable(i, out _nametablePixelData[i], out _tileData[i], out _attributeData[i]); } @@ -57,9 +61,6 @@ namespace Mesen.GUI.Debugger.Controls { _currentPpuAddress = -1; - int xScroll, yScroll; - InteropEmu.DebugGetPpuScroll(out xScroll, out yScroll); - DebugState state = new DebugState(); InteropEmu.DebugGetState(ref state); int tileIndexOffset = state.PPU.ControlFlags.BackgroundPatternAddr == 0x1000 ? 256 : 0; @@ -114,7 +115,7 @@ namespace Mesen.GUI.Debugger.Controls } if(chkShowPpuScrollOverlay.Checked) { - DrawScrollOverlay(xScroll, yScroll, g); + DrawScrollOverlay(_xScroll, _yScroll, g); } }