Skip to content

Commit

Permalink
ENDL restores the label scope from before LOAD (#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 authored Oct 26, 2023
1 parent 22def89 commit 84f3cb4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/asm/section.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -456,6 +458,7 @@ void sect_EndLoadSection(void)
curOffset += loadOffset;
loadOffset = 0;
currentLoadSection = NULL;
sym_SetCurrentSymbolScope(currentLoadScope);
}

struct Section *sect_GetSymbolSection(void)
Expand Down
25 changes: 25 additions & 0 deletions test/asm/endl-local-scope.asm
Original file line number Diff line number Diff line change
@@ -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
Empty file added test/asm/endl-local-scope.err
Empty file.
Empty file added test/asm/endl-local-scope.out
Empty file.

0 comments on commit 84f3cb4

Please sign in to comment.