From 18757bbfa4481bd17e3a03145c88e8c22fc9a801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Thu, 28 May 2020 14:14:35 +0200 Subject: [PATCH] fixing getCharacterSize marge bg and reference color when it is 0 --- sources/PPU/Background.cpp | 2 +- sources/PPU/PPU.cpp | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/sources/PPU/Background.cpp b/sources/PPU/Background.cpp index 1494040..c5c30e8 100644 --- a/sources/PPU/Background.cpp +++ b/sources/PPU/Background.cpp @@ -61,7 +61,7 @@ namespace ComSquare::PPU for (int j = 0; j < this->_characterSize.x; j++) { reference = getTilePixelReference(graphicAddress, index); color = getRealColor(palette[reference]); - if (tileData.tilePriority == this->priority) + if (tileData.tilePriority == this->priority && reference != 0) // reference 0 is considered as transparency this->buffer[pos.x][pos.y] = color; if (j == 7) { index = -1; diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index 4db4c0e..0ac1f3c 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, 0x10); // 0x1F + this->cgram->write_internal(4, 0x0F); // 0x1F this->cgram->write_internal(6, 0xFF); this->cgram->write_internal(7, 0x03); this->cgram->write_internal(66, 0xE0); @@ -104,11 +104,17 @@ namespace ComSquare::PPU this->vram->write_internal(0x80C6, 06); this->vram->write_internal(0x80C8, 04); + this->vram->write_internal(0xC000, 0x0C); + //registers this->_registers._bgmode.bgMode = 0; this->_registers._bgmode.characterSizeBg1 = true; this->_registers._bgmode.characterSizeBg2 = 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)); this->_registers._bgsc[0].tilemapAddress = 0x4000U >> 10U; this->_registers._bgsc[1].tilemapAddress = 0x6000U >> 10U; @@ -119,10 +125,6 @@ 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) @@ -346,10 +348,10 @@ namespace ComSquare::PPU (void)cycles; 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); + this->add_buffer(this->_screen, this->_subScreen); + this->add_buffer(this->_screen, this->_mainScreen); + //this->_backgrounds[2].renderBackground(); + //add_buffer(this->_screen, this->_backgrounds[2].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]); @@ -553,7 +555,7 @@ namespace ComSquare::PPU Vector2 characterSize(8, 8); //this wont work for modes 5 and 6 and will be reworked - if (this->_registers._bgmode.raw & (1U << (4 + bgNumber))) + if (this->_registers._bgmode.raw & (1U << (3 + bgNumber))) characterSize = {16, 16}; return characterSize; } @@ -683,7 +685,7 @@ namespace ComSquare::PPU { for (unsigned long i = 0; i < bufferSrc.size(); i++) { for (unsigned long j = 0; j < bufferSrc[i].size(); j++) { - if (bufferSrc[i][j]) + if (bufferSrc[i][j] > 0xFF) // 0xFF correspond to a black pixel with full brightness bufferDest[i][j] = bufferSrc[i][j]; } }