Refactor and fix sect packing's bank iteration

Moving both pieces of related code together, as it were.
This also ends up changing the behaviour of scrambling,
where sections could “leak” out of the scrambling's bank pool
and resume being placed normally.

We have discussed it offline, and decided that this was a bug.
The test suite has been updated accordingly, which even gives
the occasion to move this test from a special case to the main
generic loop!
This commit is contained in:
ISSOtm
2026-09-18 21:19:37 +02:00
committed by Eldred Habert
parent 8685bcbfbf
commit ef709fade6
10 changed files with 140 additions and 93 deletions
+15
View File
@@ -0,0 +1,15 @@
DEF N equ 6
SECTION "fixed", ROMX, BANK[3]
ds $1000, $ff
FOR i, N
SECTION "floating{d:i}", ROMX
xLabel{d:i}:: ds $2000, i
SECTION "wram{d:i}", WRAMX
wLabel{d:i}:: dw
SECTION "sram{d:i}", SRAM
sLabel{d:i}:: dw
ENDR
+1
View File
@@ -0,0 +1 @@
-S romx=3,wramx=4,sram=4
+2
View File
@@ -0,0 +1,2 @@
FATAL: Unable to place "floating0" (ROMX section) anywhere within the 3 scrambled banks
Linking aborted with 1 error
+38
View File
@@ -0,0 +1,38 @@
; XXX: This test is brittle, since it relies on more than just the scrambling algorithm.
; For example, if the order in which sections are processed changes,
; then they will also be scrambled differently, and this test will fail.
; As long as the actual values are coherent, feel free to change the assertions.
DEF N equ 6
assert BANK(xLabel5) == 3
assert BANK(xLabel4) == 2
assert BANK(xLabel3) == 1
assert BANK(xLabel2) == 3
assert BANK(xLabel1) == 2
assert BANK(xLabel0) == 1
assert BANK(sLabel5) == 3
assert BANK(sLabel4) == 2
assert BANK(sLabel3) == 1
assert BANK(sLabel2) == 0
assert BANK(sLabel1) == 3
assert BANK(sLabel0) == 2
assert BANK(wLabel5) == 4
assert BANK(wLabel4) == 3
assert BANK(wLabel3) == 2
assert BANK(wLabel2) == 1
assert BANK(wLabel1) == 4
assert BANK(wLabel0) == 3
FOR i, N
SECTION "floating{d:i}", ROMX
xLabel{d:i}:: ds $2000, i
SECTION "sram{d:i}", SRAM
sLabel{d:i}:: dw
SECTION "wram{d:i}", WRAMX
wLabel{d:i}:: dw
ENDR
+1
View File
@@ -0,0 +1 @@
-S romx=3,wramx=4,sram=4
-25
View File
@@ -1,25 +0,0 @@
DEF N = 6
SECTION "fixed", ROMX, BANK[3]
; XXX: We rely on these landing at certain banks, which isn't *guaranteed*...
FOR i, 1, N + 1
db BANK(xLabel{d:i})
ENDR
FOR i, 1, N + 1
db BANK(wLabel{d:i})
ENDR
FOR i, 1, N + 1
db BANK(sLabel{d:i})
ENDR
ds $1000 - N * 3, $ff
FOR i, 1, N + 1
SECTION "floating{d:i}", ROMX
xLabel{d:i}:: ds $2000, i
SECTION "wram{d:i}", WRAMX
wLabel{d:i}:: dw
SECTION "sram{d:i}", SRAM
sLabel{d:i}:: dw
ENDR
Binary file not shown.
-10
View File
@@ -330,16 +330,6 @@ rgblinkQuiet -o "$gbtemp" -S "romx := 4" "$otemp" 2>"$outtemp"
tryDiff "$test"/out.err "$outtemp"
evaluateTest
test="scramble-specs"
startTest
"$RGBASM" -o "$otemp" "$test"/a.asm
continueTest
rgblinkQuiet -o "$gbtemp" -S "romx=3,wramx=4,sram=4" "$otemp" 2>"$outtemp"
tryDiff "$test"/out.err "$outtemp"
# This test does not trim its output with 'dd' because it needs to verify the correct output size
tryCmp "$test"/out.gb "$gbtemp"
evaluateTest
test="script-ds"
startTest
"$RGBASM" -o "$otemp" "$test"/a.asm