[nostalgia/core] Add support for specifying palette banks
Some checks failed
Build / build (push) Failing after 40s
Some checks failed
Build / build (push) Failing after 40s
This commit is contained in:
@@ -158,9 +158,10 @@ ox::Error initGfx(Context&, InitParams const&) noexcept {
|
||||
|
||||
ox::Error loadBgPalette(
|
||||
Context &ctx,
|
||||
size_t palBank,
|
||||
ox::FileAddress const&paletteAddr) noexcept {
|
||||
auto &rom = ctx.rom();
|
||||
GbaPaletteTarget const palTarget{.palette = MEM_BG_PALETTE};
|
||||
GbaPaletteTarget const palTarget{.palette = MEM_BG_PALETTE + palBank * 16};
|
||||
oxRequire(palStat, rom.stat(paletteAddr));
|
||||
oxRequire(pal, rom.directAccess(paletteAddr));
|
||||
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &palTarget));
|
||||
@@ -189,11 +190,11 @@ static ox::Error loadTileSheetSet(
|
||||
oxRequire(ts, rom.directAccess(entry.tilesheet));
|
||||
unsigned tilesheetBpp{};
|
||||
GbaTileMapTarget target{
|
||||
.bpp = tilesheetBpp,
|
||||
.defaultPalette = {},
|
||||
.tileMap = tileMapTargetMem + tileWriteIdx,
|
||||
.targetBpp = static_cast<unsigned>(set.bpp),
|
||||
.setEntry = &entry,
|
||||
.bpp = tilesheetBpp,
|
||||
.defaultPalette = {},
|
||||
.tileMap = tileMapTargetMem + tileWriteIdx,
|
||||
.targetBpp = static_cast<unsigned>(set.bpp),
|
||||
.setEntry = &entry,
|
||||
};
|
||||
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target));
|
||||
tileWriteIdx += target.tileWriteIdx;
|
||||
@@ -205,7 +206,7 @@ ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned cbb,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
bool loadDefaultPalette) noexcept {
|
||||
ox::Optional<unsigned> const&paletteBank) noexcept {
|
||||
auto &rom = ctx.rom();
|
||||
oxRequire(tsStat, rom.stat(tilesheetAddr));
|
||||
oxRequire(ts, rom.directAccess(tilesheetAddr));
|
||||
@@ -222,8 +223,8 @@ ox::Error loadBgTileSheet(
|
||||
teagba::bgSetBpp(bgCtl, bpp);
|
||||
}
|
||||
});
|
||||
if (loadDefaultPalette && target.defaultPalette) {
|
||||
oxReturnError(loadBgPalette(ctx, target.defaultPalette));
|
||||
if (paletteBank.has_value() && target.defaultPalette) {
|
||||
oxReturnError(loadBgPalette(ctx, *paletteBank, target.defaultPalette));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -283,9 +284,14 @@ ox::Error loadSpriteTileSheet(
|
||||
return {};
|
||||
}
|
||||
|
||||
void setBgTile(Context&, uint_t bgIdx, int column, int row, uint8_t tile) noexcept {
|
||||
const auto tileIdx = static_cast<std::size_t>(row * GbaTileColumns + column);
|
||||
MEM_BG_MAP[bgIdx][tileIdx] = tile;
|
||||
void setBgTile(Context&, uint_t bgIdx, int column, int row, BgTile const&tile) noexcept {
|
||||
auto const tileIdx = static_cast<std::size_t>(row * GbaTileColumns + column);
|
||||
// see Tonc 9.3
|
||||
MEM_BG_MAP[bgIdx][tileIdx] =
|
||||
static_cast<uint16_t>(tile.tileIdx & 0b1'1111'1111) |
|
||||
static_cast<uint16_t>(tile.horizontalFlip << 0xa) |
|
||||
static_cast<uint16_t>(tile.verticalFlip << 0xb) |
|
||||
static_cast<uint16_t>(tile.palBank << 0xc);
|
||||
}
|
||||
|
||||
void clearBg(Context&, uint_t bgIdx) noexcept {
|
||||
|
Reference in New Issue
Block a user