diff --git a/include/asm/section.hpp b/include/asm/section.hpp index d7f86fdc..e7a92ef9 100644 --- a/include/asm/section.hpp +++ b/include/asm/section.hpp @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -78,7 +77,6 @@ void sect_CheckLoadClosed(); Section *sect_GetSymbolSection(); uint32_t sect_GetSymbolOffset(); uint32_t sect_GetOutputOffset(); -std::optional sect_GetOutputBank(); Patch *sect_AddOutputPatch(); diff --git a/src/asm/output.cpp b/src/asm/output.cpp index 2c22cd09..f635c9e5 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -148,7 +148,7 @@ static void initPatch(Patch &patch, uint32_t type, Expression const &expr, uint3 void out_CreatePatch(uint32_t type, Expression const &expr, uint32_t ofs, uint32_t pcShift) { // Add the patch to the list - assume(sect_GetOutputBank().has_value()); + assume(sect_GetSymbolSection() != nullptr); Patch &patch = *sect_AddOutputPatch(); initPatch(patch, type, expr, ofs); diff --git a/src/asm/rpn.cpp b/src/asm/rpn.cpp index 301c8e35..63b6c34f 100644 --- a/src/asm/rpn.cpp +++ b/src/asm/rpn.cpp @@ -83,14 +83,14 @@ void Expression::makeBankSymbol(InternedStr symName) { assume(rpn.empty()); if (Symbol const *sym = sym_FindScopedSymbol(symName); sym_IsPC(sym)) { // The @ symbol is treated differently. - if (std::optional outputBank = sect_GetOutputBank(); !outputBank) { + if (Section *section = sect_GetSymbolSection(); !section) { error("PC has no bank outside of a section"); data = 1; - } else if (*outputBank == UINT32_MAX) { + } else if (section->bank == UINT32_MAX) { data = "Current section's bank is not known"; rpn.emplace_back(RPN_BANK_SELF); } else { - data = static_cast(*outputBank); + data = static_cast(section->bank); } } else if (sym && !sym->isLabel()) { error("`BANK` argument must be a label"); diff --git a/src/asm/section.cpp b/src/asm/section.cpp index 8c6bc027..5d784466 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -644,10 +644,6 @@ uint32_t sect_GetOutputOffset() { return curOffset + loadOffset; } -std::optional sect_GetOutputBank() { - return currentSection ? std::optional(currentSection->bank) : std::nullopt; -} - Patch *sect_AddOutputPatch() { return currentSection ? ¤tSection->patches.emplace_front() : nullptr; } diff --git a/test/asm/load-pc-bank.asm b/test/asm/load-pc-bank.asm new file mode 100644 index 00000000..062c00df --- /dev/null +++ b/test/asm/load-pc-bank.asm @@ -0,0 +1,31 @@ +SECTION "rom", ROMX, BANK[1] +xLabel: +assert @ == xLabel +static_assert BANK(@) == BANK(xLabel) +static_assert SECTION(@) === SECTION(xLabel) + ds $3000, $42 + +LOAD "ram", WRAMX, BANK[2] +wLabel:: +assert @ == wLabel +static_assert BANK(@) == BANK(wLabel) +static_assert SECTION(@) === SECTION(wLabel) + ds $1000, $42 + +ENDL + +SECTION "floating rom", ROMX +xLabel2: +assert @ == xLabel2 +assert BANK(@) == BANK(xLabel2) +static_assert SECTION(@) === SECTION(xLabel2) + ds $3000, $42 + +LOAD "floating ram", WRAMX +wLabel2:: +assert @ == wLabel2 +assert BANK(@) == BANK(wLabel2) +static_assert SECTION(@) === SECTION(wLabel2) + ds $1000, $42 + +ENDL diff --git a/test/asm/ram-code.out.bin b/test/asm/ram-code.out.bin index ba867a10..b562f1e1 100644 Binary files a/test/asm/ram-code.out.bin and b/test/asm/ram-code.out.bin differ