Core: More map viewer fixes

This commit is contained in:
Vicki Pfau 2017-09-23 23:25:57 -07:00
parent f27be6e5f2
commit a7ee79ff45
5 changed files with 22 additions and 12 deletions

View File

@ -56,6 +56,7 @@ struct mMapCache {
mMapCacheSystemInfo sysConfig; mMapCacheSystemInfo sysConfig;
void (*mapParser)(struct mMapCache*, struct mMapCacheEntry* entry, void* vram); void (*mapParser)(struct mMapCache*, struct mMapCacheEntry* entry, void* vram);
void* context;
}; };
void mMapCacheInit(struct mMapCache* cache); void mMapCacheInit(struct mMapCache* cache);

View File

@ -132,21 +132,21 @@ static inline size_t _tileId(struct mMapCache* cache, unsigned x, unsigned y) {
void mMapCacheCleanTile(struct mMapCache* cache, struct mMapCacheEntry* entry, unsigned x, unsigned y) { void mMapCacheCleanTile(struct mMapCache* cache, struct mMapCacheEntry* entry, unsigned x, unsigned y) {
size_t location = _tileId(cache, x, y); size_t location = _tileId(cache, x, y);
struct mMapCacheEntry* status = &cache->status[location]; struct mMapCacheEntry* status = &cache->status[location];
int paletteId = mMapCacheEntryFlagsGetPaletteId(status->flags);
const color_t* tile = NULL; const color_t* tile = NULL;
if (!mMapCacheEntryFlagsIsVramClean(status->flags)) { if (!mMapCacheEntryFlagsIsVramClean(status->flags)) {
status->flags = mMapCacheEntryFlagsFillVramClean(status->flags); status->flags = mMapCacheEntryFlagsFillVramClean(status->flags);
cache->mapParser(cache, status, &cache->vram[cache->mapStart + (location << mMapCacheSystemInfoGetMapAlign(cache->sysConfig))]); cache->mapParser(cache, status, &cache->vram[cache->mapStart + (location << mMapCacheSystemInfoGetMapAlign(cache->sysConfig))]);
tile = mTileCacheGetTileIfDirty(cache->tileCache, &status->tileStatus[paletteId], status->tileId + cache->tileStart, mMapCacheEntryFlagsGetPaletteId(status->flags)); }
if (!tile) { unsigned tileId = status->tileId + cache->tileStart;
tile = mTileCacheGetTile(cache->tileCache, status->tileId + cache->tileStart, mMapCacheEntryFlagsGetPaletteId(status->flags)); if (tileId >= mTileCacheSystemInfoGetMaxTiles(cache->tileCache->sysConfig)) {
} tileId = 0;
} else { }
tile = mTileCacheGetTileIfDirty(cache->tileCache, &status->tileStatus[paletteId], status->tileId + cache->tileStart, mMapCacheEntryFlagsGetPaletteId(status->flags)); tile = mTileCacheGetTileIfDirty(cache->tileCache, status->tileStatus, tileId, mMapCacheEntryFlagsGetPaletteId(status->flags));
if (!tile && memcmp(status, &entry[location], sizeof(*entry)) == 0) { if (!tile) {
if (mMapCacheEntryFlagsIsVramClean(status->flags) && memcmp(status, &entry[location], sizeof(*entry)) == 0) {
return; return;
} }
tile = mTileCacheGetTile(cache->tileCache, status->tileId + cache->tileStart, mMapCacheEntryFlagsGetPaletteId(status->flags)); tile = mTileCacheGetTile(cache->tileCache, tileId, mMapCacheEntryFlagsGetPaletteId(status->flags));
} }
size_t stride = 8 << mMapCacheSystemInfoGetTilesWide(cache->sysConfig); size_t stride = 8 << mMapCacheSystemInfoGetTilesWide(cache->sysConfig);
@ -161,7 +161,11 @@ bool mMapCacheCheckTile(struct mMapCache* cache, const struct mMapCacheEntry* en
int paletteId = mMapCacheEntryFlagsGetPaletteId(status->flags); int paletteId = mMapCacheEntryFlagsGetPaletteId(status->flags);
const color_t* tile = NULL; const color_t* tile = NULL;
if (mMapCacheEntryFlagsIsVramClean(status->flags) && memcmp(status, &entry[location], sizeof(*entry)) == 0) { if (mMapCacheEntryFlagsIsVramClean(status->flags) && memcmp(status, &entry[location], sizeof(*entry)) == 0) {
tile = mTileCacheGetTileIfDirty(cache->tileCache, &status->tileStatus[paletteId], status->tileId + cache->tileStart, mMapCacheEntryFlagsGetPaletteId(status->flags)); unsigned tileId = status->tileId + cache->tileStart;
if (tileId >= mTileCacheSystemInfoGetMaxTiles(cache->tileCache->sysConfig)) {
tileId = 0;
}
tile = mTileCacheGetTileIfDirty(cache->tileCache, &status->tileStatus[paletteId], tileId, mMapCacheEntryFlagsGetPaletteId(status->flags));
return !tile; return !tile;
} }
return false; return false;

View File

@ -104,6 +104,7 @@ static void GBAVideoCacheWriteDISPCNT(struct mCacheSet* cache, uint16_t value) {
static void GBAVideoCacheWriteBGCNT(struct mCacheSet* cache, size_t bg, uint16_t value) { static void GBAVideoCacheWriteBGCNT(struct mCacheSet* cache, size_t bg, uint16_t value) {
struct mMapCache* map = mMapCacheSetGetPointer(&cache->maps, bg); struct mMapCache* map = mMapCacheSetGetPointer(&cache->maps, bg);
map->context = (void*) (uintptr_t) value;
int tileStart = GBARegisterBGCNTGetCharBase(value) * 256; int tileStart = GBARegisterBGCNTGetCharBase(value) * 256;
bool p = GBARegisterBGCNTGet256Color(value); bool p = GBARegisterBGCNTGet256Color(value);
@ -145,6 +146,10 @@ void GBAVideoCacheWriteVideoRegister(struct mCacheSet* cache, uint32_t address,
switch (address) { switch (address) {
case REG_DISPCNT: case REG_DISPCNT:
GBAVideoCacheWriteDISPCNT(cache, value); GBAVideoCacheWriteDISPCNT(cache, value);
GBAVideoCacheWriteBGCNT(cache, 0, (uint16_t) mMapCacheSetGetPointer(&cache->maps, 0)->context);
GBAVideoCacheWriteBGCNT(cache, 1, (uint16_t) mMapCacheSetGetPointer(&cache->maps, 1)->context);
GBAVideoCacheWriteBGCNT(cache, 2, (uint16_t) mMapCacheSetGetPointer(&cache->maps, 2)->context);
GBAVideoCacheWriteBGCNT(cache, 3, (uint16_t) mMapCacheSetGetPointer(&cache->maps, 3)->context);
break; break;
case REG_BG0CNT: case REG_BG0CNT:
GBAVideoCacheWriteBGCNT(cache, 0, value); GBAVideoCacheWriteBGCNT(cache, 0, value);

View File

@ -90,7 +90,7 @@ void MapView::updateTilesGBA(bool force) {
uchar* bgBits = m_rawMap.bits(); uchar* bgBits = m_rawMap.bits();
for (int j = 0; j < tilesH; ++j) { for (int j = 0; j < tilesH; ++j) {
for (int i = 0; i < tilesW; ++i) { for (int i = 0; i < tilesW; ++i) {
mMapCacheCleanTile(mapCache, &m_mapStatus[i + j * tilesW], i, j); mMapCacheCleanTile(mapCache, m_mapStatus, i, j);
} }
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
memcpy(static_cast<void*>(&bgBits[tilesW * 32 * (i + j * 8)]), mMapCacheGetRow(mapCache, i + j * 8), tilesW * 32); memcpy(static_cast<void*>(&bgBits[tilesW * 32 * (i + j * 8)]), mMapCacheGetRow(mapCache, i + j * 8), tilesW * 32);

View File

@ -40,7 +40,7 @@ private:
Ui::MapView m_ui; Ui::MapView m_ui;
std::shared_ptr<CoreController> m_controller; std::shared_ptr<CoreController> m_controller;
mMapCacheEntry m_mapStatus[1024 * 1024] = {}; // TODO: Correct size mMapCacheEntry m_mapStatus[128 * 128] = {}; // TODO: Correct size
int m_map = 0; int m_map = 0;
QImage m_rawMap; QImage m_rawMap;
}; };