mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-11-18 11:06:15 +00:00
Explicit use of OAM and VRAM
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
9796f9d600
commit
e8715b941b
@ -4,6 +4,8 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include <Ram.h>
|
||||||
|
|
||||||
#include "GameBoyBus.h"
|
#include "GameBoyBus.h"
|
||||||
#include "AbstractColourPalette.h"
|
#include "AbstractColourPalette.h"
|
||||||
#include "ObjectAttribute.h"
|
#include "ObjectAttribute.h"
|
||||||
@ -24,7 +26,7 @@ namespace EightBit {
|
|||||||
RasterHeight = 144,
|
RasterHeight = 144,
|
||||||
};
|
};
|
||||||
|
|
||||||
Display(const AbstractColourPalette* colours, Bus& bus);
|
Display(const AbstractColourPalette* colours, Bus& bus, Ram& oam, Ram& vram);
|
||||||
|
|
||||||
const std::vector<uint32_t>& pixels() const;
|
const std::vector<uint32_t>& pixels() const;
|
||||||
|
|
||||||
@ -35,6 +37,8 @@ namespace EightBit {
|
|||||||
private:
|
private:
|
||||||
std::vector<uint32_t> m_pixels;
|
std::vector<uint32_t> m_pixels;
|
||||||
Bus& m_bus;
|
Bus& m_bus;
|
||||||
|
Ram& m_oam;
|
||||||
|
Ram& m_vram;
|
||||||
const AbstractColourPalette* m_colours;
|
const AbstractColourPalette* m_colours;
|
||||||
std::array<ObjectAttribute, 40> m_objectAttributes;
|
std::array<ObjectAttribute, 40> m_objectAttributes;
|
||||||
uint8_t m_control;
|
uint8_t m_control;
|
||||||
|
@ -6,8 +6,10 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
EightBit::GameBoy::Display::Display(const AbstractColourPalette* colours, Bus& bus)
|
EightBit::GameBoy::Display::Display(const AbstractColourPalette* colours, Bus& bus, Ram& oam, Ram& vram)
|
||||||
: m_bus(bus),
|
: m_bus(bus),
|
||||||
|
m_oam(oam),
|
||||||
|
m_vram(vram),
|
||||||
m_colours(colours),
|
m_colours(colours),
|
||||||
m_control(0),
|
m_control(0),
|
||||||
m_scanLine(0) {
|
m_scanLine(0) {
|
||||||
@ -51,9 +53,8 @@ void EightBit::GameBoy::Display::renderObjects() {
|
|||||||
|
|
||||||
void EightBit::GameBoy::Display::loadObjectAttributes() {
|
void EightBit::GameBoy::Display::loadObjectAttributes() {
|
||||||
const auto objBlockHeight = (m_control & Bus::ObjectBlockCompositionSelection) ? 16 : 8;
|
const auto objBlockHeight = (m_control & Bus::ObjectBlockCompositionSelection) ? 16 : 8;
|
||||||
auto& oam = m_bus.OAMRAM();
|
|
||||||
for (int i = 0; i < 40; ++i) {
|
for (int i = 0; i < 40; ++i) {
|
||||||
m_objectAttributes[i] = ObjectAttribute(oam, 4 * i, objBlockHeight);
|
m_objectAttributes[i] = ObjectAttribute(m_oam, 4 * i, objBlockHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +64,6 @@ void EightBit::GameBoy::Display::renderObjects(int objBlockHeight) {
|
|||||||
palettes[0] = createPalette(Bus::OBP0);
|
palettes[0] = createPalette(Bus::OBP0);
|
||||||
palettes[1] = createPalette(Bus::OBP1);
|
palettes[1] = createPalette(Bus::OBP1);
|
||||||
|
|
||||||
auto& vram = m_bus.VRAM();
|
|
||||||
|
|
||||||
for (int i = 0; i < 40; ++i) {
|
for (int i = 0; i < 40; ++i) {
|
||||||
|
|
||||||
const auto& current = m_objectAttributes[i];
|
const auto& current = m_objectAttributes[i];
|
||||||
@ -78,7 +77,7 @@ void EightBit::GameBoy::Display::renderObjects(int objBlockHeight) {
|
|||||||
const auto drawX = spriteX - 8;
|
const auto drawX = spriteX - 8;
|
||||||
|
|
||||||
const auto sprite = current.pattern();
|
const auto sprite = current.pattern();
|
||||||
const auto definition = CharacterDefinition(&vram, 16 * sprite, objBlockHeight);
|
const auto definition = CharacterDefinition(&m_vram, 16 * sprite, objBlockHeight);
|
||||||
const auto& palette = palettes[current.palette()];
|
const auto& palette = palettes[current.palette()];
|
||||||
const auto flipX = current.flipX();
|
const auto flipX = current.flipX();
|
||||||
const auto flipY = current.flipY();
|
const auto flipY = current.flipY();
|
||||||
@ -118,17 +117,15 @@ 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) {
|
||||||
|
|
||||||
auto& vram = m_bus.VRAM();
|
|
||||||
|
|
||||||
const int row = (m_scanLine - offsetY) / 8;
|
const int row = (m_scanLine - offsetY) / 8;
|
||||||
const auto baseAddress = bgArea + row * BufferCharacterWidth;
|
const auto baseAddress = bgArea + row * BufferCharacterWidth;
|
||||||
|
|
||||||
for (int column = 0; column < BufferCharacterWidth; ++column) {
|
for (int column = 0; column < BufferCharacterWidth; ++column) {
|
||||||
|
|
||||||
const auto address = baseAddress + column;
|
const auto address = baseAddress + column;
|
||||||
const auto character = vram.peek(address);
|
const auto character = m_vram.peek(address);
|
||||||
|
|
||||||
const auto definition = CharacterDefinition(&vram, bgCharacters + 16 * character, 8);
|
const auto definition = CharacterDefinition(&m_vram, bgCharacters + 16 * character, 8);
|
||||||
renderTile(
|
renderTile(
|
||||||
8,
|
8,
|
||||||
column * 8 + offsetX, row * 8 + offsetY,
|
column * 8 + offsetX, row * 8 + offsetY,
|
||||||
|
@ -39,8 +39,8 @@ EightBit::GameBoy::Bus::Bus()
|
|||||||
|
|
||||||
void EightBit::GameBoy::Bus::reset() {
|
void EightBit::GameBoy::Bus::reset() {
|
||||||
|
|
||||||
poke(BASE + NR52, 0xf1);
|
pokeRegister(NR52, 0xf1);
|
||||||
poke(BASE + LCDC, DisplayBackground | BackgroundCharacterDataSelection | LcdEnable);
|
pokeRegister(LCDC, DisplayBackground | BackgroundCharacterDataSelection | LcdEnable);
|
||||||
m_divCounter.word = 0xabcc;
|
m_divCounter.word = 0xabcc;
|
||||||
m_timerCounter = 0;
|
m_timerCounter = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user