mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-05 10:59:38 +00:00
removing half of backgrounds (priority not functional)
This commit is contained in:
+15
-10
@@ -35,7 +35,8 @@ namespace ComSquare::PPU
|
||||
void Background::renderBackground()
|
||||
{
|
||||
uint16_t vramAddress = this->_tileMapStartAddress;
|
||||
Vector2<int> offset = this->_ppu.getBgScroll(this->_bgNumber);
|
||||
//Vector2<int> offset = this->_ppu.getBgScroll(this->_bgNumber);
|
||||
Vector2i offset = {0, 0};
|
||||
this->backgroundSize.x =
|
||||
(static_cast<int>(this->_tileMapMirroring.x) + 1) * this->_characterNbPixels.x * NbCharacterWidth;
|
||||
this->backgroundSize.y =
|
||||
@@ -44,10 +45,10 @@ namespace ComSquare::PPU
|
||||
this->_drawBasicTileMap(vramAddress, offset);
|
||||
for (int i = 1; i < 4; i++) {
|
||||
vramAddress += TileMapByteSize;
|
||||
offset.x += NbCharacterWidth * this->_characterNbPixels.x;
|
||||
offset.x++;
|
||||
if (i == 2) {
|
||||
offset.x = 0;
|
||||
offset.y += NbCharacterHeight * this->_characterNbPixels.y;
|
||||
offset.y++;
|
||||
}
|
||||
if (i > 1 && !this->_tileMapMirroring.y)
|
||||
break;
|
||||
@@ -79,7 +80,7 @@ namespace ComSquare::PPU
|
||||
}
|
||||
}
|
||||
|
||||
void Background::_drawTile(uint16_t data, Vector2<int> pos)
|
||||
void Background::_drawTile(uint16_t data, Vector2<int> indexOffset)
|
||||
{
|
||||
union Utils::TileData tileData;
|
||||
|
||||
@@ -87,6 +88,7 @@ namespace ComSquare::PPU
|
||||
|
||||
//if (tileData.tilePriority != this->_priority)
|
||||
// return;
|
||||
this->tilesPriority[indexOffset.x][indexOffset.y] = tileData.tilePriority;
|
||||
this->_drawTileFromMemoryToTileBuffer(tileData);
|
||||
|
||||
// todo check why i need to invert vertical and horizontal flips
|
||||
@@ -94,10 +96,12 @@ namespace ComSquare::PPU
|
||||
Utils::HFlipArray(this->_tileBuffer, {this->_characterNbPixels.x, this->_characterNbPixels.y});
|
||||
if (tileData.horizontalFlip)
|
||||
Utils::VFlipArray(this->_tileBuffer, {this->_characterNbPixels.x, this->_characterNbPixels.y});
|
||||
|
||||
Vector2<int> pixelPosition{indexOffset.x * this->_characterNbPixels.x, indexOffset.y * this->_characterNbPixels.y};
|
||||
std::for_each(this->_tileBuffer.begin(), this->_tileBuffer.begin() + this->_characterNbPixels.y,
|
||||
[this, &pos](const auto &row) {
|
||||
[this, &pixelPosition](const auto &row) {
|
||||
std::move(row.begin(), row.begin() + this->_characterNbPixels.x,
|
||||
this->buffer[pos.y++].begin() + pos.x);
|
||||
this->buffer[pixelPosition.y++].begin() + pixelPosition.x);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -111,15 +115,16 @@ namespace ComSquare::PPU
|
||||
// TODO function to read 2 bytes (LSB order or bits reversed)
|
||||
tileMapValue = this->_vram->read(vramAddress);
|
||||
tileMapValue += this->_vram->read(vramAddress + 1) << 8U;
|
||||
this->_drawTile(tileMapValue, {(pos.x * this->_characterNbPixels.x) + offset.x,
|
||||
(pos.y * this->_characterNbPixels.y) + offset.y});
|
||||
this->_drawTile(tileMapValue, {(offset.x * NbCharacterWidth) + pos.x,
|
||||
(offset.y * NbCharacterHeight) + pos.y});
|
||||
vramAddress += 2;
|
||||
if (pos.x % 31 == 0 && pos.x) {
|
||||
pos.y++;
|
||||
pos.x = 0;
|
||||
}
|
||||
else
|
||||
else {
|
||||
pos.x++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +152,7 @@ namespace ComSquare::PPU
|
||||
this->_tileRenderer.setBpp(this->_bpp);
|
||||
}
|
||||
|
||||
void Background::setTilemaps(Vector2<bool> tileMaps)
|
||||
void Background::setTileMapMirroring(Vector2<bool> tileMaps)
|
||||
{
|
||||
this->_tileMapMirroring = tileMaps;
|
||||
}
|
||||
|
||||
@@ -60,12 +60,15 @@ namespace ComSquare::PPU
|
||||
//! @brief The access to cgram
|
||||
std::shared_ptr<Ram::Ram> _cgram;
|
||||
//! @brief Draw a tile on the screen at x y pos
|
||||
void _drawTile(uint16_t data, Vector2<int> pos);
|
||||
//! @param data The VRAM value to be interpreted as a Utils::TileData
|
||||
//! @param indexOffset The index offset of the Tile (ranging from 0 to 63)
|
||||
void _drawTile(uint16_t data, Vector2<int> indexOffset);
|
||||
//! @brief Draw the tile to the tile Buffer
|
||||
//! @param tileData The tile data to use to render the tile
|
||||
void _drawTileFromMemoryToTileBuffer(const union Utils::TileData &tileData);
|
||||
//! @brief draw a tileMap 32x32 starting at baseAddress
|
||||
//! @param baseAddress The starting address of the tileMap
|
||||
//! @param offset The rendering offeset in pixels
|
||||
//! @param offset The offset of the tile map (ranging from 0 to 1)
|
||||
void _drawBasicTileMap(uint16_t baseAddress, Vector2<int> offset);
|
||||
public:
|
||||
//! @brief The size of the background (x, y)
|
||||
@@ -92,7 +95,7 @@ namespace ComSquare::PPU
|
||||
void setBpp(int bpp);
|
||||
//! @brief setter for private variable _tileMaps
|
||||
//! @param tileMaps The tileMaps to set
|
||||
void setTilemaps(Vector2<bool> tileMaps);
|
||||
void setTileMapMirroring(Vector2<bool> tileMaps);
|
||||
|
||||
//! @brief Get the BackGround Number
|
||||
//! @return the current Background number
|
||||
|
||||
+16
-18
@@ -23,13 +23,13 @@ namespace ComSquare::PPU
|
||||
_renderer(renderer),
|
||||
_backgrounds{
|
||||
Background(*this, 1, false),
|
||||
Background(*this, 1, true),
|
||||
//Background(*this, 1, true),
|
||||
Background(*this, 2, false),
|
||||
Background(*this, 2, true),
|
||||
//Background(*this, 2, true),
|
||||
Background(*this, 3, false),
|
||||
Background(*this, 3, true),
|
||||
//Background(*this, 3, true),
|
||||
Background(*this, 4, false),
|
||||
Background(*this, 4, true)
|
||||
//Background(*this, 4, true)
|
||||
},
|
||||
_mainScreen({{{0}}}),
|
||||
_subScreen({{{0}}})
|
||||
@@ -129,10 +129,10 @@ namespace ComSquare::PPU
|
||||
this->getTileMapStartAddress(addr - PpuRegisters::bg1sc + 1));
|
||||
this->_backgrounds[addr - PpuRegisters::bg1sc + 1].setTileMapStartAddress(
|
||||
this->getTileMapStartAddress(addr - PpuRegisters::bg1sc + 1));
|
||||
this->_backgrounds[addr - PpuRegisters::bg1sc].setTilemaps(
|
||||
this->_backgrounds[addr - PpuRegisters::bg1sc].setTileMapMirroring(
|
||||
{static_cast<bool>(this->_registers._bgsc[addr - PpuRegisters::bg1sc].tilemapHorizontalMirroring),
|
||||
static_cast<bool>(this->_registers._bgsc[addr - PpuRegisters::bg1sc].tilemapVerticalMirroring)});
|
||||
this->_backgrounds[addr - PpuRegisters::bg1sc + 1].setTilemaps(
|
||||
this->_backgrounds[addr - PpuRegisters::bg1sc + 1].setTileMapMirroring(
|
||||
{static_cast<bool>(this->_registers._bgsc[addr - PpuRegisters::bg1sc].tilemapHorizontalMirroring),
|
||||
static_cast<bool>(this->_registers._bgsc[addr - PpuRegisters::bg1sc].tilemapVerticalMirroring)});
|
||||
break;
|
||||
@@ -553,9 +553,7 @@ namespace ComSquare::PPU
|
||||
{
|
||||
uint16_t colorPalette;
|
||||
// should only render backgrounds needed (depending of th bgMode)
|
||||
int i = 0;
|
||||
for (auto &_background : this->_backgrounds) {
|
||||
i++;
|
||||
_background.renderBackground();
|
||||
}
|
||||
// TODO make a function getDefaultBgColor
|
||||
@@ -572,30 +570,30 @@ namespace ComSquare::PPU
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg4NoPriority]);
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg3NoPriority]);
|
||||
//sprites priority 0
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg4Priority]);
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg3Priority]);
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg4Priority]);
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg3Priority]);
|
||||
//sprites priority 1
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg2NoPriority]);
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg1NoPriority]);
|
||||
//sprites priority 2
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg2Priority]);
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg1Priority]);
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg2Priority]);
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg1Priority]);
|
||||
//sprites priority 3
|
||||
break;
|
||||
case 1:
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg3NoPriority]);
|
||||
//sprites priority 0
|
||||
if (!this->_registers._bgmode.mode1Bg3PriorityBit)
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg3Priority]);
|
||||
// if (!this->_registers._bgmode.mode1Bg3PriorityBit)
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg3Priority]);
|
||||
//sprites priority 1
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg2NoPriority]);
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg1NoPriority]);
|
||||
//sprites priority 2
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg2Priority]);
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg1Priority]);
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg2Priority]);
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg1Priority]);
|
||||
//sprites priority 3
|
||||
if (this->_registers._bgmode.mode1Bg3PriorityBit)
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg3Priority]);
|
||||
// if (this->_registers._bgmode.mode1Bg3PriorityBit)
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg3Priority]);
|
||||
break;
|
||||
case 2:
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg2NoPriority]);
|
||||
|
||||
+4
-4
@@ -34,11 +34,11 @@ namespace ComSquare::PPU
|
||||
enum BgName {
|
||||
bg1NoPriority = 0,
|
||||
bg1Priority,
|
||||
bg2NoPriority,
|
||||
bg2NoPriority = 1,
|
||||
bg2Priority,
|
||||
bg3NoPriority,
|
||||
bg3NoPriority = 2,
|
||||
bg3Priority,
|
||||
bg4NoPriority,
|
||||
bg4NoPriority = 3,
|
||||
bg4Priority
|
||||
};
|
||||
|
||||
@@ -564,7 +564,7 @@ namespace ComSquare::PPU
|
||||
Registers _registers{};
|
||||
Renderer::IRenderer &_renderer;
|
||||
//! @brief Backgrounds buffers
|
||||
Background _backgrounds[8];
|
||||
Background _backgrounds[4];
|
||||
//! @brief Main Screen buffer
|
||||
std::array<std::array<uint32_t, 1024>, 1024> _mainScreen;
|
||||
//! @brief Sub Screen buffer
|
||||
|
||||
@@ -3795,13 +3795,13 @@ namespace ComSquare::PPU::Utils::Debug
|
||||
ppu._registers._bgsc[1].tilemapHorizontalMirroring = 1;
|
||||
ppu._registers._bgsc[2].tilemapAddress = 0x5C00U >> 10U;
|
||||
ppu._backgrounds[0].setTileMapStartAddress(ppu.getTileMapStartAddress(1));
|
||||
ppu._backgrounds[0].setTilemaps(ppu.getBackgroundMirroring(1));
|
||||
ppu._backgrounds[0].setTileMapMirroring(ppu.getBackgroundMirroring(1));
|
||||
ppu._backgrounds[1].setTileMapStartAddress(ppu.getTileMapStartAddress(1));
|
||||
ppu._backgrounds[1].setTilemaps(ppu.getBackgroundMirroring(1));
|
||||
ppu._backgrounds[1].setTileMapMirroring(ppu.getBackgroundMirroring(1));
|
||||
ppu._backgrounds[2].setTileMapStartAddress(ppu.getTileMapStartAddress(2));
|
||||
ppu._backgrounds[2].setTilemaps(ppu.getBackgroundMirroring(2));
|
||||
ppu._backgrounds[2].setTileMapMirroring(ppu.getBackgroundMirroring(2));
|
||||
ppu._backgrounds[3].setTileMapStartAddress(ppu.getTileMapStartAddress(2));
|
||||
ppu._backgrounds[3].setTilemaps(ppu.getBackgroundMirroring(2));
|
||||
ppu._backgrounds[3].setTileMapMirroring(ppu.getBackgroundMirroring(2));
|
||||
ppu._backgrounds[4].setTileMapStartAddress(ppu.getTileMapStartAddress(3));
|
||||
ppu._backgrounds[5].setTileMapStartAddress(ppu.getTileMapStartAddress(3));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user