diff --git a/Core/Ppu.cpp b/Core/Ppu.cpp index 73c5bd9..e327351 100644 --- a/Core/Ppu.cpp +++ b/Core/Ppu.cpp @@ -352,9 +352,15 @@ void Ppu::RenderMode7() { RenderSprites<3, forMainScreen>(); RenderSprites<2, forMainScreen>(); + if(_mode7.ExtBgEnabled) { + RenderTilemapMode7<1, forMainScreen, false, true>(); + } RenderSprites<1, forMainScreen>(); - RenderTilemapMode7<0, forMainScreen, false>(); + RenderTilemapMode7<0, forMainScreen, false, false>(); RenderSprites<0, forMainScreen>(); + if(_mode7.ExtBgEnabled) { + RenderTilemapMode7<1, forMainScreen, false, false>(); + } RenderBgColor(); } @@ -619,7 +625,7 @@ void Ppu::RenderTilemap() } } -template +template void Ppu::RenderTilemapMode7() { uint16_t realY = _mode7.VerticalMirroring ? (255 - _scanline) : _scanline; @@ -699,7 +705,18 @@ void Ppu::RenderTilemapMode7() } uint8_t tileIndex = _vram[(((yOffset & ~0x07) << 4) | (xOffset >> 3)) << 1] & tileMask; - uint16_t paletteRamOffset = (_vram[(((tileIndex << 6) + ((yOffset & 0x07) << 3) + (xOffset & 0x07)) << 1) + 1]) << 1; + uint16_t paletteRamOffset; + + if(layerIndex == 1) { + uint8_t color = _vram[(((tileIndex << 6) + ((yOffset & 0x07) << 3) + (xOffset & 0x07)) << 1) + 1]; + if(((uint8_t)processHighPriority << 7) != (color & 0x80)) { + //Wrong priority, skip this pixel + continue; + } + paletteRamOffset = (color & 0x7F) << 1; + } else { + paletteRamOffset = (_vram[(((tileIndex << 6) + ((yOffset & 0x07) << 3) + (xOffset & 0x07)) << 1) + 1]) << 1; + } if(paletteRamOffset > 0) { if(forMainScreen) { @@ -1302,6 +1319,16 @@ void Ppu::Write(uint32_t addr, uint8_t value) } break; + case 0x2133: + //SETINI - Screen Mode/Video Select + //_externalSync = (value & 0x80) != 0; //NOT USED + _mode7.ExtBgEnabled = (value & 0x40) != 0; + //_hiresMode = (value & 0x08) != 0; //TODO + //_overscanMode = (value & 0x04) != 0; //TODO + //_objInterlace = (value & 0x02) != 0; //TODO + //_screenInterlace = (value & 0x01) != 0; //TODO + break; + default: MessageManager::DisplayMessage("Debug", "Unimplemented register write: " + HexUtilities::ToHex(addr) + " = " + HexUtilities::ToHex(value)); break; diff --git a/Core/Ppu.h b/Core/Ppu.h index 84045c9..154a44b 100644 --- a/Core/Ppu.h +++ b/Core/Ppu.h @@ -164,7 +164,7 @@ private: template void RenderTilemap(); - template + template void RenderTilemapMode7(); template diff --git a/Core/PpuTypes.h b/Core/PpuTypes.h index 37e96ff..2fe55a4 100644 --- a/Core/PpuTypes.h +++ b/Core/PpuTypes.h @@ -24,21 +24,20 @@ struct LayerConfig struct Mode7Config { + int16_t Matrix[4]; + int16_t HScroll; int16_t VScroll; - - bool LargeMap; - bool FillWithTile0; - - bool HorizontalMirroring; - bool VerticalMirroring; - int16_t CenterX; int16_t CenterY; - int16_t Matrix[4]; - uint8_t ValueLatch; + + bool LargeMap; + bool FillWithTile0; + bool HorizontalMirroring; + bool VerticalMirroring; + bool ExtBgEnabled; }; struct WindowConfig