diff --git a/src/asm/section.c b/src/asm/section.c index d33f55cb..6377ad2d 100644 --- a/src/asm/section.c +++ b/src/asm/section.c @@ -48,6 +48,7 @@ struct SectionStackEntry *sectionStack; uint32_t curOffset; // Offset into the current section (see sect_GetSymbolOffset) struct Section *currentSection = NULL; static struct Section *currentLoadSection = NULL; +char const *currentLoadScope = NULL; int32_t loadOffset; // Offset into the LOAD section's parent (see sect_GetOutputOffset) // A quick check to see if we have an initialized section @@ -439,6 +440,7 @@ void sect_SetLoadSection(char const *name, uint32_t type, uint32_t org, struct Section *sect = getSection(name, type, org, attribs, mod); + currentLoadScope = sym_GetCurrentSymbolScope(); changeSection(); loadOffset = curOffset - (mod == SECTION_UNION ? 0 : sect->size); curOffset -= loadOffset; @@ -456,6 +458,7 @@ void sect_EndLoadSection(void) curOffset += loadOffset; loadOffset = 0; currentLoadSection = NULL; + sym_SetCurrentSymbolScope(currentLoadScope); } struct Section *sect_GetSymbolSection(void) diff --git a/test/asm/endl-local-scope.asm b/test/asm/endl-local-scope.asm new file mode 100644 index 00000000..dc8fc0df --- /dev/null +++ b/test/asm/endl-local-scope.asm @@ -0,0 +1,25 @@ +SECTION "DMA ROM", ROM0[0] +SetUpDMA:: + ld c, LOW(DMARoutine) + ld b, DMARoutineCode.end - DMARoutineCode + ld hl, DMARoutineCode +.loop + ld a, [hl+] + ldh [c], a + inc c + dec b + jr nz, .loop + ret + +DMARoutineCode:: +LOAD "DMA RAM", HRAM[$FF80] +DMARoutine:: + ld a, $C0 + ldh [rDMA], a + ld a, $28 +.loop + dec a + jr nz, .loop + ret +ENDL +.end ; This label should be in the DMARoutineCode scope after ENDL diff --git a/test/asm/endl-local-scope.err b/test/asm/endl-local-scope.err new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/endl-local-scope.out b/test/asm/endl-local-scope.out new file mode 100644 index 00000000..e69de29b