mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-05-25 15:39:28 +00:00
TileRenderer.cpp is now working for 2 & 4 bpps
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "TileRenderer.hpp"
|
||||
#include "PPU/PPU.hpp"
|
||||
#include "PPU/Tile.hpp"
|
||||
#include <iostream>
|
||||
|
||||
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);
|
||||
|
||||
@@ -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<std::array<uint32_t, 1024>, 1024> buffer;
|
||||
std::array<std::array<uint32_t, 200>, 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
|
||||
|
||||
+9
-5
@@ -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 <std::size_t DEST_SIZE, std::size_t SRC_SIZE>
|
||||
void PPU::add_buffer(std::array<std::array<uint32_t, DEST_SIZE>, DEST_SIZE> &bufferDest, std::array<std::array<uint32_t, SRC_SIZE>, SRC_SIZE> &bufferSrc)
|
||||
template <std::size_t DEST_SIZE_X, std::size_t DEST_SIZE_Y, std::size_t SRC_SIZE_X, std::size_t SRC_SIZE_Y>
|
||||
void PPU::add_buffer(std::array<std::array<uint32_t, DEST_SIZE_Y>, DEST_SIZE_X> &bufferDest,
|
||||
const std::array<std::array<uint32_t, SRC_SIZE_Y>, SRC_SIZE_X> &bufferSrc,
|
||||
const Vector2<int> &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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -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 <std::size_t DEST_SIZE, std::size_t SRC_SIZE>
|
||||
void add_buffer(std::array<std::array<uint32_t, DEST_SIZE>, DEST_SIZE> &bufferDest, std::array<std::array<uint32_t, SRC_SIZE>, SRC_SIZE> &bufferSrc);
|
||||
template <std::size_t DEST_SIZE_X, std::size_t DEST_SIZE_Y, std::size_t SRC_SIZE_X, std::size_t SRC_SIZE_Y>
|
||||
void add_buffer(std::array<std::array<uint32_t, DEST_SIZE_Y>, DEST_SIZE_X> &bufferDest,
|
||||
const std::array<std::array<uint32_t, SRC_SIZE_Y>, SRC_SIZE_X> &bufferSrc,
|
||||
const Vector2<int> &offset = {0, 0});
|
||||
//! @brief Add a bg to the sub and/or main screen
|
||||
void addToMainSubScreen(Background &bg);
|
||||
//! @brief Get the current background Mode
|
||||
|
||||
Reference in New Issue
Block a user