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:
Rangi
2026-07-13 22:39:41 -04:00
committed by Rangi
parent 196d50c1d7
commit 5869e0dc60
7 changed files with 59 additions and 53 deletions
+20 -17
View File
@@ -70,31 +70,34 @@ static bool isLocationSuitable(
static MemoryLocation getStartLocation(Section const &section) {
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;