mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-06 19:32:18 +00:00
adding fixes to getPalette and creating a setter for backgrounds bpp (when bgmode is changed)
This commit is contained in:
@@ -54,9 +54,8 @@ namespace ComSquare::PPU
|
|||||||
uint8_t reference = 0;
|
uint8_t reference = 0;
|
||||||
uint32_t color = 0;
|
uint32_t color = 0;
|
||||||
|
|
||||||
//union isn't working as intended
|
|
||||||
tileData.raw = data;
|
tileData.raw = data;
|
||||||
palette = getPalettes(tileData.palette);
|
palette = getPalette(tileData.palette);
|
||||||
// X horizontal
|
// X horizontal
|
||||||
// Y vertical
|
// Y vertical
|
||||||
graphicAddress = this->_tilesetAddress + (tileData.posY * 16 * this->_bpp * 8) + (tileData.posX * this->_bpp * 8);
|
graphicAddress = this->_tilesetAddress + (tileData.posY * 16 * this->_bpp * 8) + (tileData.posX * this->_bpp * 8);
|
||||||
@@ -74,12 +73,12 @@ namespace ComSquare::PPU
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint16_t> Background::getPalettes(int nbPalette)
|
std::vector<uint16_t> Background::getPalette(int nbPalette)
|
||||||
{
|
{
|
||||||
std::vector<uint16_t> palette(0xF);
|
std::vector<uint16_t> palette(0x10);
|
||||||
uint16_t addr = nbPalette * 0x10;
|
uint16_t addr = nbPalette * 0x20;
|
||||||
|
|
||||||
for (int i = 0; i < 0xF; i++) {
|
for (int i = 0; i < 0x10; i++) {
|
||||||
palette[i] = this->_cgram->read_internal(addr);
|
palette[i] = this->_cgram->read_internal(addr);
|
||||||
palette[i] += this->_cgram->read_internal(addr + 1) << 8U;
|
palette[i] += this->_cgram->read_internal(addr + 1) << 8U;
|
||||||
addr += 2;
|
addr += 2;
|
||||||
@@ -119,8 +118,8 @@ namespace ComSquare::PPU
|
|||||||
case 8:
|
case 8:
|
||||||
return highByte;
|
return highByte;
|
||||||
case 4:
|
case 4:
|
||||||
secondHighByte = this->_vram->read_internal((tileAddress + 32) % VRAMSIZE);
|
secondHighByte = this->_vram->read_internal((tileAddress + 16) % VRAMSIZE);
|
||||||
secondLowByte = this->_vram->read_internal((tileAddress + 33) % 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)) >> (shift - 2U);
|
||||||
case 2:
|
case 2:
|
||||||
result += ((highByte & (1U << shift)) | ((lowByte & (1U << shift)) << 1U)) >> shift;
|
result += ((highByte & (1U << shift)) | ((lowByte & (1U << shift)) << 1U)) >> shift;
|
||||||
@@ -165,4 +164,12 @@ namespace ComSquare::PPU
|
|||||||
{
|
{
|
||||||
this->_characterSize = size;
|
this->_characterSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Background::setBpp(int bpp)
|
||||||
|
{
|
||||||
|
if (bpp == 2 || bpp == 4 || bpp == 8 || bpp == 7)
|
||||||
|
this->_bpp = bpp;
|
||||||
|
else
|
||||||
|
this->_bpp = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace ComSquare::PPU
|
|||||||
//! @brief Get a palette from the number of the palette
|
//! @brief Get a palette from the number of the palette
|
||||||
//! @param nbPalette The palette number (0 - 7)
|
//! @param nbPalette The palette number (0 - 7)
|
||||||
//! @return The array of color of the palette
|
//! @return The array of color of the palette
|
||||||
std::vector<uint16_t> getPalettes(int nbPalette);
|
std::vector<uint16_t> getPalette(int nbPalette);
|
||||||
//! @brief Get the color reference of a pixel from the address of the row
|
//! @brief Get the color reference of a pixel from the address of the row
|
||||||
//! @param tileAddress The address of the line of pixel
|
//! @param tileAddress The address of the line of pixel
|
||||||
//! @param pixelIndex The index of the pixel (0 - 7)
|
//! @param pixelIndex The index of the pixel (0 - 7)
|
||||||
@@ -71,6 +71,9 @@ namespace ComSquare::PPU
|
|||||||
void setCharacterSize(Vector2<int> size);
|
void setCharacterSize(Vector2<int> size);
|
||||||
//! @brief Set the tileset address of the background
|
//! @brief Set the tileset address of the background
|
||||||
void setTilesetAddress(uint16_t address);
|
void setTilesetAddress(uint16_t address);
|
||||||
|
//! @brief Set the bpp (bits per pixels) of the Background
|
||||||
|
//! @info The bpp can be 2, 4 or 8 (7 can be possible when BgMode is 7)
|
||||||
|
void setBpp(int bpp);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-1
@@ -115,6 +115,12 @@ namespace ComSquare::PPU
|
|||||||
//registers
|
//registers
|
||||||
|
|
||||||
this->_registers._bgmode.bgMode = 1;
|
this->_registers._bgmode.bgMode = 1;
|
||||||
|
this->_backgrounds[0].setBpp(this->getBPP(1));
|
||||||
|
this->_backgrounds[1].setBpp(this->getBPP(1));
|
||||||
|
this->_backgrounds[2].setBpp(this->getBPP(2));
|
||||||
|
this->_backgrounds[3].setBpp(this->getBPP(2));
|
||||||
|
this->_backgrounds[4].setBpp(this->getBPP(3));
|
||||||
|
this->_backgrounds[5].setBpp(this->getBPP(3));
|
||||||
//this->_registers._bgmode.characterSizeBg1 = false;
|
//this->_registers._bgmode.characterSizeBg1 = false;
|
||||||
//this->_registers._bgmode.characterSizeBg2 = false;
|
//this->_registers._bgmode.characterSizeBg2 = false;
|
||||||
this->_registers._bgmode.mode1Bg3PriorityBit = true;
|
this->_registers._bgmode.mode1Bg3PriorityBit = true;
|
||||||
@@ -159,6 +165,7 @@ namespace ComSquare::PPU
|
|||||||
|
|
||||||
uint8_t PPU::read(uint24_t addr)
|
uint8_t PPU::read(uint24_t addr)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
switch (addr) {
|
switch (addr) {
|
||||||
case ppuRegisters::mpyl:
|
case ppuRegisters::mpyl:
|
||||||
return this->_registers._mpy.mpyl;
|
return this->_registers._mpy.mpyl;
|
||||||
@@ -187,6 +194,7 @@ namespace ComSquare::PPU
|
|||||||
|
|
||||||
void PPU::write(uint24_t addr, uint8_t data)
|
void PPU::write(uint24_t addr, uint8_t data)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
switch (addr) {
|
switch (addr) {
|
||||||
case ppuRegisters::inidisp:
|
case ppuRegisters::inidisp:
|
||||||
this->_registers._inidisp.raw = data;
|
this->_registers._inidisp.raw = data;
|
||||||
@@ -211,8 +219,10 @@ namespace ComSquare::PPU
|
|||||||
case ppuRegisters::bgmode:
|
case ppuRegisters::bgmode:
|
||||||
this->_registers._bgmode.raw = data;
|
this->_registers._bgmode.raw = data;
|
||||||
// update backgrounds
|
// update backgrounds
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++) {
|
||||||
|
this->_backgrounds[i].setBpp(this->getBPP((i / 2) + 1));
|
||||||
this->_backgrounds[i].setCharacterSize(this->getCharacterSize((i / 2) + 1));
|
this->_backgrounds[i].setCharacterSize(this->getCharacterSize((i / 2) + 1));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ppuRegisters::mosaic:
|
case ppuRegisters::mosaic:
|
||||||
this->_registers._mosaic.raw = data;
|
this->_registers._mosaic.raw = data;
|
||||||
@@ -634,6 +644,9 @@ namespace ComSquare::PPU
|
|||||||
this->_subScreen[i][j] = getRealColor(colorPalette);
|
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 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
|
// 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) {
|
switch (this->_registers._bgmode.bgMode) {
|
||||||
case 0:
|
case 0:
|
||||||
this->addToMainSubScreen(this->_backgrounds[bgName::bg4NoPriority]);
|
this->addToMainSubScreen(this->_backgrounds[bgName::bg4NoPriority]);
|
||||||
|
|||||||
Reference in New Issue
Block a user