[turbine,nostalgia] Make memory regions cast to bounded ox::Arrays
All checks were successful
Build / build (push) Successful in 1m16s

This commit is contained in:
2025-06-29 23:32:36 -05:00
parent bf958a4a6e
commit f6ef2b5acb
2 changed files with 7 additions and 13 deletions

View File

@ -35,11 +35,6 @@ class Context {
Context(Context const &&other) noexcept = delete; Context(Context const &&other) noexcept = delete;
virtual ~Context() noexcept = default; virtual ~Context() noexcept = default;
[[nodiscard]]
ox::MemFS const &rom() const noexcept {
return static_cast<ox::MemFS const&>(*turbine::rom(turbineCtx));
}
}; };
void safeDelete(Context *ctx) noexcept { void safeDelete(Context *ctx) noexcept {
@ -81,7 +76,7 @@ ox::Error loadBgPalette(
if (palette.pages.empty()) { if (palette.pages.empty()) {
return {}; return {};
} }
auto const paletteMem = MEM_BG_PALETTE + palBank * 16; auto const paletteMem = ox::Span{MEM_BG_PALETTE} + palBank * 16;
for (auto i = 0u; i < colorCnt(palette, page); ++i) { for (auto i = 0u; i < colorCnt(palette, page); ++i) {
paletteMem[i] = color(palette, page, i); paletteMem[i] = color(palette, page, i);
} }
@ -95,9 +90,8 @@ ox::Error loadSpritePalette(
if (palette.pages.empty()) { if (palette.pages.empty()) {
return {}; return {};
} }
auto const paletteMem = MEM_SPRITE_PALETTE;
for (auto i = 0u; i < colorCnt(palette, page); ++i) { for (auto i = 0u; i < colorCnt(palette, page); ++i) {
paletteMem[i] = color(palette, page, i); MEM_SPRITE_PALETTE[i] = color(palette, page, i);
} }
return {}; return {};
} }
@ -240,7 +234,7 @@ ox::Error loadSpriteTileSheet(
Context &ctx, Context &ctx,
TileSheetSet const &set) noexcept { TileSheetSet const &set) noexcept {
auto const bpp = static_cast<unsigned>(set.bpp); auto const bpp = static_cast<unsigned>(set.bpp);
OX_RETURN_ERROR(loadTileSheetSet(ctx, {MEM_SPRITE_TILES, 32 * ox::units::KB}, set)); OX_RETURN_ERROR(loadTileSheetSet(ctx, MEM_SPRITE_TILES, set));
setSpritesBpp(bpp); setSpritesBpp(bpp);
return {}; return {};
} }
@ -349,9 +343,9 @@ void panic(char const *file, int line, char const *panicMsg, ox::Error const &er
using namespace nostalgia::gfx; using namespace nostalgia::gfx;
// reset heap to make sure we have enough memory to allocate context data // reset heap to make sure we have enough memory to allocate context data
OX_ALLOW_UNSAFE_BUFFERS_BEGIN OX_ALLOW_UNSAFE_BUFFERS_BEGIN
auto const heapBegin = reinterpret_cast<char*>(MEM_EWRAM_BEGIN); auto const heapBegin = reinterpret_cast<char*>(MEM_EWRAM.data());
auto const heapSz = (MEM_EWRAM_END - MEM_EWRAM_BEGIN) / 2; auto const heapSz = MEM_EWRAM.size() / 2;
auto const heapEnd = reinterpret_cast<char*>(MEM_EWRAM_BEGIN + heapSz); auto const heapEnd = reinterpret_cast<char*>(MEM_EWRAM.data() + heapSz);
ox::heapmgr::initHeap(heapBegin, heapEnd); ox::heapmgr::initHeap(heapBegin, heapEnd);
OX_ALLOW_UNSAFE_BUFFERS_END OX_ALLOW_UNSAFE_BUFFERS_END
auto tctx = turbine::init(keel::loadRomFs("").unwrap(), "Nostalgia").unwrap(); auto tctx = turbine::init(keel::loadRomFs("").unwrap(), "Nostalgia").unwrap();

View File

@ -50,7 +50,7 @@ OX_ALLOW_UNSAFE_BUFFERS_BEGIN
constexpr auto headerP1Len = ox::strlen(headerP2); constexpr auto headerP1Len = ox::strlen(headerP2);
constexpr auto headerP2Len = ox::strlen(headerP1); constexpr auto headerP2Len = ox::strlen(headerP1);
constexpr auto headerLen = headerP1Len + headerP2Len; constexpr auto headerLen = headerP1Len + headerP2Len;
for (auto current = MEM_ROM; current < reinterpret_cast<char*>(0x0a000000); current += headerLen) { for (auto current = MEM_ROM.data(); current < reinterpret_cast<char*>(0x0a000000); current += headerLen) {
if (memcmp(current, headerP1, headerP1Len) == 0 && if (memcmp(current, headerP1, headerP1Len) == 0 &&
memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) { memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) {
return reinterpret_cast<std::size_t>(current + headerLen); return reinterpret_cast<std::size_t>(current + headerLen);