diff --git a/sources/PPU/Background.cpp b/sources/PPU/Background.cpp index f21406c..e7a8344 100644 --- a/sources/PPU/Background.cpp +++ b/sources/PPU/Background.cpp @@ -29,18 +29,18 @@ namespace ComSquare::PPU { uint16_t vramAddress = this->_TileMapStartAddress; Vector2 offset(0, 0); - this->backgroundSize.x = this->_tileMaps.x * this->_characterSize.x * 32; - this->backgroundSize.y = this->_tileMaps.y * this->_characterSize.y * 32; + this->backgroundSize.x = this->_tileMaps.x * this->_characterSize.x * NB_CHARACTER_WIDTH; + this->backgroundSize.y = this->_tileMaps.y * this->_characterSize.y * NB_CHARACTER_HEIGHT; for (int i = 0; i < 4; i++) { if (!(i == 1 && this->_tileMaps.x == 1) && !(i > 1 && this->_tileMaps.y == 1)) { drawBasicTileMap(vramAddress, offset); } - vramAddress+= 0x800; - offset.x += 32 * this->_characterSize.x; + vramAddress += 0x800; + offset.x += NB_CHARACTER_WIDTH * this->_characterSize.x; if (i == 2) { offset.x = 0; - offset.y += 32 * this->_characterSize.y; + offset.y += NB_CHARACTER_HEIGHT * this->_characterSize.y; } } } @@ -57,7 +57,9 @@ namespace ComSquare::PPU tileData.raw = data; palette = getPalette(tileData.palette); // TODO explain X and Y and rethink the formula - graphicAddress = this->_tileSetAddress + (tileData.posX * 16 * this->_bpp * 8) + (tileData.posY * this->_bpp * 8); + // X horizontal + // Y vertical + graphicAddress = this->_tileSetAddress + (tileData.posY * 16 * this->_bpp * 8) + (tileData.posX * this->_bpp * 8); for (int i = 0; i < this->_characterSize.y; i++) { for (int j = 0; j < this->_characterSize.x; j++) { reference = getTilePixelReference(graphicAddress, index); @@ -129,6 +131,7 @@ namespace ComSquare::PPU uint16_t vramAddress = baseAddress; while (vramAddress < baseAddress + 0x800) { + // TODO function to read 2 bytes (LSB order or bits reversed) tileMapValue = this->_vram->read_internal(vramAddress); tileMapValue += this->_vram->read_internal(vramAddress + 1) << 8U; drawBgTile(tileMapValue, {(pos.x * this->_characterSize.x) + offset.x, (pos.y * this->_characterSize.y) + offset.y}); diff --git a/sources/PPU/Background.hpp b/sources/PPU/Background.hpp index 32c94c4..994d744 100644 --- a/sources/PPU/Background.hpp +++ b/sources/PPU/Background.hpp @@ -19,6 +19,8 @@ namespace ComSquare::PPU { class PPU; class Background { + #define NB_CHARACTER_WIDTH 32 + #define NB_CHARACTER_HEIGHT 32 private: Vector2 _tileMaps; Vector2 _characterSize; @@ -39,6 +41,7 @@ namespace ComSquare::PPU //! @brief draw a tilemap 32x32 starting at baseAddress void drawBasicTileMap(uint16_t baseAddress, Vector2 offset); public: + // TODO getter setter for priority and bgNumber bool priority; int bgNumber; Vector2 backgroundSize; diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index 6ecd720..c19c735 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -38,7 +38,7 @@ namespace ComSquare::PPU //colors for the cgram this->cgram->write_internal(2, 0xE0); this->cgram->write_internal(3, 0x7F); - this->cgram->write_internal(4, 0x0F); // 0x1F + this->cgram->write_internal(4, 0x1F); // 0x1F this->cgram->write_internal(6, 0xFF); this->cgram->write_internal(7, 0x03); this->cgram->write_internal(66, 0xE0); @@ -129,6 +129,7 @@ namespace ComSquare::PPU uint8_t PPU::read(uint24_t addr) { + return 0; switch (addr) { case ppuRegisters::mpyl: return this->_registers._mpy.mpyl; @@ -157,6 +158,7 @@ namespace ComSquare::PPU void PPU::write(uint24_t addr, uint8_t data) { + return; switch (addr) { case ppuRegisters::inidisp: this->_registers._inidisp.raw = data; diff --git a/sources/PPU/PPUUtils.hpp b/sources/PPU/PPUUtils.hpp index 16d90e3..80ee33a 100644 --- a/sources/PPU/PPUUtils.hpp +++ b/sources/PPU/PPUUtils.hpp @@ -11,8 +11,8 @@ namespace ComSquare::PPU { union TileMapData { struct { - uint8_t posY: 4; - uint8_t posX: 6; + uint8_t posX: 4; + uint8_t posY: 6; uint8_t palette: 3; bool tilePriority: 1; bool horizontalFlip: 1;