diff --git a/sources/PPU/Background.cpp b/sources/PPU/Background.cpp index 07f90ba..5dd7bf1 100644 --- a/sources/PPU/Background.cpp +++ b/sources/PPU/Background.cpp @@ -11,14 +11,14 @@ namespace ComSquare::PPU { Background::Background(ComSquare::PPU::PPU &_ppu, int backGroundNumber, bool hasPriority): - priority(hasPriority), - bgNumber(backGroundNumber) + _priority(hasPriority), + _bgNumber(backGroundNumber) { _cgram = _ppu.cgram; _vram = _ppu.vram; _bpp = _ppu.getBPP(backGroundNumber); _characterSize = _ppu.getCharacterSize(backGroundNumber); - _TileMapStartAddress = _ppu.getTileMapStartAddress(backGroundNumber); + _tileMapStartAddress = _ppu.getTileMapStartAddress(backGroundNumber); _tilesetAddress = _ppu.getTilesetAddress(backGroundNumber); _tileMaps = _ppu.getBackgroundSize(backGroundNumber); _directColor = false; @@ -26,9 +26,9 @@ namespace ComSquare::PPU } - void Background::renderBackground(void) + void Background::renderBackground() { - uint16_t vramAddress = this->_TileMapStartAddress; + uint16_t vramAddress = this->_tileMapStartAddress; Vector2 offset(0, 0); this->backgroundSize.x = this->_tileMaps.x * this->_characterSize.x * NB_CHARACTER_WIDTH; this->backgroundSize.y = this->_tileMaps.y * this->_characterSize.y * NB_CHARACTER_HEIGHT; @@ -69,7 +69,7 @@ namespace ComSquare::PPU for (int j = 0; j < this->_characterSize.x; j++) { reference = getPixelReferenceFromTile(graphicAddress, index); color = getRealColor(palette[reference]); - if (tileData.tilePriority == this->priority) // reference 0 is considered as transparency + if (tileData.tilePriority == this->_priority) // reference 0 is considered as transparency this->buffer[pos.x][pos.y] = (reference) ? color : 0; index += (tileData.horizontalFlip) ? -1 : 1; pos.x++; @@ -161,7 +161,7 @@ namespace ComSquare::PPU void Background::setTileMapStartAddress(uint16_t address) { - this->_TileMapStartAddress = address; + this->_tileMapStartAddress = address; } void Background::setTilesetAddress(uint16_t address) @@ -182,8 +182,28 @@ namespace ComSquare::PPU this->_bpp = 2; } - void Background::setTilemaps(Vector2 tilemaps) + void Background::setTilemaps(Vector2 tileMaps) { - this->_tileMaps = tilemaps; + this->_tileMaps = tileMaps; + } + + void Background::setBgNumber(int bgNumber) + { + this->_bgNumber = bgNumber; + } + + int Background::getBgNumber() const + { + return this->_bgNumber; + } + + void Background::setPriority(bool priority) + { + this->_priority = priority; + } + + bool Background::getPriority() const + { + return this->_priority; } } \ No newline at end of file diff --git a/sources/PPU/Background.hpp b/sources/PPU/Background.hpp index feaaab5..89c66a6 100644 --- a/sources/PPU/Background.hpp +++ b/sources/PPU/Background.hpp @@ -29,8 +29,10 @@ namespace ComSquare::PPU int _bpp; bool _directColor; bool _highRes; - uint16_t _TileMapStartAddress; + uint16_t _tileMapStartAddress; uint16_t _tilesetAddress; + bool _priority; + int _bgNumber; std::shared_ptr _vram; std::shared_ptr _cgram; @@ -50,20 +52,19 @@ namespace ComSquare::PPU //! @param pixelIndex The index of the pixel (0 - 255) //! @return The color reference uint8_t getPixelReferenceFromTile(uint16_t tileAddress, uint8_t pixelIndex); - //! @brief draw a tilemap 32x32 starting at baseAddress + //! @brief draw a tileMap 32x32 starting at baseAddress //! @param baseAddress The starting address of the tileMap //! @param offset The rendering offeset in pixels void drawBasicTileMap(uint16_t baseAddress, Vector2 offset); public: // TODO getter setter for priority and bgNumber - bool priority; - int bgNumber; + Vector2 backgroundSize; std::array, 1024> buffer; Background(ComSquare::PPU::PPU &_ppu, int backGroundNumber, bool hasPriority); //! @brief Render a background on his internal buffer - void renderBackground(void); - //! @brief Set the tilemap start address + void renderBackground(); + //! @brief Set the tileMap start address //! @param address TileMap start address void setTileMapStartAddress(uint16_t address); //! @brief Set the character Size @@ -74,7 +75,21 @@ namespace ComSquare::PPU //! @brief Set the bpp (bits per pixels) of the Background //! @info The bpp can be 2, 4 or 8 (7 can be possible when BgMode is 7) void setBpp(int bpp); - void setTilemaps(Vector2 tilemaps); + //! @brief setter for private variable _tileMaps + //! @param tileMaps The tileMaps to set + void setTilemaps(Vector2 tileMaps); + //! @brief set the Background number + //! @param bgNumber the new Background Number + void setBgNumber(int bgNumber); + //! @brief Get the BackGround Number + //! @return the current Background number + int getBgNumber() const; + //! @brief set the Background priority + //! @param bgNumber the new Background priority + void setPriority(bool priority); + //! @brief Get the Background priority + //! @return the current Background priority + bool getPriority() const; }; } diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index b155ce3..ca69803 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -750,9 +750,9 @@ namespace ComSquare::PPU void PPU::addToMainSubScreen(Background &bg) { - if (this->_registers._t[0].raw & (1U << (bg.bgNumber - 1U))) + if (this->_registers._t[0].raw & (1U << (bg.getBgNumber() - 1U))) this->add_buffer(this->_mainScreen, bg.buffer); - if (this->_registers._t[1].raw & (1U << (bg.bgNumber - 1U))) + if (this->_registers._t[1].raw & (1U << (bg.getBgNumber() - 1U))) this->add_buffer(this->_subScreen, bg.buffer); } } \ No newline at end of file diff --git a/ui/ui_cpu.h b/ui/ui_cpu.h index 5bb8f98..35c8512 100644 --- a/ui/ui_cpu.h +++ b/ui/ui_cpu.h @@ -1,7 +1,7 @@ /******************************************************************************** ** Form generated from reading UI file 'cpu.ui' ** -** Created by: Qt User Interface Compiler version 5.13.2 +** Created by: Qt User Interface Compiler version 5.15.2 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/