diff --git a/src/gfx/process.cpp b/src/gfx/process.cpp index 3bfb2f10..78520e76 100644 --- a/src/gfx/process.cpp +++ b/src/gfx/process.cpp @@ -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; - } } } } diff --git a/test/gfx/test.sh b/test/gfx/test.sh index 727c44db..4fc87fec 100755 --- a/test/gfx/test.sh +++ b/test/gfx/test.sh @@ -66,7 +66,7 @@ checkOutput () { while [[ "$ofs" -eq 0 ]]; do (( ofs = RANDOM % 256 )); done while [[ "$size" -eq 0 ]]; do (( size = RANDOM % 256 )); done for f in seed*.bin; do - for flags in ""{," -b $ofs"}{," -N $size,256"}; do + for flags in ""{," -b $ofs"}{," -N $size,256"," -N 0,256"}; do newTest ./rgbgfx_test "$f" $flags runTest || failTest $? done diff --git a/test/gfx/unoptimized_empty_bank_0.flags b/test/gfx/unoptimized_empty_bank_0.flags new file mode 100644 index 00000000..97592678 --- /dev/null +++ b/test/gfx/unoptimized_empty_bank_0.flags @@ -0,0 +1 @@ +-N 0,256 diff --git a/test/gfx/unoptimized_empty_bank_0.out.2bpp b/test/gfx/unoptimized_empty_bank_0.out.2bpp new file mode 100644 index 00000000..7066db2e --- /dev/null +++ b/test/gfx/unoptimized_empty_bank_0.out.2bpp @@ -0,0 +1 @@ +<