all repos — mgba @ 6e1483cb473b8d0d860b2b3b83436ecd47be524e

mGBA Game Boy Advance Emulator

src/platform/qt/ObjView.cpp (view raw)

  1/* Copyright (c) 2013-2016 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#include "ObjView.h"
  7
  8#include "GBAApp.h"
  9
 10#include <QFontDatabase>
 11#include <QTimer>
 12
 13extern "C" {
 14#include "gba/gba.h"
 15}
 16
 17using namespace QGBA;
 18
 19ObjView::ObjView(GameController* controller, QWidget* parent)
 20	: AssetView(controller, parent)
 21	, m_controller(controller)
 22	, m_tileStatus{}
 23	, m_objId(0)
 24{
 25	m_ui.setupUi(this);
 26	m_ui.tile->setController(controller);
 27
 28	const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
 29
 30	m_ui.x->setFont(font);
 31	m_ui.y->setFont(font);
 32	m_ui.w->setFont(font);
 33	m_ui.h->setFont(font);
 34	m_ui.address->setFont(font);
 35
 36	connect(m_ui.tiles, SIGNAL(indexPressed(int)), this, SLOT(translateIndex(int)));
 37	connect(m_ui.objId, SIGNAL(valueChanged(int)), this, SLOT(selectObj(int)));
 38	connect(m_ui.magnification, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this]() {
 39		updateTiles(true);
 40	});
 41}
 42
 43void ObjView::selectObj(int obj) {
 44	m_objId = obj;
 45	updateTiles(true);
 46}
 47
 48void ObjView::translateIndex(int index) {
 49	m_ui.tile->selectIndex(index + m_tileOffset);
 50}
 51
 52#ifdef M_CORE_GBA
 53void ObjView::updateTilesGBA(bool force) {
 54	const GBA* gba = static_cast<const GBA*>(m_controller->thread()->core->board);
 55	const GBAObj* obj = &gba->video.oam.obj[m_objId];
 56
 57	unsigned shape = GBAObjAttributesAGetShape(obj->a);
 58	unsigned size = GBAObjAttributesBGetSize(obj->b);
 59	unsigned width = GBAVideoObjSizes[shape * 4 + size][0];
 60	unsigned height = GBAVideoObjSizes[shape * 4 + size][1];
 61	m_ui.tiles->setTileCount(width * height / 64);
 62	m_ui.tiles->setMinimumSize(QSize(width, height) * m_ui.magnification->value());
 63	unsigned palette = GBAObjAttributesCGetPalette(obj->c);
 64	unsigned tile = GBAObjAttributesCGetTile(obj->c);
 65	int i = 0;
 66	// TODO: Tile stride
 67	// TODO: Check to see if parameters are changed (so as to enable force if needed)
 68	if (GBAObjAttributesAIs256Color(obj->a)) {
 69		mTileCacheSetPalette(m_tileCache.get(), 1);
 70		m_ui.tile->setPalette(0);
 71		m_ui.tile->setPaletteSet(1, 1024, 1536);
 72		tile /= 2;
 73		for (int y = 0; y < height / 8; ++y) {
 74			for (int x = 0; x < width / 8; ++x, ++i) {
 75				unsigned t = tile + i;
 76				const uint16_t* data = mTileCacheGetTileIfDirty(m_tileCache.get(), &m_tileStatus[32 * t], t + 1024, 1);
 77				if (data) {
 78					m_ui.tiles->setTile(i, data);
 79				} else if (force) {
 80					m_ui.tiles->setTile(i, mTileCacheGetTile(m_tileCache.get(), t + 1024, 1));
 81				}
 82			}
 83		}
 84		tile += 1024;
 85	} else {
 86		mTileCacheSetPalette(m_tileCache.get(), 0);
 87		m_ui.tile->setPalette(palette);
 88		m_ui.tile->setPaletteSet(0, 2048, 3072);
 89		for (int y = 0; y < height / 8; ++y) {
 90			for (int x = 0; x < width / 8; ++x, ++i) {
 91				unsigned t = tile + i;
 92				const uint16_t* data = mTileCacheGetTileIfDirty(m_tileCache.get(), &m_tileStatus[32 * t], t + 2048, palette + 16);
 93				if (data) {
 94					m_ui.tiles->setTile(i, data);
 95				} else if (force) {
 96					m_ui.tiles->setTile(i, mTileCacheGetTile(m_tileCache.get(), t + 2048, palette + 16));
 97				}
 98			}
 99		}
100		tile += 2048;
101	}
102	m_tileOffset = tile;
103
104	m_ui.x->setText(QString::number(GBAObjAttributesBGetX(obj->b)));
105	m_ui.y->setText(QString::number(GBAObjAttributesAGetY(obj->a)));
106	m_ui.w->setText(QString::number(width));
107	m_ui.h->setText(QString::number(height));
108
109	// TODO: Flags
110}
111#endif
112
113#ifdef M_CORE_GB
114void ObjView::updateTilesGB(bool force) {
115}
116#endif