GB: PPU - Improved window emulation

-Latch x/y/enabled values for the scanline (can't be changed midscanline based on wx_split test)
-Keep count of the scanlines where window rendering occurs to render the excepted lines in the window
This commit is contained in:
Sour 2020-05-28 22:07:34 -04:00
parent fd1ff4cb3e
commit dc986b72b7
2 changed files with 13 additions and 3 deletions

View file

@ -116,6 +116,7 @@ void GbPpu::ExecCycle()
ChangeMode(PpuMode::OamEvaluation);
} else if(_state.Scanline == 144) {
ChangeMode(PpuMode::VBlank);
_windowCounter = -1;
_memoryManager->RequestIrq(GbIrqSource::VerticalBlank);
SendFrame();
}
@ -124,6 +125,9 @@ void GbPpu::ExecCycle()
case 84: {
if(_state.Scanline < 144) {
_latchWindowX = _state.WindowX;
_latchWindowY = _state.WindowY;
_latchWindowEnabled = _state.WindowEnabled;
ChangeMode(PpuMode::Drawing);
ResetRenderer();
}
@ -194,11 +198,12 @@ void GbPpu::RunDrawCycle()
return;
}
bool fetchWindow = _state.WindowEnabled && _drawnPixels >= _state.WindowX - 7 && _state.Scanline >= _state.WindowY;
bool fetchWindow = _latchWindowEnabled && _drawnPixels >= _latchWindowX - 7 && _state.Scanline >= _latchWindowY;
if(_fetchWindow != fetchWindow) {
//Switched between window & background, reset fetcher & pixel FIFO
_fetchWindow = fetchWindow;
_fetchColumn = 0;
_windowCounter++;
_bgFetcher.Step = 0;
_bgFifo.Reset();
@ -344,7 +349,7 @@ void GbPpu::ClockTileFetcher()
uint8_t yOffset;
if(_fetchWindow) {
tilemapAddr = _state.WindowTilemapSelect ? 0x1C00 : 0x1800;
yOffset = _state.Scanline - _state.WindowY;
yOffset = (uint8_t)_windowCounter;
} else {
tilemapAddr = _state.BgTilemapSelect ? 0x1C00 : 0x1800;
yOffset = _state.ScrollY + _state.Scanline;
@ -731,7 +736,8 @@ void GbPpu::Serialize(Serializer& s)
_state.WindowEnabled, _state.BgTileSelect, _state.BgTilemapSelect, _state.LargeSprites, _state.SpritesEnabled, _state.BgEnabled,
_state.Status, _state.FrameCount, _lastFrameTime, _state.LyCoincidenceFlag,
_state.CgbBgPalAutoInc, _state.CgbBgPalPosition,
_state.CgbObjPalAutoInc, _state.CgbObjPalPosition, _state.CgbVramBank, _state.CgbEnabled
_state.CgbObjPalAutoInc, _state.CgbObjPalPosition, _state.CgbVramBank, _state.CgbEnabled,
_latchWindowX, _latchWindowY, _latchWindowEnabled, _windowCounter
);
s.StreamArray(_state.CgbBgPalettes, 4 * 8);

View file

@ -38,6 +38,10 @@ private:
int16_t _drawnPixels = 0;
uint8_t _fetchColumn = 0;
bool _fetchWindow = false;
int16_t _windowCounter = -1;
uint8_t _latchWindowX = 0;
uint8_t _latchWindowY = 0;
bool _latchWindowEnabled = false;
int16_t _fetchSprite = -1;
uint8_t _spriteCount = 0;