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 000000000..5b5d841ce Binary files /dev/null and b/test/asm/load-fragment.out.bin differ 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 000000000..ef2d63ad3 Binary files /dev/null and b/test/link/load-fragment-jr.out.bin differ diff --git a/test/link/load-fragment/base/a.asm b/test/link/load-fragment/base/a.asm new file mode 100644 index 000000000..8dbd349bd --- /dev/null +++ b/test/link/load-fragment/base/a.asm @@ -0,0 +1,4 @@ +SECTION "main", ROM0 +LOAD FRAGMENT "test", SRAM + db 0 +ENDL diff --git a/test/link/load-fragment/base/b.asm b/test/link/load-fragment/base/b.asm new file mode 100644 index 000000000..246005c82 --- /dev/null +++ b/test/link/load-fragment/base/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/base/ref.out.bin b/test/link/load-fragment/base/ref.out.bin new file mode 100644 index 000000000..9445df535 Binary files /dev/null and b/test/link/load-fragment/base/ref.out.bin differ 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 000000000..a62e9bba5 Binary files /dev/null and b/test/link/load-fragment/section-fragment/ref.out.bin differ 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 000000000..55edf8130 Binary files /dev/null and b/test/link/section-fragment/jr-offset-load/ref.out.bin differ diff --git a/test/link/test.sh b/test/link/test.sh index 3a7e06da4..489fd986a 100755 --- a/test/link/test.sh +++ b/test/link/test.sh @@ -172,6 +172,27 @@ rgblinkQuiet -o "$gbtemp2" "$outtemp" tryCmp "$gbtemp" "$gbtemp2" evaluateTest +test="load-fragment/base" +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 +278,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