From b0a22e4ce9be1f38707332b7ff4b1beab60d637f Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 4 Jan 2022 02:10:06 +0100 Subject: [PATCH] re-add 'open file' event, whatever that is also remove a bunch of cruft --- src/GBACart.cpp | 32 ------ src/GBACart.h | 7 -- src/NDS.cpp | 62 ---------- src/NDSCart.cpp | 217 ----------------------------------- src/NDSCart.h | 15 --- src/frontend/qt_sdl/main.cpp | 70 ++--------- src/frontend/qt_sdl/main.h | 2 +- 7 files changed, 9 insertions(+), 396 deletions(-) diff --git a/src/GBACart.cpp b/src/GBACart.cpp index c1eb1107..7ae58831 100644 --- a/src/GBACart.cpp +++ b/src/GBACart.cpp @@ -76,14 +76,6 @@ void CartCommon::LoadSave(const u8* savedata, u32 savelen) { } -/*void CartCommon::LoadSave(const char* path, u32 type) -{ -} - -void CartCommon::RelocateSave(const char* path, bool write) -{ -}*/ - int CartCommon::SetInput(int num, bool pressed) { return -1; @@ -116,7 +108,6 @@ CartGame::CartGame(u8* rom, u32 len) : CartCommon() CartGame::~CartGame() { - //if (SRAMFile) fclose(SRAMFile); if (SRAM) delete[] SRAM; } @@ -125,7 +116,6 @@ void CartGame::Reset() memset(&GPIO, 0, sizeof(GPIO)); SRAM = nullptr; - //SRAMFile = nullptr; SRAMLength = 0; SRAMType = S_NULL; SRAMFlashState = {}; @@ -237,28 +227,6 @@ void CartGame::LoadSave(const u8* savedata, u32 savelen) memcpy(SRAM, savedata, std::min(savelen, SRAMLength)); } -/*void CartGame::RelocateSave(const char* path, bool write) -{ - if (!write) - { - LoadSave(path, 0); // lazy - return; - } - - strncpy(SRAMPath, path, 1023); - SRAMPath[1023] = '\0'; - - FILE *f = Platform::OpenFile(path, "r+b"); - if (!f) - { - printf("GBACart_SRAM::RelocateSave: failed to create new file. fuck\n"); - return; - } - - SRAMFile = f; - fwrite(SRAM, SRAMLength, 1, SRAMFile); -}*/ - u16 CartGame::ROMRead(u32 addr) { addr &= 0x01FFFFFF; diff --git a/src/GBACart.h b/src/GBACart.h index b5d2ba11..eae3fd90 100644 --- a/src/GBACart.h +++ b/src/GBACart.h @@ -37,8 +37,6 @@ public: virtual void SetupSave(u32 type); virtual void LoadSave(const u8* savedata, u32 savelen); - //virtual void LoadSave(const char* path, u32 type); - //virtual void RelocateSave(const char* path, bool write); virtual int SetInput(int num, bool pressed); @@ -61,8 +59,6 @@ public: virtual void SetupSave(u32 type) override; virtual void LoadSave(const u8* savedata, u32 savelen) override; - //virtual void LoadSave(const char* path, u32 type) override; - //virtual void RelocateSave(const char* path, bool write) override; virtual u16 ROMRead(u32 addr) override; virtual void ROMWrite(u32 addr, u16 val) override; @@ -113,11 +109,8 @@ protected: } SRAMFlashState; u8* SRAM; - //FILE* SRAMFile; u32 SRAMLength; SaveType SRAMType; - - //char SRAMPath[1024]; }; // CartGameSolarSensor -- Boktai game cart diff --git a/src/NDS.cpp b/src/NDS.cpp index 3faed85a..1b913b53 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -957,73 +957,11 @@ void EjectGBACart() GBACart::EjectCart(); } -/*bool LoadROM(const u8* romdata, u32 filelength, const char *sram, bool direct) -{ - if (NDSCart::LoadROM(romdata, filelength, sram, direct)) - { - Running = true; - return true; - } - else - { - printf("Failed to load ROM from archive\n"); - return false; - } -} - -bool LoadROM(const char* path, const char* sram, bool direct) -{ - if (NDSCart::LoadROM(path, sram, direct)) - { - Running = true; - return true; - } - else - { - printf("Failed to load ROM %s\n", path); - return false; - } -} - -bool LoadGBAROM(const char* path, const char* sram) -{ - if (GBACart::LoadROM(path, sram)) - { - return true; - } - else - { - printf("Failed to load ROM %s\n", path); - return false; - } -} - -bool LoadGBAROM(const u8* romdata, u32 filelength, const char *filename, const char *sram) -{ - if (GBACart::LoadROM(romdata, filelength, sram)) - { - return true; - } - else - { - printf("Failed to load ROM %s from archive\n", filename); - return false; - } -}*/ - void LoadBIOS() { Reset(); - //Running = true; } -/*void RelocateSave(const char* path, bool write) -{ - printf("SRAM: relocating to %s (write=%s)\n", path, write?"true":"false"); - NDSCart::RelocateSave(path, write); -}*/ - - u64 NextTarget() { diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index c24111a3..f806fff7 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -51,7 +51,6 @@ u32 TransferDir; u8 TransferCmd[8]; bool CartInserted; -//char CartName[256]; u8* CartROM; u32 CartROMSize; u32 CartID; @@ -220,19 +219,6 @@ void CartCommon::LoadSave(const u8* savedata, u32 savelen) { } -/*void CartCommon::RelocateSave(const char* path, bool write) -{ -} - -int CartCommon::ImportSRAM(const u8* data, u32 length) -{ - return 0; -} - -void CartCommon::FlushSRAMFile() -{ -}*/ - int CartCommon::ROMCommandStart(u8* cmd, u8* data, u32 len) { if (CmdEncMode == 0) @@ -479,101 +465,6 @@ void CartRetail::LoadSave(const u8* savedata, u32 savelen) memcpy(SRAM, savedata, std::min(savelen, SRAMLength)); } -/*void CartRetail::LoadSave(const char* path, u32 type) -{ - if (SRAM) delete[] SRAM; - - strncpy(SRAMPath, path, 1023); - SRAMPath[1023] = '\0'; - - if (type > 10) type = 0; - int sramlen[] = - { - 0, - 512, - 8192, 65536, 128*1024, - 256*1024, 512*1024, 1024*1024, - 8192*1024, 16384*1024, 65536*1024 - }; - SRAMLength = sramlen[type]; - - if (SRAMLength) - { - SRAM = new u8[SRAMLength]; - memset(SRAM, 0xFF, SRAMLength); - } - - FILE* f = Platform::OpenFile(path, "rb"); - if (f) - { - fseek(f, 0, SEEK_SET); - fread(SRAM, 1, SRAMLength, f); - - fclose(f); - } - - SRAMFileDirty = false; - NDSCart_SRAMManager::Setup(path, SRAM, SRAMLength); - - switch (type) - { - case 1: SRAMType = 1; break; // EEPROM, small - case 2: - case 3: - case 4: SRAMType = 2; break; // EEPROM, regular - case 5: - case 6: - case 7: SRAMType = 3; break; // FLASH - case 8: - case 9: - case 10: SRAMType = 4; break; // NAND - default: SRAMType = 0; break; // ...whatever else - } -}*/ - -/*void CartRetail::RelocateSave(const char* path, bool write) -{ - if (!write) - { - LoadSave(path, 0); // lazy - return; - } - - strncpy(SRAMPath, path, 1023); - SRAMPath[1023] = '\0'; - - FILE* f = Platform::OpenFile(path, "wb"); - if (!f) - { - printf("NDSCart_SRAM::RelocateSave: failed to create new file. fuck\n"); - return; - } - - fwrite(SRAM, SRAMLength, 1, f); - fclose(f); -} - -int CartRetail::ImportSRAM(const u8* data, u32 length) -{ - memcpy(SRAM, data, std::min(length, SRAMLength)); - FILE* f = Platform::OpenFile(SRAMPath, "wb"); - if (f) - { - fwrite(SRAM, SRAMLength, 1, f); - fclose(f); - } - - return length - SRAMLength; -} - -void CartRetail::FlushSRAMFile() -{ - if (!SRAMFileDirty) return; - - SRAMFileDirty = false; - NDSCart_SRAMManager::RequestFlush(); -}*/ - int CartRetail::ROMCommandStart(u8* cmd, u8* data, u32 len) { if (CmdEncMode != 2) return CartCommon::ROMCommandStart(cmd, data, len); @@ -968,13 +859,6 @@ void CartRetailNAND::LoadSave(const u8* savedata, u32 savelen) BuildSRAMID(); } -/*int CartRetailNAND::ImportSRAM(const u8* data, u32 length) -{ - int ret = CartRetail::ImportSRAM(data, length); - BuildSRAMID(); - return ret; -}*/ - int CartRetailNAND::ROMCommandStart(u8* cmd, u8* data, u32 len) { if (CmdEncMode != 2) return CartCommon::ROMCommandStart(cmd, data, len); @@ -1542,15 +1426,6 @@ void DeInit() void Reset() { - /*if (Cart) delete Cart; - Cart = nullptr; - - CartInserted = false; - if (CartROM) delete[] CartROM; - CartROM = nullptr; - CartROMSize = 0; - CartID = 0;*/ - ResetCart(); } @@ -1656,7 +1531,6 @@ void DecryptSecureArea(u8* out) } } -//bool LoadROMCommon(u32 filelength, const char *sram, bool direct) bool LoadROM(const u8* romdata, u32 romlen) { if (CartInserted) @@ -1780,22 +1654,7 @@ bool LoadROM(const u8* romdata, u32 romlen) if (Cart) Cart->Reset(); - /*{ - Cart->Reset(); - if (direct) - { - NDS::SetupDirectBoot(); - Cart->SetupDirectBoot(); - } - }*/ - // encryption - // needed???? - //Key1_InitKeycode(false, gamecode, 2, 2); - - // save - //printf("Save file: %s\n", sram); - //if (Cart) Cart->LoadSave(sram, romparams.SaveMemType); if (Cart && romparams.SaveMemType > 0) Cart->SetupSave(romparams.SaveMemType); @@ -1808,88 +1667,12 @@ void LoadSave(const u8* savedata, u32 savelen) Cart->LoadSave(savedata, savelen); } -/*bool LoadROM(const char* path, const char* sram, bool direct) -{ - // TODO: streaming mode? for really big ROMs or systems with limited RAM - // for now we're lazy - // also TODO: validate what we're loading!! - - FILE* f = Platform::OpenFile(path, "rb"); - if (!f) - { - return false; - } - - NDS::Reset(); - - char* romname = strrchr((char*)path, '/'); - if (!romname) - { - romname = strrchr((char*)path, '\\'); - if (!romname) - romname = (char*)&path[-1]; - } - romname++; - strncpy(CartName, romname, 255); CartName[255] = '\0'; - - fseek(f, 0, SEEK_END); - u32 len = (u32)ftell(f); - - CartROMSize = 0x200; - while (CartROMSize < len) - CartROMSize <<= 1; - - CartROM = new u8[CartROMSize]; - memset(CartROM, 0, CartROMSize); - fseek(f, 0, SEEK_SET); - fread(CartROM, 1, len, f); - - fclose(f); - - return LoadROMCommon(len, sram, direct); -} - -bool LoadROM(const u8* romdata, u32 filelength, const char *sram, bool direct) -{ - NDS::Reset(); - - // TODO: make it more meaningful? - strncpy(CartName, "rom.nds", 256); - - u32 len = filelength; - CartROMSize = 0x200; - while (CartROMSize < len) - CartROMSize <<= 1; - - CartROM = new u8[CartROMSize]; - memset(CartROM, 0, CartROMSize); - memcpy(CartROM, romdata, filelength); - - return LoadROMCommon(filelength, sram, direct); -}*/ - void SetupDirectBoot(std::string romname) { if (Cart) Cart->SetupDirectBoot(romname); } -/*void RelocateSave(const char* path, bool write) -{ - if (Cart) Cart->RelocateSave(path, write); -} - -void FlushSRAMFile() -{ - if (Cart) Cart->FlushSRAMFile(); -} - -int ImportSRAM(const u8* data, u32 length) -{ - if (Cart) return Cart->ImportSRAM(data, length); - return 0; -}*/ - void EjectCart() { if (!CartInserted) return; diff --git a/src/NDSCart.h b/src/NDSCart.h index 37290ee1..0d83ce1a 100644 --- a/src/NDSCart.h +++ b/src/NDSCart.h @@ -42,9 +42,6 @@ public: virtual void SetupSave(u32 type); virtual void LoadSave(const u8* savedata, u32 savelen); - //virtual void RelocateSave(const char* path, bool write); - //virtual int ImportSRAM(const u8* data, u32 length); - //virtual void FlushSRAMFile(); virtual int ROMCommandStart(u8* cmd, u8* data, u32 len); virtual void ROMCommandFinish(u8* cmd, u8* data, u32 len); @@ -80,9 +77,6 @@ public: virtual void SetupSave(u32 type) override; virtual void LoadSave(const u8* savedata, u32 savelen) override; - //virtual void RelocateSave(const char* path, bool write) override; - //virtual int ImportSRAM(const u8* data, u32 length) override; - //virtual void FlushSRAMFile() override; virtual int ROMCommandStart(u8* cmd, u8* data, u32 len) override; @@ -117,7 +111,6 @@ public: void DoSavestate(Savestate* file) override; void LoadSave(const u8* savedata, u32 savelen) override; - //int ImportSRAM(const u8* data, u32 length) override; int ROMCommandStart(u8* cmd, u8* data, u32 len) override; void ROMCommandFinish(u8* cmd, u8* data, u32 len) override; @@ -210,8 +203,6 @@ void Reset(); void DoSavestate(Savestate* file); void DecryptSecureArea(u8* out); -//bool LoadROM(const char* path, const char* sram, bool direct); -//bool LoadROM(const u8* romdata, u32 filelength, const char *sram, bool direct); bool LoadROM(const u8* romdata, u32 romlen); void LoadSave(const u8* savedata, u32 savelen); @@ -219,12 +210,6 @@ void SetupDirectBoot(std::string romname); void EjectCart(); -//void FlushSRAMFile(); - -//void RelocateSave(const char* path, bool write); - -//int ImportSRAM(const u8* data, u32 length); - void ResetCart(); void WriteROMCnt(u32 val); diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 1b6e7466..cebe74f9 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1891,11 +1891,11 @@ bool MainWindow::verifySetup() return true; } -void MainWindow::preloadROMs(QString filename, QString gbafilename) +bool MainWindow::preloadROMs(QString filename, QString gbafilename) { if (!verifySetup()) { - return; + return false; } bool gbaloaded = false; @@ -1906,7 +1906,7 @@ void MainWindow::preloadROMs(QString filename, QString gbafilename) { // TODO: better error reporting? QMessageBox::critical(this, "melonDS", "Failed to load the GBA ROM."); - return; + return false; } gbaloaded = true; @@ -1917,7 +1917,7 @@ void MainWindow::preloadROMs(QString filename, QString gbafilename) { // TODO: better error reporting? QMessageBox::critical(this, "melonDS", "Failed to load the ROM."); - return; + return false; } recentFileList.removeAll(filename); @@ -1935,6 +1935,8 @@ void MainWindow::preloadROMs(QString filename, QString gbafilename) actCurrentGBACart->setText("GBA slot: " + ROMManager::GBACartLabel()); actEjectGBACart->setEnabled(true); } + + return true; } QString MainWindow::pickFileFromArchive(QString archiveFileName) @@ -2071,60 +2073,6 @@ void MainWindow::onOpenFile() actEjectCart->setEnabled(true); } -/*QString MainWindow::pickAndExtractFileFromArchive(QString archiveFileName, QByteArray *romBuffer) -{ - printf("Finding list of ROMs...\n"); - QVector archiveROMList = Archive::ListArchive(archiveFileName.toUtf8().constData()); - - - QString romFileName = ""; // file name inside archive - - if (archiveROMList.size() > 2) - { - archiveROMList.removeFirst(); - - bool ok; - QString toLoad = QInputDialog::getItem(this, "melonDS", - "The archive was found to have multiple files. Select which ROM you want to load.", archiveROMList.toList(), 0, false, &ok); - if (!ok) // User clicked on cancel - return QString(); - - printf("Extracting '%s'\n", toLoad.toUtf8().constData()); - QVector extractResult = Archive::ExtractFileFromArchive(archiveFileName.toUtf8().constData(), toLoad.toUtf8().constData(), romBuffer); - if (extractResult[0] != QString("Err")) - { - romFileName = extractResult[0]; - } - else - { - QMessageBox::critical(this, "melonDS", QString("There was an error while trying to extract the ROM from the archive: ") + extractResult[1]); - } - } - else if (archiveROMList.size() == 2) - { - printf("Extracting the only ROM in archive\n"); - QVector extractResult = Archive::ExtractFileFromArchive(archiveFileName.toUtf8().constData(), archiveROMList.at(1).toUtf8().constData(), romBuffer); - if (extractResult[0] != QString("Err")) - { - romFileName = extractResult[0]; - } - else - { - QMessageBox::critical(this, "melonDS", QString("There was an error while trying to extract the ROM from the archive: ") + extractResult[1]); - } - } - else if ((archiveROMList.size() == 1) && (archiveROMList[0] == QString("OK"))) - { - QMessageBox::warning(this, "melonDS", "The archive is intact, but there are no files inside."); - } - else - { - QMessageBox::critical(this, "melonDS", "The archive could not be read. It may be corrupt or you don't have the permissions."); - } - - return romFileName; -}*/ - void MainWindow::onClearRecentFiles() { recentFileList.clear(); @@ -2219,8 +2167,6 @@ void MainWindow::onClickRecentFile() void MainWindow::onBootFirmware() { - // TODO: check the whole GBA cart shito - emuThread->emuPause(); if (!verifySetup()) @@ -2943,8 +2889,8 @@ bool MelonApplication::event(QEvent *event) QFileOpenEvent *openEvent = static_cast(event); emuThread->emuPause(); - //mainWindow->loadROM(openEvent->file()); - printf("ASS EVENT???\n"); + if (!mainWindow->preloadROMs(openEvent->file(), "")) + emuThread->emuUnpause(); } return QApplication::event(event); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index fa21892d..a4df7d19 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -210,7 +210,7 @@ public: bool hasOGL; QOpenGLContext* getOGLContext(); - void preloadROMs(QString filename, QString gbafilename); + bool preloadROMs(QString filename, QString gbafilename); void onAppStateChanged(Qt::ApplicationState state);