adding test for render in 2bpp and using mesen formula for getRealColor function

This commit is contained in:
Clément Le Bihan
2021-07-11 20:10:39 +02:00
parent 8a84258c5a
commit 09520658a1
4 changed files with 68 additions and 28 deletions
+9 -17
View File
@@ -8,6 +8,7 @@
#include <string> #include <string>
#include <QtWidgets/QTableWidget> #include <QtWidgets/QTableWidget>
#include "Utility/Utility.hpp" #include "Utility/Utility.hpp"
#include "PPU/PPUUtils.hpp"
namespace ComSquare::Debugger namespace ComSquare::Debugger
{ {
@@ -45,16 +46,14 @@ namespace ComSquare::Debugger
uint8_t blue = (cgramValue & 0x7D00U) >> 10U; uint8_t blue = (cgramValue & 0x7D00U) >> 10U;
uint8_t green = (cgramValue & 0x03E0U) >> 5U; uint8_t green = (cgramValue & 0x03E0U) >> 5U;
uint8_t red = (cgramValue & 0x001FU); uint8_t red = (cgramValue & 0x001FU);
uint24_t hexColorValue = 0; uint32_t hexColorValue = PPU::Utils::getRealColor(cgramValue);
this->_ui.indexLineEdit->setText(std::to_string(addr / 2).c_str()); this->_ui.indexLineEdit->setText(std::to_string(addr / 2).c_str());
this->_ui.valueLineEdit->setText(Utility::to_hex(cgramValue).c_str()); this->_ui.valueLineEdit->setText(Utility::to_hex(cgramValue).c_str());
this->_ui.rLineEdit->setText(std::to_string(red).c_str()); this->_ui.rLineEdit->setText(std::to_string(red).c_str());
this->_ui.gLineEdit->setText(std::to_string(green).c_str()); this->_ui.gLineEdit->setText(std::to_string(green).c_str());
this->_ui.bLineEdit->setText(std::to_string(blue).c_str()); this->_ui.bLineEdit->setText(std::to_string(blue).c_str());
hexColorValue += (red * 255U / 31U) << 16U; hexColorValue >>= 8;
hexColorValue += (green * 255U / 31U) << 8U;
hexColorValue += (blue * 255U / 31U);
this->_ui.hexLineEdit->setText(Utility::to_hex(hexColorValue).c_str()); this->_ui.hexLineEdit->setText(Utility::to_hex(hexColorValue).c_str());
} }
@@ -81,27 +80,20 @@ namespace ComSquare::Debugger
QVariant CGramModel::data(const QModelIndex &index, int role) const QVariant CGramModel::data(const QModelIndex &index, int role) const
{ {
u_int16_t addressValue;
uint8_t red;
uint8_t green;
uint8_t blue;
if (role == Qt::TextAlignmentRole) if (role == Qt::TextAlignmentRole)
return Qt::AlignCenter; return Qt::AlignCenter;
if (role != Qt::BackgroundRole) if (role != Qt::BackgroundRole)
return QVariant(); return QVariant();
int idDisplayTile = index.row() * 16 + index.column(); int idDisplayTile = index.row() * 16 + index.column();
uint16_t cgramAddress = idDisplayTile / 8 * 16 + (idDisplayTile % 8 * 2); uint16_t cgramAddress = idDisplayTile / 8 * 16 + (idDisplayTile % 8 * 2);
addressValue = this->_ppu.cgramRead(cgramAddress); uint16_t addressValue = this->_ppu.cgramRead(cgramAddress);
addressValue += this->_ppu.cgramRead(cgramAddress + 1) << 8U; addressValue += this->_ppu.cgramRead(cgramAddress + 1) << 8U;
uint32_t color = PPU::Utils::getRealColor(addressValue);
blue = (addressValue & 0x7D00U) >> 10U; return QColor(static_cast<int>((color & 0xFF000000) >> 24),
green = (addressValue & 0x03E0U) >> 5U; static_cast<int>((color & 0x00FF0000) >> 16),
red = (addressValue & 0x001FU); static_cast<int>((color & 0x0000FF00) >> 8));
red = red * 255U / 31U;
green = green * 255U / 31U;
blue = blue * 255U / 31U;
return QColor(red, green, blue);
} }
} }
+10 -9
View File
@@ -7,16 +7,17 @@
namespace ComSquare::PPU::Utils namespace ComSquare::PPU::Utils
{ {
uint32_t getRealColor(uint16_t color) uint8_t To8Bit(int color)
{ {
uint8_t blue = (color & 0x7D00U) >> 10U; return (uint)((color << 3) + (color >> 2));
uint8_t green = (color & 0x03E0U) >> 5U; }
uint8_t red = (color & 0x001FU);
uint32_t pixelTmp = 0xFF;
pixelTmp += (red * 255U / 31U) << 24U; uint32_t getRealColor(uint16_t cgramColor)
pixelTmp += (green * 255U / 31U) << 16U; {
pixelTmp += (blue * 255U / 31U) << 8U; uint b = To8Bit(cgramColor >> 10);
return pixelTmp; uint g = To8Bit((cgramColor >> 5) & 0x1F);
uint r = To8Bit(cgramColor & 0x1F);
return (0x000000FF | (r << 24) | (g << 16) | (b << 8));
} }
} }
+2 -2
View File
@@ -18,8 +18,8 @@ namespace ComSquare::PPU
namespace ComSquare::PPU::Utils namespace ComSquare::PPU::Utils
{ {
//! @brief Transform SNES color code BGR to uint32_t RGB //! @brief Transform SNES color code BGR to uint32_t RGBA
uint32_t getRealColor(uint16_t color); uint32_t getRealColor(uint16_t cgramColor);
//! @brief Used to parse easily VRAM Tile information //! @brief Used to parse easily VRAM Tile information
union TileData { union TileData {
struct { struct {
+47
View File
@@ -526,4 +526,51 @@ TEST_CASE("getPalette 8bpp", "[PPU][TileRenderer]")
} }
i = 0; i = 0;
} }
}
TEST_CASE("render 2bpp", "[PPU][TileRenderer]")
{
ComSquare::Ram::Ram vram(100, static_cast<ComSquare::Component>(0), "vramTest");
ComSquare::Ram::Ram cgram(512, static_cast<ComSquare::Component>(0), "cgramTest");
ComSquare::PPU::TileRenderer tileRenderer(vram, cgram);
tileRenderer.setBpp(2);
tileRenderer.setPaletteIndex(1);
std::vector<std::string> vramValues {
"7C00BA7C827C7C00",
"1000D6007C003800"
};
std::vector<int> cgramValues = {
0xCE, 0x69, 0xDF, 0x63, 0xDE, 0x16, 0x8B, 0x00,
0x00, 0x00, 0xBF, 0x67, 0x98, 0x42, 0x0E, 0x15
};
//{0x3600, 0x67bf, 0x4298, 0x150e},
// 0 FFEFCE C6A584 734229
uint32_t correctValues[8][8] = {
{0x00000000, 0xFFEFCEFF, 0xFFEFCEFF, 0xFFEFCEFF, 0xFFEFCEFF, 0xFFEFCEFF, 0x00000000, 0x00000000},
{0xFFEFCEFF, 0xC6A584FF, 0x734229FF, 0x734229FF, 0x734229FF, 0xC6A584FF, 0xFFEFCEFF, 0x00000000},
{0xFFEFCEFF, 0xC6A584FF, 0xC6A584FF, 0xC6A584FF, 0xC6A584FF, 0xC6A584FF, 0xFFEFCEFF, 0x00000000},
{0x00000000, 0xFFEFCEFF, 0xFFEFCEFF, 0xFFEFCEFF, 0xFFEFCEFF, 0xFFEFCEFF, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0xFFEFCEFF, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0xFFEFCEFF, 0xFFEFCEFF, 0x00000000, 0xFFEFCEFF, 0x00000000, 0xFFEFCEFF, 0xFFEFCEFF, 0x00000000},
{0x00000000, 0xFFEFCEFF, 0xFFEFCEFF, 0xFFEFCEFF, 0xFFEFCEFF, 0xFFEFCEFF, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0xFFEFCEFF, 0xFFEFCEFF, 0xFFEFCEFF, 0x00000000, 0x00000000, 0x00000000}
};
fillRAM(vramValues, vram);
fillRAM(cgramValues, cgram);
tileRenderer.render(0);
int i = 0;
int j = 0;
for (const auto &row : tileRenderer.buffer) {
for (const auto &pixel : row) {
CHECK(correctValues[i][j++] == pixel);
}
j = 0;
i++;
}
} }