diff --git a/src/core/map-cache.c b/src/core/map-cache.c index ec59b3ce0..3f1f7a007 100644 --- a/src/core/map-cache.c +++ b/src/core/map-cache.c @@ -114,8 +114,23 @@ 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; + x &= (1 << tilesWide) - 1; + y &= (1 << tilesHigh) - 1; + unsigned xMajor = x & ~0x1F; + unsigned yMajor = y >> 5; + x &= 0x1F; + y &= 0x1F; + yMajor <<= tilesHigh; + y += xMajor + yMajor; + return stride * y + x; +} + void mMapCacheCleanTile(struct mMapCache* cache, struct mMapCacheEntry* entry, unsigned x, unsigned y) { - size_t location = (1 << mMapCacheSystemInfoGetTilesWide(cache->sysConfig)) * y + x; + size_t location = _tileId(cache, x, y); struct mMapCacheEntry* status = &cache->status[location]; int paletteId = mMapCacheEntryFlagsGetPaletteId(status->flags); const color_t* tile = NULL; @@ -141,7 +156,7 @@ void mMapCacheCleanTile(struct mMapCache* cache, struct mMapCacheEntry* entry, u } bool mMapCacheCheckTile(struct mMapCache* cache, const struct mMapCacheEntry* entry, unsigned x, unsigned y) { - size_t location = (1 << mMapCacheSystemInfoGetTilesWide(cache->sysConfig)) * y + x; + size_t location = _tileId(cache, x, y); struct mMapCacheEntry* status = &cache->status[location]; int paletteId = mMapCacheEntryFlagsGetPaletteId(status->flags); const color_t* tile = NULL; diff --git a/src/gba/renderers/cache-set.c b/src/gba/renderers/cache-set.c index ae008594d..395cbbaac 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, 512); + sysconfig = mMapCacheSystemInfoSetMaxTiles(sysconfig, 1024); sysconfig = mMapCacheSystemInfoSetMapAlign(sysconfig, 1); tilesWide = 5; tilesHigh = 5; diff --git a/src/platform/qt/MapView.cpp b/src/platform/qt/MapView.cpp index bd70ac164..0d4460a99 100644 --- a/src/platform/qt/MapView.cpp +++ b/src/platform/qt/MapView.cpp @@ -8,7 +8,9 @@ #include "CoreController.h" #include "GBAApp.h" +#include #include +#include #include using namespace QGBA; @@ -38,19 +40,51 @@ MapView::MapView(std::shared_ptr controller, QWidget* parent) connect(m_ui.magnification, static_cast(&QSpinBox::valueChanged), [this]() { updateTiles(true); }); + + CoreController::Interrupter interrupter(m_controller); + const mCoreChannelInfo* videoLayers; + size_t nVideo = m_controller->thread()->core->listVideoLayers(m_controller->thread()->core, &videoLayers); + QButtonGroup* group = new QButtonGroup(this); + for (size_t i = 0; i < nVideo; ++i) { + if (strncmp(videoLayers[i].internalName, "bg", 2) != 0) { + continue; + } + QRadioButton* button = new QRadioButton(tr(videoLayers[i].visibleName)); + if (!i) { + button->setChecked(true); + } + m_ui.bgLayout->addWidget(button); + connect(button, &QAbstractButton::pressed, button, [this, i]() { + selectMap(i); + }); + group->addButton(button); + } +} + +void MapView::selectMap(int map) { + if (map >= mMapCacheSetSize(&m_cacheSet->maps)) { + return; + } + m_map = map; } #ifdef M_CORE_GBA void MapView::updateTilesGBA(bool force) { - QImage bg(QSize(256, 256), QImage::Format_ARGB32); - uchar* bgBits = bg.bits(); - mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, 0); - for (int j = 0; j < 32; ++j) { - for (int i = 0; i < 32; ++i) { - mMapCacheCleanTile(mapCache, &m_mapStatus[i + j * 32], i, j); - } - for (int i = 0; i < 8; ++i) { - memcpy(static_cast(&bgBits[256 * 4 * (i + j * 8)]), mMapCacheGetRow(mapCache, i + j * 8), 256 * 4); + QImage bg; + { + CoreController::Interrupter interrupter(m_controller); + mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, m_map); + int tilesW = 1 << mMapCacheSystemInfoGetTilesWide(mapCache->sysConfig); + int tilesH = 1 << mMapCacheSystemInfoGetTilesHigh(mapCache->sysConfig); + bg = QImage(QSize(tilesW * 8, tilesH * 8), QImage::Format_ARGB32); + uchar* bgBits = bg.bits(); + for (int j = 0; j < tilesH; ++j) { + for (int i = 0; i < tilesW; ++i) { + mMapCacheCleanTile(mapCache, &m_mapStatus[i + j * tilesW], i, j); + } + for (int i = 0; i < 8; ++i) { + memcpy(static_cast(&bgBits[tilesW * 32 * (i + j * 8)]), mMapCacheGetRow(mapCache, i + j * 8), tilesW * 32); + } } } bg = bg.convertToFormat(QImage::Format_RGB32).rgbSwapped(); diff --git a/src/platform/qt/MapView.h b/src/platform/qt/MapView.h index affc5d4bf..3f185a44d 100644 --- a/src/platform/qt/MapView.h +++ b/src/platform/qt/MapView.h @@ -21,6 +21,9 @@ Q_OBJECT public: MapView(std::shared_ptr controller, QWidget* parent = nullptr); +private slots: + void selectMap(int); + private: #ifdef M_CORE_GBA void updateTilesGBA(bool force) override; @@ -33,6 +36,7 @@ private: std::shared_ptr m_controller; mMapCacheEntry m_mapStatus[1024 * 1024] = {}; // TODO: Correct size + int m_map = 0; }; } diff --git a/src/platform/qt/MapView.ui b/src/platform/qt/MapView.ui index 683c6a611..3e4a9c2d1 100644 --- a/src/platform/qt/MapView.ui +++ b/src/platform/qt/MapView.ui @@ -14,14 +14,14 @@ Maps - - - - + true + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + @@ -44,6 +44,9 @@ + + + Qt::Vertical @@ -56,7 +59,7 @@ - + @@ -86,6 +89,9 @@ + + +