From a012a6b110652aa27f5676f2f18b0ee448096cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 25 May 2020 15:50:15 +0200 Subject: [PATCH] moving internal functions of background to private area --- sources/PPU/Background.cpp | 12 +----------- sources/PPU/Background.hpp | 10 +++++----- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/sources/PPU/Background.cpp b/sources/PPU/Background.cpp index 3fa7cd7..0ad3a46 100644 --- a/sources/PPU/Background.cpp +++ b/sources/PPU/Background.cpp @@ -38,16 +38,6 @@ namespace ComSquare::PPU } } - /*uint16_t Background::getGraphicVramAddress(int x, int y, int bg, int bpp) - { - uint16_t baseAddress = this->_registers._bgnba[bg > 2].raw; - int step = bpp * 8; - - baseAddress = (bg % 2) ? baseAddress & 0xFU : (baseAddress & 0xFU) >> 4U; - baseAddress = baseAddress << 12U; - return baseAddress + (x * 16 * step) + (y * step); - }*/ - void Background::drawBgTile(uint16_t data, Vector2 pos) { uint16_t graphicAddress; @@ -64,7 +54,7 @@ namespace ComSquare::PPU palette = getPalette(tileData.palette); reference = getTilePixelReference(graphicAddress, index); color = getRealColor(palette[reference]); - this->_renderer.putPixel(pos.x, pos.y, color); + this->_buffer[pos.x][pos.y] = color; index++; pos.x++; if (index == (8 / this->_bpp) - 1) { diff --git a/sources/PPU/Background.hpp b/sources/PPU/Background.hpp index 67fb32d..2dab158 100644 --- a/sources/PPU/Background.hpp +++ b/sources/PPU/Background.hpp @@ -22,12 +22,8 @@ namespace ComSquare::PPU bool _priority; uint16_t _vramAddress; uint16_t _graphicVramAddress; - std::array, 1024> _buffer; - public: - Background(int bpp, Vector2 backgroundSize, Vector2 characterSize, bool directColor, bool highRes, bool priority, uint16_t vramAddress, uint16_t graphicVramAddress); - //! @brief Render a background on the screen - void renderBackground(void); + //! @brief Draw a tile on the screen at x y pos void drawBgTile(uint16_t data, Vector2 pos); //! @brief Get a palette from the number of the palette (0 - 7) @@ -38,6 +34,10 @@ namespace ComSquare::PPU uint8_t getTilePixelReference(uint16_t addr, int nb); //! @brief draw a tilemap 32x32 starting at baseAddress void drawBasicTileMap(uint16_t baseAddress, Vector2 offset); + public: + Background(int bpp, Vector2 backgroundSize, Vector2 characterSize, bool directColor, bool highRes, bool priority, uint16_t vramAddress, uint16_t graphicVramAddress); + //! @brief Render a background on the screen + void renderBackground(void); }; }