From fef78e5802aaeb753f2510e05326961dcc9dd351 Mon Sep 17 00:00:00 2001 From: Sour Date: Sat, 23 Feb 2019 01:28:41 -0500 Subject: [PATCH] PPU: Support for 16x16 tiles --- Core/Ppu.cpp | 28 +++++++++++++++++++++++----- Core/Ppu.h | 3 +++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Core/Ppu.cpp b/Core/Ppu.cpp index b29ea68..f0be58b 100644 --- a/Core/Ppu.cpp +++ b/Core/Ppu.cpp @@ -444,6 +444,16 @@ void Ppu::RenderBgColor() template void Ppu::RenderTilemap() +{ + if(_layerConfig[layerIndex].LargeTiles) { + RenderTilemap(); + } else { + RenderTilemap(); + } +} + +template +void Ppu::RenderTilemap() { if(forMainScreen) { if(_pixelsDrawn == 256 || ((_mainScreenLayers >> layerIndex) & 0x01) == 0) { @@ -470,14 +480,14 @@ void Ppu::RenderTilemap() LayerConfig &config = _layerConfig[layerIndex]; uint16_t tilemapAddr = config.TilemapAddress >> 1; uint16_t chrAddr = config.ChrAddress; - uint16_t row = (_scanline + config.VScroll) >> 3; + uint16_t row = (_scanline + config.VScroll) >> (largeTiles ? 4 : 3); uint8_t baseYOffset = (_scanline + config.VScroll) & 0x07; uint16_t addrVerticalScrollingOffset = config.VerticalMirroring ? ((row & 0x20) << (config.HorizontalMirroring ? 6 : 5)) : 0; uint16_t baseOffset = tilemapAddr + addrVerticalScrollingOffset + ((row & 0x1F) << 5); for(int x = 0; x < 256; x++) { - uint16_t column = (x + config.HScroll) >> 3; + uint16_t column = (x + config.HScroll) >> (largeTiles ? 4 : 3); uint32_t addr = (baseOffset + (column & 0x1F) + (config.HorizontalMirroring ? ((column & 0x20) << 5) : 0)) << 1; if(forMainScreen) { @@ -507,10 +517,18 @@ void Ppu::RenderTilemap() continue; } - uint16_t tileIndex = ((_vram[addr + 1] & 0x03) << 8) | _vram[addr]; bool vMirror = (_vram[addr + 1] & 0x80) != 0; bool hMirror = (_vram[addr + 1] & 0x40) != 0; + uint16_t tileIndex = ((_vram[addr + 1] & 0x03) << 8) | _vram[addr]; + if(largeTiles) { + tileIndex = ( + tileIndex + + (((_scanline + config.VScroll) & 0x08) ? (vMirror ? 0 : 16) : (vMirror ? 16 : 0)) + + (((x + config.HScroll) & 0x08) ? (hMirror ? 0 : 1) : (hMirror ? 1 : 0)) + ) & 0x3FF; + } + uint16_t tileStart = chrAddr + tileIndex * 8 * bpp; uint8_t yOffset = vMirror ? (7 - baseYOffset) : baseYOffset; @@ -894,8 +912,8 @@ void Ppu::Write(uint32_t addr, uint8_t value) _layerConfig[0].LargeTiles = (value & 0x10) != 0; _layerConfig[1].LargeTiles = (value & 0x20) != 0; - _layerConfig[2].LargeTiles = (value & 0x30) != 0; - _layerConfig[3].LargeTiles = (value & 0x40) != 0; + _layerConfig[2].LargeTiles = (value & 0x40) != 0; + _layerConfig[3].LargeTiles = (value & 0x80) != 0; break; case 0x2106: diff --git a/Core/Ppu.h b/Core/Ppu.h index ba398ed..bc35837 100644 --- a/Core/Ppu.h +++ b/Core/Ppu.h @@ -160,6 +160,9 @@ private: template void RenderTilemap(); + template + void RenderTilemap(); + void ApplyColorMath(); void ApplyBrightness();