diff --git a/src/nostalgia/core/gba/gfx.cpp b/src/nostalgia/core/gba/gfx.cpp index 91698ee6..3ef65965 100644 --- a/src/nostalgia/core/gba/gfx.cpp +++ b/src/nostalgia/core/gba/gfx.cpp @@ -164,28 +164,28 @@ ox::Error initConsole(Context *ctx) noexcept { ox::Error loadBgTileSheet(Context *ctx, int section, - ox::FileAddress tilesheetAddr, - ox::FileAddress paletteAddr) noexcept { + const ox::FileAddress &tilesheetAddr, + const ox::FileAddress &paletteAddr) noexcept { oxRequire(tsStat, ctx->rom->stat(tilesheetAddr)); oxRequire(ts, ctx->rom->directAccess(tilesheetAddr)); GbaTileMapTarget target; target.pal.palette = &MEM_BG_PALETTE[section]; target.bgCtl = &bgCtl(section); target.tileMap = &ox::bit_cast(MEM_BG_TILES)[section * 512]; - oxReturnError(ox::readMC(ts, tsStat.size, &target)); + oxReturnError(ox::readMC(ox::bit_cast(ts), tsStat.size, &target)); // load external palette if available if (paletteAddr) { oxRequire(palStat, ctx->rom->stat(paletteAddr)); oxRequire(pal, ctx->rom->directAccess(paletteAddr)); - oxReturnError(ox::readMC(pal, palStat.size, &target.pal)); + oxReturnError(ox::readMC(ox::bit_cast(pal), palStat.size, &target.pal)); } return OxError(0); } ox::Error loadSpriteTileSheet(Context *ctx, int section, - ox::FileAddress tilesheetAddr, - ox::FileAddress paletteAddr) noexcept { + const ox::FileAddress &tilesheetAddr, + const ox::FileAddress &paletteAddr) noexcept { oxRequire(tsStat, ctx->rom->stat(tilesheetAddr)); oxRequire(ts, ctx->rom->directAccess(tilesheetAddr)); GbaTileMapTarget target; @@ -193,31 +193,31 @@ ox::Error loadSpriteTileSheet(Context *ctx, // Is this needed? Should this be written to an equivalent sprite value? // target.bgCtl = &bgCtl(section); target.tileMap = &ox::bit_cast(MEM_SPRITE_TILES)[section * 512]; - oxReturnError(ox::readMC(ts, tsStat.size, &target)); + oxReturnError(ox::readMC(ox::bit_cast(ts), tsStat.size, &target)); // load external palette if available if (paletteAddr) { oxRequire(palStat, ctx->rom->stat(paletteAddr)); oxRequire(pal, ctx->rom->directAccess(paletteAddr)); - oxReturnError(ox::readMC(pal, palStat.size, &target.pal)); + oxReturnError(ox::readMC(ox::bit_cast(pal), palStat.size, &target.pal)); } return OxError(0); } -ox::Error loadBgPalette(Context *ctx, int section, ox::FileAddress paletteAddr) noexcept { +ox::Error loadBgPalette(Context *ctx, int section, const ox::FileAddress &paletteAddr) noexcept { GbaPaletteTarget target; target.palette = &MEM_BG_PALETTE[section]; oxRequire(palStat, ctx->rom->stat(paletteAddr)); oxRequire(pal, ctx->rom->directAccess(paletteAddr)); - oxReturnError(ox::readMC(pal, palStat.size, &target)); + oxReturnError(ox::readMC(ox::bit_cast(pal), palStat.size, &target)); return OxError(0); } -ox::Error loadSpritePalette(Context *ctx, int section, ox::FileAddress paletteAddr) noexcept { +ox::Error loadSpritePalette(Context *ctx, int section, const ox::FileAddress &paletteAddr) noexcept { GbaPaletteTarget target; target.palette = &MEM_SPRITE_PALETTE[section]; oxRequire(palStat, ctx->rom->stat(paletteAddr)); oxRequire(pal, ctx->rom->directAccess(paletteAddr)); - oxReturnError(ox::readMC(pal, palStat.size, &target)); + oxReturnError(ox::readMC(ox::bit_cast(pal), palStat.size, &target)); return OxError(0); } diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index 9f2ea706..80602b0a 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -99,12 +99,12 @@ ox::Error initConsole(Context *ctx) noexcept; /** * @param section describes which section of the selected TileSheetSpace to use (e.g. MEM_PALLETE_BG[section]) */ -ox::Error loadBgTileSheet(Context *ctx, int section, ox::FileAddress tilesheet, ox::FileAddress palette = nullptr) noexcept; +ox::Error loadBgTileSheet(Context *ctx, int section, const ox::FileAddress &tilesheet, const ox::FileAddress &palette = nullptr) noexcept; ox::Error loadSpriteTileSheet(Context *ctx, int section, - ox::FileAddress tilesheetAddr, - ox::FileAddress paletteAddr) noexcept; + const ox::FileAddress &tilesheetAddr, + const ox::FileAddress &paletteAddr) noexcept; void puts(Context *ctx, int column, int row, const char *str) noexcept; diff --git a/src/nostalgia/core/userland/gfx.cpp b/src/nostalgia/core/userland/gfx.cpp index e94c8831..e432257f 100644 --- a/src/nostalgia/core/userland/gfx.cpp +++ b/src/nostalgia/core/userland/gfx.cpp @@ -29,20 +29,17 @@ ox::Error initConsole(Context *ctx) noexcept { ox::Error loadSpriteTileSheet(Context*, int, - ox::FileAddress, - ox::FileAddress) noexcept { + const ox::FileAddress&, + const ox::FileAddress&) noexcept { return OxError(0); } ox::Error loadBgTileSheet(Context *ctx, int section, - ox::FileAddress tilesheetPath, - ox::FileAddress palettePath) noexcept { + const ox::FileAddress &tilesheetPath, + const ox::FileAddress &palettePath) noexcept { oxRequire(tilesheet, readObj(ctx, tilesheetPath)); - if (!palettePath) { - palettePath = tilesheet.defaultPalette; - } - oxRequire(palette, readObj(ctx, palettePath)); + oxRequire(palette, readObj(ctx, palettePath ? palettePath : tilesheet.defaultPalette)); const unsigned bytesPerTile = tilesheet.bpp == 8 ? 64 : 32; const auto tiles = tilesheet.pixels.size() / bytesPerTile; constexpr int width = 8;