mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-23 15:29:24 +00:00
Slightly better use of vector/array for pixel display.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
0b2c1fa084
commit
740cf01085
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
@ -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<uint32_t>& pixels() const;
|
||||
const std::array<uint32_t, PixelCount>& pixels() const;
|
||||
|
||||
void initialise();
|
||||
void render();
|
||||
void loadObjectAttributes();
|
||||
|
||||
private:
|
||||
std::vector<uint32_t> m_pixels;
|
||||
std::array<uint32_t, PixelCount> m_pixels;
|
||||
Bus& m_bus;
|
||||
Ram& m_oam;
|
||||
Ram& m_vram;
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "AbstractColourPalette.h"
|
||||
|
||||
#include <Processor.h>
|
||||
#include <vector>
|
||||
|
||||
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<uint32_t>& EightBit::GameBoy::Display::pixels() const {
|
||||
const std::array<uint32_t, EightBit::GameBoy::Display::PixelCount>& 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;
|
||||
|
Loading…
Reference in New Issue
Block a user