diff --git a/src/GBACart.cpp b/src/GBACart.cpp index 34e6fb60..c1eb1107 100644 --- a/src/GBACart.cpp +++ b/src/GBACart.cpp @@ -487,11 +487,7 @@ void CartGame::SRAMWrite_FLASH(u32 addr, u8 val) u32 start_addr = addr + 0x10000 * SRAMFlashState.bank; memset((u8*)&SRAM[start_addr], 0xFF, 0x1000); - /*if (SRAMFile) - { - fseek(SRAMFile, start_addr, SEEK_SET); - fwrite((u8*)&SRAM[start_addr], 1, 0x1000, SRAMFile); - }*/ + Platform::WriteGBASave(SRAM, SRAMLength, start_addr, 0x1000); } SRAMFlashState.state = 0; SRAMFlashState.cmd = 0; @@ -549,11 +545,8 @@ void CartGame::SRAMWrite_SRAM(u32 addr, u8 val) { *(u8*)&SRAM[addr] = val; - /*if (SRAMFile) - { - fseek(SRAMFile, addr, SEEK_SET); - fwrite((u8*)&SRAM[addr], 1, 1, SRAMFile); - }*/ + // TODO: optimize this!! + Platform::WriteGBASave(SRAM, SRAMLength, addr, 1); } } diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index ebfe6af6..0197264c 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -381,7 +381,8 @@ void WriteNDSSave(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen void WriteGBASave(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen) { - // + if (ROMManager::GBASave) + ROMManager::GBASave->RequestFlush(savedata, savelen, writeoffset, writelen); } diff --git a/src/frontend/qt_sdl/ROMManager.cpp b/src/frontend/qt_sdl/ROMManager.cpp index 650b87a5..6c58b74a 100644 --- a/src/frontend/qt_sdl/ROMManager.cpp +++ b/src/frontend/qt_sdl/ROMManager.cpp @@ -46,6 +46,7 @@ std::string BaseAssetName = ""; int GBACartType = -1; SaveManager* NDSSave = nullptr; +SaveManager* GBASave = nullptr; int LastSep(std::string path) @@ -300,7 +301,6 @@ bool LoadROM(QStringList filepath, bool reset) u8* filedata; u32 filelen; - std::string fullpath; std::string basepath; std::string romname; @@ -334,8 +334,6 @@ bool LoadROM(QStringList filepath, bool reset) fclose(f); filelen = (u32)len; - fullpath = filename; - int pos = LastSep(filename); basepath = filename.substr(0, pos); romname = filename.substr(pos+1); @@ -359,8 +357,6 @@ bool LoadROM(QStringList filepath, bool reset) std::string std_romname = filepath.at(1).toStdString(); romname = std_romname.substr(LastSep(std_romname)+1); - - fullpath = std_archivepath + "//" + std_romname; } #endif else @@ -369,7 +365,7 @@ bool LoadROM(QStringList filepath, bool reset) if (NDSSave) delete NDSSave; NDSSave = nullptr; - FullROMPath = fullpath; + FullROMPath = filepath.join('|').toStdString(); BaseROMDir = basepath; BaseROMName = romname; BaseAssetName = romname.substr(0, romname.rfind('.')); diff --git a/src/frontend/qt_sdl/ROMManager.h b/src/frontend/qt_sdl/ROMManager.h index c6e7837a..638be3f5 100644 --- a/src/frontend/qt_sdl/ROMManager.h +++ b/src/frontend/qt_sdl/ROMManager.h @@ -29,6 +29,7 @@ namespace ROMManager { extern SaveManager* NDSSave; +extern SaveManager* GBASave; QString VerifySetup(); void Reset(); diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 5f340522..0b211b6b 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -546,6 +546,9 @@ void EmuThread::run() if (ROMManager::NDSSave) ROMManager::NDSSave->CheckFlush(); + if (ROMManager::GBASave) + ROMManager::GBASave->CheckFlush(); + FrontBufferLock.lock(); FrontBuffer = GPU::FrontBuffer; #ifdef OGLRENDERER_ENABLED @@ -1883,7 +1886,7 @@ void MainWindow::onAppStateChanged(Qt::ApplicationState state) QString MainWindow::loadErrorStr(int error) { - switch (error) + /*switch (error) { case Frontend::Load_BIOS9Missing: return "DS ARM9 BIOS was not found or could not be accessed. Check your emu settings."; @@ -1921,7 +1924,8 @@ QString MainWindow::loadErrorStr(int error) return "Failed to load the ROM. Make sure the file is accessible and isn't used by another application."; default: return "Unknown error during launch; smack Arisotura."; - } + }*/ + return "REMOVE ME"; } /*void MainWindow::loadROM(QByteArray *romData, QString archiveFileName, QString romFileName) @@ -2146,8 +2150,6 @@ void MainWindow::onOpenFile() return; } - // TODO: add to recent ROM list - if (!ROMManager::LoadROM(file, true)) { // TODO: better error reporting? @@ -2156,6 +2158,11 @@ void MainWindow::onOpenFile() return; } + QString filename = file.join('|'); + recentFileList.removeAll(filename); + recentFileList.prepend(filename); + updateRecentFilesMenu(); + NDS::Start(); emuThread->emuRun(); @@ -2229,8 +2236,10 @@ void MainWindow::updateRecentFilesMenu() { recentMenu->clear(); - for(int i = 0; i < recentFileList.size(); ++i) + for (int i = 0; i < recentFileList.size(); ++i) { + if (i >= 10) break; + QString item_full = recentFileList.at(i); QString item_display = item_full; int itemlen = item_full.length(); @@ -2257,16 +2266,18 @@ void MainWindow::updateRecentFilesMenu() actRecentFile_i->setData(item_full); connect(actRecentFile_i, &QAction::triggered, this, &MainWindow::onClickRecentFile); - if (i < 10) - Config::RecentROMList[i] = recentFileList.at(i).toStdString(); + Config::RecentROMList[i] = recentFileList.at(i).toStdString(); } + while (recentFileList.size() > 10) + recentFileList.removeLast(); + recentMenu->addSeparator(); QAction *actClearRecentList = recentMenu->addAction("Clear"); connect(actClearRecentList, &QAction::triggered, this, &MainWindow::onClearRecentFiles); - if(recentFileList.empty()) + if (recentFileList.empty()) actClearRecentList->setEnabled(false); Config::Save(); @@ -2274,29 +2285,35 @@ void MainWindow::updateRecentFilesMenu() void MainWindow::onClickRecentFile() { - /*QAction *act = (QAction *)sender(); - QString fileName = act->data().toString(); + QAction *act = (QAction *)sender(); + QString filename = act->data().toString(); + QStringList file = filename.split('|'); - if (fileName.endsWith(".gba", Qt::CaseInsensitive) || - fileName.endsWith(".nds", Qt::CaseInsensitive) || - fileName.endsWith(".srl", Qt::CaseInsensitive) || - fileName.endsWith(".dsi", Qt::CaseInsensitive)) + emuThread->emuPause(); + + if (!verifySetup()) { - emuThread->emuPause(); - loadROM(fileName); + emuThread->emuUnpause(); + return; } - else + + if (!ROMManager::LoadROM(file, true)) { - // Archives - QString archiveFileName = fileName; - QByteArray romBuffer; - QString romFileName = MainWindow::pickAndExtractFileFromArchive(archiveFileName, &romBuffer); - if(!romFileName.isEmpty()) - { - emuThread->emuPause(); - loadROM(&romBuffer, archiveFileName, romFileName); - } - }*/ + // TODO: better error reporting? + QMessageBox::critical(this, "melonDS", "Failed to load the ROM."); + emuThread->emuUnpause(); + return; + } + + recentFileList.removeAll(filename); + recentFileList.prepend(filename); + updateRecentFilesMenu(); + + NDS::Start(); + emuThread->emuRun(); + + actCurrentCart->setText("DS slot: " + ROMManager::CartLabel()); + actEjectCart->setEnabled(true); } void MainWindow::onBootFirmware()