mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-05-31 09:32:36 +00:00
adding getter setter for public vars of Background Class and norm fixes
This commit is contained in:
@@ -11,14 +11,14 @@
|
|||||||
namespace ComSquare::PPU
|
namespace ComSquare::PPU
|
||||||
{
|
{
|
||||||
Background::Background(ComSquare::PPU::PPU &_ppu, int backGroundNumber, bool hasPriority):
|
Background::Background(ComSquare::PPU::PPU &_ppu, int backGroundNumber, bool hasPriority):
|
||||||
priority(hasPriority),
|
_priority(hasPriority),
|
||||||
bgNumber(backGroundNumber)
|
_bgNumber(backGroundNumber)
|
||||||
{
|
{
|
||||||
_cgram = _ppu.cgram;
|
_cgram = _ppu.cgram;
|
||||||
_vram = _ppu.vram;
|
_vram = _ppu.vram;
|
||||||
_bpp = _ppu.getBPP(backGroundNumber);
|
_bpp = _ppu.getBPP(backGroundNumber);
|
||||||
_characterSize = _ppu.getCharacterSize(backGroundNumber);
|
_characterSize = _ppu.getCharacterSize(backGroundNumber);
|
||||||
_TileMapStartAddress = _ppu.getTileMapStartAddress(backGroundNumber);
|
_tileMapStartAddress = _ppu.getTileMapStartAddress(backGroundNumber);
|
||||||
_tilesetAddress = _ppu.getTilesetAddress(backGroundNumber);
|
_tilesetAddress = _ppu.getTilesetAddress(backGroundNumber);
|
||||||
_tileMaps = _ppu.getBackgroundSize(backGroundNumber);
|
_tileMaps = _ppu.getBackgroundSize(backGroundNumber);
|
||||||
_directColor = false;
|
_directColor = false;
|
||||||
@@ -26,9 +26,9 @@ namespace ComSquare::PPU
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Background::renderBackground(void)
|
void Background::renderBackground()
|
||||||
{
|
{
|
||||||
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 * NB_CHARACTER_WIDTH;
|
this->backgroundSize.x = this->_tileMaps.x * this->_characterSize.x * NB_CHARACTER_WIDTH;
|
||||||
this->backgroundSize.y = this->_tileMaps.y * this->_characterSize.y * NB_CHARACTER_HEIGHT;
|
this->backgroundSize.y = this->_tileMaps.y * this->_characterSize.y * NB_CHARACTER_HEIGHT;
|
||||||
@@ -69,7 +69,7 @@ namespace ComSquare::PPU
|
|||||||
for (int j = 0; j < this->_characterSize.x; j++) {
|
for (int j = 0; j < this->_characterSize.x; j++) {
|
||||||
reference = getPixelReferenceFromTile(graphicAddress, index);
|
reference = getPixelReferenceFromTile(graphicAddress, index);
|
||||||
color = getRealColor(palette[reference]);
|
color = getRealColor(palette[reference]);
|
||||||
if (tileData.tilePriority == this->priority) // reference 0 is considered as transparency
|
if (tileData.tilePriority == this->_priority) // reference 0 is considered as transparency
|
||||||
this->buffer[pos.x][pos.y] = (reference) ? color : 0;
|
this->buffer[pos.x][pos.y] = (reference) ? color : 0;
|
||||||
index += (tileData.horizontalFlip) ? -1 : 1;
|
index += (tileData.horizontalFlip) ? -1 : 1;
|
||||||
pos.x++;
|
pos.x++;
|
||||||
@@ -161,7 +161,7 @@ namespace ComSquare::PPU
|
|||||||
|
|
||||||
void Background::setTileMapStartAddress(uint16_t address)
|
void Background::setTileMapStartAddress(uint16_t address)
|
||||||
{
|
{
|
||||||
this->_TileMapStartAddress = address;
|
this->_tileMapStartAddress = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Background::setTilesetAddress(uint16_t address)
|
void Background::setTilesetAddress(uint16_t address)
|
||||||
@@ -182,8 +182,28 @@ namespace ComSquare::PPU
|
|||||||
this->_bpp = 2;
|
this->_bpp = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Background::setTilemaps(Vector2<int> tilemaps)
|
void Background::setTilemaps(Vector2<int> tileMaps)
|
||||||
{
|
{
|
||||||
this->_tileMaps = tilemaps;
|
this->_tileMaps = tileMaps;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Background::setBgNumber(int bgNumber)
|
||||||
|
{
|
||||||
|
this->_bgNumber = bgNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Background::getBgNumber() const
|
||||||
|
{
|
||||||
|
return this->_bgNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Background::setPriority(bool priority)
|
||||||
|
{
|
||||||
|
this->_priority = priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Background::getPriority() const
|
||||||
|
{
|
||||||
|
return this->_priority;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,8 +29,10 @@ namespace ComSquare::PPU
|
|||||||
int _bpp;
|
int _bpp;
|
||||||
bool _directColor;
|
bool _directColor;
|
||||||
bool _highRes;
|
bool _highRes;
|
||||||
uint16_t _TileMapStartAddress;
|
uint16_t _tileMapStartAddress;
|
||||||
uint16_t _tilesetAddress;
|
uint16_t _tilesetAddress;
|
||||||
|
bool _priority;
|
||||||
|
int _bgNumber;
|
||||||
|
|
||||||
std::shared_ptr<Ram::Ram> _vram;
|
std::shared_ptr<Ram::Ram> _vram;
|
||||||
std::shared_ptr<Ram::Ram> _cgram;
|
std::shared_ptr<Ram::Ram> _cgram;
|
||||||
@@ -50,20 +52,19 @@ namespace ComSquare::PPU
|
|||||||
//! @param pixelIndex The index of the pixel (0 - 255)
|
//! @param pixelIndex The index of the pixel (0 - 255)
|
||||||
//! @return The color reference
|
//! @return The color reference
|
||||||
uint8_t getPixelReferenceFromTile(uint16_t tileAddress, uint8_t pixelIndex);
|
uint8_t getPixelReferenceFromTile(uint16_t tileAddress, uint8_t pixelIndex);
|
||||||
//! @brief draw a tilemap 32x32 starting at baseAddress
|
//! @brief draw a tileMap 32x32 starting at baseAddress
|
||||||
//! @param baseAddress The starting address of the tileMap
|
//! @param baseAddress The starting address of the tileMap
|
||||||
//! @param offset The rendering offeset in pixels
|
//! @param offset The rendering offeset in pixels
|
||||||
void drawBasicTileMap(uint16_t baseAddress, Vector2<int> offset);
|
void drawBasicTileMap(uint16_t baseAddress, Vector2<int> offset);
|
||||||
public:
|
public:
|
||||||
// TODO getter setter for priority and bgNumber
|
// TODO getter setter for priority and bgNumber
|
||||||
bool priority;
|
|
||||||
int bgNumber;
|
|
||||||
Vector2<int> backgroundSize;
|
Vector2<int> backgroundSize;
|
||||||
std::array<std::array<uint32_t, 1024>, 1024> buffer;
|
std::array<std::array<uint32_t, 1024>, 1024> buffer;
|
||||||
Background(ComSquare::PPU::PPU &_ppu, int backGroundNumber, bool hasPriority);
|
Background(ComSquare::PPU::PPU &_ppu, int backGroundNumber, bool hasPriority);
|
||||||
//! @brief Render a background on his internal buffer
|
//! @brief Render a background on his internal buffer
|
||||||
void renderBackground(void);
|
void renderBackground();
|
||||||
//! @brief Set the tilemap start address
|
//! @brief Set the tileMap start address
|
||||||
//! @param address TileMap start address
|
//! @param address TileMap start address
|
||||||
void setTileMapStartAddress(uint16_t address);
|
void setTileMapStartAddress(uint16_t address);
|
||||||
//! @brief Set the character Size
|
//! @brief Set the character Size
|
||||||
@@ -74,7 +75,21 @@ namespace ComSquare::PPU
|
|||||||
//! @brief Set the bpp (bits per pixels) of the Background
|
//! @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)
|
//! @info The bpp can be 2, 4 or 8 (7 can be possible when BgMode is 7)
|
||||||
void setBpp(int bpp);
|
void setBpp(int bpp);
|
||||||
void setTilemaps(Vector2<int> tilemaps);
|
//! @brief setter for private variable _tileMaps
|
||||||
|
//! @param tileMaps The tileMaps to set
|
||||||
|
void setTilemaps(Vector2<int> tileMaps);
|
||||||
|
//! @brief set the Background number
|
||||||
|
//! @param bgNumber the new Background Number
|
||||||
|
void setBgNumber(int bgNumber);
|
||||||
|
//! @brief Get the BackGround Number
|
||||||
|
//! @return the current Background number
|
||||||
|
int getBgNumber() const;
|
||||||
|
//! @brief set the Background priority
|
||||||
|
//! @param bgNumber the new Background priority
|
||||||
|
void setPriority(bool priority);
|
||||||
|
//! @brief Get the Background priority
|
||||||
|
//! @return the current Background priority
|
||||||
|
bool getPriority() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -750,9 +750,9 @@ namespace ComSquare::PPU
|
|||||||
|
|
||||||
void PPU::addToMainSubScreen(Background &bg)
|
void PPU::addToMainSubScreen(Background &bg)
|
||||||
{
|
{
|
||||||
if (this->_registers._t[0].raw & (1U << (bg.bgNumber - 1U)))
|
if (this->_registers._t[0].raw & (1U << (bg.getBgNumber() - 1U)))
|
||||||
this->add_buffer(this->_mainScreen, bg.buffer);
|
this->add_buffer(this->_mainScreen, bg.buffer);
|
||||||
if (this->_registers._t[1].raw & (1U << (bg.bgNumber - 1U)))
|
if (this->_registers._t[1].raw & (1U << (bg.getBgNumber() - 1U)))
|
||||||
this->add_buffer(this->_subScreen, bg.buffer);
|
this->add_buffer(this->_subScreen, bg.buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
** Form generated from reading UI file 'cpu.ui'
|
** Form generated from reading UI file 'cpu.ui'
|
||||||
**
|
**
|
||||||
** Created by: Qt User Interface Compiler version 5.13.2
|
** Created by: Qt User Interface Compiler version 5.15.2
|
||||||
**
|
**
|
||||||
** WARNING! All changes made in this file will be lost when recompiling UI file!
|
** WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user