From 740cf01085cf9d1c7bc3ed97206e84fe4e61e789 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Fri, 4 May 2018 03:38:39 +0100 Subject: [PATCH] Slightly better use of vector/array for pixel display. Signed-off-by: Adrian Conlon --- LR35902/inc/Display.h | 7 +++---- LR35902/src/Display.cpp | 13 +++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/LR35902/inc/Display.h b/LR35902/inc/Display.h index fe99cf9..27254a2 100644 --- a/LR35902/inc/Display.h +++ b/LR35902/inc/Display.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -25,18 +24,18 @@ namespace EightBit { BufferCharacterHeight = BufferHeight / 8, RasterWidth = 160, RasterHeight = 144, + PixelCount = RasterWidth * RasterHeight, }; Display(const AbstractColourPalette* colours, Bus& bus, Ram& oam, Ram& vram); - const std::vector& pixels() const; + const std::array& pixels() const; - void initialise(); void render(); void loadObjectAttributes(); private: - std::vector m_pixels; + std::array m_pixels; Bus& m_bus; Ram& m_oam; Ram& m_vram; diff --git a/LR35902/src/Display.cpp b/LR35902/src/Display.cpp index a2fa9a6..33cfcc2 100644 --- a/LR35902/src/Display.cpp +++ b/LR35902/src/Display.cpp @@ -6,7 +6,6 @@ #include "AbstractColourPalette.h" #include -#include EightBit::GameBoy::Display::Display(const AbstractColourPalette* colours, Bus& bus, Ram& oam, Ram& vram) : m_bus(bus), @@ -15,14 +14,10 @@ EightBit::GameBoy::Display::Display(const AbstractColourPalette* colours, Bus& b m_colours(colours) { } -const std::vector& EightBit::GameBoy::Display::pixels() const { +const std::array& EightBit::GameBoy::Display::pixels() const { return m_pixels; } -void EightBit::GameBoy::Display::initialise() { - m_pixels.resize(RasterWidth * RasterHeight); -} - void EightBit::GameBoy::Display::render() { m_scanLine = m_bus.IO().peek(IoRegisters::LY); if (m_scanLine < RasterHeight) { @@ -61,6 +56,8 @@ void EightBit::GameBoy::Display::renderObjects() { createPalette(IoRegisters::OBP1) }; + const auto characterAddressMultiplier = objBlockHeight == 8 ? 16 : 8; + for (int i = 0; i < 40; ++i) { const auto& current = m_objectAttributes[i]; @@ -74,7 +71,7 @@ void EightBit::GameBoy::Display::renderObjects() { const auto drawX = spriteX - 8; const auto sprite = current.pattern(); - const auto definition = CharacterDefinition(m_vram, (objBlockHeight == 8 ? 16 : 8) * sprite); + const auto definition = CharacterDefinition(m_vram, characterAddressMultiplier * sprite); const auto& palette = palettes[current.palette()]; const auto flipX = current.flipX(); const auto flipY = current.flipY(); @@ -91,7 +88,7 @@ void EightBit::GameBoy::Display::renderObjects() { void EightBit::GameBoy::Display::renderBackground() { - auto palette = createPalette(IoRegisters::BGP); + const auto palette = createPalette(IoRegisters::BGP); const auto window = (m_control & IoRegisters::WindowEnable) != 0; const auto bgArea = (m_control & IoRegisters::BackgroundCodeAreaSelection) ? 0x1c00 : 0x1800;