Skip to content

Commit

Permalink
Scramble banks from the end of the ROM
Browse files Browse the repository at this point in the history
This is more likely to test edge cases, such as having
content in banks with their highest bit set.
  • Loading branch information
Rangi42 committed Dec 12, 2023
1 parent 495d701 commit 8345e5e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/link/assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,25 @@ static bool isLocationSuitable(struct Section const *section,
static struct FreeSpace *getPlacement(struct Section const *section,
struct MemoryLocation *location)
{
static uint16_t curScrambleROM = 1;
static uint8_t curScrambleWRAM = 1;
static uint8_t curScrambleSRAM = 1;
static uint16_t curScrambleROM = 0;
static uint8_t curScrambleWRAM = 0;
static int8_t curScrambleSRAM = 0;

// Determine which bank we should start searching in
if (section->isBankFixed) {
location->bank = section->bank;
} else if (scrambleROMX && section->type == SECTTYPE_ROMX) {
location->bank = curScrambleROM++;
if (curScrambleROM > scrambleROMX)
curScrambleROM = 1;
if (curScrambleROM < 1)
curScrambleROM = scrambleROMX;
location->bank = curScrambleROM--;
} else if (scrambleWRAMX && section->type == SECTTYPE_WRAMX) {
location->bank = curScrambleWRAM++;
if (curScrambleWRAM > scrambleWRAMX)
curScrambleWRAM = 1;
if (curScrambleWRAM < 1)
curScrambleWRAM = scrambleWRAMX;
location->bank = curScrambleWRAM--;
} else if (scrambleSRAM && section->type == SECTTYPE_SRAM) {
location->bank = curScrambleSRAM++;
if (curScrambleSRAM > scrambleSRAM)
curScrambleSRAM = 0;
if (curScrambleSRAM < 0)
curScrambleSRAM = scrambleSRAM;
location->bank = curScrambleSRAM--;
} else {
location->bank = sectionTypeInfo[section->type].firstBank;
}
Expand Down Expand Up @@ -168,8 +168,7 @@ static struct FreeSpace *getPlacement(struct Section const *section,
// Ensure we're there (e.g. on first check)
location->address &= ~section->alignMask;
// Go to next align boundary and add offset
location->address += section->alignMask + 1
+ section->alignOfs;
location->address += section->alignMask + 1 + section->alignOfs;
} else {
// Any location is fine, so, next free block
space = space->next;
Expand All @@ -179,8 +178,7 @@ static struct FreeSpace *getPlacement(struct Section const *section,

// If that location is past the current block's end,
// go forwards until that is no longer the case.
while (space && location->address >=
space->address + space->size)
while (space && location->address >= space->address + space->size)
space = space->next;

// Try again with the new location/free space combo
Expand Down
5 changes: 5 additions & 0 deletions test/link/scramble-romx/a.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SECTION "fixed", ROMX, BANK[3]
ds $4000, 1

SECTION "floating", ROMX
db 2
Empty file added test/link/scramble-romx/out.err
Empty file.
Binary file added test/link/scramble-romx/out.gb
Binary file not shown.
10 changes: 10 additions & 0 deletions test/link/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ tryDiff overlay/out.err "$outtemp"
tryCmp overlay/out.gb "$gbtemp"
(( rc = rc || $? ))

i="scramble-romx.asm"
startTest
"$RGBASM" -o "$otemp" scramble-romx/a.asm
rgblinkQuiet -o "$gbtemp" -S romx=3 "$otemp" >"$outtemp" 2>&1
tryDiff scramble-romx/out.err "$outtemp"
(( rc = rc || $? ))
# This test does not compare its exact output with 'tryCmpRom' because no scrambling order is guaranteed
test $(wc -c <"$gbtemp") = 65536
(( rc = rc || $? ))

i="section-fragment/jr-offset.asm"
startTest
"$RGBASM" -o "$otemp" section-fragment/jr-offset/a.asm
Expand Down

0 comments on commit 8345e5e

Please sign in to comment.