From 3964da952688399c8546ec216185ceec6cbe2d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Thu, 8 Jul 2021 00:48:10 +0200 Subject: [PATCH] general clean up --- sources/PPU/Background.cpp | 2 -- sources/PPU/Background.hpp | 5 +++-- sources/PPU/PPU.cpp | 37 ++++++++++++++++++++++++------------- sources/PPU/PpuDebug.cpp | 27 ++++++++++----------------- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/sources/PPU/Background.cpp b/sources/PPU/Background.cpp index 7854e25..6ba526f 100644 --- a/sources/PPU/Background.cpp +++ b/sources/PPU/Background.cpp @@ -86,8 +86,6 @@ namespace ComSquare::PPU tileData.raw = data; - //if (tileData.tilePriority != this->_priority) - // return; this->tilesPriority[indexOffset.y][indexOffset.x] = tileData.tilePriority; this->_drawTileFromMemoryToTileBuffer(tileData); diff --git a/sources/PPU/Background.hpp b/sources/PPU/Background.hpp index 7ca9421..552a5c7 100644 --- a/sources/PPU/Background.hpp +++ b/sources/PPU/Background.hpp @@ -127,10 +127,11 @@ namespace ComSquare::PPU return; } pixelLevel = backgroundSrc.isPriorityPixel(i, j) ? levelHigh : levelLow; + auto &pixelInitialLevel = pixelDestinationLevelMap[i][j]; - if (pixelLevel >= pixelDestinationLevelMap[i][j]) { + if (pixelLevel >= pixelInitialLevel) { bufferDest[i][j] = pixel; - pixelDestinationLevelMap[i][j] = pixelLevel; + pixelInitialLevel = pixelLevel; } j++; }); diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index 1fccd12..f648786 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -32,7 +32,7 @@ namespace ComSquare::PPU { this->_registers._isLowByte = true; - Utils::Debug::populateEnvironment(*this, 1); + Utils::Debug::populateEnvironment(*this, 0); } uint8_t PPU::read(uint24_t addr) @@ -309,20 +309,33 @@ namespace ComSquare::PPU this->renderMainAndSubScreen(); Utils::addBuffer(this->_screen, this->_subScreen); Utils::addBuffer(this->_screen, this->_mainScreen); - //this->_backgrounds[2].renderBackground(); - //add_buffer(this->_screen, this->_backgrounds[2].buffer); + + int i = 0; + int j = 0; + std::for_each(this->_screen.begin(), this->_screen.end(), [this, &i, &j](const auto &row) { + std::for_each(row.begin(), row.end(), [this, &i, &j](const auto &pixel) { + this->_renderer.putPixel(i, j++, pixel); + }); + j = 0; + i++; + }); + + + /* + // loop used for debug for (unsigned long i = 0; i < this->_screen.size(); i++) { for (unsigned long j = 0; j < this->_screen[i].size(); j++) { - this->_renderer.putPixel(i + 200, j, this->_screen[i][j]); + this->_renderer.putPixel(i, j, this->_screen[i][j]); } - if (i > 500) - break; + //if (i > 500) + // break; } + */ this->_renderer.drawScreen(); - for (auto &i : this->_mainScreen) - i.fill(0XFF); - for (auto &i : this->_subScreen) - i.fill(0XFF); + for (auto &row : this->_mainScreen) + row.fill(0XFF); + for (auto &row : this->_subScreen) + row.fill(0XFF); } std::string PPU::getName() const @@ -649,7 +662,7 @@ namespace ComSquare::PPU // Not implemented throw std::runtime_error("not implemented"); default: - break; + throw std::runtime_error("Bg mode not implemented or commented (bg nb " + std::to_string(this->_registers._bgmode.bgMode) + ")"); } } @@ -658,9 +671,7 @@ namespace ComSquare::PPU if (this->_registers._t[0].raw & (1U << (bg.getBgNumber() - 1U))) { Background::mergeBackgroundBuffer(this->_mainScreen, this->_mainScreenLevelMap, bg, level.x, level.y); } - // Utils::addBuffer(this->_mainScreen, bg.buffer); if (this->_registers._t[1].raw & (1U << (bg.getBgNumber() - 1U))) { - //Utils::addBuffer(this->_subScreen, bg.buffer); Background::mergeBackgroundBuffer(this->_subScreen, this->_subScreenLevelMap, bg, level.x, level.y); } } diff --git a/sources/PPU/PpuDebug.cpp b/sources/PPU/PpuDebug.cpp index 2de7ba1..b1ae774 100644 --- a/sources/PPU/PpuDebug.cpp +++ b/sources/PPU/PpuDebug.cpp @@ -3833,31 +3833,24 @@ namespace ComSquare::PPU::Utils::Debug //registers tic tac toe ppu._registers._bgmode.bgMode = 0; ppu._backgrounds[0].setBpp(ppu.getBPP(1)); - ppu._backgrounds[1].setBpp(ppu.getBPP(1)); - ppu._backgrounds[2].setBpp(ppu.getBPP(2)); - ppu._backgrounds[3].setBpp(ppu.getBPP(2)); - ppu._backgrounds[4].setBpp(ppu.getBPP(3)); - ppu._backgrounds[5].setBpp(ppu.getBPP(3)); - ppu._backgrounds[6].setBpp(ppu.getBPP(4)); - ppu._backgrounds[7].setBpp(ppu.getBPP(4)); + ppu._backgrounds[1].setBpp(ppu.getBPP(2)); + ppu._backgrounds[2].setBpp(ppu.getBPP(3)); + ppu._backgrounds[3].setBpp(ppu.getBPP(4)); ppu._registers._bgmode.characterSizeBg1 = true; ppu._registers._bgmode.characterSizeBg2 = true; ppu._backgrounds[0].setCharacterSize(ppu.getCharacterSize(1)); - ppu._backgrounds[1].setCharacterSize(ppu.getCharacterSize(1)); - ppu._backgrounds[2].setCharacterSize(ppu.getCharacterSize(2)); - ppu._backgrounds[3].setCharacterSize(ppu.getCharacterSize(2)); - ppu._backgrounds[4].setCharacterSize(ppu.getCharacterSize(3)); - ppu._backgrounds[5].setCharacterSize(ppu.getCharacterSize(3)); - ppu._backgrounds[6].setCharacterSize(ppu.getCharacterSize(4)); - ppu._backgrounds[7].setCharacterSize(ppu.getCharacterSize(4)); + ppu._backgrounds[1].setCharacterSize(ppu.getCharacterSize(2)); + ppu._backgrounds[2].setCharacterSize(ppu.getCharacterSize(3)); + ppu._backgrounds[3].setCharacterSize(ppu.getCharacterSize(4)); + ppu._registers._bgsc[0].tilemapAddress = 0x4000 >> 10U; ppu._registers._bgsc[1].tilemapAddress = 0x6000 >> 10U; ppu._backgrounds[0].setTileMapStartAddress(ppu.getTileMapStartAddress(1)); - ppu._backgrounds[1].setTileMapStartAddress(ppu.getTileMapStartAddress(1)); - ppu._backgrounds[2].setTileMapStartAddress(ppu.getTileMapStartAddress(2)); - ppu._backgrounds[3].setTileMapStartAddress(ppu.getTileMapStartAddress(2)); + ppu._backgrounds[1].setTileMapStartAddress(ppu.getTileMapStartAddress(2)); + ppu._backgrounds[2].setTileMapStartAddress(ppu.getTileMapStartAddress(3)); + ppu._backgrounds[3].setTileMapStartAddress(ppu.getTileMapStartAddress(4)); //ppu._registers._bgofs[2].raw = 0x03E0; //ppu._registers._bgofs[3].raw = 0x03DF;