mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-04 10:44:37 +00:00
tile renderer is working fine with 2 bpp
This commit is contained in:
+1
-1
@@ -242,7 +242,7 @@ add_executable(ComSquare
|
||||
sources/Renderer/QtRenderer/QtRenderSfml.hpp
|
||||
sources/Debugger/TileViewer/TileViewer.cpp
|
||||
sources/Debugger/TileViewer/TileViewer.hpp
|
||||
sources/Debugger/TileViewer/TileRenderer.cpp sources/Debugger/TileViewer/TileRenderer.hpp)
|
||||
sources/Debugger/TileViewer/TileRenderer.cpp sources/Debugger/TileViewer/TileRenderer.hpp sources/PPU/Tile.hpp)
|
||||
|
||||
include_directories(ComSquare sources)
|
||||
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
//
|
||||
|
||||
#include <complex>
|
||||
#include <cmath>
|
||||
#include "TileRenderer.hpp"
|
||||
#include "PPU/PPU.hpp"
|
||||
#include "PPU/Tile.hpp"
|
||||
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
@@ -13,6 +15,8 @@ namespace ComSquare::Debugger
|
||||
_cgram(nullptr),
|
||||
_bpp(2),
|
||||
_palette(0),
|
||||
_renderSize(5000),
|
||||
_nbColumns(16),
|
||||
buffer({{{0}}})
|
||||
{
|
||||
}
|
||||
@@ -27,25 +31,26 @@ namespace ComSquare::Debugger
|
||||
uint8_t colorReference;
|
||||
uint24_t color;
|
||||
std::vector<uint16_t> palette = this->getPalette(this->_palette);
|
||||
int bufX = 0;
|
||||
int bufY = 0;
|
||||
int bufX = this->_offsetX;
|
||||
int bufY = this->_offsetY;
|
||||
int nbTilesDrawn = 0;
|
||||
int resetX = 0;
|
||||
int resetX = bufX;
|
||||
int it = 0;
|
||||
|
||||
for (uint24_t i = 0; i < this->_ram->getSize(); i += this->_bpp, it++) {
|
||||
for (uint24_t i = 0; i < fmin(this->_ram->getSize(), this->_renderSize); i += this->_bpp, it++) {
|
||||
if (bufX >= 1024 || bufY >= 1024)
|
||||
break;
|
||||
if (it && it % 8 == 0) {
|
||||
resetX += 8;
|
||||
resetX += PPU::Tile::NbPixelsWidth;
|
||||
bufX = resetX;
|
||||
bufY -= 8;
|
||||
bufY -= PPU::Tile::NbPixelsHeight;
|
||||
nbTilesDrawn++;
|
||||
}
|
||||
if (nbTilesDrawn && nbTilesDrawn % 16 == 0) {
|
||||
resetX = 0;
|
||||
nbTilesDrawn = 0;
|
||||
resetX = this->_offsetX;
|
||||
bufX = resetX;
|
||||
bufY += 8;
|
||||
bufY += PPU::Tile::NbPixelsHeight;
|
||||
}
|
||||
for (int j = 0; j < 8; j++) {
|
||||
colorReference = this->getPixelReferenceFromTileRow(i, j);
|
||||
@@ -112,4 +117,14 @@ namespace ComSquare::Debugger
|
||||
{
|
||||
this->_cgram = std::move(ram);
|
||||
}
|
||||
|
||||
void TileRenderer::setRenderSize(int size)
|
||||
{
|
||||
this->_renderSize = size;
|
||||
}
|
||||
|
||||
void TileRenderer::setNbColumns(int nbColumns)
|
||||
{
|
||||
this->_nbColumns = nbColumns;
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,22 @@ namespace ComSquare::Debugger
|
||||
int _bpp;
|
||||
//! @brief The palette number to use while rendering
|
||||
int _palette;
|
||||
//! @brief The size to render in the ram
|
||||
int _renderSize;
|
||||
//! @brief The number of tile columns to display
|
||||
int _nbColumns;
|
||||
//! @brief render offset in x
|
||||
int _offsetX = 100;
|
||||
//! @brief render offset in y
|
||||
int _offsetY = 120;
|
||||
public:
|
||||
//! @brief internal buffer
|
||||
std::array<std::array<uint32_t, 1024>, 1024> buffer;
|
||||
void setPalette(int palette);
|
||||
void setCgram(std::shared_ptr<Ram::Ram> ram);
|
||||
void setBpp(int bpp);
|
||||
void setNbColumns(int nbColumns);
|
||||
void setRenderSize(int size);
|
||||
void setRam(std::shared_ptr<Ram::Ram> ram);
|
||||
uint8_t getPixelReferenceFromTileRow(uint16_t tileRowAddress, uint8_t pixelIndex);
|
||||
std::vector<uint16_t> getPalette(int nbPalette);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "PPU.hpp"
|
||||
#include "Background.hpp"
|
||||
#include <cmath>
|
||||
#include "Tile.hpp"
|
||||
#include "Models/Vector2.hpp"
|
||||
|
||||
namespace ComSquare::PPU
|
||||
@@ -107,13 +108,13 @@ namespace ComSquare::PPU
|
||||
uint8_t row = pixelIndex / this->_characterNbPixels.x;
|
||||
uint8_t column = pixelIndex % this->_characterNbPixels.y;
|
||||
|
||||
if (row >= TileNbPixelsHeight) {
|
||||
if (row >= Tile::NbPixelsHeight) {
|
||||
tileAddress += 0x80 * this->_bpp;
|
||||
row -= TileNbPixelsHeight;
|
||||
row -= Tile::NbPixelsHeight;
|
||||
}
|
||||
if (column >= TileNbPixelsWidth) {
|
||||
if (column >= Tile::NbPixelsWidth) {
|
||||
tileAddress += 0x8 * this->_bpp;
|
||||
column -= TileNbPixelsWidth;
|
||||
column -= Tile::NbPixelsWidth;
|
||||
}
|
||||
// TODO might not work with 8 bpp must check
|
||||
tileAddress += 2 * row;
|
||||
@@ -128,7 +129,7 @@ namespace ComSquare::PPU
|
||||
uint8_t secondHighByte;
|
||||
uint8_t secondLowByte;
|
||||
uint16_t result = 0;
|
||||
uint8_t shift = TileNbPixelsWidth - 1U - pixelIndex;
|
||||
uint8_t shift = Tile::NbPixelsWidth - 1U - pixelIndex;
|
||||
|
||||
switch (this->_bpp) {
|
||||
case 8:
|
||||
|
||||
@@ -24,10 +24,6 @@ namespace ComSquare::PPU
|
||||
static constexpr int NbCharacterWidth = 32;
|
||||
//! @brief The number of character a TileMap has in height
|
||||
static constexpr int NbCharacterHeight = 32;
|
||||
//! @brief The minimum number of pixel a tile can have in width
|
||||
static constexpr int TileNbPixelsWidth = 8;
|
||||
//! @brief The minimum number of pixel a tile can have in height
|
||||
static constexpr int TileNbPixelsHeight = 8;
|
||||
//! @brief The number of bytes used by a range of pixels (1 pixel per byte)
|
||||
//! @note Used like: bpp * TileBaseByteSize to get the size of byte of 1 row of pixels
|
||||
static constexpr unsigned TileBaseByteSize = 8;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by cbihan on 25/05/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ComSquare::PPU
|
||||
{
|
||||
//! @brief Info on tile struct
|
||||
struct Tile
|
||||
{
|
||||
//! @brief The number of pixel a base tile can have in width
|
||||
static constexpr int NbPixelsWidth = 8;
|
||||
//! @brief The number of pixel a base tile can have in height
|
||||
static constexpr int NbPixelsHeight = 8;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user