mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-09-30 22:55:20 +00:00
First stab at scan line rendering.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
27acba97ff
commit
c92b0642a1
@ -37,6 +37,7 @@ namespace EightBit {
|
|||||||
Bus& m_bus;
|
Bus& m_bus;
|
||||||
const AbstractColourPalette* m_colours;
|
const AbstractColourPalette* m_colours;
|
||||||
std::array<ObjectAttribute, 40> m_objectAttributes;
|
std::array<ObjectAttribute, 40> m_objectAttributes;
|
||||||
|
uint8_t m_currentScanLine;
|
||||||
|
|
||||||
std::array<int, 4> createPalette(int address);
|
std::array<int, 4> createPalette(int address);
|
||||||
|
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
|
|
||||||
EightBit::GameBoy::Display::Display(const AbstractColourPalette* colours, Bus& bus)
|
EightBit::GameBoy::Display::Display(const AbstractColourPalette* colours, Bus& bus)
|
||||||
: m_bus(bus),
|
: m_bus(bus),
|
||||||
m_colours(colours) {
|
m_colours(colours),
|
||||||
|
m_currentScanLine(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<uint32_t>& EightBit::GameBoy::Display::pixels() const {
|
const std::vector<uint32_t>& EightBit::GameBoy::Display::pixels() const {
|
||||||
@ -24,6 +25,7 @@ void EightBit::GameBoy::Display::render() {
|
|||||||
auto control = m_bus.peekRegister(Bus::LCDC);
|
auto control = m_bus.peekRegister(Bus::LCDC);
|
||||||
if (control & Bus::LcdEnable) {
|
if (control & Bus::LcdEnable) {
|
||||||
|
|
||||||
|
m_currentScanLine = m_bus.peekRegister(Bus::LY);
|
||||||
if (control & Bus::DisplayBackground)
|
if (control & Bus::DisplayBackground)
|
||||||
renderBackground();
|
renderBackground();
|
||||||
|
|
||||||
@ -122,21 +124,14 @@ void EightBit::GameBoy::Display::renderBackground(
|
|||||||
int offsetX, int offsetY,
|
int offsetX, int offsetY,
|
||||||
const std::array<int, 4>& palette) {
|
const std::array<int, 4>& palette) {
|
||||||
|
|
||||||
std::map<int, CharacterDefinition> 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 address = bgArea + row * BufferCharacterWidth + column;
|
||||||
const auto character = m_bus.peek(address);
|
const auto character = m_bus.peek(address);
|
||||||
|
|
||||||
auto definitionPair = definitions.find(character);
|
const auto definition = CharacterDefinition(&m_bus, bgCharacters + 16 * character, 8);
|
||||||
if (definitionPair == definitions.end()) {
|
|
||||||
definitions[character] = CharacterDefinition(&m_bus, bgCharacters + 16 * character, 8);
|
|
||||||
definitionPair = definitions.find(character);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto definition = definitionPair->second;
|
|
||||||
renderTile(
|
renderTile(
|
||||||
8,
|
8,
|
||||||
column * 8 + offsetX, row * 8 + offsetY,
|
column * 8 + offsetX, row * 8 + offsetY,
|
||||||
@ -145,7 +140,6 @@ void EightBit::GameBoy::Display::renderBackground(
|
|||||||
definition);
|
definition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void EightBit::GameBoy::Display::renderTile(
|
void EightBit::GameBoy::Display::renderTile(
|
||||||
int height,
|
int height,
|
||||||
@ -165,6 +159,9 @@ void EightBit::GameBoy::Display::renderTile(
|
|||||||
if (y >= RasterHeight)
|
if (y >= RasterHeight)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (y != m_currentScanLine)
|
||||||
|
continue;
|
||||||
|
|
||||||
const auto rowDefinition = definition.get(cy);
|
const auto rowDefinition = definition.get(cy);
|
||||||
|
|
||||||
for (int cx = 0; cx < width; ++cx) {
|
for (int cx = 0; cx < width; ++cx) {
|
||||||
@ -179,5 +176,7 @@ void EightBit::GameBoy::Display::renderTile(
|
|||||||
m_pixels[outputPixel] = m_colours->getColour(palette[colour]);
|
m_pixels[outputPixel] = m_colours->getColour(palette[colour]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user