ComSquare
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ComSquare::PPU::Background Class Reference

#include <Background.hpp>

Collaboration diagram for ComSquare::PPU::Background:

Public Member Functions

bool isPriorityPixel (int x, int y) const
 Tells if a pixel has high priority. More...
 
void renderBackground ()
 Render a background on his internal buffer. More...
 
void setTileMapStartAddress (uint16_t address)
 Set the tileMap start address. More...
 
void setCharacterSize (Vector2< int > size)
 Set the character Size. More...
 
void setTilesetAddress (uint16_t address)
 Set the tileset address of the background. More...
 
void setBpp (int bpp)
 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) More...
 
void setTileMapMirroring (Vector2< bool > tileMaps)
 setter for private variable _tileMaps More...
 
int getBgNumber () const
 Get the BackGround Number. More...
 
 Background (PPU &_ppu, int backgroundNumber)
 ctor More...
 
 Background (const Background &)=default
 Default copy ctor. More...
 
 ~Background ()=default
 Default destructor. More...
 
Backgroundoperator= (const Background &)=delete
 Delete assignment operator. More...
 

Static Public Member Functions

template<int levelLow, int levelHigh, std::size_t DEST_SIZE_X, std::size_t DEST_SIZE_Y>
static void mergeBackgroundBuffer (std::array< std::array< uint32_t, DEST_SIZE_Y >, DEST_SIZE_X > &bufferDest, std::array< std::array< unsigned char, DEST_SIZE_Y >, DEST_SIZE_X > &pixelDestinationLevelMap, const Background &backgroundSrc)
 Add a bg buffer to another buffer. More...
 

Public Attributes

Vector2< unsigned > backgroundSize
 The size of the background (x, y) More...
 
std::array< std::array< uint32_t, 1024 >, 1024 > buffer
 The output buffer (pixels are written on it) More...
 
std::array< std::array< bool, 64 >, 64 > tilesPriority
 The buffer of tile priority level. More...
 

Private Member Functions

void _drawTile (uint16_t data, Vector2< int > indexOffset)
 Draw a tile on the screen at x y pos. More...
 
void _drawTileFromMemoryToTileBuffer (const union Utils::TileData &tileData)
 Draw the tile to the tile Buffer. More...
 
void _drawBasicTileMap (uint16_t baseAddress, Vector2< int > offset)
 draw a tileMap 32x32 starting at baseAddress More...
 

Private Attributes

PPU_ppu
 the ppu used to get registers values (ex: bg scroll) More...
 
Vector2< bool > _tileMapMirroring
 The tilemap configuration nb of tileMap vertically and horizontally. More...
 
Vector2< int > _characterNbPixels
 The number of pixels of a character (x: width, y: height) More...
 
int _bpp
 The number of bits per pixels to currently look for each pixel. More...
 
bool _directColor
 PPU official direct color mode. More...
 
bool _highRes
 PPU offical highRes mode. More...
 
uint16_t _tileMapStartAddress
 The first address of the tilemap data. More...
 
uint16_t _tilesetAddress
 The first address for tileset data. More...
 
int _bgNumber
 The bg number (used to get the corresponding scroll) More...
 
std::array< std::array< uint32_t, 16 >, 16 > _tileBuffer
 Buffer if we have tiles that are more than 8x8. More...
 
Ram::Ram_vram
 the access to vram More...
 
Ram::Ram_cgram
 The access to cgram. More...
 
TileRenderer _tileRenderer
 Class that actually render a tile. More...
 

Static Private Attributes

static constexpr int NbCharacterWidth = 32
 The number of character a TileMap has in width. More...
 
static constexpr int NbCharacterHeight = 32
 The number of character a TileMap has in height. More...
 
static constexpr unsigned NbTilePerRow = 16
 The number of rows in one line of VRAM. More...
 
static constexpr unsigned short TileMapByteSize = 0x800
 The size of a TileMap in memory. More...
 

Constructor & Destructor Documentation

◆ Background() [1/2]

ComSquare::PPU::Background::Background ( PPU _ppu,
int  backgroundNumber 
)

ctor

◆ Background() [2/2]

ComSquare::PPU::Background::Background ( const Background )
default

Default copy ctor.

◆ ~Background()

ComSquare::PPU::Background::~Background ( )
default

Default destructor.

Member Function Documentation

◆ _drawBasicTileMap()

void ComSquare::PPU::Background::_drawBasicTileMap ( uint16_t  baseAddress,
Vector2< int >  offset 
)
private

draw a tileMap 32x32 starting at baseAddress

Parameters
baseAddressThe starting address of the tileMap
offsetThe offset of the tile map (ranging from 0 to 1)

◆ _drawTile()

void ComSquare::PPU::Background::_drawTile ( uint16_t  data,
Vector2< int >  indexOffset 
)
private

Draw a tile on the screen at x y pos.

Parameters
dataThe VRAM value to be interpreted as a Utils::TileData
indexOffsetThe index offset of the Tile (ranging from 0 to 63)

◆ _drawTileFromMemoryToTileBuffer()

void ComSquare::PPU::Background::_drawTileFromMemoryToTileBuffer ( const union Utils::TileData tileData)
private

Draw the tile to the tile Buffer.

Parameters
tileDataThe tile data to use to render the tile

◆ getBgNumber()

int ComSquare::PPU::Background::getBgNumber ( ) const

Get the BackGround Number.

Returns
the current Background number

