mirror of
https://github.com/gbdev/rgbds.git
synced 2026-08-23 15:24:35 +00:00
Fix RGBLINK scrambling algorithm to work for SRAM
Since SRAM sections start from 0, we had been using a signed `int8_t curScrambleSRAM` counter to allow 0 as a scrambled bank, but this actually just placed all floating SRAM sections in bank 0.
This commit is contained in:
+20
-17
@@ -70,31 +70,34 @@ static bool isLocationSuitable(
|
||||
|
||||
static MemoryLocation getStartLocation(Section const §ion) {
|
||||
static uint16_t curScrambleROM = 0;
|
||||
static uint8_t curScrambleWRAM = 0;
|
||||
static int8_t curScrambleSRAM = 0;
|
||||
static uint16_t curScrambleWRAM = 0;
|
||||
static uint16_t curScrambleSRAM = 0;
|
||||
|
||||
MemoryLocation location;
|
||||
|
||||
// Determine which bank we should start searching in
|
||||
if (section.isBankFixed) {
|
||||
location.bank = section.bank;
|
||||
} else if (options.scrambleROMX && section.type == SECTTYPE_ROMX) {
|
||||
if (curScrambleROM < 1) {
|
||||
curScrambleROM = options.scrambleROMX;
|
||||
}
|
||||
location.bank = curScrambleROM--;
|
||||
} else if (options.scrambleWRAMX && section.type == SECTTYPE_WRAMX) {
|
||||
if (curScrambleWRAM < 1) {
|
||||
curScrambleWRAM = options.scrambleWRAMX;
|
||||
}
|
||||
location.bank = curScrambleWRAM--;
|
||||
} else if (options.scrambleSRAM && section.type == SECTTYPE_SRAM) {
|
||||
if (curScrambleSRAM < 0) {
|
||||
curScrambleSRAM = options.scrambleSRAM;
|
||||
}
|
||||
location.bank = curScrambleSRAM--;
|
||||
} else {
|
||||
location.bank = sectionTypeInfo[section.type].firstBank;
|
||||
|
||||
// Scramble the bank if applicable
|
||||
if (options.scrambleROMX && section.type == SECTTYPE_ROMX) {
|
||||
if (curScrambleROM == 0) {
|
||||
curScrambleROM = options.scrambleROMX;
|
||||
}
|
||||
location.bank += --curScrambleROM;
|
||||
} else if (options.scrambleWRAMX && section.type == SECTTYPE_WRAMX) {
|
||||
if (curScrambleWRAM == 0) {
|
||||
curScrambleWRAM = options.scrambleWRAMX;
|
||||
}
|
||||
location.bank += --curScrambleWRAM;
|
||||
} else if (options.scrambleSRAM && section.type == SECTTYPE_SRAM) {
|
||||
if (curScrambleSRAM == 0) {
|
||||
curScrambleSRAM = options.scrambleSRAM;
|
||||
}
|
||||
location.bank += --curScrambleSRAM;
|
||||
}
|
||||
}
|
||||
|
||||
return location;
|
||||
|
||||
Reference in New Issue
Block a user