Skip to content

Commit 5efd303

Browse files
authored
Allow LOAD FRAGMENT (#1552)
This was implemented in #736 but removed after discussion in #869. Fixes #1537
1 parent 0d3980d commit 5efd303

File tree

24 files changed

+170
-12
lines changed

24 files changed

+170
-12
lines changed

man/rgbasm.5

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,11 +968,11 @@ block before performing its own function.
968968
.Ic LOAD
969969
blocks can use the
970970
.Ic UNION
971-
modifier as described in
972-
.Sx Unionized sections
973-
below, but not the
971+
or
974972
.Ic FRAGMENT
975-
modifier.
973+
modifiers as described in
974+
.Sx Unionized sections
975+
below.
976976
.Ss Unionized sections
977977
When you're tight on RAM, you may want to define overlapping static memory allocations, as explained in the
978978
.Sx Allocating overlapping spaces in RAM

src/asm/section.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,6 @@ void sect_SetLoadSection(
462462
return;
463463
}
464464

465-
if (mod == SECTION_FRAGMENT) {
466-
error("`LOAD FRAGMENT` is not allowed\n");
467-
return;
468-
}
469-
470465
if (currentLoadSection)
471466
sect_EndLoadSection("LOAD");
472467

test/asm/load-fragment.asm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
11
SECTION "A", ROM0
2+
AData::
23
LOAD FRAGMENT "RAM", WRAM0
4+
AMem::
5+
db 0, 1, 2
6+
AMemEnd::
7+
ENDL
8+
ADataEnd::
9+
dw AMem
10+
11+
SECTION "B", ROM0
12+
BData::
13+
LOAD FRAGMENT "RAM", WRAM0
14+
BMem::
15+
db 3, 4, 5, 6, 7
16+
BMemEnd::
17+
ENDL
18+
BDataEnd::
19+
dw BMem
20+
21+
SECTION "C", ROM0
22+
CData::
23+
LOAD FRAGMENT "RAM", WRAM0
24+
CMem::
25+
db 8, 9
26+
CMemEnd::
27+
ENDL
28+
CDataEnd::
29+
dw CMem

test/asm/load-fragment.err

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/asm/load-fragment.out.bin

16 Bytes
Binary file not shown.

test/link/load-fragment-jr.asm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
SECTION "main", ROM0
2+
LOAD FRAGMENT "test", SRAM
3+
ENDL
4+
5+
; The RPN patch for 'jr Label' in section "alt" refers to section "test",
6+
; but the object file puts section "test" after section "alt".
7+
; This case needs to be handled when identifying patches' PC sections.
8+
SECTION "alt", ROM0
9+
LOAD FRAGMENT "test", SRAM
10+
jr Label
11+
Label:
12+
ENDL

test/link/load-fragment-jr.out

Whitespace-only changes.

test/link/load-fragment-jr.out.bin

2 Bytes
Binary file not shown.

test/link/load-fragment/base/a.asm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SECTION "Test", ROM0[0]
2+
AA: db 1
3+
LOAD FRAGMENT "RAM section", WRAM0[$c000]
4+
BB: db 2
5+
ENDL
6+
CC: db 3
7+
LOAD FRAGMENT "RAM section", WRAM0
8+
DD: db 4
9+
ENDL
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; File generated by rgblink
2+
00:0000 AA
3+
00:0002 CC
4+
00:c000 BB
5+
00:c001 DD
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SECTION "main", ROM0
2+
LOAD FRAGMENT "test", SRAM
3+
db 0
4+
ENDL
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SECTION "SECTION2", ROM0
2+
LOAD FRAGMENT "test", SRAM
3+
jr Label
4+
Label:
5+
dw Label
6+
ENDL
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SECTION FRAGMENT "rom", ROM0
2+
Part1::
3+
LOAD FRAGMENT "ram", WRAM0
4+
wPart1::
5+
jr wPart1
6+
jr wPart3
7+
ENDL
8+
Part1End::
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SECTION FRAGMENT "rom", ROM0
2+
Part2::
3+
db "Hello world!"
4+
Part2End::
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SECTION FRAGMENT "rom", ROM0
2+
Part3::
3+
LOAD FRAGMENT "ram", WRAM0
4+
wPart3::
5+
jr wPart1
6+
jr wPart3
7+
ENDL
8+
Part3End::
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
SUMMARY:
2+
ROM0: 20 bytes used / 16364 free
3+
WRAM0: 8 bytes used / 4088 free
4+
5+
ROM0 bank #0:
6+
SECTION: $0000-$0013 ($0014 bytes) ["rom"]
7+
$0000 = Part1
8+
$0004 = Part1End
9+
; Next fragment
10+
$0010 = Part3
11+
$0014 = Part3End
12+
; Next fragment
13+
$0004 = Part2
14+
$0010 = Part2End
15+
EMPTY: $0014-$3fff ($3fec bytes)
16+
TOTAL EMPTY: $3fec bytes
17+
18+
WRAM0 bank #0:
19+
SECTION: $c000-$c007 ($0008 bytes) ["ram"]
20+
$c000 = wPart1
21+
; Next fragment
22+
$c004 = wPart3
23+
EMPTY: $c008-$cfff ($0ff8 bytes)
24+
TOTAL EMPTY: $0ff8 bytes
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; File generated by rgblink
2+
00:0000 Part1
3+
00:0004 Part1End
4+
00:0004 Part2
5+
00:0010 Part3
6+
00:0010 Part2End
7+
00:0014 Part3End
8+
00:c000 wPart1
9+
00:c004 wPart3
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SECTION FRAGMENT "output", ROM0
2+
LOAD FRAGMENT "loaded", SRAM
3+
ds 128
4+
ENDL
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SECTION FRAGMENT "output", ROM0
2+
LOAD FRAGMENT "loaded", SRAM
3+
label:
4+
jr nz, label2
5+
label2:
6+
ENDL
Binary file not shown.

test/link/test.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,36 @@ rgblinkQuiet -o "$gbtemp2" "$outtemp"
172172
tryCmp "$gbtemp" "$gbtemp2"
173173
evaluateTest
174174

175+
test="load-fragment/base"
176+
startTest
177+
"$RGBASM" -o "$otemp" "$test"/a.asm
178+
continueTest
179+
rgblinkQuiet -o "$gbtemp" -n "$outtemp" "$otemp"
180+
tryCmpRom "$test"/ref.out.bin
181+
tryDiff "$test"/ref.out.sym "$outtemp"
182+
evaluateTest
183+
184+
test="load-fragment/multiple-objects"
185+
startTest
186+
"$RGBASM" -o "$otemp" "$test"/a.asm
187+
"$RGBASM" -o "$gbtemp2" "$test"/b.asm
188+
continueTest
189+
rgblinkQuiet -o "$gbtemp" "$otemp" "$gbtemp2"
190+
tryCmpRom "$test"/ref.out.bin
191+
evaluateTest
192+
193+
test="load-fragment/section-fragment"
194+
startTest
195+
"$RGBASM" -o "$otemp" "$test"/a.asm
196+
"$RGBASM" -o "$outtemp" "$test"/b.asm
197+
"$RGBASM" -o "$outtemp2" "$test"/c.asm
198+
continueTest
199+
rgblinkQuiet -o "$gbtemp" -m "$outtemp3" -n "$gbtemp2" "$otemp" "$outtemp" "$outtemp2"
200+
tryCmpRom "$test"/ref.out.bin
201+
tryDiff "$test"/ref.out.map "$outtemp3"
202+
tryDiff "$test"/ref.out.sym "$gbtemp2"
203+
evaluateTest
204+
175205
test="map-file"
176206
startTest
177207
"$RGBASM" -o "$otemp" "$test"/a.asm
@@ -257,6 +287,15 @@ rgblinkQuiet -o "$gbtemp" "$otemp" "$gbtemp2"
257287
tryCmpRom "$test"/ref.out.bin
258288
evaluateTest
259289

290+
test="section-fragment/jr-offset-load"
291+
startTest
292+
"$RGBASM" -o "$otemp" "$test"/a.asm
293+
"$RGBASM" -o "$gbtemp2" "$test"/b.asm
294+
continueTest
295+
rgblinkQuiet -o "$gbtemp" "$otemp" "$gbtemp2"
296+
tryCmpRom "$test"/ref.out.bin
297+
evaluateTest
298+
260299
test="section-normal/same-name"
261300
startTest
262301
"$RGBASM" -o "$otemp" "$test"/a.asm

0 commit comments

Comments
 (0)