◆ isPriorityPixel()

bool ComSquare::PPU::Background::isPriorityPixel ( int  x,
int  y 
) const

Tells if a pixel has high priority.

◆ mergeBackgroundBuffer()

template<int levelLow, int levelHigh, std::size_t DEST_SIZE_X, std::size_t DEST_SIZE_Y>
static void ComSquare::PPU::Background::mergeBackgroundBuffer ( std::array< std::array< uint32_t, DEST_SIZE_Y >, DEST_SIZE_X > &  bufferDest,
std::array< std::array< unsigned char, DEST_SIZE_Y >, DEST_SIZE_X > &  pixelDestinationLevelMap,
const Background backgroundSrc 
)
inlinestatic

Add a bg buffer to another buffer.

Template Parameters
levelLowThe priority of a low priority pixel (working like z-index CSS property)
levelHighThe priority of a high priority pixel (working like z-index CSS property)
DEST_SIZE_XThe Horizontal array size
DEST_SIZE_YThe Vertical array size
Parameters
bufferDestThe destination buffer (buffer that will be written on)
pixelDestinationLevelMapThe destination buffer level map to use as reference and will be updated if a pixel has an higher level than the actual one
backgroundSrcThe Background to use as a source

◆ operator=()

Background& ComSquare::PPU::Background::operator= ( const Background )
delete

Delete assignment operator.

◆ renderBackground()

void ComSquare::PPU::Background::renderBackground ( )

Render a background on his internal buffer.

◆ setBpp()

void ComSquare::PPU::Background::setBpp ( int  bpp)

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)

◆ setCharacterSize()

void ComSquare::PPU::Background::setCharacterSize ( Vector2< int >  size)

Set the character Size.

Parameters
sizeThe character size (8x8, 16x16, 16x8, 8x16)

◆ setTileMapMirroring()

void ComSquare::PPU::Background::setTileMapMirroring ( Vector2< bool >  tileMaps)

setter for private variable _tileMaps

Parameters
tileMapsThe tileMaps to set

◆ setTileMapStartAddress()

void ComSquare::PPU::Background::setTileMapStartAddress ( uint16_t  address)

Set the tileMap start address.

Parameters
addressTileMap start address

◆ setTilesetAddress()

void ComSquare::PPU::Background::setTilesetAddress ( uint16_t  address)

Set the tileset address of the background.

Member Data Documentation

◆ _bgNumber

int ComSquare::PPU::Background::_bgNumber
private

The bg number (used to get the corresponding scroll)

◆ _bpp

int ComSquare::PPU::Background::_bpp
private

The number of bits per pixels to currently look for each pixel.

◆ _cgram

Ram::Ram& ComSquare::PPU::Background::_cgram
private

The access to cgram.

◆ _characterNbPixels

Vector2<int> ComSquare::PPU::Background::_characterNbPixels
private

The number of pixels of a character (x: width, y: height)

◆ _directColor

bool ComSquare::PPU::Background::_directColor
private

PPU official direct color mode.

◆ _highRes

bool ComSquare::PPU::Background::_highRes
private

PPU offical highRes mode.

◆ _ppu

PPU& ComSquare::PPU::Background::_ppu
private

the ppu used to get registers values (ex: bg scroll)

◆ _tileBuffer

std::array<std::array<uint32_t, 16>, 16> ComSquare::PPU::Background::_tileBuffer
private

Buffer if we have tiles that are more than 8x8.

◆ _tileMapMirroring

Vector2<bool> ComSquare::PPU::Background::_tileMapMirroring
private

The tilemap configuration nb of tileMap vertically and horizontally.

Note
members are set to true if the tilemap is expended in their direction

◆ _tileMapStartAddress

uint16_t ComSquare::PPU::Background::_tileMapStartAddress
private

The first address of the tilemap data.

◆ _tileRenderer

TileRenderer ComSquare::PPU::Background::_tileRenderer
private

Class that actually render a tile.

◆ _tilesetAddress

uint16_t ComSquare::PPU::Background::_tilesetAddress
private

The first address for tileset data.

◆ _vram

Ram::Ram& ComSquare::PPU::Background::_vram
private

the access to vram

◆ backgroundSize

Vector2<unsigned> ComSquare::PPU::Background::backgroundSize

The size of the background (x, y)

◆ buffer

std::array<std::array<uint32_t, 1024>, 1024> ComSquare::PPU::Background::buffer

The output buffer (pixels are written on it)

◆ NbCharacterHeight

constexpr int ComSquare::PPU::Background::NbCharacterHeight = 32
staticconstexprprivate

The number of character a TileMap has in height.

◆ NbCharacterWidth

constexpr int ComSquare::PPU::Background::NbCharacterWidth = 32
staticconstexprprivate

The number of character a TileMap has in width.

◆ NbTilePerRow

constexpr unsigned ComSquare::PPU::Background::NbTilePerRow = 16
staticconstexprprivate

The number of rows in one line of VRAM.

Note
If you're lost by this description, open a tile viewer in an emulator, and set the number of tiles in width to 16 graphics

◆ TileMapByteSize

constexpr unsigned short ComSquare::PPU::Background::TileMapByteSize = 0x800
staticconstexprprivate

The size of a TileMap in memory.

◆ tilesPriority

std::array<std::array<bool, 64>, 64> ComSquare::PPU::Background::tilesPriority

The buffer of tile priority level.


The documentation for this class was generated from the following files: