diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index a5db727..2cf58d3 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -47,26 +47,18 @@ namespace ComSquare::PPU case 0x05: //! @brief $2105 BGMODE (BG Mode and Character Size). this->_bgmode.raw = data; break; - case 0x06: + case 0x06: //! $2106 MOSAIC (Screen Pixelation) this->_mosaic.raw = data; break; - case 0x07: - this->_bg1sc.raw = data; + case 0x07: // BG1SC (BG1 Tilemap Address and Size) + case 0x08: // BG2SC (BG2 Tilemap Address and Size) + case 0x09: //! @brief BG3SC (BG3 Tilemap Address and Size) + case 0x0A: //! @brief BG4SC (BG4 Tilemap Address and Size) + this->_bgsc[addr - 0x07].raw = data; break; - case 0x08: - this->_bg2sc.raw = data; - break; - case 0x09: - this->_bg3sc.raw = data; - break; - case 0x0A: - this->_bg4sc.raw = data; - break; - case 0x0B: - this->_bg12nba.raw = data; - break; - case 0x0C: - this->_bg34nba.raw = data; + case 0x0B: //! @brief BG12NBA (BG1 and 2 Chr Address) + case 0x0C: //! @brief BG34NBA (BG3 and 4 Chr Address) + this->_bgnba[addr - 0x0B].raw = data; break; //TODO adding the rest of the registers. oaf ! default: diff --git a/sources/PPU/PPU.hpp b/sources/PPU/PPU.hpp index e0bcfe9..f6db2f5 100644 --- a/sources/PPU/PPU.hpp +++ b/sources/PPU/PPU.hpp @@ -129,50 +129,23 @@ namespace ComSquare::PPU }; uint8_t raw; } _mosaic; - //! @brief BG1SC Register (BG1 Tilemap Address and Size) + //! @brief BGSC Registers (BG Tilemap Address and Size) union { struct { - uint8_t tilemapAddress: 6; bool tilemapHorizontalMirroring: 1; bool tilemapVerticalMirroring: 1; - }; - uint8_t raw; - } _bg1sc; - //! @brief BG2SC Register (BG2 Tilemap Address and Size) - union { - struct { uint8_t tilemapAddress: 6; - bool tilemapHorizontalMirroring: 1; - bool tilemapVerticalMirroring: 1; }; uint8_t raw; - } _bg2sc; - //! @brief BG3SC Register (BG3 Tilemap Address and Size) + } _bgsc[4]; + //! @brief BGNBA Registers (BG1/2/3/4 Chr Address) union { struct { - uint8_t tilemapAddress: 6; - bool tilemapHorizontalMirroring: 1; - bool tilemapVerticalMirroring: 1; - }; - uint8_t raw; - } _bg3sc; - //! @brief BG4SC Register (BG4 Tilemap Address and Size) - union { - struct { - uint8_t tilemapAddress: 6; - bool tilemapHorizontalMirroring: 1; - bool tilemapVerticalMirroring: 1; - }; - uint8_t raw; - } _bg4sc; - //! @brief BG12NBA Register (BG1 and 2 Chr Address) - union { - struct { - uint8_t baseAddressBg2a4: 4; uint8_t baseAddressBg1a3: 4; + uint8_t baseAddressBg2a4: 4; }; uint8_t raw; - } _bg12nba; + } _bgnba[2]; //! @brief BG34NBA Register (BG3 and 4 Chr Address) union { struct { diff --git a/tests/PPU/testPpuWrite.cpp b/tests/PPU/testPpuWrite.cpp index 1b4170d..27e3b00 100644 --- a/tests/PPU/testPpuWrite.cpp +++ b/tests/PPU/testPpuWrite.cpp @@ -155,33 +155,111 @@ Test(PPU_write, bgmode_bgmode_5_and_bg24_on) Test(PPU_write, mosaic_data_full) { -auto pair = Init(); -pair.first->write(0x2106, 0b11111111); -cr_assert_eq(pair.second.ppu->_mosaic.affectBg1, true); -cr_assert_eq(pair.second.ppu->_mosaic.affectBg2, true); -cr_assert_eq(pair.second.ppu->_mosaic.affectBg3, true); -cr_assert_eq(pair.second.ppu->_mosaic.affectBg4, true); -cr_assert_eq(pair.second.ppu->_mosaic.pixelSize, 0xF); + auto pair = Init(); + pair.first->write(0x2106, 0b11111111); + cr_assert_eq(pair.second.ppu->_mosaic.affectBg1, true); + cr_assert_eq(pair.second.ppu->_mosaic.affectBg2, true); + cr_assert_eq(pair.second.ppu->_mosaic.affectBg3, true); + cr_assert_eq(pair.second.ppu->_mosaic.affectBg4, true); + cr_assert_eq(pair.second.ppu->_mosaic.pixelSize, 0xF); } Test(PPU_write, mosaic_affectbg23_w_1x1_size) { -auto pair = Init(); -pair.first->write(0x2106, 0b00000110); -cr_assert_eq(pair.second.ppu->_mosaic.affectBg1, false); -cr_assert_eq(pair.second.ppu->_mosaic.affectBg2, true); -cr_assert_eq(pair.second.ppu->_mosaic.affectBg3, true); -cr_assert_eq(pair.second.ppu->_mosaic.affectBg4, false); -cr_assert_eq(pair.second.ppu->_mosaic.pixelSize, 0x0); + auto pair = Init(); + pair.first->write(0x2106, 0b00000110); + cr_assert_eq(pair.second.ppu->_mosaic.affectBg1, false); + cr_assert_eq(pair.second.ppu->_mosaic.affectBg2, true); + cr_assert_eq(pair.second.ppu->_mosaic.affectBg3, true); + cr_assert_eq(pair.second.ppu->_mosaic.affectBg4, false); + cr_assert_eq(pair.second.ppu->_mosaic.pixelSize, 0x0); } Test(PPU_write, mosaic_affectbg14_w_2x2_size) { -auto pair = Init(); -pair.first->write(0x2106, 0b00101001); -cr_assert_eq(pair.second.ppu->_mosaic.affectBg1, true); -cr_assert_eq(pair.second.ppu->_mosaic.affectBg2, false); -cr_assert_eq(pair.second.ppu->_mosaic.affectBg3, false); -cr_assert_eq(pair.second.ppu->_mosaic.affectBg4, true); -cr_assert_eq(pair.second.ppu->_mosaic.pixelSize, 0x2); + auto pair = Init(); + pair.first->write(0x2106, 0b00101001); + cr_assert_eq(pair.second.ppu->_mosaic.affectBg1, true); + cr_assert_eq(pair.second.ppu->_mosaic.affectBg2, false); + cr_assert_eq(pair.second.ppu->_mosaic.affectBg3, false); + cr_assert_eq(pair.second.ppu->_mosaic.affectBg4, true); + cr_assert_eq(pair.second.ppu->_mosaic.pixelSize, 0x2); +} + +Test(PPU_write, bg1sc_data_full) +{ + auto pair = Init(); + pair.first->write(0x2107, 0b11111111); + cr_assert_eq(pair.second.ppu->_bgsc[0].tilemapAddress, 0b111111); + cr_assert_eq(pair.second.ppu->_bgsc[0].tilemapHorizontalMirroring, true); + cr_assert_eq(pair.second.ppu->_bgsc[0].tilemapVerticalMirroring, true); +} + +Test(PPU_write, bg2sc_data_full) +{ + auto pair = Init(); + pair.first->write(0x2108, 0b11111111); + cr_assert_eq(pair.second.ppu->_bgsc[1].tilemapAddress, 0b111111); + cr_assert_eq(pair.second.ppu->_bgsc[1].tilemapHorizontalMirroring, true); + cr_assert_eq(pair.second.ppu->_bgsc[1].tilemapVerticalMirroring, true); +} + +Test(PPU_write, bg3sc_data_full) +{ + auto pair = Init(); + pair.first->write(0x2109, 0b11111111); + cr_assert_eq(pair.second.ppu->_bgsc[2].tilemapAddress, 0b111111); + cr_assert_eq(pair.second.ppu->_bgsc[2].tilemapHorizontalMirroring, true); + cr_assert_eq(pair.second.ppu->_bgsc[2].tilemapVerticalMirroring, true); +} + +Test(PPU_write, bg4sc_data_full) +{ + auto pair = Init(); + pair.first->write(0x210A, 0b11111111); + cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapAddress, 0b111111); + cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapHorizontalMirroring, true); + cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapVerticalMirroring, true); +} + +Test(PPU_write, bg4sc_data_null) +{ + auto pair = Init(); + pair.first->write(0x210A, 0b00000000); + cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapAddress, 0); + cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapHorizontalMirroring, false); + cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapVerticalMirroring, false); +} + +Test(PPU_write, bg4sc_horizontal_off_vertical_on_random_tilemapAdress) +{ + auto pair = Init(); + pair.first->write(0x210A, 0b11000110); + cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapAddress, 0b110001); + cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapHorizontalMirroring, false); + cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapVerticalMirroring, true); +} + +Test(PPU_write, bg12nba_data_full) +{ + auto pair = Init(); + pair.first->write(0x210B, 0b11111111); + cr_assert_eq(pair.second.ppu->_bgnba[0].baseAddressBg1a3, 0b1111); + cr_assert_eq(pair.second.ppu->_bgnba[0].baseAddressBg2a4, 0b1111); +} + +Test(PPU_write, bg34nba_data_full) +{ + auto pair = Init(); + pair.first->write(0x210C, 0b11111111); + cr_assert_eq(pair.second.ppu->_bgnba[1].baseAddressBg1a3, 0b1111); + cr_assert_eq(pair.second.ppu->_bgnba[1].baseAddressBg2a4, 0b1111); +} + +Test(PPU_write, bg12nba_data_random_data) +{ + auto pair = Init(); + pair.first->write(0x210B, 0b10101010); + cr_assert_eq(pair.second.ppu->_bgnba[0].baseAddressBg1a3, 0b1010); + cr_assert_eq(pair.second.ppu->_bgnba[0].baseAddressBg2a4, 0b1010); } \ No newline at end of file