Fix incorrect bank for first unoptimized tile with no tiles in bank 0 (#2244)

This commit is contained in:
Rangi authored and GitHub committed 2026-11-18 16:24:07 -05:00
1 parent c6b6a42458
commit 4c29408a80
7 files changed
+16 -11

No files matched your search

+12 -10
View File
@@ -721,15 +721,21 @@ static void outputUnoptimizedMaps(
// (though not in the palmap), which was already warned about.
uint8_t palID = attr.getPalID(mappings) + options.basePalID;
if (attr.isBackgroundTile()) {
// The tile bank may be 2 here, which is fine since background tiles are emitted as
// if they used the base tile ID and bank 0.
assume(bank <= NB_BANKS);
assume(bank < NB_BANKS);
// Background tiles are emitted as if they used the base tile ID and bank 0.
emit(tilemapOutput, options.baseTileIDs[0]);
emit(attrmapOutput, palID & 0b111); // The other flags are all zeros.
emit(palmapOutput, palID);
// Since background tiles are not in tile data, they do not increment the tile index.
} else {
// The `bank` may need incrementing before emitting any tiles if bank 0 takes no tiles.
if (tileIdx >= options.maxNbTiles[bank]) {
tileIdx = 0;
++bank;
}
// The only valid tile banks are 0 and 1.
assume(bank < NB_BANKS);
@@ -742,14 +748,10 @@ static void outputUnoptimizedMaps(
emit(attrmapOutput, (palID & 0b111) | bank << 3); // The other flags are all zeros.
emit(palmapOutput, palID);
// The tile index may be incremented above the maximum for its `bank` here. This is fine
// since the above check will wrap it back to 0 if there are more tiles to emit, or else
// there will only be background tiles left to skip.
++tileIdx;
// The `bank` may increment from 1 to 2, if banks 0 and 1 are both full. By then all
// the tiles should have been emitted, since there cannot be more tiles than could fit
// in both banks, but there may still be background tiles to skip.
if (tileIdx >= options.maxNbTiles[bank]) {
tileIdx = 0;
++bank;
}
}
}
}