|
|
|
@@ -16,6 +16,8 @@
|
|
|
|
|
#include <nostalgia/core/context.hpp>
|
|
|
|
|
#include <nostalgia/core/gfx.hpp>
|
|
|
|
|
|
|
|
|
|
#include "context.hpp"
|
|
|
|
|
|
|
|
|
|
namespace nostalgia::core {
|
|
|
|
|
|
|
|
|
|
struct BgCbbData {
|
|
|
|
@@ -102,14 +104,14 @@ ox::Error initConsole(Context *ctx) noexcept {
|
|
|
|
|
constexpr ox::FileAddress PaletteAddr("/Palettes/Charset.npal");
|
|
|
|
|
setBgStatus(ctx, 0b0001);
|
|
|
|
|
if (!ctx) {
|
|
|
|
|
ctx = new(ox_alloca(sizeof(Context))) Context;
|
|
|
|
|
const auto gctx = new(ox_alloca(sizeof(GbaContext))) GbaContext;
|
|
|
|
|
oxRequire(rom, keel::loadRom());
|
|
|
|
|
auto romFs = new(ox_alloca(sizeof(ox::FileSystem32)))
|
|
|
|
|
ox::FileSystem32(ox::FileStore32(rom, 32 * ox::units::MB));
|
|
|
|
|
oxRequireM(tctx, turbine::init(ox::UPtr<ox::FileSystem>(romFs), ""));
|
|
|
|
|
ctx->turbineCtx = tctx.release();
|
|
|
|
|
oxReturnError(loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr));
|
|
|
|
|
setBgCbb(ctx, 0, 0);
|
|
|
|
|
gctx->turbineCtx = tctx.release();
|
|
|
|
|
oxReturnError(loadBgTileSheet(gctx, 0, TilesheetAddr, PaletteAddr));
|
|
|
|
|
setBgCbb(gctx, 0, 0);
|
|
|
|
|
return {};
|
|
|
|
|
} else {
|
|
|
|
|
oxReturnError(loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr));
|
|
|
|
@@ -129,8 +131,9 @@ ox::Error loadBgTileSheet(Context *ctx,
|
|
|
|
|
unsigned cbb,
|
|
|
|
|
const ox::FileAddress &tilesheetAddr,
|
|
|
|
|
const ox::FileAddress &paletteAddr) noexcept {
|
|
|
|
|
oxRequire(tsStat, ctx->rom().stat(tilesheetAddr));
|
|
|
|
|
oxRequire(ts, static_cast<const ox::MemFS&>(ctx->rom()).directAccess(tilesheetAddr));
|
|
|
|
|
auto &gctx = static_cast<GbaContext&>(*ctx);
|
|
|
|
|
oxRequire(tsStat, gctx.rom().stat(tilesheetAddr));
|
|
|
|
|
oxRequire(ts, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(tilesheetAddr));
|
|
|
|
|
GbaTileMapTarget target;
|
|
|
|
|
target.pal.palette = MEM_BG_PALETTE;
|
|
|
|
|
target.cbbData = &g_cbbData[cbb];
|
|
|
|
@@ -138,8 +141,8 @@ ox::Error loadBgTileSheet(Context *ctx,
|
|
|
|
|
oxReturnError(ox::readMC(ts, tsStat.size, &target));
|
|
|
|
|
// load external palette if available
|
|
|
|
|
if (paletteAddr) {
|
|
|
|
|
oxRequire(palStat, ctx->rom().stat(paletteAddr));
|
|
|
|
|
oxRequire(pal, static_cast<const ox::MemFS&>(ctx->rom()).directAccess(paletteAddr));
|
|
|
|
|
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
|
|
|
|
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
|
|
|
|
|
oxReturnError(ox::readMC(pal, palStat.size, &target.pal));
|
|
|
|
|
}
|
|
|
|
|
// update bpp of all bgs with the updated cbb
|
|
|
|
@@ -155,35 +158,38 @@ ox::Error loadBgTileSheet(Context *ctx,
|
|
|
|
|
ox::Error loadSpriteTileSheet(Context *ctx,
|
|
|
|
|
const ox::FileAddress &tilesheetAddr,
|
|
|
|
|
const ox::FileAddress &paletteAddr) noexcept {
|
|
|
|
|
oxRequire(tsStat, ctx->rom().stat(tilesheetAddr));
|
|
|
|
|
oxRequire(ts, static_cast<const ox::MemFS&>(ctx->rom()).directAccess(tilesheetAddr));
|
|
|
|
|
auto &gctx = static_cast<GbaContext&>(*ctx);
|
|
|
|
|
oxRequire(tsStat, gctx.rom().stat(tilesheetAddr));
|
|
|
|
|
oxRequire(ts, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(tilesheetAddr));
|
|
|
|
|
GbaTileMapTarget target;
|
|
|
|
|
target.pal.palette = MEM_SPRITE_PALETTE;
|
|
|
|
|
target.tileMap = MEM_SPRITE_TILES;
|
|
|
|
|
oxReturnError(ox::readMC(ts, tsStat.size, &target));
|
|
|
|
|
// load external palette if available
|
|
|
|
|
if (paletteAddr) {
|
|
|
|
|
oxRequire(palStat, ctx->rom().stat(paletteAddr));
|
|
|
|
|
oxRequire(pal, static_cast<const ox::MemFS&>(ctx->rom()).directAccess(paletteAddr));
|
|
|
|
|
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
|
|
|
|
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
|
|
|
|
|
oxReturnError(ox::readMC(pal, palStat.size, &target.pal));
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ox::Error loadBgPalette(Context *ctx, unsigned, const ox::FileAddress &paletteAddr) noexcept {
|
|
|
|
|
auto &gctx = static_cast<GbaContext&>(*ctx);
|
|
|
|
|
GbaPaletteTarget target;
|
|
|
|
|
target.palette = MEM_BG_PALETTE;
|
|
|
|
|
oxRequire(palStat, ctx->rom().stat(paletteAddr));
|
|
|
|
|
oxRequire(pal, static_cast<const ox::MemFS&>(ctx->rom()).directAccess(paletteAddr));
|
|
|
|
|
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
|
|
|
|
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
|
|
|
|
|
oxReturnError(ox::readMC(pal, palStat.size, &target));
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ox::Error loadSpritePalette(Context *ctx, unsigned cbb, const ox::FileAddress &paletteAddr) noexcept {
|
|
|
|
|
auto &gctx = static_cast<GbaContext&>(*ctx);
|
|
|
|
|
GbaPaletteTarget target;
|
|
|
|
|
target.palette = &MEM_SPRITE_PALETTE[cbb];
|
|
|
|
|
oxRequire(palStat, ctx->rom().stat(paletteAddr));
|
|
|
|
|
oxRequire(pal, static_cast<const ox::MemFS&>(ctx->rom()).directAccess(paletteAddr));
|
|
|
|
|
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
|
|
|
|
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
|
|
|
|
|
oxReturnError(ox::readMC(pal, palStat.size, &target));
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|