starting implementing bg scroll

This commit is contained in:
Clément Le Bihan
2021-02-04 19:06:54 +01:00
parent 58fd02c8ec
commit d5af9fe98a
3 changed files with 14 additions and 2 deletions

View File

@@ -30,7 +30,7 @@ namespace ComSquare::PPU
void Background::renderBackground()
{
uint16_t vramAddress = this->_tileMapStartAddress;
Vector2<int> offset(0, 0);
Vector2<int> offset = this->_ppu.getBgScroll(this->_bgNumber);
this->backgroundSize.x = this->_tileMaps.x * this->_characterSize.x * NB_CHARACTER_WIDTH;
this->backgroundSize.y = this->_tileMaps.y * this->_characterSize.y * NB_CHARACTER_HEIGHT;

View File

@@ -141,6 +141,8 @@ namespace ComSquare::PPU
this->_backgrounds[2].setTileMapStartAddress(this->getTileMapStartAddress(2));
this->_backgrounds[3].setTileMapStartAddress(this->getTileMapStartAddress(2));
//this->_registers._bgofs[2].raw = 0x03E0;
//this->_registers._bgofs[3].raw = 0x03DF;
this->_registers._t[0].enableWindowDisplayBg1 = true;
this->_registers._t[0].enableWindowDisplayBg2 = true;
@@ -699,8 +701,11 @@ namespace ComSquare::PPU
{
uint16_t colorPalette;
// should only render backgrounds needed (depending of th bgMode)
for (auto & _background : this->_backgrounds)
int i = 0;
for (auto &_background : this->_backgrounds) {
i++;
_background.renderBackground();
}
// TODO make a function getDefaultBgColor
colorPalette = this->cgram->read_internal(0);
colorPalette += this->cgram->read_internal(1) << 8U;
@@ -824,4 +829,9 @@ namespace ComSquare::PPU
this->_vramReadBuffer = this->vram->read_internal(this->getVramAddress());
this->_vramReadBuffer += this->vram->read_internal(this->getVramAddress() + 1) << 8;
}
Vector2<int> PPU::getBgScroll(int bgNumber) const
{
return Vector2<int>(this->_registers._bgofs[(bgNumber - 1) * 2].offsetBg, this->_registers._bgofs[(bgNumber - 1) * 2 + 1].offsetBg);
}
}

View File

@@ -627,6 +627,8 @@ namespace ComSquare::PPU
int getBgMode() const;
//! @brief update the Vram buffer
void updateVramReadBuffer();
//! @brief update the Vram buffer
Vector2<int> getBgScroll(int bgNumber) const;
};
}