From bdce5a6ea4cb4cfc00a467f12a6f65a601fd96d4 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Wed, 23 Oct 2024 14:56:29 -0400 Subject: [PATCH] Allow `LOAD FRAGMENT` This was implemented in #736 but removed after discussion in #869. Fixes #1537 --- man/rgbasm.5 | 8 ++-- src/asm/section.cpp | 5 --- test/asm/load-fragment.asm | 27 ++++++++++++ test/asm/load-fragment.err | 3 -- test/asm/load-fragment.out.bin | Bin 0 -> 16 bytes test/link/load-fragment-jr.asm | 12 ++++++ test/link/load-fragment-jr.out | 0 test/link/load-fragment-jr.out.bin | Bin 0 -> 2 bytes test/link/load-fragment/base/a.asm | 9 ++++ test/link/load-fragment/base/ref.out.bin | 1 + test/link/load-fragment/base/ref.out.sym | 5 +++ .../link/load-fragment/multiple-objects/a.asm | 4 ++ .../link/load-fragment/multiple-objects/b.asm | 6 +++ .../multiple-objects/ref.out.bin | Bin 0 -> 5 bytes .../link/load-fragment/section-fragment/a.asm | 8 ++++ .../link/load-fragment/section-fragment/b.asm | 4 ++ .../link/load-fragment/section-fragment/c.asm | 8 ++++ .../section-fragment/ref.out.bin | Bin 0 -> 20 bytes .../section-fragment/ref.out.map | 24 +++++++++++ .../section-fragment/ref.out.sym | 9 ++++ .../section-fragment/jr-offset-load/a.asm | 4 ++ .../section-fragment/jr-offset-load/b.asm | 6 +++ .../jr-offset-load/ref.out.bin | Bin 0 -> 130 bytes test/link/test.sh | 39 ++++++++++++++++++ 24 files changed, 170 insertions(+), 12 deletions(-) delete mode 100644 test/asm/load-fragment.err create mode 100644 test/asm/load-fragment.out.bin create mode 100644 test/link/load-fragment-jr.asm create mode 100644 test/link/load-fragment-jr.out create mode 100644 test/link/load-fragment-jr.out.bin create mode 100644 test/link/load-fragment/base/a.asm create mode 100644 test/link/load-fragment/base/ref.out.bin create mode 100644 test/link/load-fragment/base/ref.out.sym create mode 100644 test/link/load-fragment/multiple-objects/a.asm create mode 100644 test/link/load-fragment/multiple-objects/b.asm create mode 100644 test/link/load-fragment/multiple-objects/ref.out.bin create mode 100644 test/link/load-fragment/section-fragment/a.asm create mode 100644 test/link/load-fragment/section-fragment/b.asm create mode 100644 test/link/load-fragment/section-fragment/c.asm create mode 100644 test/link/load-fragment/section-fragment/ref.out.bin create mode 100644 test/link/load-fragment/section-fragment/ref.out.map create mode 100644 test/link/load-fragment/section-fragment/ref.out.sym create mode 100644 test/link/section-fragment/jr-offset-load/a.asm create mode 100644 test/link/section-fragment/jr-offset-load/b.asm create mode 100644 test/link/section-fragment/jr-offset-load/ref.out.bin diff --git a/man/rgbasm.5 b/man/rgbasm.5 index 463fb53d0..78f7b28d8 100644 --- a/man/rgbasm.5 +++ b/man/rgbasm.5 @@ -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 diff --git a/src/asm/section.cpp b/src/asm/section.cpp index 6d4b1a2aa..3df440659 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -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"); diff --git a/test/asm/load-fragment.asm b/test/asm/load-fragment.asm index 7280e70ae..a0225726e 100644 --- a/test/asm/load-fragment.asm +++ b/test/asm/load-fragment.asm @@ -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 diff --git a/test/asm/load-fragment.err b/test/asm/load-fragment.err deleted file mode 100644 index 9d3a68e85..000000000 --- a/test/asm/load-fragment.err +++ /dev/null @@ -1,3 +0,0 @@ -error: load-fragment.asm(2): - `LOAD FRAGMENT` is not allowed -error: Assembly aborted (1 error)! diff --git a/test/asm/load-fragment.out.bin b/test/asm/load-fragment.out.bin new file mode 100644 index 0000000000000000000000000000000000000000..5b5d841ce1692996d721ce7abba9de921930f9e7 GIT binary patch literal 16 XcmZQ(VP#`yKES}p#BhLvlj8sY4dw!Q literal 0 HcmV?d00001 diff --git a/test/link/load-fragment-jr.asm b/test/link/load-fragment-jr.asm new file mode 100644 index 000000000..007a01611 --- /dev/null +++ b/test/link/load-fragment-jr.asm @@ -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 diff --git a/test/link/load-fragment-jr.out b/test/link/load-fragment-jr.out new file mode 100644 index 000000000..e69de29bb diff --git a/test/link/load-fragment-jr.out.bin b/test/link/load-fragment-jr.out.bin new file mode 100644 index 0000000000000000000000000000000000000000..ef2d63ad3c0a4d4152b8b689020734b1b926dc0b GIT binary patch literal 2 Jcmb1O0000o02u%P literal 0 HcmV?d00001 diff --git a/test/link/load-fragment/base/a.asm b/test/link/load-fragment/base/a.asm new file mode 100644 index 000000000..3107dd088 --- /dev/null +++ b/test/link/load-fragment/base/a.asm @@ -0,0 +1,9 @@ +SECTION "Test", ROM0[0] +AA: db 1 +LOAD FRAGMENT "RAM section", WRAM0[$c000] +BB: db 2 +ENDL +CC: db 3 +LOAD FRAGMENT "RAM section", WRAM0 +DD: db 4 +ENDL diff --git a/test/link/load-fragment/base/ref.out.bin b/test/link/load-fragment/base/ref.out.bin new file mode 100644 index 000000000..82090ee2c --- /dev/null +++ b/test/link/load-fragment/base/ref.out.bin @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/link/load-fragment/base/ref.out.sym b/test/link/load-fragment/base/ref.out.sym new file mode 100644 index 000000000..c0b57a89c --- /dev/null +++ b/test/link/load-fragment/base/ref.out.sym @@ -0,0 +1,5 @@ +; File generated by rgblink +00:0000 AA +00:0002 CC +00:c000 BB +00:c001 DD diff --git a/test/link/load-fragment/multiple-objects/a.asm b/test/link/load-fragment/multiple-objects/a.asm new file mode 100644 index 000000000..8dbd349bd --- /dev/null +++ b/test/link/load-fragment/multiple-objects/a.asm @@ -0,0 +1,4 @@ +SECTION "main", ROM0 +LOAD FRAGMENT "test", SRAM + db 0 +ENDL diff --git a/test/link/load-fragment/multiple-objects/b.asm b/test/link/load-fragment/multiple-objects/b.asm new file mode 100644 index 000000000..246005c82 --- /dev/null +++ b/test/link/load-fragment/multiple-objects/b.asm @@ -0,0 +1,6 @@ +SECTION "SECTION2", ROM0 +LOAD FRAGMENT "test", SRAM + jr Label +Label: + dw Label +ENDL diff --git a/test/link/load-fragment/multiple-objects/ref.out.bin b/test/link/load-fragment/multiple-objects/ref.out.bin new file mode 100644 index 0000000000000000000000000000000000000000..9445df53526eb869193e5e092971678eec3e7c03 GIT binary patch literal 5 Mcmb1OWM04k00GJXy#N3J literal 0 HcmV?d00001 diff --git a/test/link/load-fragment/section-fragment/a.asm b/test/link/load-fragment/section-fragment/a.asm new file mode 100644 index 000000000..41b359060 --- /dev/null +++ b/test/link/load-fragment/section-fragment/a.asm @@ -0,0 +1,8 @@ +SECTION FRAGMENT "rom", ROM0 +Part1:: +LOAD FRAGMENT "ram", WRAM0 +wPart1:: + jr wPart1 + jr wPart3 +ENDL +Part1End:: diff --git a/test/link/load-fragment/section-fragment/b.asm b/test/link/load-fragment/section-fragment/b.asm new file mode 100644 index 000000000..f3f4a78a4 --- /dev/null +++ b/test/link/load-fragment/section-fragment/b.asm @@ -0,0 +1,4 @@ +SECTION FRAGMENT "rom", ROM0 +Part2:: +db "Hello world!" +Part2End:: diff --git a/test/link/load-fragment/section-fragment/c.asm b/test/link/load-fragment/section-fragment/c.asm new file mode 100644 index 000000000..27ed94c0f --- /dev/null +++ b/test/link/load-fragment/section-fragment/c.asm @@ -0,0 +1,8 @@ +SECTION FRAGMENT "rom", ROM0 +Part3:: +LOAD FRAGMENT "ram", WRAM0 +wPart3:: + jr wPart1 + jr wPart3 +ENDL +Part3End:: diff --git a/test/link/load-fragment/section-fragment/ref.out.bin b/test/link/load-fragment/section-fragment/ref.out.bin new file mode 100644 index 0000000000000000000000000000000000000000..a62e9bba5f037e3f99b283a457ced48268685c26 GIT binary patch literal 20 bcmb36C&A#6nv;{SP@Z3ulcFf`PT~&$Nks>y literal 0 HcmV?d00001 diff --git a/test/link/load-fragment/section-fragment/ref.out.map b/test/link/load-fragment/section-fragment/ref.out.map new file mode 100644 index 000000000..bb7b7b973 --- /dev/null +++ b/test/link/load-fragment/section-fragment/ref.out.map @@ -0,0 +1,24 @@ +SUMMARY: + ROM0: 20 bytes used / 16364 free + WRAM0: 8 bytes used / 4088 free + +ROM0 bank #0: + SECTION: $0000-$0013 ($0014 bytes) ["rom"] + $0000 = Part1 + $0004 = Part1End + ; Next fragment + $0010 = Part3 + $0014 = Part3End + ; Next fragment + $0004 = Part2 + $0010 = Part2End + EMPTY: $0014-$3fff ($3fec bytes) + TOTAL EMPTY: $3fec bytes + +WRAM0 bank #0: + SECTION: $c000-$c007 ($0008 bytes) ["ram"] + $c000 = wPart1 + ; Next fragment + $c004 = wPart3 + EMPTY: $c008-$cfff ($0ff8 bytes) + TOTAL EMPTY: $0ff8 bytes diff --git a/test/link/load-fragment/section-fragment/ref.out.sym b/test/link/load-fragment/section-fragment/ref.out.sym new file mode 100644 index 000000000..190de2444 --- /dev/null +++ b/test/link/load-fragment/section-fragment/ref.out.sym @@ -0,0 +1,9 @@ +; File generated by rgblink +00:0000 Part1 +00:0004 Part1End +00:0004 Part2 +00:0010 Part3 +00:0010 Part2End +00:0014 Part3End +00:c000 wPart1 +00:c004 wPart3 diff --git a/test/link/section-fragment/jr-offset-load/a.asm b/test/link/section-fragment/jr-offset-load/a.asm new file mode 100644 index 000000000..825a41fe4 --- /dev/null +++ b/test/link/section-fragment/jr-offset-load/a.asm @@ -0,0 +1,4 @@ +SECTION FRAGMENT "output", ROM0 +LOAD FRAGMENT "loaded", SRAM + ds 128 +ENDL diff --git a/test/link/section-fragment/jr-offset-load/b.asm b/test/link/section-fragment/jr-offset-load/b.asm new file mode 100644 index 000000000..2b1af8f96 --- /dev/null +++ b/test/link/section-fragment/jr-offset-load/b.asm @@ -0,0 +1,6 @@ +SECTION FRAGMENT "output", ROM0 +LOAD FRAGMENT "loaded", SRAM +label: + jr nz, label2 +label2: +ENDL diff --git a/test/link/section-fragment/jr-offset-load/ref.out.bin b/test/link/section-fragment/jr-offset-load/ref.out.bin new file mode 100644 index 0000000000000000000000000000000000000000..55edf813038ab50f12602a11f62e8e672f78dcad GIT binary patch literal 130 NcmZQz7+9dd0002O03iSX literal 0 HcmV?d00001 diff --git a/test/link/test.sh b/test/link/test.sh index 3a7e06da4..3c6d1ff42 100755 --- a/test/link/test.sh +++ b/test/link/test.sh @@ -172,6 +172,36 @@ rgblinkQuiet -o "$gbtemp2" "$outtemp" tryCmp "$gbtemp" "$gbtemp2" evaluateTest +test="load-fragment/base" +startTest +"$RGBASM" -o "$otemp" "$test"/a.asm +continueTest +rgblinkQuiet -o "$gbtemp" -n "$outtemp" "$otemp" +tryCmpRom "$test"/ref.out.bin +tryDiff "$test"/ref.out.sym "$outtemp" +evaluateTest + +test="load-fragment/multiple-objects" +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="load-fragment/section-fragment" +startTest +"$RGBASM" -o "$otemp" "$test"/a.asm +"$RGBASM" -o "$outtemp" "$test"/b.asm +"$RGBASM" -o "$outtemp2" "$test"/c.asm +continueTest +rgblinkQuiet -o "$gbtemp" -m "$outtemp3" -n "$gbtemp2" "$otemp" "$outtemp" "$outtemp2" +tryCmpRom "$test"/ref.out.bin +tryDiff "$test"/ref.out.map "$outtemp3" +tryDiff "$test"/ref.out.sym "$gbtemp2" +evaluateTest + test="map-file" startTest "$RGBASM" -o "$otemp" "$test"/a.asm @@ -257,6 +287,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