diff --git a/sources/Debugger/TileViewer/TileRenderer.cpp b/sources/Debugger/TileViewer/TileRenderer.cpp index 4f24d41..06925ca 100644 --- a/sources/Debugger/TileViewer/TileRenderer.cpp +++ b/sources/Debugger/TileViewer/TileRenderer.cpp @@ -7,6 +7,7 @@ #include "TileRenderer.hpp" #include "PPU/PPU.hpp" #include "PPU/Tile.hpp" +#include namespace ComSquare::Debugger { @@ -37,18 +38,19 @@ namespace ComSquare::Debugger int resetX = bufX; int it = 0; - for (uint24_t i = 0; i < fmin(this->_ram->getSize(), this->_renderSize); i += this->_bpp, it++) { - if (bufX >= 1024 || bufY >= 1024) + for (uint24_t i = 0; i < fmin(this->_ram->getSize(), this->_renderSize); i += 2, it++) { + if (bufX > 128 || bufY > 128) break; if (it && it % 8 == 0) { resetX += PPU::Tile::NbPixelsWidth; bufX = resetX; bufY -= PPU::Tile::NbPixelsHeight; + i += (this->_bpp - 2) * 0x8; nbTilesDrawn++; } if (nbTilesDrawn && nbTilesDrawn % this->_nbColumns == 0) { nbTilesDrawn = 0; - break; + //break; resetX = this->_offsetX; bufX = resetX; bufY += PPU::Tile::NbPixelsHeight; @@ -87,7 +89,7 @@ namespace ComSquare::Debugger case 8: return highByte; case 4: - secondHighByte = this->_ram->read((tileRowAddress + 16) % size); + secondHighByte = this->_ram->read((tileRowAddress + 16) % size); secondLowByte = this->_ram->read((tileRowAddress + 17) % size); result = ((secondHighByte & (1U << shift)) | ((secondLowByte & (1U << shift)) << 1U)); result = (shift - 2 >= 0) ? result >> (shift - 2) : result << ((shift - 2) * -1); diff --git a/sources/Debugger/TileViewer/TileRenderer.hpp b/sources/Debugger/TileViewer/TileRenderer.hpp index 8788566..9fc2620 100644 --- a/sources/Debugger/TileViewer/TileRenderer.hpp +++ b/sources/Debugger/TileViewer/TileRenderer.hpp @@ -24,12 +24,12 @@ namespace ComSquare::Debugger //! @brief The number of tile columns to display int _nbColumns; //! @brief render offset in x - int _offsetX = 100; + int _offsetX = 0; //! @brief render offset in y - int _offsetY = 120; + int _offsetY = 0; public: //! @brief internal buffer - std::array, 1024> buffer; + std::array, 128> buffer; //! @brief Set the palette to use for render (index of palette) void setPaletteIndex(int paletteIndex); //! @brief Set the ram to look for color references diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index 21c348d..4b4ce3e 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -470,9 +470,11 @@ namespace ComSquare::PPU (void)cycles; this->tileRenderer.setBpp(4); this->tileRenderer.setPaletteIndex(2); - this->tileRenderer.setNbColumns(1); + this->tileRenderer.setNbColumns(16); this->tileRenderer.render(); - this->add_buffer(this->_screen, this->tileRenderer.buffer); + // for (auto &i : this->_screen) + // i.fill(0xde571dff); + this->add_buffer(this->_screen, this->tileRenderer.buffer, {200, 200}); /* this->renderMainAndSubScreen(); @@ -815,13 +817,15 @@ namespace ComSquare::PPU } } - template - void PPU::add_buffer(std::array, DEST_SIZE> &bufferDest, std::array, SRC_SIZE> &bufferSrc) + template + void PPU::add_buffer(std::array, DEST_SIZE_X> &bufferDest, + const std::array, SRC_SIZE_X> &bufferSrc, + const Vector2 &offset) { for (unsigned long i = 0; i < bufferSrc.size(); i++) { for (unsigned long j = 0; j < bufferSrc[i].size(); j++) { if (bufferSrc[i][j] > 0xFF) // 0xFF correspond to a black pixel with full brightness - bufferDest[i][j] = bufferSrc[i][j]; + bufferDest[i + offset.x ][j + offset.y] = bufferSrc[i][j]; } } } diff --git a/sources/PPU/PPU.hpp b/sources/PPU/PPU.hpp index f68595b..4347101 100644 --- a/sources/PPU/PPU.hpp +++ b/sources/PPU/PPU.hpp @@ -620,8 +620,10 @@ namespace ComSquare::PPU //! @brief Render the Main and sub screen correctly void renderMainAndSubScreen(); //! @brief Add a bg buffer to another buffer - template - void add_buffer(std::array, DEST_SIZE> &bufferDest, std::array, SRC_SIZE> &bufferSrc); + template + void add_buffer(std::array, DEST_SIZE_X> &bufferDest, + const std::array, SRC_SIZE_X> &bufferSrc, + const Vector2 &offset = {0, 0}); //! @brief Add a bg to the sub and/or main screen void addToMainSubScreen(Background &bg); //! @brief Get the current background Mode