all repos — mgba @ f27be6e5f2cd94ffdee7dfa993a13680619ee763

mGBA Game Boy Advance Emulator

Core: Fix "macro" tile dynamic sizing
Vicki Pfau vi@endrift.com
Sat, 23 Sep 2017 18:12:44 -0700
commit

f27be6e5f2cd94ffdee7dfa993a13680619ee763

parent

229d138dacd0df43d14a498ad190200bde17df9c

M include/mgba/core/map-cache.hinclude/mgba/core/map-cache.h

@@ -21,8 +21,8 @@ DECL_BITS(mMapCacheSystemInfo, PaletteBPP, 0, 2);

DECL_BITS(mMapCacheSystemInfo, PaletteCount, 2, 4); DECL_BITS(mMapCacheSystemInfo, TilesWide, 8, 4); DECL_BITS(mMapCacheSystemInfo, TilesHigh, 12, 4); -DECL_BITS(mMapCacheSystemInfo, MaxTiles, 16, 13); -DECL_BITS(mMapCacheSystemInfo, MapAlign, 29, 2); +DECL_BITS(mMapCacheSystemInfo, MacroTileSize, 16, 7); +DECL_BITS(mMapCacheSystemInfo, MapAlign, 23, 2); DECL_BITFIELD(mMapCacheEntryFlags, uint16_t); DECL_BITS(mMapCacheEntryFlags, PaletteId, 0, 4);
M src/core/map-cache.csrc/core/map-cache.c

@@ -117,14 +117,14 @@

static inline size_t _tileId(struct mMapCache* cache, unsigned x, unsigned y) { int tilesWide = mMapCacheSystemInfoGetTilesWide(cache->sysConfig); int tilesHigh = mMapCacheSystemInfoGetTilesHigh(cache->sysConfig); - int stride = tilesHigh < 5 ? (1 << tilesHigh) : 32; + int stride = 1 << mMapCacheSystemInfoGetMacroTileSize(cache->sysConfig); x &= (1 << tilesWide) - 1; y &= (1 << tilesHigh) - 1; - unsigned xMajor = x & ~0x1F; - unsigned yMajor = y >> 5; - x &= 0x1F; - y &= 0x1F; - yMajor <<= tilesHigh; + unsigned xMajor = x & ~(stride - 1); + unsigned yMajor = y >> mMapCacheSystemInfoGetMacroTileSize(cache->sysConfig); + x &= stride - 1; + y &= stride - 1; + yMajor <<= tilesWide; y += xMajor + yMajor; return stride * y + x; }
M src/gb/renderers/cache-set.csrc/gb/renderers/cache-set.c

@@ -117,11 +117,7 @@ tileStart = 0x80;

} map->tileStart = tileStart; window->tileStart = tileStart; - if (sysconfig) { - sysconfig = mMapCacheSystemInfoSetMaxTiles(sysconfig, 896); - } else { - sysconfig = mMapCacheSystemInfoSetMaxTiles(sysconfig, 384); - } + sysconfig = mMapCacheSystemInfoSetMacroTileSize(sysconfig, 5); sysconfig = mMapCacheSystemInfoSetPaletteBPP(sysconfig, 1); sysconfig = mMapCacheSystemInfoSetMapAlign(sysconfig, 0); sysconfig = mMapCacheSystemInfoSetTilesHigh(sysconfig, 5);
M src/gba/renderers/cache-set.csrc/gba/renderers/cache-set.c

@@ -114,7 +114,7 @@ mMapCacheSystemInfo sysconfig = 0;

if (map->mapParser == mapParser0) { sysconfig = mMapCacheSystemInfoSetPaletteBPP(sysconfig, 2 + p); sysconfig = mMapCacheSystemInfoSetPaletteCount(sysconfig, 4 * !p); - sysconfig = mMapCacheSystemInfoSetMaxTiles(sysconfig, 1024); + sysconfig = mMapCacheSystemInfoSetMacroTileSize(sysconfig, 5); sysconfig = mMapCacheSystemInfoSetMapAlign(sysconfig, 1); tilesWide = 5; tilesHigh = 5;

@@ -128,7 +128,7 @@ map->tileStart = tileStart * 2;

} else if (map->mapParser == mapParser2) { sysconfig = mMapCacheSystemInfoSetPaletteBPP(sysconfig, 3); sysconfig = mMapCacheSystemInfoSetPaletteCount(sysconfig, 0); - sysconfig = mMapCacheSystemInfoSetMaxTiles(sysconfig, 256); + sysconfig = mMapCacheSystemInfoSetMacroTileSize(sysconfig, 4 + size); sysconfig = mMapCacheSystemInfoSetMapAlign(sysconfig, 0); tilesHigh = 4 + size;