mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Scramble banks from the end of the ROM (#1273)
This is more likely to test edge cases, such as having content in banks with their highest bit set.
This commit is contained in:
@@ -114,25 +114,25 @@ static bool isLocationSuitable(struct Section const *section,
|
|||||||
static struct FreeSpace *getPlacement(struct Section const *section,
|
static struct FreeSpace *getPlacement(struct Section const *section,
|
||||||
struct MemoryLocation *location)
|
struct MemoryLocation *location)
|
||||||
{
|
{
|
||||||
static uint16_t curScrambleROM = 1;
|
static uint16_t curScrambleROM = 0;
|
||||||
static uint8_t curScrambleWRAM = 1;
|
static uint8_t curScrambleWRAM = 0;
|
||||||
static uint8_t curScrambleSRAM = 1;
|
static int8_t curScrambleSRAM = 0;
|
||||||
|
|
||||||
// Determine which bank we should start searching in
|
// Determine which bank we should start searching in
|
||||||
if (section->isBankFixed) {
|
if (section->isBankFixed) {
|
||||||
location->bank = section->bank;
|
location->bank = section->bank;
|
||||||
} else if (scrambleROMX && section->type == SECTTYPE_ROMX) {
|
} else if (scrambleROMX && section->type == SECTTYPE_ROMX) {
|
||||||
location->bank = curScrambleROM++;
|
if (curScrambleROM < 1)
|
||||||
if (curScrambleROM > scrambleROMX)
|
curScrambleROM = scrambleROMX;
|
||||||
curScrambleROM = 1;
|
location->bank = curScrambleROM--;
|
||||||
} else if (scrambleWRAMX && section->type == SECTTYPE_WRAMX) {
|
} else if (scrambleWRAMX && section->type == SECTTYPE_WRAMX) {
|
||||||
location->bank = curScrambleWRAM++;
|
if (curScrambleWRAM < 1)
|
||||||
if (curScrambleWRAM > scrambleWRAMX)
|
curScrambleWRAM = scrambleWRAMX;
|
||||||
curScrambleWRAM = 1;
|
location->bank = curScrambleWRAM--;
|
||||||
} else if (scrambleSRAM && section->type == SECTTYPE_SRAM) {
|
} else if (scrambleSRAM && section->type == SECTTYPE_SRAM) {
|
||||||
location->bank = curScrambleSRAM++;
|
if (curScrambleSRAM < 0)
|
||||||
if (curScrambleSRAM > scrambleSRAM)
|
curScrambleSRAM = scrambleSRAM;
|
||||||
curScrambleSRAM = 0;
|
location->bank = curScrambleSRAM--;
|
||||||
} else {
|
} else {
|
||||||
location->bank = sectionTypeInfo[section->type].firstBank;
|
location->bank = sectionTypeInfo[section->type].firstBank;
|
||||||
}
|
}
|
||||||
@@ -168,8 +168,7 @@ static struct FreeSpace *getPlacement(struct Section const *section,
|
|||||||
// Ensure we're there (e.g. on first check)
|
// Ensure we're there (e.g. on first check)
|
||||||
location->address &= ~section->alignMask;
|
location->address &= ~section->alignMask;
|
||||||
// Go to next align boundary and add offset
|
// Go to next align boundary and add offset
|
||||||
location->address += section->alignMask + 1
|
location->address += section->alignMask + 1 + section->alignOfs;
|
||||||
+ section->alignOfs;
|
|
||||||
} else {
|
} else {
|
||||||
// Any location is fine, so, next free block
|
// Any location is fine, so, next free block
|
||||||
space = space->next;
|
space = space->next;
|
||||||
@@ -179,20 +178,43 @@ static struct FreeSpace *getPlacement(struct Section const *section,
|
|||||||
|
|
||||||
// If that location is past the current block's end,
|
// If that location is past the current block's end,
|
||||||
// go forwards until that is no longer the case.
|
// go forwards until that is no longer the case.
|
||||||
while (space && location->address >=
|
while (space && location->address >= space->address + space->size)
|
||||||
space->address + space->size)
|
|
||||||
space = space->next;
|
space = space->next;
|
||||||
|
|
||||||
// Try again with the new location/free space combo
|
// Try again with the new location/free space combo
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section->isBankFixed)
|
// Try again in the next bank, if one is available.
|
||||||
|
// Try scrambled banks in descending order until no bank in the scrambled range is available.
|
||||||
|
// Otherwise, try in ascending order.
|
||||||
|
if (section->isBankFixed) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
} else if (scrambleROMX && section->type == SECTTYPE_ROMX && location->bank <= scrambleROMX) {
|
||||||
// Try again in the next bank
|
if (location->bank > sectionTypeInfo[section->type].firstBank)
|
||||||
|
location->bank--;
|
||||||
|
else if (scrambleROMX < sectionTypeInfo[section->type].lastBank)
|
||||||
|
location->bank = scrambleROMX + 1;
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
} else if (scrambleWRAMX && section->type == SECTTYPE_WRAMX && location->bank <= scrambleWRAMX) {
|
||||||
|
if (location->bank > sectionTypeInfo[section->type].firstBank)
|
||||||
|
location->bank--;
|
||||||
|
else if (scrambleWRAMX < sectionTypeInfo[section->type].lastBank)
|
||||||
|
location->bank = scrambleWRAMX + 1;
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
} else if (scrambleSRAM && section->type == SECTTYPE_SRAM && location->bank <= scrambleSRAM) {
|
||||||
|
if (location->bank > sectionTypeInfo[section->type].firstBank)
|
||||||
|
location->bank--;
|
||||||
|
else if (scrambleSRAM < sectionTypeInfo[section->type].lastBank)
|
||||||
|
location->bank = scrambleSRAM + 1;
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
} else if (location->bank < sectionTypeInfo[section->type].lastBank) {
|
||||||
location->bank++;
|
location->bank++;
|
||||||
if (location->bank > sectionTypeInfo[section->type].lastBank)
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
#undef BANK_INDEX
|
#undef BANK_INDEX
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ for i in *.asm; do
|
|||||||
desired_binname=${i%.asm}.out.bin
|
desired_binname=${i%.asm}.out.bin
|
||||||
if [ -f "$desired_binname" ]; then
|
if [ -f "$desired_binname" ]; then
|
||||||
"$RGBLINK" -o "$gb" "$o"
|
"$RGBLINK" -o "$gb" "$o"
|
||||||
rom_size=$(wc -c < "$desired_binname")
|
rom_size=$(printf %s $(wc -c <"$desired_binname"))
|
||||||
dd if="$gb" count=1 bs="$rom_size" >"$output" 2>/dev/null
|
dd if="$gb" count=1 bs="$rom_size" >"$output" 2>/dev/null
|
||||||
tryCmp "$desired_binname" "$output" gb
|
tryCmp "$desired_binname" "$output" gb
|
||||||
(( our_rc = our_rc || $? ))
|
(( our_rc = our_rc || $? ))
|
||||||
|
|||||||
5
test/link/scramble-romx/a.asm
Normal file
5
test/link/scramble-romx/a.asm
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
SECTION "fixed", ROMX, BANK[3]
|
||||||
|
ds $4000, 1
|
||||||
|
|
||||||
|
SECTION "floating", ROMX
|
||||||
|
db 2
|
||||||
0
test/link/scramble-romx/out.err
Normal file
0
test/link/scramble-romx/out.err
Normal file
@@ -41,7 +41,7 @@ tryCmp () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
tryCmpRom () {
|
tryCmpRom () {
|
||||||
# `printf` lets us keep only the first returned word.
|
# `printf` lets us keep only the first returned word from `wc`.
|
||||||
rom_size=$(printf %s $(wc -c <"$1"))
|
rom_size=$(printf %s $(wc -c <"$1"))
|
||||||
dd if="$gbtemp" count=1 bs="$rom_size" >"$otemp" 2>/dev/null
|
dd if="$gbtemp" count=1 bs="$rom_size" >"$otemp" 2>/dev/null
|
||||||
tryCmp "$1" "$otemp"
|
tryCmp "$1" "$otemp"
|
||||||
@@ -146,6 +146,17 @@ tryDiff overlay/out.err "$outtemp"
|
|||||||
tryCmp overlay/out.gb "$gbtemp"
|
tryCmp overlay/out.gb "$gbtemp"
|
||||||
(( rc = rc || $? ))
|
(( 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
|
||||||
|
rom_size=$(printf %s $(wc -c <"$gbtemp"))
|
||||||
|
test "$rom_size" = 65536 # Check for exactly 3 ROMX banks
|
||||||
|
(( rc = rc || $? ))
|
||||||
|
|
||||||
i="section-fragment/jr-offset.asm"
|
i="section-fragment/jr-offset.asm"
|
||||||
startTest
|
startTest
|
||||||
"$RGBASM" -o "$otemp" section-fragment/jr-offset/a.asm
|
"$RGBASM" -o "$otemp" section-fragment/jr-offset/a.asm
|
||||||
|
|||||||
Reference in New Issue
Block a user