[nostalgia/core/gba] Add hardware target types for loading tile maps and palettes

This commit is contained in:
Gary Talent 2019-11-01 01:31:11 -05:00
parent 0825c9869a
commit 7105c19c72
2 changed files with 48 additions and 7 deletions

View File

@ -158,6 +158,47 @@ static char charMap[128] = {
0, // ~
};
struct GbaPaletteTarget {
uint16_t *palette = nullptr;
};
struct GbaTileMapTarget {
static constexpr auto Fields = 4;
uint8_t bpp = 0;
ox::FileAddress defaultPalette;
GbaPaletteTarget pal;
uint16_t *tileMap = nullptr;
};
template<typename T>
ox::Error modelRead(T *io, GbaPaletteTarget *t) {
io->setTypeInfo("nostalgia::core::NostalgiaPalette", NostalgiaPalette::Fields);
oxReturnError(io->template field<uint16_t>("colors", [t](auto i, uint16_t c) {
t->palette[i] = c;
return OxError(0);
}));
return OxError(0);
}
template<typename T>
ox::Error modelRead(T *io, GbaTileMapTarget *t) {
io->setTypeInfo("nostalgia::core::NostalgiaGraphic", NostalgiaGraphic::Fields);
oxReturnError(io->field("bpp", &t->bpp));
oxReturnError(io->field("defaultPalette", &t->defaultPalette));
oxReturnError(io->field("pal", &t->pal));
uint16_t intermediate;
oxReturnError(io->template field<uint8_t>("tileMap", [t, &intermediate](auto i, uint8_t tile) {
if (i & 1) { // i is odd
intermediate |= tile >> 8;
t->tileMap[i / 2] = intermediate;
} else { // i is even
intermediate = tile & 0xff;
}
return OxError(0);
}));
return OxError(0);
}
ox::Error initGfx(Context*) {
/* Sprite Mode ----\ */
/* ---\| */

View File

@ -35,6 +35,13 @@ struct NostalgiaGraphic {
ox::Vector<uint8_t> tiles;
};
template<typename T>
ox::Error model(T *io, NostalgiaPalette *pal) {
io->setTypeInfo("nostalgia::core::NostalgiaPalette", NostalgiaPalette::Fields);
oxReturnError(io->field("colors", &pal->colors));
return OxError(0);
}
template<typename T>
ox::Error model(T *io, NostalgiaGraphic *ng) {
io->setTypeInfo("nostalgia::core::NostalgiaGraphic", NostalgiaGraphic::Fields);
@ -45,13 +52,6 @@ ox::Error model(T *io, NostalgiaGraphic *ng) {
return OxError(0);
}
template<typename T>
ox::Error model(T *io, NostalgiaPalette *pal) {
io->setTypeInfo("nostalgia::core::NostalgiaPalette", NostalgiaPalette::Fields);
oxReturnError(io->field("colors", &pal->colors));
return OxError(0);
}
[[nodiscard]] ox::Error initGfx(Context *ctx);
[[nodiscard]] ox::Error shutdownGfx();