mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-05-24 15:18:44 +00:00
fixing the get palette and getTilesetAddress
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "PPUUtils.hpp"
|
||||
#include "PPU.hpp"
|
||||
#include "Background.hpp"
|
||||
#include <cmath>
|
||||
#include "../Models/Vector2.hpp"
|
||||
|
||||
namespace ComSquare::PPU
|
||||
@@ -75,10 +76,11 @@ namespace ComSquare::PPU
|
||||
|
||||
std::vector<uint16_t> Background::getPalette(int nbPalette)
|
||||
{
|
||||
std::vector<uint16_t> 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<uint16_t> 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);
|
||||
}
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user