mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-21 05:09:46 -06:00
Split the cart parsing and loading steps (#1707)
* Split ROMList into a .cpp file - Its definition in ROMList.h was causing multiple-definition linker errors - Introduce ROMListSize, since you can't take a sizeof() of an extern declaration - Mark ROMList and ROMListSize as const * Update ReadROMParams to accommodate ROMList changes * Split parsing and loading of NDS ROMs - Introduce an NDSCartData class for parsing a ROM file - Introduce InsertROM for loading a NDS cart - Refactor LoadROM to use NDSCartData and InsertROM under the hood * Reset cart state and initialize save memory in the NDSCartData constructor - Otherwise there's no way to know about SRAM-specific attributes before inserting the game * Add a comment to NDSCartData * First crack at splitting parsing and loading for GBACart * Add some logging calls for encrypting the secure area * Log the XXH64 hash of the inserted NDS ROM * Log the XXH64 hash of the secure area after decryption * Add some logging to Key1_LoadKeyBuf * Re-encrypt the secure area when inserting the cart, not when parsing it - This way, constructing a NDSCart doesn't imply a read from the filesystem (as is done in Key1_KeyBuf) * Load Key1_KeyBuf from memory, not from the file system - Now that the cart's secure area isn't re-encrypted until insertion, we can expect that the BIOS will be ready at this point * Add some helper query methods to NDSHeader * Query the DSi region directly from the header instead of checking the ROM again * Introduce a CartType enum - So CartCommon::Type doesn't have to return magic numbers * Reset the cart in NDSCart::InsertROM instead of the NDSCartData constructor - That way the constructor doesn't rely on the config or on file I/O when loading homebrew - This keeps the use of global state closer to one place * Add non-const getters for the carts * Add InsertROM overloads that accept unique_ptrs * Fix a comment * Rename member functions on NDSCartData and GBACartData to adhere to the convention * Rename members on NDSCartData and GBACartData to adhere to the convention * Fix build errors on some platforms * Add NDSHeader::IsDSiWare * Add a ROMListEntry parameter to the cart constructors - To allow for looking up details of SRAM or expected ROM size * Add some new getters to CartCommon * Use the Header/Banner members instead of globals * Make CartCommon abstract - It's not supposed to be instantiated anyway * Change the signature of CartCommon::Checksum - It's neither overridden nor mutating * Add some clarifying comments to NDSHeader * Delete CartCommon::ROM in its destructor - ParseROM copies its input and gives that copy to the cart object, so it's okay * Add some getters to CartCommon * Refactor NDSCart - Get rid of NDSCartData - Get rid of cart-specific global state within NDSCart (so registers are untouched) - Refactor uses of removed global variables to use the Cart pointer instead - Refactor ROMInfoDialog's icon functions to accept const arguments * Return the cart pointer - So *that's* why it was crashing. Whoops - Why is this even allowed? * Refactor GBACart - Delete CartGame::ROM in the destructor - Get rid of GBACartData - Remove some global state * Mark NDSCart::CartCommon::Type as const * Slightly refactor GBACart::CartCommon - Mark Type as const - Use enum constants - Make CartCommon itself abstract * Mark CRC32's data parameter as const * Mark GBACart::CartCommon::Checksum as const * Use assert.h instead of cassert - As demanded by the style guide * Fix some includes to adhere to the style guide * Get the ARM9 entry address directly from the header object * Use more Header fields directly * Rename some parameters to match the style guide * Remove some unused includes * Slightly change NDS_Header::IsHomebrew for clarity
This commit is contained in:

committed by
GitHub

parent
7b948e6ec9
commit
b659bce3c1
@ -43,16 +43,17 @@ ROMInfoDialog::ROMInfoDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ROMI
|
||||
ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
|
||||
const NDSBanner* banner = NDSCart::Cart->Banner();
|
||||
const NDSHeader& header = NDSCart::Cart->GetHeader();
|
||||
u32 iconData[32 * 32];
|
||||
ROMManager::ROMIcon(NDSCart::Banner.Icon, NDSCart::Banner.Palette, iconData);
|
||||
ROMManager::ROMIcon(banner->Icon, banner->Palette, iconData);
|
||||
iconImage = QImage(reinterpret_cast<unsigned char*>(iconData), 32, 32, QImage::Format_ARGB32).copy();
|
||||
ui->iconImage->setPixmap(QPixmap::fromImage(iconImage));
|
||||
|
||||
if (NDSCart::Banner.Version == 0x103)
|
||||
if (banner->Version == 0x103)
|
||||
{
|
||||
u32 animatedIconData[32 * 32 * 64] = {0};
|
||||
ROMManager::AnimatedROMIcon(NDSCart::Banner.DSiIcon, NDSCart::Banner.DSiPalette, NDSCart::Banner.DSiSequence, animatedIconData, animatedSequence);
|
||||
ROMManager::AnimatedROMIcon(banner->DSiIcon, banner->DSiPalette, banner->DSiSequence, animatedIconData, animatedSequence);
|
||||
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
@ -73,44 +74,44 @@ ROMInfoDialog::ROMInfoDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ROMI
|
||||
ui->dsiIconImage->setPixmap(QPixmap::fromImage(iconImage));
|
||||
}
|
||||
|
||||
ui->iconTitle->setText(QString::fromUtf16(NDSCart::Banner.EnglishTitle));
|
||||
ui->iconTitle->setText(QString::fromUtf16(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));
|
||||
ui->japaneseTitle->setText(QString::fromUtf16(banner->JapaneseTitle));
|
||||
ui->englishTitle->setText(QString::fromUtf16(banner->EnglishTitle));
|
||||
ui->frenchTitle->setText(QString::fromUtf16(banner->FrenchTitle));
|
||||
ui->germanTitle->setText(QString::fromUtf16(banner->GermanTitle));
|
||||
ui->italianTitle->setText(QString::fromUtf16(banner->ItalianTitle));
|
||||
ui->spanishTitle->setText(QString::fromUtf16(banner->SpanishTitle));
|
||||
|
||||
if (NDSCart::Banner.Version > 1)
|
||||
ui->chineseTitle->setText(QString::fromUtf16(NDSCart::Banner.ChineseTitle));
|
||||
if (banner->Version > 1)
|
||||
ui->chineseTitle->setText(QString::fromUtf16(banner->ChineseTitle));
|
||||
else
|
||||
ui->chineseTitle->setText("None");
|
||||
|
||||
if (NDSCart::Banner.Version > 2)
|
||||
ui->koreanTitle->setText(QString::fromUtf16(NDSCart::Banner.KoreanTitle));
|
||||
if (banner->Version > 2)
|
||||
ui->koreanTitle->setText(QString::fromUtf16(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->gameTitle->setText(QString::fromLatin1(header.GameTitle, 12));
|
||||
ui->gameCode->setText(QString::fromLatin1(header.GameCode, 4));
|
||||
ui->makerCode->setText(QString::fromLatin1(header.MakerCode, 2));
|
||||
ui->cardSize->setText(QString::number(128 << 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->arm9RomOffset->setText(IntToHex(header.ARM9ROMOffset));
|
||||
ui->arm9EntryAddress->setText(IntToHex(header.ARM9EntryAddress));
|
||||
ui->arm9RamAddress->setText(IntToHex(header.ARM9RAMAddress));
|
||||
ui->arm9Size->setText(QStringBytes(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->arm7RomOffset->setText(IntToHex(header.ARM7ROMOffset));
|
||||
ui->arm7EntryAddress->setText(IntToHex(header.ARM7EntryAddress));
|
||||
ui->arm7RamAddress->setText(IntToHex(header.ARM7RAMAddress));
|
||||
ui->arm7Size->setText(QStringBytes(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));
|
||||
ui->fntOffset->setText(IntToHex(header.FNTOffset));
|
||||
ui->fntSize->setText(QStringBytes(header.FNTSize));
|
||||
ui->fatOffset->setText(IntToHex(header.FATOffset));
|
||||
ui->fatSize->setText(QStringBytes(header.FATSize));
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user