EightBit/LR35902/inc/CharacterDefinition.h
Adrian.Conlon ea3f154989 Preliminary support for 16 row high sprites. Don't think it's working!
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
2017-09-17 09:46:28 +01:00

47 lines
915 B
C++

#pragma once
#include <cstdint>
#include <vector>
#include <Bus.h>
namespace EightBit {
namespace GameBoy {
class CharacterDefinition {
public:
CharacterDefinition() {}
CharacterDefinition(Bus& bus, uint16_t address, int height) {
const int width = 8;
m_definition.resize(width * height);
for (auto row = 0; row < height; ++row) {
auto planeAddress = address + row * 2;
auto planeLow = bus.peek(planeAddress);
auto planeHigh = bus.peek(planeAddress + 1);
for (int bit = 0; bit < width; ++bit) {
auto mask = 1 << bit;
auto bitLow = planeLow & mask ? 1 : 0;
auto bitHigh = planeHigh & mask ? 0b10 : 0;
auto colour = bitHigh | bitLow;
m_definition[row * width + ((width - 1) - bit)] = colour;
}
}
}
const std::vector<int>& get() const { return m_definition; }
private:
std::vector<int> m_definition;
};
}
}