[nostalgia/core] Make FileAddress args const ref

This commit is contained in:
Gary Talent 2021-05-03 14:32:02 -04:00
parent 937bf3ad91
commit 504d248ce3
3 changed files with 20 additions and 23 deletions

View File

@ -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<uint16_t*>(MEM_BG_TILES)[section * 512];
oxReturnError(ox::readMC(ts, tsStat.size, &target));
oxReturnError(ox::readMC(ox::bit_cast<char*>(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<char*>(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<uint16_t*>(MEM_SPRITE_TILES)[section * 512];
oxReturnError(ox::readMC(ts, tsStat.size, &target));
oxReturnError(ox::readMC(ox::bit_cast<char*>(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<char*>(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<char*>(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<char*>(pal), palStat.size, &target));
return OxError(0);
}

View File

@ -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;

View File

@ -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<NostalgiaGraphic>(ctx, tilesheetPath));
if (!palettePath) {
palettePath = tilesheet.defaultPalette;
}
oxRequire(palette, readObj<NostalgiaPalette>(ctx, palettePath));
oxRequire(palette, readObj<NostalgiaPalette>(ctx, palettePath ? palettePath : tilesheet.defaultPalette));
const unsigned bytesPerTile = tilesheet.bpp == 8 ? 64 : 32;
const auto tiles = tilesheet.pixels.size() / bytesPerTile;
constexpr int width = 8;