all repos — mgba @ 4e7f70c102dda40db7061da906ce80f0dc027d1c

mGBA Game Boy Advance Emulator

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

 1/* Copyright (c) 2013-2015 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 "ROMInfo.h"
 7
 8#include "GBAApp.h"
 9#include "GameController.h"
10
11extern "C" {
12#include "core/core.h"
13#ifdef M_CORE_GB
14#include "gb/gb.h"
15#endif
16#ifdef M_CORE_GBA
17#include "gba/gba.h"
18#endif
19#include "util/nointro.h"
20}
21
22using namespace QGBA;
23
24ROMInfo::ROMInfo(GameController* controller, QWidget* parent)
25	: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
26{
27	m_ui.setupUi(this);
28
29	if (!controller->isLoaded()) {
30		return;
31	}
32
33	const NoIntroDB* db = GBAApp::app()->gameDB();
34
35	controller->threadInterrupt();
36	mCore* core = controller->thread()->core;
37	char title[17] = {};
38	core->getGameTitle(core, title);
39	m_ui.title->setText(QLatin1String(title));
40	core->getGameCode(core, title);
41	title[4] = '\0';
42	if (title[0]) {
43		m_ui.id->setText(QLatin1String(title));
44	} else {
45		m_ui.id->setText(tr("(unknown)"));
46	}
47
48	switch (controller->thread()->core->platform(controller->thread()->core)) {
49#ifdef M_CORE_GBA
50	case PLATFORM_GBA: {
51		GBA* gba = static_cast<GBA*>(core->board);
52		m_ui.size->setText(QString::number(gba->pristineRomSize) + tr(" bytes"));
53		m_ui.crc->setText(QString::number(gba->romCrc32, 16));
54		if (db) {
55			NoIntroGame game;
56			if (NoIntroDBLookupGameByCRC(db, gba->romCrc32, &game)) {
57				m_ui.name->setText(game.name);
58			} else {
59				m_ui.name->setText(tr("(unknown)"));
60			}
61		} else {
62			m_ui.name->setText(tr("(no database present)"));
63		}
64		break;
65	}
66#endif
67#ifdef M_CORE_GB
68	case PLATFORM_GB: {
69		GB* gb = static_cast<GB*>(core->board);
70		m_ui.size->setText(QString::number(gb->pristineRomSize) + tr(" bytes"));
71		m_ui.crc->setText(QString::number(gb->romCrc32, 16));
72		m_ui.name->setText(tr("(unknown)"));
73		break;
74	}
75#endif
76	default:
77		m_ui.size->setText(tr("(unknown)"));
78		m_ui.crc->setText(tr("(unknown)"));
79		m_ui.name->setText(tr("(unknown)"));
80
81	}
82	controller->threadContinue();
83}