factorisation is done

This commit is contained in:
Clément Le Bihan
2020-10-03 00:11:18 +02:00
parent 85fe6cf0aa
commit 8f6ee75c38
2 changed files with 19 additions and 58 deletions
+18 -57
View File
@@ -56,37 +56,20 @@ namespace ComSquare::PPU
tileData.raw = data;
palette = getPalette(tileData.palette);
// TODO explain X and Y and rethink the formula
// X horizontal
// Y vertical
graphicAddress = this->_tileSetAddress + (tileData.posY * 16 * this->_bpp * 8) + (tileData.posX * this->_bpp * 8);
for (int i = 0; i < this->_characterSize.y; i++) {
for (int j = 0; j < this->_characterSize.x; j++) {
/*if (index == 14) {
printf("cc");
}*/
reference = getPixelReferenceFromTile(graphicAddress, index);
color = getRealColor(palette[reference]);
if (tileData.tilePriority == this->priority) // reference 0 is considered as transparency
this->buffer[pos.x][pos.y] = (reference) ? color : 0;
/* if (j == 7) {
index = -1;
// to go to the tile to the right
graphicAddress += 0x8 * this->_bpp;
}
if (index == 7 || this->_bpp == 8) {
index = -1;
graphicAddress += 2;
}*/
index++;
pos.x++;
}
//graphicAddress -= (0x8 * this->_bpp);
//index = 0;
pos.x -= this->_characterSize.x;
pos.y++;
// if (i == 7)
// graphicAddress += 0x100 - 8 * this->_bpp;
}
}
@@ -105,30 +88,31 @@ namespace ComSquare::PPU
uint8_t Background::getPixelReferenceFromTile(uint16_t tileAddress, uint8_t pixelIndex)
{
this->getCorrespondingBasicTileRowAndPixelIndex(&tileAddress, &pixelIndex);
return this->getPixelReferenceFromTileRow(tileAddress, pixelIndex);
uint8_t row = pixelIndex / this->_characterSize.x;
uint8_t column = pixelIndex % this->_characterSize.y;
if (row >= TILE_PIXEL_HEIGHT) {
tileAddress += 0x80 * this->_bpp;
row -= TILE_PIXEL_HEIGHT;
}
if (column >= TILE_PIXEL_WIDTH) {
tileAddress += 0x8 * this->_bpp;
column -= TILE_PIXEL_WIDTH;
}
// might not work with 8 bpp must check
tileAddress += this->_bpp * row;
return this->getPixelReferenceFromTileRow(tileAddress, column);
}
uint8_t Background::getPixelReferenceFromTileRow(uint16_t tileAddress, uint8_t pixelIndex)
{
//line by line for each pixel of the line
uint8_t highByte;
uint8_t lowByte;
uint8_t highByte = this->_vram->read_internal(tileAddress % VRAMSIZE);
uint8_t lowByte = this->_vram->read_internal((tileAddress + 1) % VRAMSIZE);
uint8_t secondHighByte;
uint8_t secondLowByte;
uint8_t result = 0;
uint8_t shift;
uint8_t rowNumber = pixelIndex / TILE_PIXEL_WIDTH;
// C000
//gérer le character size mauvais pour le retour de ligne
//pixelIndex -= rowNumber * TILE_PIXEL_WIDTH; //get the index relative to the row
//tileAddress += rowNumber * TILE_PIXEL_WIDTH * this->_bpp; // get row address
highByte = this->_vram->read_internal(tileAddress % VRAMSIZE);
lowByte = this->_vram->read_internal((tileAddress + 1) % VRAMSIZE);
shift = (TILE_PIXEL_WIDTH - 1U - pixelIndex);
uint8_t shift = (TILE_PIXEL_WIDTH - 1U - pixelIndex);
switch (this->_bpp) {
case 8:
@@ -175,27 +159,4 @@ namespace ComSquare::PPU
{
this->_characterSize = size;
}
void Background::getCorrespondingBasicTileRowAndPixelIndex(uint16_t *tileAddress, uint8_t *pixelIndex)
{
uint16_t tmpTileAddress = *tileAddress;
uint16_t tmpPixelIndex = *pixelIndex;
uint8_t row = tmpPixelIndex / this->_characterSize.x;
uint8_t column = tmpPixelIndex / this->_characterSize.y;
if (row >= TILE_PIXEL_HEIGHT) {
tmpTileAddress += 0x80 * this->_bpp;
row -= TILE_PIXEL_HEIGHT;
}
if (column >= TILE_PIXEL_WIDTH) {
tmpTileAddress += 0x8 * this->_bpp;
column -= TILE_PIXEL_WIDTH;
}
// might not work with 8 bpp must check
tmpTileAddress += this->_bpp * row;
*tileAddress = tmpTileAddress;
*pixelIndex = tmpPixelIndex;
}
}
+1 -1
View File
@@ -43,7 +43,7 @@ namespace ComSquare::PPU
//TODO support addr as the address of the start of the tile and index goes from 0 to 63 regardless of the bpp
uint8_t getPixelReferenceFromTileRow(uint16_t tileAddress, uint8_t pixelIndex);
uint8_t getPixelReferenceFromTile(uint16_t tileAddress, uint8_t pixelIndex);
void getCorrespondingBasicTileRowAndPixelIndex(uint16_t *tileAddress, uint8_t *pixelIndex);
//! @brief draw a tilemap 32x32 starting at baseAddress
void drawBasicTileMap(uint16_t baseAddress, Vector2<int> offset);
public: