From c92b0642a1f4165aa44061b7f32679b7662e9020 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Tue, 3 Oct 2017 23:54:39 +0100 Subject: [PATCH] First stab at scan line rendering. Signed-off-by: Adrian Conlon --- LR35902/inc/Display.h | 1 + LR35902/src/Display.cpp | 39 +++++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/LR35902/inc/Display.h b/LR35902/inc/Display.h index bf75608..80a2f5e 100644 --- a/LR35902/inc/Display.h +++ b/LR35902/inc/Display.h @@ -37,6 +37,7 @@ namespace EightBit { Bus& m_bus; const AbstractColourPalette* m_colours; std::array m_objectAttributes; + uint8_t m_currentScanLine; std::array createPalette(int address); diff --git a/LR35902/src/Display.cpp b/LR35902/src/Display.cpp index bdd62a4..32ec4e1 100644 --- a/LR35902/src/Display.cpp +++ b/LR35902/src/Display.cpp @@ -8,7 +8,8 @@ EightBit::GameBoy::Display::Display(const AbstractColourPalette* colours, Bus& bus) : m_bus(bus), - m_colours(colours) { + m_colours(colours), + m_currentScanLine(0) { } const std::vector& EightBit::GameBoy::Display::pixels() const { @@ -24,6 +25,7 @@ void EightBit::GameBoy::Display::render() { auto control = m_bus.peekRegister(Bus::LCDC); if (control & Bus::LcdEnable) { + m_currentScanLine = m_bus.peekRegister(Bus::LY); if (control & Bus::DisplayBackground) renderBackground(); @@ -122,28 +124,20 @@ void EightBit::GameBoy::Display::renderBackground( int offsetX, int offsetY, const std::array& palette) { - std::map definitions; + const int row = (m_currentScanLine - offsetY) / 8; - for (int row = 0; row < BufferCharacterHeight; ++row) { - for (int column = 0; column < BufferCharacterWidth; ++column) { + for (int column = 0; column < BufferCharacterWidth; ++column) { - const auto address = bgArea + row * BufferCharacterWidth + column; - const auto character = m_bus.peek(address); + const auto address = bgArea + row * BufferCharacterWidth + column; + const auto character = m_bus.peek(address); - auto definitionPair = definitions.find(character); - if (definitionPair == definitions.end()) { - definitions[character] = CharacterDefinition(&m_bus, bgCharacters + 16 * character, 8); - definitionPair = definitions.find(character); - } - - const auto definition = definitionPair->second; - renderTile( - 8, - column * 8 + offsetX, row * 8 + offsetY, - false, false, false, - palette, - definition); - } + const auto definition = CharacterDefinition(&m_bus, bgCharacters + 16 * character, 8); + renderTile( + 8, + column * 8 + offsetX, row * 8 + offsetY, + false, false, false, + palette, + definition); } } @@ -165,6 +159,9 @@ void EightBit::GameBoy::Display::renderTile( if (y >= RasterHeight) continue; + if (y != m_currentScanLine) + continue; + const auto rowDefinition = definition.get(cy); for (int cx = 0; cx < width; ++cx) { @@ -179,5 +176,7 @@ void EightBit::GameBoy::Display::renderTile( m_pixels[outputPixel] = m_colours->getColour(palette[colour]); } } + + break; } }