Qt: Add GB to sprite viewer, fix tile addresses

This commit is contained in:
Jeffrey Pfau 2016-10-21 11:14:26 -07:00
parent 2176202bcd
commit 7f443f2fae
4 changed files with 91 additions and 13 deletions

View File

@ -53,17 +53,20 @@ void AssetTile::setController(GameController* controller) {
case PLATFORM_GBA: case PLATFORM_GBA:
m_addressWidth = 8; m_addressWidth = 8;
m_addressBase = BASE_VRAM; m_addressBase = BASE_VRAM;
m_boundaryBase = BASE_VRAM | 0x10000;
break; break;
#endif #endif
#ifdef M_CORE_GB #ifdef M_CORE_GB
case PLATFORM_GB: case PLATFORM_GB:
m_addressWidth = 4; m_addressWidth = 4;
m_addressBase = GB_BASE_VRAM; m_addressBase = GB_BASE_VRAM;
m_boundaryBase = GB_BASE_VRAM;
break; break;
#endif #endif
default: default:
m_addressWidth = 0; m_addressWidth = 0;
m_addressBase = 0; m_addressBase = 0;
m_boundaryBase = 0;
break; break;
} }
} }
@ -86,16 +89,28 @@ void AssetTile::setPaletteSet(int palette, int boundary, int max) {
void AssetTile::selectIndex(int index) { void AssetTile::selectIndex(int index) {
m_index = index; m_index = index;
const uint16_t* data; const uint16_t* data;
m_ui.tileId->setText(QString::number(index * (1 + m_paletteSet)));
mTileCacheSetPalette(m_tileCache.get(), m_paletteSet); mTileCacheSetPalette(m_tileCache.get(), m_paletteSet);
unsigned bpp = 8 << m_tileCache->bpp; unsigned bpp = 8 << m_tileCache->bpp;
m_ui.address->setText(tr("0x%0").arg(index * bpp | m_addressBase, m_addressWidth, 16, QChar('0'))); int dispIndex = index;
if (index < m_boundary) { int paletteId = m_paletteId;
data = mTileCacheGetTile(m_tileCache.get(), index, m_paletteId); int base = m_addressBase;
} else { if (index >= m_boundary) {
data = mTileCacheGetTile(m_tileCache.get(), index, m_paletteId + m_tileCache->count / 2); base = m_boundaryBase;
// XXX: Do this better
#ifdef M_CORE_GBA
if (m_boundaryBase == (BASE_VRAM | 0x10000)) {
paletteId += m_tileCache->count / 2;
}
#endif
dispIndex -= m_boundary;
} }
data = mTileCacheGetTile(m_tileCache.get(), index, paletteId);
m_ui.tileId->setText(QString::number(dispIndex * (1 + m_paletteSet)));
m_ui.address->setText(tr("%0%1%2")
.arg(m_addressWidth == 4 ? index >= m_boundary : 0)
.arg(m_addressWidth == 4 ? ":" : "x")
.arg(dispIndex * bpp | base, m_addressWidth, 16, QChar('0')));
for (int i = 0; i < 64; ++i) { for (int i = 0; i < 64; ++i) {
m_ui.preview->setColor(i, data[i]); m_ui.preview->setColor(i, data[i]);
} }
@ -106,11 +121,14 @@ void AssetTile::selectColor(int index) {
const uint16_t* data; const uint16_t* data;
mTileCacheSetPalette(m_tileCache.get(), m_paletteSet); mTileCacheSetPalette(m_tileCache.get(), m_paletteSet);
unsigned bpp = 8 << m_tileCache->bpp; unsigned bpp = 8 << m_tileCache->bpp;
if (m_index < m_boundary) { int paletteId = m_paletteId;
data = mTileCacheGetTile(m_tileCache.get(), m_index, m_paletteId); // XXX: Do this better
} else { #ifdef M_CORE_GBA
data = mTileCacheGetTile(m_tileCache.get(), m_index, m_paletteId + m_tileCache->count / 2); if (m_index >= m_boundary && m_boundaryBase == (BASE_VRAM | 0x10000)) {
paletteId += m_tileCache->count / 2;
} }
#endif
data = mTileCacheGetTile(m_tileCache.get(), m_index, m_paletteId);
uint16_t color = data[index]; uint16_t color = data[index];
m_ui.color->setColor(0, color); m_ui.color->setColor(0, color);
m_ui.color->update(); m_ui.color->update();

View File

@ -40,6 +40,7 @@ private:
int m_addressWidth; int m_addressWidth;
int m_addressBase; int m_addressBase;
int m_boundary; int m_boundary;
int m_boundaryBase;
}; };
} }

View File

