From f27be6e5f2cd94ffdee7dfa993a13680619ee763 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 23 Sep 2017 18:12:44 -0700 Subject: [PATCH] Core: Fix "macro" tile dynamic sizing --- include/mgba/core/map-cache.h | 4 ++-- src/core/map-cache.c | 12 ++++++------ src/gb/renderers/cache-set.c | 6 +----- src/gba/renderers/cache-set.c | 4 ++-- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/mgba/core/map-cache.h b/include/mgba/core/map-cache.h index 5a2c61b45..5d16287b4 100644 --- a/include/mgba/core/map-cache.h +++ b/include/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); diff --git a/src/core/map-cache.c b/src/core/map-cache.c index 3f1f7a007..f818c7e2f 100644 --- a/src/core/map-cache.c +++ b/src/core/map-cache.c @@ -117,14 +117,14 @@ static inline void _cleanTile(struct mMapCache* cache, const color_t* tile, colo 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; } diff --git a/src/gb/renderers/cache-set.c b/src/gb/renderers/cache-set.c index 07327ab7f..741d043cd 100644 --- a/src/gb/renderers/cache-set.c +++ b/src/gb/renderers/cache-set.c @@ -117,11 +117,7 @@ void GBVideoCacheWriteVideoRegister(struct mCacheSet* cache, uint16_t address, u } 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); diff --git a/src/gba/renderers/cache-set.c b/src/gba/renderers/cache-set.c index 395cbbaac..ddbeb0dfc 100644 --- a/src/gba/renderers/cache-set.c +++ b/src/gba/renderers/cache-set.c @@ -114,7 +114,7 @@ static void GBAVideoCacheWriteBGCNT(struct mCacheSet* cache, size_t bg, uint16_t 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 @@ static void GBAVideoCacheWriteBGCNT(struct mCacheSet* cache, size_t bg, uint16_t } 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;