mirror of https://github.com/mgba-emu/mgba.git
Core: Fix unitialized memory issues with graphics caches
This commit is contained in:
parent
6900d130ae
commit
5e37df6cf5
1
CHANGES
1
CHANGES
|
@ -94,6 +94,7 @@ Emulation fixes:
|
||||||
- GBA Memory: Fix open bus from IWRAM (fixes mgba.io/i/1575)
|
- GBA Memory: Fix open bus from IWRAM (fixes mgba.io/i/1575)
|
||||||
Other fixes:
|
Other fixes:
|
||||||
- 3DS: Fix screen darkening (fixes mgba.io/i/1562)
|
- 3DS: Fix screen darkening (fixes mgba.io/i/1562)
|
||||||
|
- Core: Fix uninitialized memory issues with graphics caches
|
||||||
- Vita: Fix analog controls (fixes mgba.io/i/1554)
|
- Vita: Fix analog controls (fixes mgba.io/i/1554)
|
||||||
- Qt: Fix fast forward mute being reset (fixes mgba.io/i/1574)
|
- Qt: Fix fast forward mute being reset (fixes mgba.io/i/1574)
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ void mBitmapCacheInit(struct mBitmapCache* cache) {
|
||||||
// TODO: Reconfigurable cache for space savings
|
// TODO: Reconfigurable cache for space savings
|
||||||
cache->cache = NULL;
|
cache->cache = NULL;
|
||||||
cache->config = mBitmapCacheConfigurationFillShouldStore(0);
|
cache->config = mBitmapCacheConfigurationFillShouldStore(0);
|
||||||
|
cache->sysConfig = 0;
|
||||||
cache->status = NULL;
|
cache->status = NULL;
|
||||||
cache->palette = NULL;
|
cache->palette = NULL;
|
||||||
cache->buffer = 0;
|
cache->buffer = 0;
|
||||||
|
@ -18,14 +19,18 @@ void mBitmapCacheInit(struct mBitmapCache* cache) {
|
||||||
|
|
||||||
static void _freeCache(struct mBitmapCache* cache) {
|
static void _freeCache(struct mBitmapCache* cache) {
|
||||||
size_t size = mBitmapCacheSystemInfoGetHeight(cache->sysConfig) * mBitmapCacheSystemInfoGetBuffers(cache->sysConfig);
|
size_t size = mBitmapCacheSystemInfoGetHeight(cache->sysConfig) * mBitmapCacheSystemInfoGetBuffers(cache->sysConfig);
|
||||||
mappedMemoryFree(cache->cache, mBitmapCacheSystemInfoGetWidth(cache->sysConfig) * size * sizeof(color_t));
|
if (cache->cache) {
|
||||||
mappedMemoryFree(cache->status, size * sizeof(*cache->status));
|
mappedMemoryFree(cache->cache, mBitmapCacheSystemInfoGetWidth(cache->sysConfig) * size * sizeof(color_t));
|
||||||
|
cache->cache = NULL;
|
||||||
|
}
|
||||||
|
if (cache->status) {
|
||||||
|
mappedMemoryFree(cache->status, size * sizeof(*cache->status));
|
||||||
|
cache->status = NULL;
|
||||||
|
}
|
||||||
if (cache->palette) {
|
if (cache->palette) {
|
||||||
free(cache->palette);
|
free(cache->palette);
|
||||||
|
cache->palette = NULL;
|
||||||
}
|
}
|
||||||
cache->cache = NULL;
|
|
||||||
cache->status = NULL;
|
|
||||||
cache->palette = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _redoCacheSize(struct mBitmapCache* cache) {
|
static void _redoCacheSize(struct mBitmapCache* cache) {
|
||||||
|
|
|
@ -11,15 +11,20 @@ void mMapCacheInit(struct mMapCache* cache) {
|
||||||
// TODO: Reconfigurable cache for space savings
|
// TODO: Reconfigurable cache for space savings
|
||||||
cache->cache = NULL;
|
cache->cache = NULL;
|
||||||
cache->config = mMapCacheConfigurationFillShouldStore(0);
|
cache->config = mMapCacheConfigurationFillShouldStore(0);
|
||||||
|
cache->sysConfig = 0;
|
||||||
cache->status = NULL;
|
cache->status = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _freeCache(struct mMapCache* cache) {
|
static void _freeCache(struct mMapCache* cache) {
|
||||||
size_t tiles = (1 << mMapCacheSystemInfoGetTilesWide(cache->sysConfig)) * (1 << mMapCacheSystemInfoGetTilesHigh(cache->sysConfig));
|
size_t tiles = (1 << mMapCacheSystemInfoGetTilesWide(cache->sysConfig)) * (1 << mMapCacheSystemInfoGetTilesHigh(cache->sysConfig));
|
||||||
mappedMemoryFree(cache->cache, 8 * 8 * sizeof(color_t) * tiles);
|
if (cache->cache) {
|
||||||
mappedMemoryFree(cache->status, tiles * sizeof(*cache->status));
|
mappedMemoryFree(cache->cache, 8 * 8 * sizeof(color_t) * tiles);
|
||||||
cache->cache = NULL;
|
cache->cache = NULL;
|
||||||
cache->status = NULL;
|
}
|
||||||
|
if (cache->status) {
|
||||||
|
mappedMemoryFree(cache->status, tiles * sizeof(*cache->status));
|
||||||
|
cache->status = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _redoCacheSize(struct mMapCache* cache) {
|
static void _redoCacheSize(struct mMapCache* cache) {
|
||||||
|
|
|
@ -51,6 +51,9 @@ static void _redoCacheSize(struct mTileCache* cache) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void mTileCacheConfigure(struct mTileCache* cache, mTileCacheConfiguration config) {
|
void mTileCacheConfigure(struct mTileCache* cache, mTileCacheConfiguration config) {
|
||||||
|
if (cache->config == config) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_freeCache(cache);
|
_freeCache(cache);
|
||||||
cache->config = config;
|
cache->config = config;
|
||||||
_redoCacheSize(cache);
|
_redoCacheSize(cache);
|
||||||
|
|
|
@ -12,11 +12,13 @@
|
||||||
|
|
||||||
void GBVideoCacheInit(struct mCacheSet* cache) {
|
void GBVideoCacheInit(struct mCacheSet* cache) {
|
||||||
mCacheSetInit(cache, 2, 0, 1);
|
mCacheSetInit(cache, 2, 0, 1);
|
||||||
mTileCacheConfiguration config = 0;
|
mTileCacheSystemInfo sysconfig = 0;
|
||||||
config = mTileCacheSystemInfoSetPaletteBPP(config, 1); // 2^(2^1) = 4 entries
|
mTileCacheConfiguration config = mTileCacheConfigurationFillShouldStore(0);
|
||||||
config = mTileCacheSystemInfoSetPaletteCount(config, 4); // 16 palettes
|
sysconfig = mTileCacheSystemInfoSetPaletteBPP(sysconfig, 1); // 2^(2^1) = 4 entries
|
||||||
config = mTileCacheSystemInfoSetMaxTiles(config, 1024);
|
sysconfig = mTileCacheSystemInfoSetPaletteCount(sysconfig, 4); // 16 palettes
|
||||||
mTileCacheConfigureSystem(mTileCacheSetGetPointer(&cache->tiles, 0), config, 0, 0);
|
sysconfig = mTileCacheSystemInfoSetMaxTiles(sysconfig, 1024);
|
||||||
|
mTileCacheConfigureSystem(mTileCacheSetGetPointer(&cache->tiles, 0), sysconfig, 0, 0);
|
||||||
|
mTileCacheConfigure(mTileCacheSetGetPointer(&cache->tiles, 0), config);
|
||||||
|
|
||||||
mMapCacheSetGetPointer(&cache->maps, 0)->tileCache = mTileCacheSetGetPointer(&cache->tiles, 0);
|
mMapCacheSetGetPointer(&cache->maps, 0)->tileCache = mTileCacheSetGetPointer(&cache->tiles, 0);
|
||||||
mMapCacheSetGetPointer(&cache->maps, 1)->tileCache = mTileCacheSetGetPointer(&cache->tiles, 0);
|
mMapCacheSetGetPointer(&cache->maps, 1)->tileCache = mTileCacheSetGetPointer(&cache->tiles, 0);
|
||||||
|
|
|
@ -17,20 +17,20 @@ void GBAVideoCacheInit(struct mCacheSet* cache) {
|
||||||
sysconfig = mTileCacheSystemInfoSetPaletteBPP(sysconfig, 2); // 2^(2^2) = 16 entries
|
sysconfig = mTileCacheSystemInfoSetPaletteBPP(sysconfig, 2); // 2^(2^2) = 16 entries
|
||||||
sysconfig = mTileCacheSystemInfoSetPaletteCount(sysconfig, 4); // 16 palettes
|
sysconfig = mTileCacheSystemInfoSetPaletteCount(sysconfig, 4); // 16 palettes
|
||||||
sysconfig = mTileCacheSystemInfoSetMaxTiles(sysconfig, 2048);
|
sysconfig = mTileCacheSystemInfoSetMaxTiles(sysconfig, 2048);
|
||||||
mTileCacheConfigure(mTileCacheSetGetPointer(&cache->tiles, 0), config);
|
|
||||||
mTileCacheConfigureSystem(mTileCacheSetGetPointer(&cache->tiles, 0), sysconfig, 0, 0);
|
mTileCacheConfigureSystem(mTileCacheSetGetPointer(&cache->tiles, 0), sysconfig, 0, 0);
|
||||||
|
mTileCacheConfigure(mTileCacheSetGetPointer(&cache->tiles, 0), config);
|
||||||
sysconfig = mTileCacheSystemInfoSetMaxTiles(sysconfig, 1024);
|
sysconfig = mTileCacheSystemInfoSetMaxTiles(sysconfig, 1024);
|
||||||
mTileCacheConfigure(mTileCacheSetGetPointer(&cache->tiles, 2), config);
|
|
||||||
mTileCacheConfigureSystem(mTileCacheSetGetPointer(&cache->tiles, 2), sysconfig, 0x10000, 0x100);
|
mTileCacheConfigureSystem(mTileCacheSetGetPointer(&cache->tiles, 2), sysconfig, 0x10000, 0x100);
|
||||||
|
mTileCacheConfigure(mTileCacheSetGetPointer(&cache->tiles, 2), config);
|
||||||
|
|
||||||
sysconfig = mTileCacheSystemInfoSetPaletteBPP(sysconfig, 3); // 2^(2^3) = 256 entries
|
sysconfig = mTileCacheSystemInfoSetPaletteBPP(sysconfig, 3); // 2^(2^3) = 256 entries
|
||||||
sysconfig = mTileCacheSystemInfoSetPaletteCount(sysconfig, 0); // 1 palettes
|
sysconfig = mTileCacheSystemInfoSetPaletteCount(sysconfig, 0); // 1 palettes
|
||||||
sysconfig = mTileCacheSystemInfoSetMaxTiles(sysconfig, 2048);
|
sysconfig = mTileCacheSystemInfoSetMaxTiles(sysconfig, 2048);
|
||||||
mTileCacheConfigure(mTileCacheSetGetPointer(&cache->tiles, 1), config);
|
|
||||||
mTileCacheConfigureSystem(mTileCacheSetGetPointer(&cache->tiles, 1), sysconfig, 0, 0);
|
mTileCacheConfigureSystem(mTileCacheSetGetPointer(&cache->tiles, 1), sysconfig, 0, 0);
|
||||||
|
mTileCacheConfigure(mTileCacheSetGetPointer(&cache->tiles, 1), config);
|
||||||
sysconfig = mTileCacheSystemInfoSetMaxTiles(sysconfig, 1024);
|
sysconfig = mTileCacheSystemInfoSetMaxTiles(sysconfig, 1024);
|
||||||
mTileCacheConfigure(mTileCacheSetGetPointer(&cache->tiles, 3), config);
|
|
||||||
mTileCacheConfigureSystem(mTileCacheSetGetPointer(&cache->tiles, 3), sysconfig, 0x10000, 0x100);
|
mTileCacheConfigureSystem(mTileCacheSetGetPointer(&cache->tiles, 3), sysconfig, 0x10000, 0x100);
|
||||||
|
mTileCacheConfigure(mTileCacheSetGetPointer(&cache->tiles, 3), config);
|
||||||
|
|
||||||
mBitmapCacheSystemInfo bitConfig;
|
mBitmapCacheSystemInfo bitConfig;
|
||||||
bitConfig = mBitmapCacheSystemInfoSetEntryBPP(0, 4);
|
bitConfig = mBitmapCacheSystemInfoSetEntryBPP(0, 4);
|
||||||
|
@ -50,6 +50,11 @@ void GBAVideoCacheInit(struct mCacheSet* cache) {
|
||||||
mBitmapCacheConfigureSystem(mBitmapCacheSetGetPointer(&cache->bitmaps, 1), bitConfig);
|
mBitmapCacheConfigureSystem(mBitmapCacheSetGetPointer(&cache->bitmaps, 1), bitConfig);
|
||||||
mBitmapCacheSetGetPointer(&cache->bitmaps, 1)->bitsStart[0] = 0;
|
mBitmapCacheSetGetPointer(&cache->bitmaps, 1)->bitsStart[0] = 0;
|
||||||
mBitmapCacheSetGetPointer(&cache->bitmaps, 1)->bitsStart[1] = 0xA000;
|
mBitmapCacheSetGetPointer(&cache->bitmaps, 1)->bitsStart[1] = 0xA000;
|
||||||
|
|
||||||
|
mMapCacheSetGetPointer(&cache->maps, 0)->context = NULL;
|
||||||
|
mMapCacheSetGetPointer(&cache->maps, 1)->context = NULL;
|
||||||
|
mMapCacheSetGetPointer(&cache->maps, 2)->context = NULL;
|
||||||
|
mMapCacheSetGetPointer(&cache->maps, 3)->context = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAVideoCacheAssociate(struct mCacheSet* cache, struct GBAVideo* video) {
|
void GBAVideoCacheAssociate(struct mCacheSet* cache, struct GBAVideo* video) {
|
||||||
|
|
Loading…
Reference in New Issue