From 44ec270c56236286607f01e02e9373dd566d1dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Tue, 13 Oct 2020 23:48:40 +0200 Subject: [PATCH] fixing the get palette and getTilesetAddress --- sources/PPU/Background.cpp | 10 ++++++---- sources/PPU/PPU.cpp | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sources/PPU/Background.cpp b/sources/PPU/Background.cpp index fb985f2..49e53c2 100644 --- a/sources/PPU/Background.cpp +++ b/sources/PPU/Background.cpp @@ -5,6 +5,7 @@ #include "PPUUtils.hpp" #include "PPU.hpp" #include "Background.hpp" +#include #include "../Models/Vector2.hpp" namespace ComSquare::PPU @@ -75,10 +76,11 @@ namespace ComSquare::PPU std::vector Background::getPalette(int nbPalette) { - std::vector palette(0x10); - uint16_t addr = nbPalette * 0x20; + uint8_t nbColors = std::pow(2, this->_bpp); + uint16_t addr = nbPalette * this->_bpp * this->_bpp * 2; + std::vector palette(nbColors); - for (int i = 0; i < 0x10; i++) { + for (int i = 0; i < nbColors; i++) { palette[i] = this->_cgram->read_internal(addr); palette[i] += this->_cgram->read_internal(addr + 1) << 8U; addr += 2; @@ -100,7 +102,7 @@ namespace ComSquare::PPU column -= TILE_PIXEL_WIDTH; } // might not work with 8 bpp must check - tileAddress += this->_bpp * row / 2; + tileAddress += 2 * row; return this->getPixelReferenceFromTileRow(tileAddress, column); } diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index 388e622..43d03b0 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -616,7 +616,7 @@ namespace ComSquare::PPU uint16_t baseAddress = this->_registers._bgnba[bgNumber > 2].raw; baseAddress = (bgNumber % 2) ? baseAddress & 0xFU : (baseAddress & 0xFU) >> 4U; - baseAddress = baseAddress << 12U; + baseAddress = baseAddress << 13U; return baseAddress; } @@ -632,9 +632,9 @@ namespace ComSquare::PPU void PPU::renderMainAndSubScreen(void) { uint16_t colorPalette; + // should only render backgrounds needed (depending of th bgMode) for (auto & _background : this->_backgrounds) _background.renderBackground(); - // TODO make a function getDefaultBgColor colorPalette = this->cgram->read_internal(0); colorPalette += this->cgram->read_internal(1) << 8U;