fixing rendering for bg 1 and 2 in 4bpp

This commit is contained in:
Clément Le Bihan
2020-10-13 00:13:31 +02:00
parent 1708e73619
commit 9193daccdb
2 changed files with 7 additions and 7 deletions
+7 -4
View File
@@ -100,7 +100,7 @@ namespace ComSquare::PPU
column -= TILE_PIXEL_WIDTH;
}
// might not work with 8 bpp must check
tileAddress += this->_bpp * row;
tileAddress += this->_bpp * row / 2;
return this->getPixelReferenceFromTileRow(tileAddress, column);
}
@@ -111,8 +111,9 @@ namespace ComSquare::PPU
uint8_t lowByte = this->_vram->read_internal((tileAddress + 1) % VRAMSIZE);
uint8_t secondHighByte;
uint8_t secondLowByte;
uint8_t result = 0;
uint16_t result = 0;
uint8_t shift = (TILE_PIXEL_WIDTH - 1U - pixelIndex);
uint16_t tmp;
switch (this->_bpp) {
case 8:
@@ -120,9 +121,11 @@ namespace ComSquare::PPU
case 4:
secondHighByte = this->_vram->read_internal((tileAddress + 16) % VRAMSIZE);
secondLowByte = this->_vram->read_internal((tileAddress + 17) % VRAMSIZE);
result = ((secondHighByte & (1U << shift)) | ((secondLowByte & (1U << shift)) << 1U)) >> (shift - 2U);
result = ((secondHighByte & (1U << shift)) | ((secondLowByte & (1U << shift)) << 1U));
result = (shift - 2 >= 0) ? result >> (shift - 2) : result << ((shift - 2) * -1);
case 2:
result += ((highByte & (1U << shift)) | ((lowByte & (1U << shift)) << 1U)) >> shift;
tmp = ((highByte & (1U << shift)) | ((lowByte & (1U << shift)) << 1U));
result += (shift >= 0) ? tmp >> shift : tmp << shift;
default:
break;
}
-3
View File
@@ -644,9 +644,6 @@ namespace ComSquare::PPU
this->_subScreen[i][j] = getRealColor(colorPalette);
// the buffer is overwrite if necessary by a new bg so the background priority is from back to front
// the starting palette index isn't implemented
this->addToMainSubScreen(this->_backgrounds[bgName::bg1NoPriority]);
this->addToMainSubScreen(this->_backgrounds[bgName::bg1Priority]);
return;
switch (this->_registers._bgmode.bgMode) {
case 0:
this->addToMainSubScreen(this->_backgrounds[bgName::bg4NoPriority]);