From 98e6a83c15d72a68f501e80725f0cb97d86115c9 Mon Sep 17 00:00:00 2001 From: Souryo Date: Sun, 13 Nov 2016 22:46:55 -0500 Subject: [PATCH] PPU: Fixed issue with Remove Sprite Limit option that could cause the game to display the extra sprites from the wrong chr banks (i.e MMC5 Castlevania 3) due to calling LoadExtraSprites() on cycle 256 --- Core/PPU.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Core/PPU.cpp b/Core/PPU.cpp index 5e0755f3..024226b8 100644 --- a/Core/PPU.cpp +++ b/Core/PPU.cpp @@ -511,23 +511,27 @@ void PPU::LoadSprite(uint8_t spriteY, uint8_t tileIndex, uint8_t attributes, uin tileAddr = ((tileIndex << 4) | _flags.SpritePatternAddr) + lineOffset; } + bool fetchLastSprite = true; if((_spriteIndex < _spriteCount || extraSprite) && spriteY < 240) { _spriteTiles[_spriteIndex].BackgroundPriority = backgroundPriority; _spriteTiles[_spriteIndex].HorizontalMirror = horizontalMirror; _spriteTiles[_spriteIndex].VerticalMirror = verticalMirror; _spriteTiles[_spriteIndex].PaletteOffset = ((attributes & 0x03) << 2) | 0x10; if(extraSprite) { - //Use DebugReadVRAM for extra sprites to prevent most side-effects. + //Use DebugReadVRAM for extra sprites to prevent side-effects. _spriteTiles[_spriteIndex].LowByte = _memoryManager->DebugReadVRAM(tileAddr); _spriteTiles[_spriteIndex].HighByte = _memoryManager->DebugReadVRAM(tileAddr + 8); } else { + fetchLastSprite = false; _spriteTiles[_spriteIndex].LowByte = _memoryManager->ReadVRAM(tileAddr); _spriteTiles[_spriteIndex].HighByte = _memoryManager->ReadVRAM(tileAddr + 8); } _spriteTiles[_spriteIndex].TileAddr = tileAddr; _spriteTiles[_spriteIndex].OffsetY = lineOffset; _spriteTiles[_spriteIndex].SpriteX = spriteX; - } else if(!extraSprite) { + } + + if(fetchLastSprite) { //Fetches to sprite 0xFF for remaining sprites/hidden - used by MMC3 IRQ counter lineOffset = 0; tileIndex = 0xFF; @@ -561,6 +565,9 @@ void PPU::LoadSpriteTileInfo() { uint8_t *spriteAddr = _secondarySpriteRAM + _spriteIndex * 4; LoadSprite(*spriteAddr, *(spriteAddr+1), *(spriteAddr+2), *(spriteAddr+3), false); + if(_cycle == 316) { + LoadExtraSprites(); + } } void PPU::LoadNextTile() @@ -776,8 +783,6 @@ void PPU::CopyOAMData() } else if(_cycle == 256) { _sprite0Visible = _sprite0Added; _spriteCount = (_secondaryOAMAddr >> 2); - - LoadExtraSprites(); } if(_cycle & 0x01) {