splitting more conveniently drawTile function

This commit is contained in:
Clément Le Bihan
2021-07-06 23:13:37 +02:00
parent 6e37b8f250
commit 213f1608a7
4 changed files with 30 additions and 14 deletions
+19 -10
View File
@@ -57,15 +57,8 @@ namespace ComSquare::PPU
}
}
void Background::_drawBgTile(uint16_t data, Vector2<int> pos)
void Background::_drawTileFromMemoryToTileBuffer(const Utils::TileData &tileData)
{
union Utils::TileMapData tileData;
tileData.raw = data;
if (tileData.tilePriority != this->_priority)
return;
uint16_t graphicAddress;
Vector2i tileOffset = {0, 0};
// X horizontal
@@ -84,6 +77,17 @@ namespace ComSquare::PPU
tileOffset.x = 0;
tileOffset.y++;
}
}
void Background::_drawTile(uint16_t data, Vector2<int> pos)
{
union Utils::TileData tileData;
tileData.raw = data;
//if (tileData.tilePriority != this->_priority)
// return;
this->_drawTileFromMemoryToTileBuffer(tileData);
// todo check why i need to invert vertical and horizontal flips
if (tileData.verticalFlip)
@@ -107,8 +111,8 @@ namespace ComSquare::PPU
// TODO function to read 2 bytes (LSB order or bits reversed)
tileMapValue = this->_vram->read(vramAddress);
tileMapValue += this->_vram->read(vramAddress + 1) << 8U;
_drawBgTile(tileMapValue, {(pos.x * this->_characterNbPixels.x) + offset.x,
(pos.y * this->_characterNbPixels.y) + offset.y});
this->_drawTile(tileMapValue, {(pos.x * this->_characterNbPixels.x) + offset.x,
(pos.y * this->_characterNbPixels.y) + offset.y});
vramAddress += 2;
if (pos.x % 31 == 0 && pos.x) {
pos.y++;
@@ -162,4 +166,9 @@ namespace ComSquare::PPU
{
return this->_priority;
}
bool Background::isPriorityPixel(int y, int x) const
{
return this->tilesPriority[y / this->_characterNbPixels.y][x / this->_characterNbPixels.x];
}
}
+9 -2
View File
@@ -11,6 +11,7 @@
#include "TileRenderer.hpp"
#include "../Ram/Ram.hpp"
#include "PPU.hpp"
#include "PPUUtils.hpp"
namespace ComSquare::PPU
{
@@ -33,7 +34,7 @@ namespace ComSquare::PPU
//! @brief The tilemap configuration nb of tileMap vertically and horizontally
//! @note members are set to true if the tilemap is expended in their direction
Vector2<bool> _tileMapMirroring;
//! @brief The number of pixels of a character (x: width, y:height)
//! @brief The number of pixels of a character (x: height, y:width)
Vector2<int> _characterNbPixels;
//! @brief The number of bits per pixels to currently look for each pixel
int _bpp;
@@ -59,7 +60,9 @@ namespace ComSquare::PPU
//! @brief The access to cgram
std::shared_ptr<Ram::Ram> _cgram;
//! @brief Draw a tile on the screen at x y pos
void _drawBgTile(uint16_t data, Vector2<int> pos);
void _drawTile(uint16_t data, Vector2<int> pos);
//! @brief Draw the tile to the tile Buffer
void _drawTileFromMemoryToTileBuffer(const union Utils::TileData &tileData);
//! @brief draw a tileMap 32x32 starting at baseAddress
//! @param baseAddress The starting address of the tileMap
//! @param offset The rendering offeset in pixels
@@ -70,6 +73,10 @@ namespace ComSquare::PPU
//! @brief The output buffer (pixels are written on it)
std::array<std::array<uint32_t, 1024>, 1024> buffer;
std::array<std::array<bool, 64>, 64> tilesPriority;
bool isPriorityPixel(int x, int y) const;
//! @brief Render a background on his internal buffer
void renderBackground();
//! @brief Set the tileMap start address
+1 -1
View File
@@ -36,7 +36,7 @@ namespace ComSquare::PPU
{
this->_registers._isLowByte = true;
//Utils::Debug::populateEnvironment(*this, 0);
Utils::Debug::populateEnvironment(*this, 1);
}
uint8_t PPU::read(uint24_t addr)
+1 -1
View File
@@ -22,7 +22,7 @@ namespace ComSquare::PPU::Utils
//! @brief Transform SNES color code BGR to uint32_t RGB
uint32_t getRealColor(uint16_t color);
//! @brief Used to parse easily VRAM Tile information
union TileMapData {
union TileData {
struct {
//! @brief Tile X offset
uint16_t posX: 4;