From d1b0e039efe2a7d9d3a87d3096ee34bd76681723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Thu, 15 Oct 2020 23:16:59 +0200 Subject: [PATCH] handling tilemap mirroring --- sources/PPU/Background.cpp | 5 +++++ sources/PPU/Background.hpp | 1 + sources/PPU/PPU.cpp | 12 ++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sources/PPU/Background.cpp b/sources/PPU/Background.cpp index 70cad9a..07f90ba 100644 --- a/sources/PPU/Background.cpp +++ b/sources/PPU/Background.cpp @@ -181,4 +181,9 @@ namespace ComSquare::PPU else this->_bpp = 2; } + + void Background::setTilemaps(Vector2 tilemaps) + { + this->_tileMaps = tilemaps; + } } \ No newline at end of file diff --git a/sources/PPU/Background.hpp b/sources/PPU/Background.hpp index 45f006f..feaaab5 100644 --- a/sources/PPU/Background.hpp +++ b/sources/PPU/Background.hpp @@ -74,6 +74,7 @@ namespace ComSquare::PPU //! @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) void setBpp(int bpp); + void setTilemaps(Vector2 tilemaps); }; } diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index 43d03b0..47cbd90 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -129,13 +129,19 @@ namespace ComSquare::PPU this->_backgrounds[2].setCharacterSize(this->getCharacterSize(2)); this->_backgrounds[3].setCharacterSize(this->getCharacterSize(2)); - this->_registers._bgsc[0].tilemapAddress = 0x4800U >> 10U; - this->_registers._bgsc[1].tilemapAddress = 0x4000U >> 10U; + this->_registers._bgsc[0].tilemapAddress = 0x4800U >> 10U; // 0x4800 + this->_registers._bgsc[0].tilemapHorizontalMirroring = 1; + this->_registers._bgsc[1].tilemapAddress = 0x4000U >> 10U; // 0x4000 + this->_registers._bgsc[1].tilemapHorizontalMirroring = 1; this->_registers._bgsc[2].tilemapAddress = 0x5C00U >> 10U; this->_backgrounds[0].setTileMapStartAddress(this->getTileMapStartAddress(1)); + this->_backgrounds[0].setTilemaps(this->getBackgroundSize(1)); this->_backgrounds[1].setTileMapStartAddress(this->getTileMapStartAddress(1)); + this->_backgrounds[1].setTilemaps(this->getBackgroundSize(1)); this->_backgrounds[2].setTileMapStartAddress(this->getTileMapStartAddress(2)); + this->_backgrounds[2].setTilemaps(this->getBackgroundSize(2)); this->_backgrounds[3].setTileMapStartAddress(this->getTileMapStartAddress(2)); + this->_backgrounds[3].setTilemaps(this->getBackgroundSize(2)); this->_backgrounds[4].setTileMapStartAddress(this->getTileMapStartAddress(3)); this->_backgrounds[5].setTileMapStartAddress(this->getTileMapStartAddress(3)); @@ -235,6 +241,8 @@ namespace ComSquare::PPU // update background tilemap address this->_backgrounds[addr - 0x07].setTileMapStartAddress(this->getTileMapStartAddress(addr - 0x07 + 1)); this->_backgrounds[addr - 0x07 + 1].setTileMapStartAddress(this->getTileMapStartAddress(addr - 0x07 + 1)); + this->_backgrounds[addr - 0x07].setTilemaps({this->_registers._bgsc[addr - 0x07].tilemapHorizontalMirroring, this->_registers._bgsc[addr - 0x07].tilemapVerticalMirroring}); + this->_backgrounds[addr - 0x07 + 1].setTilemaps({this->_registers._bgsc[addr - 0x07].tilemapHorizontalMirroring, this->_registers._bgsc[addr - 0x07].tilemapVerticalMirroring}); break; case ppuRegisters::bg12nba: case ppuRegisters::bg34nba: