From d5af9fe98ab96af7eb26bd5a21e13cebbbd5faa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Thu, 4 Feb 2021 19:06:54 +0100 Subject: [PATCH] starting implementing bg scroll --- sources/PPU/Background.cpp | 2 +- sources/PPU/PPU.cpp | 12 +++++++++++- sources/PPU/PPU.hpp | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sources/PPU/Background.cpp b/sources/PPU/Background.cpp index 1fa3b52..412b7d7 100644 --- a/sources/PPU/Background.cpp +++ b/sources/PPU/Background.cpp @@ -30,7 +30,7 @@ namespace ComSquare::PPU void Background::renderBackground() { uint16_t vramAddress = this->_tileMapStartAddress; - Vector2 offset(0, 0); + Vector2 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; diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index cb9067e..f458af6 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -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 PPU::getBgScroll(int bgNumber) const + { + return Vector2(this->_registers._bgofs[(bgNumber - 1) * 2].offsetBg, this->_registers._bgofs[(bgNumber - 1) * 2 + 1].offsetBg); + } } \ No newline at end of file diff --git a/sources/PPU/PPU.hpp b/sources/PPU/PPU.hpp index c3b0adb..5c3cf3a 100644 --- a/sources/PPU/PPU.hpp +++ b/sources/PPU/PPU.hpp @@ -627,6 +627,8 @@ namespace ComSquare::PPU int getBgMode() const; //! @brief update the Vram buffer void updateVramReadBuffer(); + //! @brief update the Vram buffer + Vector2 getBgScroll(int bgNumber) const; }; }