diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a69f10..7ab29b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,7 +98,9 @@ add_executable(unit_tests tests/CPU/Math/testOthersMath.cpp tests/testRectangleMemory.cpp tests/CPU/Math/testCMP.cpp - sources/PPU/Background.cpp sources/PPU/Background.hpp) + sources/PPU/Background.cpp + sources/PPU/Background.hpp + sources/PPU/PPUUtils.cpp) # include criterion & coverage target_link_libraries(unit_tests criterion -lgcov) @@ -213,7 +215,9 @@ add_executable(ComSquare sources/Debugger/CGramDebug.cpp sources/Debugger/CGramDebug.hpp sources/Models/Vector2.hpp - sources/PPU/Background.cpp sources/PPU/Background.hpp sources/PPU/PPUUtils.cpp) + sources/PPU/Background.cpp + sources/PPU/Background.hpp + sources/PPU/PPUUtils.cpp) target_compile_definitions(ComSquare PUBLIC DEBUGGER_ENABLED) diff --git a/sources/PPU/Background.cpp b/sources/PPU/Background.cpp index dc50328..9ab26cb 100644 --- a/sources/PPU/Background.cpp +++ b/sources/PPU/Background.cpp @@ -5,6 +5,7 @@ #include "PPUUtils.hpp" #include "PPU.hpp" #include "Background.hpp" +#include "../Models/Vector2.hpp" namespace ComSquare::PPU { @@ -72,6 +73,8 @@ namespace ComSquare::PPU index = 0; pos.x -= this->_characterSize.x; pos.y++; + if (i == 7) + graphicAddress += 0x100 - this->_characterSize.x * this->_bpp; } } @@ -103,9 +106,9 @@ namespace ComSquare::PPU case 4: secondHightByte = this->_vram->read_internal((addr + 32) % VRAMSIZE); secondLowByte = this->_vram->read_internal((addr + 33) %VRAMSIZE); - result = (((secondLowByte & (1U << (7U - nb))) + ((secondHightByte & (1U << (7U - nb))) << 1U)) << 2U) >> (7U - nb - 2); + result = ((secondHightByte & (1U << (7U - nb))) | ((secondLowByte & (1U << (7U - nb))) << 1U)) >> (7U - nb - 2); case 2: - result += ((lowByte & (1U << (7U - nb))) + ((highByte & (1U << (7U - nb))) << 1U)) >> (7U - nb - 1); + result += ((highByte & (1U << (7U - nb))) | ((lowByte & (1U << (7U - nb))) << 1U)) >> (7U - nb); default: break; } @@ -137,5 +140,10 @@ namespace ComSquare::PPU this->_TileMapStartAddress = address; } + void Background::setCharacterSize(Vector2 size) + { + this->_characterSize = size; + } + } \ No newline at end of file diff --git a/sources/PPU/Background.hpp b/sources/PPU/Background.hpp index 719770f..32c94c4 100644 --- a/sources/PPU/Background.hpp +++ b/sources/PPU/Background.hpp @@ -48,6 +48,8 @@ namespace ComSquare::PPU void renderBackground(void); //! @brief Set the tilemap start address void setTileMapStartAddress(uint16_t address); + //! @brief Set the character Size + void setCharacterSize(Vector2 size); }; } diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index 0c094cd..7179383 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -80,22 +80,16 @@ namespace ComSquare::PPU for (int i = 0; vram_test[i] != -1; i++) { this->vram->write_internal(i, vram_test[i]); } - int vram_test_2[] = {8, 00, 02, 00, 0x0A, 00, 02, 00, 0x0A, 00, 00, 00, 00, 00, 00, -1}; - for (int i = 0; vram_test[i] != -1; i++) { + int vram_test_2[] = {8, 00, 02, 00, 0x0A, 00, 02, 00, 0x0A, 00, 00, 00, 00, 00, 00, -1}; + for (int i = 0; vram_test_2[i] != -1; i++) { this->vram->write_internal(i + 0x8000, vram_test_2[i]); } - for (int i = 0; vram_test[i] != -1; i++) { - this->vram->write_internal(i, vram_test[i]); - } - int vram_test_3[] = {8, 00, 02, 00, 0x0A, 00, 02, 00, 0x0A, 00, 00, 00, 00, 00, 00, -1}; - for (int i = 0; vram_test[i] != -1; i++) { + int vram_test_3[] = {8, 00, 02, 00, 0x8, 00, 02, 00, 0x8, 00, 00, 00, 00, 00, 00, -1}; + for (int i = 0; vram_test_3[i] != -1; i++) { this->vram->write_internal(i + 0x8080, vram_test_3[i]); } - for (int i = 0; vram_test[i] != -1; i++) { - this->vram->write_internal(i, vram_test[i]); - } int vram_test_4[] = {8, 00, 02, 00, 0x0A, 00, 02, 00, 0x0A, 00, 00, 00, 00, 00, 00, -1}; - for (int i = 0; vram_test[i] != -1; i++) { + for (int i = 0; vram_test_4[i] != -1; i++) { this->vram->write_internal(i + 0x8100, vram_test_4[i]); } this->vram->write_internal(0x8040, 04); @@ -125,6 +119,10 @@ namespace ComSquare::PPU this->_registers._t[0].enableWindowDisplayBg1 = true; this->_registers._t[0].enableWindowDisplayBg2 = true; + this->_backgrounds[0].setCharacterSize(this->getCharacterSize(1)); + this->_backgrounds[1].setCharacterSize(this->getCharacterSize(1)); + this->_backgrounds[2].setCharacterSize(this->getCharacterSize(2)); + this->_backgrounds[3].setCharacterSize(this->getCharacterSize(2)); } uint8_t PPU::read(uint24_t addr) @@ -349,9 +347,11 @@ namespace ComSquare::PPU { (void)cycles; - this->renderMainAndSubScreen(); - add_buffer(this->_screen, this->_subScreen); - add_buffer(this->_screen, this->_mainScreen); + //this->renderMainAndSubScreen(); + //add_buffer(this->_screen, this->_subScreen); + //add_buffer(this->_screen, this->_mainScreen); + this->_backgrounds[0].renderBackground(); + add_buffer(this->_screen, this->_backgrounds[0].buffer); for (unsigned long i = 0; i < this->_screen.size(); i++) { for (unsigned long j = 0; j < this->_screen[i].size(); j++) { this->_renderer.putPixel(j, i, this->_screen[i][j]); @@ -693,8 +693,6 @@ namespace ComSquare::PPU void PPU::addToMainSubScreen(Background &bg) { - int i = bg.bgNumber + bg.priority; - if (this->_registers._t[0].raw & (1U << (bg.bgNumber - 1U))) this->add_buffer(this->_mainScreen, bg.buffer); if (this->_registers._t[1].raw & (1U << (bg.bgNumber - 1U)))