all repos — mgba @ 7d009ec43c0ce59903643913609bc7766f3cb7fb

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	uint32_t crc32 = 0;
35
36	GameController::Interrupter interrupter(controller);
37	mCore* core = controller->thread()->core;
38	char title[17] = {};
39	core->getGameTitle(core, title);
40	m_ui.title->setText(QLatin1String(title));
41	title[8] = '\0';
42	core->getGameCode(core, title);
43	if (title[0]) {
44		m_ui.id->setText(QLatin1String(title));
45	} else {
46		m_ui.id->setText(tr("(unknown)"));
47	}
48
49	switch (controller->thread()->core->platform(controller->thread()->core)) {
50#ifdef M_CORE_GBA
51	case PLATFORM_GBA: {
52		GBA* gba = static_cast<GBA*>(core->board);
53		m_ui.size->setText(QString::number(gba->pristineRomSize) + tr(" bytes"));
54		crc32 = gba->romCrc32;
55		break;
56	}
57#endif
58#ifdef M_CORE_GB
59	case PLATFORM_GB: {
60		GB* gb = static_cast<GB*>(core->board);
61		m_ui.size->setText(QString::number(gb->pristineRomSize) + tr(" bytes"));
62		crc32 = gb->romCrc32;
63		break;
64	}
65#endif
66	default:
67		m_ui.size->setText(tr("(unknown)"));
68		break;
69	}
70	if (crc32) {
71		m_ui.crc->setText(QString::number(crc32, 16));
72		if (db) {
73			NoIntroGame game{};
74			if (NoIntroDBLookupGameByCRC(db, crc32, &game)) {
75				m_ui.name->setText(game.name);
76			} else {
77				m_ui.name->setText(tr("(unknown)"));
78			}
79		} else {
80			m_ui.name->setText(tr("(no database present)"));
81		}
82	} else {
83		m_ui.crc->setText(tr("(unknown)"));
84		m_ui.name->setText(tr("(unknown)"));
85	}
86}