@ -12,6 +12,9 @@
extern "C" { extern "C" {
#include "gba/gba.h" #include "gba/gba.h"
#ifdef M_CORE_GB
#include "gb/gb.h"
#endif
} }
using namespace QGBA; using namespace QGBA;
@ -145,5 +148,53 @@ void ObjView::updateTilesGBA(bool force) {
#ifdef M_CORE_GB #ifdef M_CORE_GB
void ObjView::updateTilesGB(bool force) { void ObjView::updateTilesGB(bool force) {
const GB* gb = static_cast<const GB*>(m_controller->thread()->core->board);
const GBObj* obj = &gb->video.oam.obj[m_objId];
unsigned width = 8;
unsigned height = 8; // TODO
m_ui.tiles->setTileCount(width * height / 64);
m_ui.tiles->setMinimumSize(QSize(width, height) * m_ui.magnification->value());
int palette = 0;
unsigned tile = obj->tile;
if (gb->model >= GB_MODEL_CGB) {
if (GBObjAttributesIsBank(obj->attr)) {
tile += 512;
}
palette = GBObjAttributesGetCGBPalette(obj->attr);
} else {
palette = GBObjAttributesGetPalette(obj->attr);
}
int i = 0;
// TODO: Check to see if parameters are changed (so as to enable force if needed)
m_ui.palette->setText(QString::number(palette));
mTileCacheSetPalette(m_tileCache.get(), 0);
m_ui.tile->setPalette(palette + 8);
m_ui.tile->setPaletteSet(0, 512, 1024);
for (int y = 0; y < height / 8; ++y, ++i) {
unsigned t = tile + i;
const uint16_t* data = mTileCacheGetTileIfDirty(m_tileCache.get(), &m_tileStatus[16 * t], t, palette + 8);
if (data) {
m_ui.tiles->setTile(i, data);
} else if (force) {
m_ui.tiles->setTile(i, mTileCacheGetTile(m_tileCache.get(), t, palette + 8));
}
}
m_tileOffset = tile;
m_ui.x->setText(QString::number(obj->x));
m_ui.y->setText(QString::number(obj->y));
m_ui.w->setText(QString::number(width));
m_ui.h->setText(QString::number(height));
m_ui.address->setText(tr("0x%0").arg(GB_BASE_OAM + m_objId * sizeof(*obj), 4, 16, QChar('0')));
m_ui.priority->setText(QString::number(GBObjAttributesGetPriority(obj->attr)));
m_ui.flippedH->setChecked(GBObjAttributesIsXFlip(obj->attr));
m_ui.flippedV->setChecked(GBObjAttributesIsYFlip(obj->attr));
m_ui.enabled->setChecked(obj->y == 0 || obj->y >= 160);
m_ui.doubleSize->setChecked(false);
m_ui.mosaic->setChecked(false);
m_ui.transform->setText(tr("N/A"));
m_ui.mode->setText(tr("N/A"));
} }
#endif #endif

View File

@ -10,6 +10,12 @@
#include <QFontDatabase> #include <QFontDatabase>
#include <QTimer> #include <QTimer>
extern "C" {
#ifdef M_CORE_GB
#include "gb/gb.h"
#endif
}
using namespace QGBA; using namespace QGBA;
TileView::TileView(GameController* controller, QWidget* parent) TileView::TileView(GameController* controller, QWidget* parent)
@ -36,7 +42,7 @@ TileView::TileView(GameController* controller, QWidget* parent)
#ifdef M_CORE_GB #ifdef M_CORE_GB
case PLATFORM_GB: case PLATFORM_GB:
max = 1024; max = 1024;
boundary = 1024; boundary = 512;
m_ui.palette256->setEnabled(false); m_ui.palette256->setEnabled(false);
break; break;
#endif #endif
@ -119,9 +125,11 @@ void TileView::updateTilesGBA(bool force) {
#ifdef M_CORE_GB #ifdef M_CORE_GB
void TileView::updateTilesGB(bool force) { void TileView::updateTilesGB(bool force) {
m_ui.tiles->setTileCount(1024); const GB* gb = static_cast<const GB*>(m_controller->thread()->core->board);
int count = gb->model >= GB_MODEL_CGB ? 1024 : 512;
m_ui.tiles->setTileCount(count);
mTileCacheSetPalette(m_tileCache.get(), 0); mTileCacheSetPalette(m_tileCache.get(), 0);
for (int i = 0; i < 1024; ++i) { for (int i = 0; i < count; ++i) {
const uint16_t* data = mTileCacheGetTileIfDirty(m_tileCache.get(), &m_tileStatus[16 * i], i, m_paletteId); const uint16_t* data = mTileCacheGetTileIfDirty(m_tileCache.get(), &m_tileStatus[16 * i], i, m_paletteId);
if (data) { if (data) {
m_ui.tiles->setTile(i, data); m_ui.tiles->setTile(i, data);