Skip to content

Commit

Permalink
Allow LOAD FRAGMENT
Browse files Browse the repository at this point in the history
This was implemented in #736 but removed after discussion in #869.

Fixes #1537
  • Loading branch information
Rangi42 committed Oct 23, 2024
1 parent 0d3980d commit 941ff16
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 12 deletions.
8 changes: 4 additions & 4 deletions man/rgbasm.5
Original file line number Diff line number Diff line change
Expand Up @@ -968,11 +968,11 @@ block before performing its own function.
.Ic LOAD
blocks can use the
.Ic UNION
modifier as described in
.Sx Unionized sections
below, but not the
or
.Ic FRAGMENT
modifier.
modifiers as described in
.Sx Unionized sections
below.
.Ss Unionized sections
When you're tight on RAM, you may want to define overlapping static memory allocations, as explained in the
.Sx Allocating overlapping spaces in RAM
Expand Down
5 changes: 0 additions & 5 deletions src/asm/section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,6 @@ void sect_SetLoadSection(
return;
}

if (mod == SECTION_FRAGMENT) {
error("`LOAD FRAGMENT` is not allowed\n");
return;
}

if (currentLoadSection)
sect_EndLoadSection("LOAD");

Expand Down
27 changes: 27 additions & 0 deletions test/asm/load-fragment.asm
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
SECTION "A", ROM0
AData::
LOAD FRAGMENT "RAM", WRAM0
AMem::
db 0, 1, 2
AMemEnd::
ENDL
ADataEnd::
dw AMem

SECTION "B", ROM0
BData::
LOAD FRAGMENT "RAM", WRAM0
BMem::
db 3, 4, 5, 6, 7
BMemEnd::
ENDL
BDataEnd::
dw BMem

SECTION "C", ROM0
CData::
LOAD FRAGMENT "RAM", WRAM0
CMem::
db 8, 9
CMemEnd::
ENDL
CDataEnd::
dw CMem
3 changes: 0 additions & 3 deletions test/asm/load-fragment.err

This file was deleted.

Binary file added test/asm/load-fragment.out.bin
Binary file not shown.
12 changes: 12 additions & 0 deletions test/link/load-fragment-jr.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SECTION "main", ROM0
LOAD FRAGMENT "test", SRAM
ENDL

; The RPN patch for 'jr Label' in section "alt" refers to section "test",
; but the object file puts section "test" after section "alt".
; This case needs to be handled when identifying patches' PC sections.
SECTION "alt", ROM0
LOAD FRAGMENT "test", SRAM
jr Label
Label:
ENDL
Binary file added test/link/load-fragment-jr.out.bin
Binary file not shown.
4 changes: 4 additions & 0 deletions test/link/load-fragment/a.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SECTION "main", ROM0
LOAD FRAGMENT "test", SRAM
db 0
ENDL
6 changes: 6 additions & 0 deletions test/link/load-fragment/b.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SECTION "SECTION2", ROM0
LOAD FRAGMENT "test", SRAM
jr Label
Label:
dw Label
ENDL
Binary file added test/link/load-fragment/ref.out.bin
Binary file not shown.
4 changes: 4 additions & 0 deletions test/link/section-fragment/jr-offset-load/a.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SECTION FRAGMENT "output", ROM0
LOAD FRAGMENT "loaded", SRAM
ds 128
ENDL
6 changes: 6 additions & 0 deletions test/link/section-fragment/jr-offset-load/b.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SECTION FRAGMENT "output", ROM0
LOAD FRAGMENT "loaded", SRAM
label:
jr nz, label2
label2:
ENDL
Binary file not shown.
9 changes: 9 additions & 0 deletions test/link/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@ rgblinkQuiet -o "$gbtemp" "$otemp" "$gbtemp2"
tryCmpRom "$test"/ref.out.bin
evaluateTest

test="section-fragment/jr-offset-load"
startTest
"$RGBASM" -o "$otemp" "$test"/a.asm
"$RGBASM" -o "$gbtemp2" "$test"/b.asm
continueTest
rgblinkQuiet -o "$gbtemp" "$otemp" "$gbtemp2"
tryCmpRom "$test"/ref.out.bin
evaluateTest

test="section-normal/same-name"
startTest
"$RGBASM" -o "$otemp" "$test"/a.asm
Expand Down

0 comments on commit 941ff16

Please sign in to comment.