From e5240a688c54d07dd6d6b4994a920137d15bbad3 Mon Sep 17 00:00:00 2001 From: WaluigiWare64 <68647953+WaluigiWare64@users.noreply.github.com> Date: Fri, 2 Jul 2021 17:42:54 +0100 Subject: Add ROM Header struct and ROM info dialog (#1095) --- src/frontend/qt_sdl/CMakeLists.txt | 1 + src/frontend/qt_sdl/ROMInfoDialog.cpp | 145 ++++++ src/frontend/qt_sdl/ROMInfoDialog.h | 75 +++ src/frontend/qt_sdl/ROMInfoDialog.ui | 831 ++++++++++++++++++++++++++++++++++ src/frontend/qt_sdl/main.cpp | 17 +- src/frontend/qt_sdl/main.h | 2 + 6 files changed, 1070 insertions(+), 1 deletion(-) create mode 100644 src/frontend/qt_sdl/ROMInfoDialog.cpp create mode 100644 src/frontend/qt_sdl/ROMInfoDialog.h create mode 100644 src/frontend/qt_sdl/ROMInfoDialog.ui (limited to 'src/frontend/qt_sdl') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 05dce4a..1ec01b1 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -10,6 +10,7 @@ SET(SOURCES_QT_SDL AudioSettingsDialog.cpp WifiSettingsDialog.cpp InterfaceSettingsDialog.cpp + ROMInfoDialog.cpp Input.cpp LAN_PCap.cpp LAN_Socket.cpp diff --git a/src/frontend/qt_sdl/ROMInfoDialog.cpp b/src/frontend/qt_sdl/ROMInfoDialog.cpp new file mode 100644 index 0000000..673aaee --- /dev/null +++ b/src/frontend/qt_sdl/ROMInfoDialog.cpp @@ -0,0 +1,145 @@ +/* + Copyright 2016-2021 Arisotura, WaluigiWare64 + + This file is part of melonDS. + + melonDS is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + melonDS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include "ROMInfoDialog.h" +#include "ui_ROMInfoDialog.h" + +#include + +#include "NDS.h" +#include "NDSCart.h" +#include "Platform.h" +#include "Config.h" +#include "PlatformConfig.h" + +QString IntToHex(u64 num) +{ + return ("0x" + QString::number(num, 16).toUpper()); +} + +QString QStringBytes(u64 num) +{ + return (QString::number(num) + " Bytes"); +} + +ROMInfoDialog* ROMInfoDialog::currentDlg = nullptr; + +ROMInfoDialog::ROMInfoDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ROMInfoDialog) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + + u32 iconData[32 * 32]; + Frontend::ROMIcon(NDSCart::Banner.Icon, NDSCart::Banner.Palette, iconData); + iconImage = QImage(reinterpret_cast(iconData), 32, 32, QImage::Format_ARGB32).copy(); + ui->iconImage->setPixmap(QPixmap::fromImage(iconImage)); + + if (NDSCart::Banner.Version == 0x103) + { + u32 animatedIconData[32 * 32 * 64] = {0}; + Frontend::AnimatedROMIcon(NDSCart::Banner.DSiIcon, NDSCart::Banner.DSiPalette, NDSCart::Banner.DSiSequence, animatedIconData, animatedSequence); + + for (int i = 0; i < 64; i++) + { + if (animatedIconData[32 * 32 * i] == 0) + break; + animatedIconImages.push_back(QPixmap::fromImage(QImage(reinterpret_cast(&animatedIconData[32 * 32 * i]), 32, 32, QImage::Format_ARGB32).copy())); + } + + iconTimeline = new QTimeLine(animatedSequence.size() / 60 * 1000, this); + iconTimeline->setFrameRange(0, animatedSequence.size() - 1); + iconTimeline->setLoopCount(0); + iconTimeline->setEasingCurve(QEasingCurve::Linear); + connect(iconTimeline, &QTimeLine::frameChanged, this, &ROMInfoDialog::iconSetFrame); + iconTimeline->start(); + } + else + { + ui->dsiIconImage->setPixmap(QPixmap::fromImage(iconImage)); + } + + ui->iconTitle->setText(QString::fromUtf16(NDSCart::Banner.EnglishTitle)); + + ui->japaneseTitle->setText(QString::fromUtf16(NDSCart::Banner.JapaneseTitle)); + ui->englishTitle->setText(QString::fromUtf16(NDSCart::Banner.EnglishTitle)); + ui->frenchTitle->setText(QString::fromUtf16(NDSCart::Banner.FrenchTitle)); + ui->germanTitle->setText(QString::fromUtf16(NDSCart::Banner.GermanTitle)); + ui->italianTitle->setText(QString::fromUtf16(NDSCart::Banner.ItalianTitle)); + ui->spanishTitle->setText(QString::fromUtf16(NDSCart::Banner.SpanishTitle)); + + if (NDSCart::Banner.Version > 1) + ui->chineseTitle->setText(QString::fromUtf16(NDSCart::Banner.ChineseTitle)); + else + ui->chineseTitle->setText("None"); + + if (NDSCart::Banner.Version > 2) + ui->koreanTitle->setText(QString::fromUtf16(NDSCart::Banner.KoreanTitle)); + else + ui->koreanTitle->setText("None"); + + ui->gameTitle->setText(QString::fromLatin1(NDSCart::Header.GameTitle, 12)); + ui->gameCode->setText(QString::fromLatin1(NDSCart::Header.GameCode, 4)); + ui->makerCode->setText(QString::fromLatin1(NDSCart::Header.MakerCode, 2)); + ui->cardSize->setText(QString::number(128 << NDSCart::Header.CardSize) + " KB"); + + ui->arm9RomOffset->setText(IntToHex(NDSCart::Header.ARM9ROMOffset)); + ui->arm9EntryAddress->setText(IntToHex(NDSCart::Header.ARM9EntryAddress)); + ui->arm9RamAddress->setText(IntToHex(NDSCart::Header.ARM9RAMAddress)); + ui->arm9Size->setText(QStringBytes(NDSCart::Header.ARM9Size)); + + ui->arm7RomOffset->setText(IntToHex(NDSCart::Header.ARM7ROMOffset)); + ui->arm7EntryAddress->setText(IntToHex(NDSCart::Header.ARM7EntryAddress)); + ui->arm7RamAddress->setText(IntToHex(NDSCart::Header.ARM7RAMAddress)); + ui->arm7Size->setText(QStringBytes(NDSCart::Header.ARM7Size)); + + ui->fntOffset->setText(IntToHex(NDSCart::Header.FNTOffset)); + ui->fntSize->setText(QStringBytes(NDSCart::Header.FNTSize)); + ui->fatOffset->setText(IntToHex(NDSCart::Header.FATOffset)); + ui->fatSize->setText(QStringBytes(NDSCart::Header.FATSize)); + +} + +ROMInfoDialog::~ROMInfoDialog() +{ + delete ui; +} + +void ROMInfoDialog::done(int r) +{ + QDialog::done(r); + + closeDlg(); +} + +void ROMInfoDialog::on_saveIconButton_clicked() +{ + QString filename = QFileDialog::getSaveFileName(this, + "Save Icon", + Config::LastROMFolder, + "PNG Images (*.png)"); + if (filename.isEmpty()) + return; + + iconImage.save(filename, "PNG"); +} + +void ROMInfoDialog::iconSetFrame(int frame) +{ + ui->dsiIconImage->setPixmap(animatedIconImages[animatedSequence[frame]]); +} diff --git a/src/frontend/qt_sdl/ROMInfoDialog.h b/src/frontend/qt_sdl/ROMInfoDialog.h new file mode 100644 index 0000000..5193554 --- /dev/null +++ b/src/frontend/qt_sdl/ROMInfoDialog.h @@ -0,0 +1,75 @@ +/* + Copyright 2016-2021 Arisotura, WaluigiWare64 + + This file is part of melonDS. + + melonDS is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + melonDS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef ROMINFODIALOG_H +#define ROMINFODIALOG_H + +#include +#include +#include +#include + +#include "types.h" +#include "FrontendUtil.h" + +namespace Ui { class ROMInfoDialog; } +class ROMInfoDialog; + +class ROMInfoDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ROMInfoDialog(QWidget* parent); + ~ROMInfoDialog(); + + static ROMInfoDialog* currentDlg; + static ROMInfoDialog* openDlg(QWidget* parent) + { + if (currentDlg) + { + currentDlg->activateWindow(); + return currentDlg; + } + + currentDlg = new ROMInfoDialog(parent); + currentDlg->open(); + return currentDlg; + } + static void closeDlg() + { + currentDlg = nullptr; + } + +private slots: + void done(int r); + + void on_saveIconButton_clicked(); + + void iconSetFrame(int frame); + +private: + Ui::ROMInfoDialog* ui; + + QImage iconImage; + QTimeLine* iconTimeline; + std::vector animatedIconImages; + std::vector animatedSequence; +}; + +#endif // ROMINFODIALOG_H diff --git a/src/frontend/qt_sdl/ROMInfoDialog.ui b/src/frontend/qt_sdl/ROMInfoDialog.ui new file mode 100644 index 0000000..4c5d7d3 --- /dev/null +++ b/src/frontend/qt_sdl/ROMInfoDialog.ui @@ -0,0 +1,831 @@ + + + ROMInfoDialog + + + + 0 + 0 + 427 + 434 + + + + + 0 + 0 + + + + ROM Info - melonDS + + + + + + + 0 + 0 + + + + Titles + + + + + + + false + + + + Japanese Title: + + + + + + + [japanese title] + + + + + + + + false + + + + English Title: + + + + + + + [english title] + + + + + + + + false + + + + French Title: + + + + + + + [french title] + + + + + + + + false + + + + German Title: + + + + + + + [german title] + + + + + + + + false + + + + Italian Title: + + + + + + + [italian title] + + + + + + + + false + + + + Spanish Title: + + + + + + + [spanish title] + + + + + + + + false + + + + Chinese Title: + + + + + + + [chinese title] + + + + + + + + false + + + + Korean Title: + + + + + + + [korean title] + + + + + + + + + + ARM7 and ARM9 binaries + + + + + + + false + + + + ARM9 ROM Offset: + + + + + + + [arm9 rom offset] + + + + + + + + false + + + + ARM9 Entry Address: + + + + + + + [arm9 entry address] + + + + + + + + false + + + + ARM9 RAM Address: + + + + + + + [arm9 ram address] + + + + + + + + false + + + + ARM9 Size: + + + + + + + [arm9 size] + + + + + + + + false + + + + ARM7 ROM Offset: + + + + + + + [arm7 rom offset] + + + + + + + + false + + + + ARM7 Entry Address: + + + + + + + [arm7 entry address] + + + + + + + + false + + + + ARM7 RAM Address: + + + + + + + [arm7 ram address] + + + + + + + + false + + + + ARM7 Size: + + + + + + + [arm7 size] + + + + + + + + + + + 0 + 0 + + + + Filesystem + + + + + + + false + + + + FNT Offset: + + + + + + + [fnt offset] + + + + + + + + false + + + + FNT Size: + + + + + + + [fnt size] + + + + + + + + false + + + + FAT Offset: + + + + + + + [fat offset] + + + + + + + + false + + + + FAT Size: + + + + + + + [fat size] + + + + + + + + + + + 0 + 0 + + + + General Info + + + + + + + false + + + + Game Title: + + + + + + + [game title] + + + + + + + + false + + + + Game Code: + + + + + + + [game code] + + + + + + + + false + + + + Maker Code: + + + + + + + [maker code] + + + + + + + + false + + + + Card Size: + + + + + + + [card size] + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + + + + 0 + 0 + + + + #iconBox { + border: 1px solid black; + background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, + stop: 0 white, + stop: 1 lightgrey); +} + +#titleBox { + border: 0.5px solid grey; + background-color: #fbfbfb; +} + +#iconTitle { + color: black; +} + + + + + + + Qt::AlignCenter + + + false + + + false + + + + 2 + + + 2 + + + + + + 0 + 0 + + + + + 32 + 32 + + + + + 32 + 32 + + + + [icon] + + + + + + + + 0 + 0 + + + + + + + + 1 + + + 1 + + + 1 + + + 1 + + + + + + 0 + 0 + + + + + Courier New + 8 + 50 + false + false + + + + [title] + + + Qt::AlignCenter + + + + + + + + + + + + + + 0 + 0 + + + + #dsiIconBox { + border-radius: 4px; + background-color: #515151; +} + +#dsiIconImage { + background-color: white; +} + + + + + + Qt::AlignCenter + + + false + + + false + + + + 8 + + + 6 + + + 8 + + + 6 + + + + + + 0 + 0 + + + + + 32 + 32 + + + + + 32 + 32 + + + + [dsi icon] + + + Qt::AlignCenter + + + + + + + + + + Qt::Horizontal + + + + 55 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Save Icon + + + + + + + + + + + + buttonBox + accepted() + ROMInfoDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ROMInfoDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 8407acb..acb8d29 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -57,6 +57,7 @@ #include "AudioSettingsDialog.h" #include "WifiSettingsDialog.h" #include "InterfaceSettingsDialog.h" +#include "ROMInfoDialog.h" #include "types.h" #include "version.h" @@ -65,6 +66,7 @@ #include "OSD.h" #include "NDS.h" +#include "NDSCart.h" #include "GBACart.h" #include "GPU.h" #include "SPU.h" @@ -1331,6 +1333,10 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) actSetupCheats = menu->addAction("Setup cheat codes"); actSetupCheats->setMenuRole(QAction::NoRole); connect(actSetupCheats, &QAction::triggered, this, &MainWindow::onSetupCheats); + + menu->addSeparator(); + actROMInfo = menu->addAction("ROM Info"); + connect(actROMInfo, &QAction::triggered, this, &MainWindow::onROMInfo); } { QMenu* menu = menubar->addMenu("Config"); @@ -1533,9 +1539,10 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) actSetupCheats->setEnabled(false); - actEnableCheats->setChecked(Config::EnableCheats != 0); + actROMInfo->setEnabled(false); + actSavestateSRAMReloc->setChecked(Config::SavestateRelocSRAM != 0); actScreenRotation[Config::ScreenRotation]->setChecked(true); @@ -2335,6 +2342,10 @@ void MainWindow::onCheatsDialogFinished(int res) emuThread->emuUnpause(); } +void MainWindow::onROMInfo() +{ + ROMInfoDialog* dlg = ROMInfoDialog::openDlg(this); +} void MainWindow::onOpenEmuSettings() { @@ -2589,6 +2600,8 @@ void MainWindow::onEmuStart() actImportSavefile->setEnabled(true); actSetupCheats->setEnabled(true); + + actROMInfo->setEnabled(true); } void MainWindow::onEmuStop() @@ -2609,6 +2622,8 @@ void MainWindow::onEmuStop() actFrameStep->setEnabled(false); actSetupCheats->setEnabled(false); + + actROMInfo->setEnabled(false); } void MainWindow::onUpdateVideoSettings(bool glchange) diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 024af8a..9d9e40e 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -235,6 +235,7 @@ private slots: void onEnableCheats(bool checked); void onSetupCheats(); void onCheatsDialogFinished(int res); + void onROMInfo(); void onOpenEmuSettings(); void onEmuSettingsDialogFinished(int res); @@ -310,6 +311,7 @@ public: QAction* actFrameStep; QAction* actEnableCheats; QAction* actSetupCheats; + QAction* actROMInfo; QAction* actEmuSettings; QAction* actInputConfig; -- cgit v1.2.3