[nostalgia/core] Cleanup
This commit is contained in:
parent
56e980385c
commit
690935e4ec
@ -48,8 +48,6 @@ bool bgStatus(Context *ctx, unsigned bg) noexcept;
|
|||||||
|
|
||||||
void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept;
|
void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept;
|
||||||
|
|
||||||
ox::Error initConsole(Context *ctx) noexcept;
|
|
||||||
|
|
||||||
void setBgCbb(Context *ctx, unsigned bgIdx, unsigned cbb) noexcept;
|
void setBgCbb(Context *ctx, unsigned bgIdx, unsigned cbb) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,6 +60,8 @@ ox::Error loadSpriteTileSheet(Context *ctx,
|
|||||||
const ox::FileAddress &tilesheetAddr,
|
const ox::FileAddress &tilesheetAddr,
|
||||||
const ox::FileAddress &paletteAddr) noexcept;
|
const ox::FileAddress &paletteAddr) noexcept;
|
||||||
|
|
||||||
|
ox::Error initConsole(Context *ctx) noexcept;
|
||||||
|
|
||||||
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept;
|
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept;
|
||||||
|
|
||||||
void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept;
|
void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept;
|
||||||
|
@ -8,11 +8,13 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
|
GbaContext::GbaContext(turbine::Context *tctx) noexcept: turbineCtx(tctx) {
|
||||||
|
}
|
||||||
|
|
||||||
ox::Error initGfx(Context *ctx, const InitParams&) noexcept;
|
ox::Error initGfx(Context *ctx, const InitParams&) noexcept;
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, const InitParams ¶ms) noexcept {
|
ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, const InitParams ¶ms) noexcept {
|
||||||
auto ctx = ox::make_unique<GbaContext>();
|
auto ctx = ox::make_unique<GbaContext>(tctx);
|
||||||
ctx->turbineCtx = tctx;
|
|
||||||
oxReturnError(initGfx(ctx.get(), params));
|
oxReturnError(initGfx(ctx.get(), params));
|
||||||
return ox::UPtr<Context>(ctx.release());
|
return ox::UPtr<Context>(ctx.release());
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,9 @@ namespace nostalgia::core {
|
|||||||
|
|
||||||
struct GbaContext: public core::Context {
|
struct GbaContext: public core::Context {
|
||||||
|
|
||||||
turbine::Context *turbineCtx = nullptr;
|
turbine::Context const*turbineCtx = nullptr;
|
||||||
|
|
||||||
|
explicit GbaContext(turbine::Context *tctx) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
const auto &rom() const noexcept {
|
const auto &rom() const noexcept {
|
||||||
|
@ -80,7 +80,7 @@ void shutdownGfx(Context*) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t bgStatus(Context*) noexcept {
|
uint8_t bgStatus(Context*) noexcept {
|
||||||
return (REG_DISPCTL >> 8) & 0b1111;
|
return (REG_DISPCTL >> 8u) & 0b1111u;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBgStatus(Context*, uint32_t status) noexcept {
|
void setBgStatus(Context*, uint32_t status) noexcept {
|
||||||
@ -98,28 +98,6 @@ void setBgStatus(Context*, unsigned bg, bool status) noexcept {
|
|||||||
REG_DISPCTL = REG_DISPCTL | ((REG_DISPCTL & ~mask) | mask);
|
REG_DISPCTL = REG_DISPCTL | ((REG_DISPCTL & ~mask) | mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do NOT rely on Context in the GBA version of this function.
|
|
||||||
ox::Error initConsole(Context *ctx) noexcept {
|
|
||||||
constexpr ox::FileAddress TilesheetAddr("/TileSheets/Charset.ng");
|
|
||||||
constexpr ox::FileAddress PaletteAddr("/Palettes/Charset.npal");
|
|
||||||
setBgStatus(ctx, 0b0001);
|
|
||||||
if (!ctx) {
|
|
||||||
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), ""));
|
|
||||||
gctx->turbineCtx = tctx.release();
|
|
||||||
oxReturnError(loadBgTileSheet(gctx, 0, TilesheetAddr, PaletteAddr));
|
|
||||||
setBgCbb(gctx, 0, 0);
|
|
||||||
return {};
|
|
||||||
} else {
|
|
||||||
oxReturnError(loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr));
|
|
||||||
setBgCbb(ctx, 0, 0);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setBgCbb(Context*, unsigned bgIdx, unsigned cbb) noexcept {
|
void setBgCbb(Context*, unsigned bgIdx, unsigned cbb) noexcept {
|
||||||
auto &bgCtl = regBgCtl(bgIdx);
|
auto &bgCtl = regBgCtl(bgIdx);
|
||||||
const auto &cbbData = g_cbbData[cbb];
|
const auto &cbbData = g_cbbData[cbb];
|
||||||
@ -127,13 +105,13 @@ void setBgCbb(Context*, unsigned bgIdx, unsigned cbb) noexcept {
|
|||||||
teagba::bgSetCbb(&bgCtl, cbb);
|
teagba::bgSetCbb(&bgCtl, cbb);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error loadBgTileSheet(Context *ctx,
|
static ox::Error loadBgTileSheet(
|
||||||
|
const ox::MemFS &rom,
|
||||||
unsigned cbb,
|
unsigned cbb,
|
||||||
const ox::FileAddress &tilesheetAddr,
|
const ox::FileAddress &tilesheetAddr,
|
||||||
const ox::FileAddress &paletteAddr) noexcept {
|
const ox::FileAddress &paletteAddr) noexcept {
|
||||||
auto &gctx = static_cast<GbaContext&>(*ctx);
|
oxRequire(tsStat, rom.stat(tilesheetAddr));
|
||||||
oxRequire(tsStat, gctx.rom().stat(tilesheetAddr));
|
oxRequire(ts, rom.directAccess(tilesheetAddr));
|
||||||
oxRequire(ts, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(tilesheetAddr));
|
|
||||||
GbaTileMapTarget target;
|
GbaTileMapTarget target;
|
||||||
target.pal.palette = MEM_BG_PALETTE;
|
target.pal.palette = MEM_BG_PALETTE;
|
||||||
target.cbbData = &g_cbbData[cbb];
|
target.cbbData = &g_cbbData[cbb];
|
||||||
@ -141,8 +119,8 @@ ox::Error loadBgTileSheet(Context *ctx,
|
|||||||
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target));
|
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target));
|
||||||
// load external palette if available
|
// load external palette if available
|
||||||
if (paletteAddr) {
|
if (paletteAddr) {
|
||||||
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
oxRequire(palStat, rom.stat(paletteAddr));
|
||||||
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
|
oxRequire(pal, rom.directAccess(paletteAddr));
|
||||||
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target.pal));
|
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target.pal));
|
||||||
}
|
}
|
||||||
// update bpp of all bgs with the updated cbb
|
// update bpp of all bgs with the updated cbb
|
||||||
@ -155,6 +133,15 @@ ox::Error loadBgTileSheet(Context *ctx,
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ox::Error loadBgTileSheet(Context *ctx,
|
||||||
|
unsigned cbb,
|
||||||
|
const ox::FileAddress &tilesheetAddr,
|
||||||
|
const ox::FileAddress &paletteAddr) noexcept {
|
||||||
|
auto &gctx = static_cast<GbaContext&>(*ctx);
|
||||||
|
auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
|
||||||
|
return loadBgTileSheet(rom, cbb, tilesheetAddr, paletteAddr);
|
||||||
|
}
|
||||||
|
|
||||||
ox::Error loadSpriteTileSheet(Context *ctx,
|
ox::Error loadSpriteTileSheet(Context *ctx,
|
||||||
const ox::FileAddress &tilesheetAddr,
|
const ox::FileAddress &tilesheetAddr,
|
||||||
const ox::FileAddress &paletteAddr) noexcept {
|
const ox::FileAddress &paletteAddr) noexcept {
|
||||||
@ -186,14 +173,33 @@ ox::Error loadBgPalette(Context *ctx, unsigned, const ox::FileAddress &paletteAd
|
|||||||
|
|
||||||
ox::Error loadSpritePalette(Context *ctx, unsigned cbb, const ox::FileAddress &paletteAddr) noexcept {
|
ox::Error loadSpritePalette(Context *ctx, unsigned cbb, const ox::FileAddress &paletteAddr) noexcept {
|
||||||
auto &gctx = static_cast<GbaContext&>(*ctx);
|
auto &gctx = static_cast<GbaContext&>(*ctx);
|
||||||
|
auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
|
||||||
GbaPaletteTarget target;
|
GbaPaletteTarget target;
|
||||||
target.palette = &MEM_SPRITE_PALETTE[cbb];
|
target.palette = &MEM_SPRITE_PALETTE[cbb];
|
||||||
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
oxRequire(palStat, rom.stat(paletteAddr));
|
||||||
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
|
oxRequire(pal, rom.directAccess(paletteAddr));
|
||||||
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target));
|
oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do NOT rely on Context in the GBA version of this function.
|
||||||
|
ox::Error initConsole(Context *ctx) noexcept {
|
||||||
|
constexpr ox::FileAddress TilesheetAddr("/TileSheets/Charset.ng");
|
||||||
|
constexpr ox::FileAddress PaletteAddr("/Palettes/Charset.npal");
|
||||||
|
setBgStatus(ctx, 0b0001);
|
||||||
|
if (!ctx) {
|
||||||
|
oxRequire(rom, keel::loadRom());
|
||||||
|
const ox::FileSystem32 romFs(ox::FileStore32(rom, 32 * ox::units::MB));
|
||||||
|
oxReturnError(loadBgTileSheet(romFs, 0, TilesheetAddr, PaletteAddr));
|
||||||
|
setBgCbb(nullptr, 0, 0);
|
||||||
|
return {};
|
||||||
|
} else {
|
||||||
|
oxReturnError(loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr));
|
||||||
|
setBgCbb(ctx, 0, 0);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
|
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
|
||||||
const auto col = static_cast<unsigned>(column);
|
const auto col = static_cast<unsigned>(column);
|
||||||
for (auto i = 0u; i < str.bytes(); i++) {
|
for (auto i = 0u; i < str.bytes(); i++) {
|
||||||
|
@ -363,14 +363,6 @@ void shutdownGfx(Context &ctx) noexcept {
|
|||||||
turbine::gl::removeDrawer(gctx.turbineCtx, &gctx.drawer);
|
turbine::gl::removeDrawer(gctx.turbineCtx, &gctx.drawer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error initConsole(Context *ctx) noexcept {
|
|
||||||
constexpr ox::FileAddress TilesheetAddr("/TileSheets/Charset.ng");
|
|
||||||
constexpr ox::FileAddress PaletteAddr("/Palettes/Charset.npal");
|
|
||||||
setBgStatus(ctx, 0b0001);
|
|
||||||
setBgCbb(ctx, 0, 0);
|
|
||||||
return loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct TileSheetData {
|
struct TileSheetData {
|
||||||
ox::Vector<uint32_t> pixels;
|
ox::Vector<uint32_t> pixels;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
@ -430,6 +422,14 @@ ox::Error loadSpriteTileSheet(
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ox::Error initConsole(Context *ctx) noexcept {
|
||||||
|
constexpr ox::FileAddress TilesheetAddr("/TileSheets/Charset.ng");
|
||||||
|
constexpr ox::FileAddress PaletteAddr("/Palettes/Charset.npal");
|
||||||
|
setBgStatus(ctx, 0b0001);
|
||||||
|
setBgCbb(ctx, 0, 0);
|
||||||
|
return loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr);
|
||||||
|
}
|
||||||
|
|
||||||
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
|
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
|
||||||
const auto col = static_cast<unsigned>(column);
|
const auto col = static_cast<unsigned>(column);
|
||||||
for (auto i = 0u; i < str.bytes(); ++i) {
|
for (auto i = 0u; i < str.bytes(); ++i) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user