mirror of
https://github.com/zoriya/ComSquare.git
synced 2025-12-06 07:16:17 +00:00
renaming getRealColor to CGRAMColorToRGBA and finishing great random test on 8bpp rander
This commit is contained in:
@@ -46,7 +46,7 @@ namespace ComSquare::Debugger
|
||||
uint8_t blue = (cgramValue & 0x7D00U) >> 10U;
|
||||
uint8_t green = (cgramValue & 0x03E0U) >> 5U;
|
||||
uint8_t red = (cgramValue & 0x001FU);
|
||||
uint32_t hexColorValue = PPU::Utils::getRealColor(cgramValue);
|
||||
uint32_t hexColorValue = PPU::Utils::CGRAMColorToRGBA(cgramValue);
|
||||
|
||||
this->_ui.indexLineEdit->setText(std::to_string(addr / 2).c_str());
|
||||
this->_ui.valueLineEdit->setText(Utility::to_hex(cgramValue).c_str());
|
||||
@@ -90,7 +90,7 @@ namespace ComSquare::Debugger
|
||||
uint16_t cgramAddress = idDisplayTile / 8 * 16 + (idDisplayTile % 8 * 2);
|
||||
uint16_t addressValue = this->_ppu.cgramRead(cgramAddress);
|
||||
addressValue += this->_ppu.cgramRead(cgramAddress + 1) << 8U;
|
||||
uint32_t color = PPU::Utils::getRealColor(addressValue);
|
||||
uint32_t color = PPU::Utils::CGRAMColorToRGBA(addressValue);
|
||||
|
||||
return QColor(static_cast<int>((color & 0xFF000000) >> 24),
|
||||
static_cast<int>((color & 0x00FF0000) >> 16),
|
||||
|
||||
@@ -559,7 +559,7 @@ namespace ComSquare::PPU
|
||||
colorPalette = this->cgram.read(0);
|
||||
colorPalette += this->cgram.read(1) << 8U;
|
||||
|
||||
uint32_t color = Utils::getRealColor(colorPalette);
|
||||
uint32_t color = Utils::CGRAMColorToRGBA(colorPalette);
|
||||
for (auto &row : this->_subScreen)
|
||||
row.fill(color);
|
||||
for (auto &row : this->_mainScreenLevelMap)
|
||||
|
||||
@@ -7,16 +7,16 @@
|
||||
namespace ComSquare::PPU::Utils
|
||||
{
|
||||
|
||||
uint8_t To8Bit(int color)
|
||||
inline uint8_t to8Bit(int color)
|
||||
{
|
||||
return (uint)((color << 3) + (color >> 2));
|
||||
return static_cast<uint8_t>((color << 3) + (color >> 2));
|
||||
}
|
||||
|
||||
uint32_t getRealColor(uint16_t cgramColor)
|
||||
uint32_t CGRAMColorToRGBA(uint16_t CGRAMColor)
|
||||
{
|
||||
uint b = To8Bit(cgramColor >> 10);
|
||||
uint g = To8Bit((cgramColor >> 5) & 0x1F);
|
||||
uint r = To8Bit(cgramColor & 0x1F);
|
||||
uint8_t b = to8Bit(CGRAMColor >> 10);
|
||||
uint8_t g = to8Bit((CGRAMColor >> 5) & 0x1F);
|
||||
uint8_t r = to8Bit(CGRAMColor & 0x1F);
|
||||
|
||||
return (0x000000FF | (r << 24) | (g << 16) | (b << 8));
|
||||
}
|
||||
|
||||
@@ -17,9 +17,14 @@ namespace ComSquare::PPU
|
||||
|
||||
namespace ComSquare::PPU::Utils
|
||||
{
|
||||
|
||||
//! @brief Transform CGRAM color data to 8bits
|
||||
//! @note Used with b, g and r values
|
||||
//! @return The 8 bit value of the color
|
||||
inline uint8_t to8Bit(int color);
|
||||
//! @brief Transform SNES color code BGR to uint32_t RGBA
|
||||
uint32_t getRealColor(uint16_t cgramColor);
|
||||
//! @param CGRAMColor The color of the CGRAM
|
||||
//! @return The CGRAM color to RGBA format
|
||||
uint32_t CGRAMColorToRGBA(uint16_t CGRAMColor);
|
||||
//! @brief Used to parse easily VRAM Tile information
|
||||
union TileData {
|
||||
struct {
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace ComSquare::PPU
|
||||
for (auto &row : this->buffer) {
|
||||
for (auto &pixel : row) {
|
||||
uint8_t pixelReference = this->getPixelReferenceFromTile(tileAddress, it++);
|
||||
pixel = pixelReference ? Utils::getRealColor(palette[pixelReference]) : 0;
|
||||
pixel = pixelReference ? Utils::CGRAMColorToRGBA(palette[pixelReference]) : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace ComSquare::PPU
|
||||
//! @param nbPalette The index of the palette wanted
|
||||
//! @return The array of color of the palette
|
||||
//! @note The return and argument depends on the current bpp
|
||||
//! @warning Values are CGRAM colors use PPU::getRealColor function to get the actual real color
|
||||
//! @warning Values are CGRAM colors use PPU::CGRAMColorToRGBA function to get the actual real color
|
||||
std::vector<uint16_t> getPalette(int nbPalette);
|
||||
//! @brief read the 2bpp value for a pixel (used multple times for 4bpp and 8bpp)
|
||||
//! @param tileRowAddress Address where the read is done. Usage: Address of the tile row to render
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
#include <span>
|
||||
#include <vector>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <iomanip>
|
||||
#include "PPU/TileRenderer.hpp"
|
||||
#include "Ram/Ram.hpp"
|
||||
#include "PPU/Tile.hpp"
|
||||
#include "PPU/PPUUtils.hpp"
|
||||
|
||||
void fillRAM(const std::vector<std::string> &values, ComSquare::Ram::Ram &ram)
|
||||
{
|
||||
@@ -564,6 +566,134 @@ TEST_CASE("render 2bpp", "[PPU][TileRenderer]")
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("render 4bpp", "[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(4);
|
||||
tileRenderer.setPaletteIndex(0);
|
||||
|
||||
std::vector<std::string> vramValues {
|
||||
"7C7C82EE82FE7C7C",
|
||||
"0000D68254443838",
|
||||
"7C00AA1082007C00",
|
||||
"1000540038000000"
|
||||
};
|
||||
|
||||
std::vector<int> cgramValues = {
|
||||
0x00, 0x00,
|
||||
0x00, 0x00,
|
||||
0xFF, 0x7F,
|
||||
0x21, 0x0E,
|
||||
0xE2, 0x0E,
|
||||
0xE3, 0x0F,
|
||||
0x79, 0x0C,
|
||||
0xFD, 0x11,
|
||||
0x9F, 0x07,
|
||||
0xBF, 0x4B,
|
||||
0xDD, 0x01,
|
||||
0xCB, 0x0C,
|
||||
0x00, 0x00,
|
||||
0xDF, 0x55,
|
||||
0x3C, 0x0C,
|
||||
0x8B, 0x10,
|
||||
0xCE, 0x69,
|
||||
0x95, 0x7A
|
||||
};
|
||||
|
||||
uint32_t correctValues[8][8] = {
|
||||
{0x00000000, 0xef7b21ff, 0xef7b21ff, 0xef7b21ff, 0xef7b21ff, 0xef7b21ff, 0x00000000, 0x00000000},
|
||||
{0xef7b21ff, 0xffffffff, 0xce1818ff, 0xffe708ff, 0xce1818ff, 0xffffffff, 0xef7b21ff, 0x00000000},
|
||||
{0xef7b21ff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xef7b21ff, 0x00000000},
|
||||
{0x00000000, 0xef7b21ff, 0xef7b21ff, 0xef7b21ff, 0xef7b21ff, 0xef7b21ff, 0x00000000, 0x00000000},
|
||||
{0x00000000, 0x00000000, 0x00000000, 0x10bd18ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
|
||||
{0x088c18ff, 0x18ff18ff, 0x00000000, 0x18ff18ff, 0x00000000, 0x18ff18ff, 0x088c18ff, 0x00000000},
|
||||
{0x00000000, 0x088c18ff, 0x10bd18ff, 0x18ff18ff, 0x10bd18ff, 0x088c18ff, 0x00000000, 0x00000000},
|
||||
{0x00000000, 0x00000000, 0x088c18ff, 0x088c18ff, 0x088c18ff, 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++;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("render 8bpp", "[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(8);
|
||||
tileRenderer.setPaletteIndex(0);
|
||||
|
||||
std::vector<std::string> vramValues{
|
||||
"0C7C5CA0C0BC3C001010964038282018",
|
||||
"0000020002007C000000820044003800",
|
||||
"007C44927C82007C1010D6D67C7C3838",
|
||||
"00002800000000000000000000000000"
|
||||
};
|
||||
|
||||
uint8_t correctReferences[8][8] = {
|
||||
{0x00, 0x22, 0x22, 0x22, 0x23, 0x23, 0x00, 0x00},
|
||||
{0x22, 0x11, 0x42, 0x21, 0x41, 0x11, 0x24, 0x00},
|
||||
{0x23, 0x11, 0x12, 0x12, 0x12, 0x12, 0x24, 0x00},
|
||||
{0x00, 0x24, 0x25, 0x25, 0x25, 0x25, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x35, 0x32, 0x00, 0x31, 0x00, 0x31, 0x35, 0x00},
|
||||
{0x00, 0x34, 0x33, 0x31, 0x33, 0x34, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x35, 0x36, 0x36, 0x00, 0x00, 0x00},
|
||||
};
|
||||
|
||||
for (int i = 0; i < 512; i++) {
|
||||
cgram.write(i, std::rand());
|
||||
}
|
||||
|
||||
uint32_t correctValues[8][8] = {{0}};
|
||||
|
||||
int k = 0;
|
||||
int l = 0;
|
||||
for (const auto &row : correctReferences) {
|
||||
for (const auto &reference : row) {
|
||||
if (reference == 0) {
|
||||
l++;
|
||||
continue;
|
||||
}
|
||||
correctValues[k][l++] = ComSquare::PPU::Utils::CGRAMColorToRGBA(
|
||||
cgram.read(reference * 2)
|
||||
| (cgram.read((reference * 2) + 1) << 8)
|
||||
);
|
||||
}
|
||||
l = 0;
|
||||
k++;
|
||||
}
|
||||
|
||||
fillRAM(vramValues, vram);
|
||||
tileRenderer.render(0);
|
||||
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
for (const auto &row : tileRenderer.buffer) {
|
||||
|
||||
Reference in New Issue
Block a user