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