mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-07 11:45:07 +00:00
starting the renderMainandSubScreen fct
This commit is contained in:
@@ -9,7 +9,8 @@
|
|||||||
namespace ComSquare::PPU
|
namespace ComSquare::PPU
|
||||||
{
|
{
|
||||||
Background::Background(ComSquare::PPU::PPU &_ppu, int bgNumber, bool priority):
|
Background::Background(ComSquare::PPU::PPU &_ppu, int bgNumber, bool priority):
|
||||||
_priority(priority)
|
priority(priority),
|
||||||
|
bgNumber(bgNumber)
|
||||||
{
|
{
|
||||||
_cgram = _ppu.cgram;
|
_cgram = _ppu.cgram;
|
||||||
_vram = _ppu.vram;
|
_vram = _ppu.vram;
|
||||||
@@ -27,8 +28,8 @@ namespace ComSquare::PPU
|
|||||||
{
|
{
|
||||||
uint16_t vramAddress = this->_TileMapStartAddress;
|
uint16_t vramAddress = this->_TileMapStartAddress;
|
||||||
Vector2<int> offset(0, 0);
|
Vector2<int> offset(0, 0);
|
||||||
this->_backgroundSize.x = this->_tileMaps.x * this->_characterSize.x * 32;
|
this->backgroundSize.x = this->_tileMaps.x * this->_characterSize.x * 32;
|
||||||
this->_backgroundSize.y = this->_tileMaps.y * this->_characterSize.y * 32;
|
this->backgroundSize.y = this->_tileMaps.y * this->_characterSize.y * 32;
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (!(i == 1 && this->_tileMaps.x == 1) && !(i > 1 && this->_tileMaps.y == 1)) {
|
if (!(i == 1 && this->_tileMaps.x == 1) && !(i > 1 && this->_tileMaps.y == 1)) {
|
||||||
@@ -59,7 +60,8 @@ namespace ComSquare::PPU
|
|||||||
palette = getPalette(tileData.palette);
|
palette = getPalette(tileData.palette);
|
||||||
reference = getTilePixelReference(graphicAddress, index);
|
reference = getTilePixelReference(graphicAddress, index);
|
||||||
color = getRealColor(palette[reference]);
|
color = getRealColor(palette[reference]);
|
||||||
this->_buffer[pos.x][pos.y] = color;
|
if (tileData.tilePriority == this->priority)
|
||||||
|
this->buffer[pos.x][pos.y] = color;
|
||||||
index++;
|
index++;
|
||||||
pos.x++;
|
pos.x++;
|
||||||
if (index == (8 / this->_bpp) - 1) {
|
if (index == (8 / this->_bpp) - 1) {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ namespace ComSquare::PPU
|
|||||||
int _bpp;
|
int _bpp;
|
||||||
bool _directColor;
|
bool _directColor;
|
||||||
bool _highRes;
|
bool _highRes;
|
||||||
bool _priority;
|
|
||||||
uint16_t _TileMapStartAddress;
|
uint16_t _TileMapStartAddress;
|
||||||
uint16_t _tileSetAddress;
|
uint16_t _tileSetAddress;
|
||||||
|
|
||||||
@@ -39,8 +38,10 @@ namespace ComSquare::PPU
|
|||||||
//! @brief draw a tilemap 32x32 starting at baseAddress
|
//! @brief draw a tilemap 32x32 starting at baseAddress
|
||||||
void drawBasicTileMap(uint16_t baseAddress, Vector2<int> offset);
|
void drawBasicTileMap(uint16_t baseAddress, Vector2<int> offset);
|
||||||
public:
|
public:
|
||||||
Vector2<int> _backgroundSize;
|
bool priority;
|
||||||
std::array<std::array<uint32_t, 1024>, 1024> _buffer;
|
int bgNumber;
|
||||||
|
Vector2<int> backgroundSize;
|
||||||
|
std::array<std::array<uint32_t, 1024>, 1024> buffer;
|
||||||
Background(ComSquare::PPU::PPU &_ppu, int bgNumber, bool priority);
|
Background(ComSquare::PPU::PPU &_ppu, int bgNumber, bool priority);
|
||||||
//! @brief Render a background on the screen
|
//! @brief Render a background on the screen
|
||||||
void renderBackground(void);
|
void renderBackground(void);
|
||||||
|
|||||||
+48
-3
@@ -253,9 +253,9 @@ namespace ComSquare::PPU
|
|||||||
(void)cycles;
|
(void)cycles;
|
||||||
|
|
||||||
this->_backgrounds[0].renderBackground();
|
this->_backgrounds[0].renderBackground();
|
||||||
for (int i = 0; i < this->_backgrounds[0]._backgroundSize.y; i++) {
|
for (int i = 0; i < this->_backgrounds[0].backgroundSize.y; i++) {
|
||||||
for (int j = 0; j < this->_backgrounds[0]._backgroundSize.x; j++) {
|
for (int j = 0; j < this->_backgrounds[0].backgroundSize.x; j++) {
|
||||||
this->_renderer.putPixel(j, i, this->_backgrounds[0]._buffer[i][j]);
|
this->_renderer.putPixel(j, i, this->_backgrounds[0].buffer[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->_renderer.drawScreen();
|
this->_renderer.drawScreen();
|
||||||
@@ -483,4 +483,49 @@ namespace ComSquare::PPU
|
|||||||
backgroundSize.x = (this->_registers._bgsc[bgNumber - 1].tilemapHorizontalMirroring) ? 2 : 1;
|
backgroundSize.x = (this->_registers._bgsc[bgNumber - 1].tilemapHorizontalMirroring) ? 2 : 1;
|
||||||
return backgroundSize;
|
return backgroundSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PPU::renderMainAndSubScreen(void)
|
||||||
|
{
|
||||||
|
for (auto & _background : this->_backgrounds)
|
||||||
|
_background.renderBackground();
|
||||||
|
|
||||||
|
// the buffer is overwrite if necessery by a new bg so the background priority is from back to front
|
||||||
|
switch (this->_registers._bgmode.bgMode) {
|
||||||
|
case 0:
|
||||||
|
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]);
|
||||||
|
//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]);
|
||||||
|
//sprites priority 3
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::size_t SIZE>
|
||||||
|
void PPU::add_buffer(std::array<std::array<uint32_t, SIZE>, SIZE> &buffer, Background &bg)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < bg.backgroundSize.y; i++) {
|
||||||
|
for (int j = 0; j < bg.backgroundSize.x; j++) {
|
||||||
|
if (bg.buffer[i][j])
|
||||||
|
buffer[i][j] = bg.buffer[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPU::addToMainSubScreen(Background &bg)
|
||||||
|
{
|
||||||
|
int i = bg.bgNumber + bg.priority;
|
||||||
|
|
||||||
|
if (this->_registers._t[0].raw & (1U << bg.bgNumber - 1U))
|
||||||
|
this->add_buffer(this->_mainScreen, this->_backgrounds[i]);
|
||||||
|
if (this->_registers._t[1].raw & (1U << bg.bgNumber - 1U))
|
||||||
|
this->add_buffer(this->_subScreen, this->_backgrounds[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,17 @@
|
|||||||
namespace ComSquare::PPU
|
namespace ComSquare::PPU
|
||||||
{
|
{
|
||||||
class Background;
|
class Background;
|
||||||
|
enum bgName {
|
||||||
|
bg1NoPriority = 0,
|
||||||
|
bg1Priority,
|
||||||
|
bg2NoPriority,
|
||||||
|
bg2Priority,
|
||||||
|
bg3NoPriority,
|
||||||
|
bg3Priority,
|
||||||
|
bg4NoPriority,
|
||||||
|
bg4Priority
|
||||||
|
};
|
||||||
|
|
||||||
enum ppuRegisters {
|
enum ppuRegisters {
|
||||||
//! @brief INIDISP Register (F-blank and Brightness)
|
//! @brief INIDISP Register (F-blank and Brightness)
|
||||||
inidisp = 0x00,
|
inidisp = 0x00,
|
||||||
@@ -605,6 +616,13 @@ namespace ComSquare::PPU
|
|||||||
uint16_t getTileSetAddress(int bgNumber);
|
uint16_t getTileSetAddress(int bgNumber);
|
||||||
//! @brief Give the number of tilemaps to be rendered
|
//! @brief Give the number of tilemaps to be rendered
|
||||||
Vector2<int> getBackgroundSize(int bgNumber);
|
Vector2<int> getBackgroundSize(int bgNumber);
|
||||||
|
//! @brief Render the Main and sub screen correctly
|
||||||
|
void renderMainAndSubScreen(void);
|
||||||
|
//! @brief Add a bg buffer to another buffer
|
||||||
|
template <std::size_t SIZE>
|
||||||
|
void PPU::add_buffer(std::array<std::array<uint32_t, SIZE>, SIZE> &buffer, Background &bg);
|
||||||
|
//! @brief Add a bg to the sub and/or main screen
|
||||||
|
void addToMainSubScreen(Background &bg);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif //COMSQUARE_PPU_HPP
|
#endif //COMSQUARE_PPU_HPP
|
||||||
|
|||||||
Reference in New Issue
Block a user