re-add SRAM import

This commit is contained in:
Arisotura 2022-01-04 12:02:52 +01:00
parent 5c924c9f01
commit 7c104310d7
5 changed files with 54 additions and 83 deletions

View File

@ -224,7 +224,9 @@ void CartGame::LoadSave(const u8* savedata, u32 savelen)
{
if (!SRAM) return;
memcpy(SRAM, savedata, std::min(savelen, SRAMLength));
u32 len = std::min(savelen, SRAMLength);
memcpy(SRAM, savedata, len);
Platform::WriteGBASave(savedata, len, 0, len);
}
u16 CartGame::ROMRead(u32 addr)
@ -744,7 +746,6 @@ void DoSavestate(Savestate* file)
if (Cart) Cart->DoSavestate(file);
}
//void LoadROMCommon(const char *sram)
bool LoadROM(const u8* romdata, u32 romlen)
{
if (CartInserted)
@ -852,56 +853,6 @@ void EjectCart()
CartID = 0;
}
/*bool LoadROM(const char* path, const char* sram)
{
FILE* f = Platform::OpenFile(path, "rb");
if (!f)
{
return false;
}
if (CartInserted)
{
Reset();
}
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);
LoadROMCommon(sram);
return true;
}
bool LoadROM(const u8* romdata, u32 filelength, const char *sram)
{
CartROMSize = 0x200;
while (CartROMSize < filelength)
CartROMSize <<= 1;
CartROM = new u8[CartROMSize];
memcpy(CartROM, romdata, filelength);
LoadROMCommon(sram);
return true;
}
void RelocateSave(const char* path, bool write)
{
if (Cart) Cart->RelocateSave(path, write);
}*/
int SetInput(int num, bool pressed)
{

View File

@ -926,6 +926,12 @@ bool LoadCart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen)
return true;
}
void LoadSave(const u8* savedata, u32 savelen)
{
if (savedata && savelen)
NDSCart::LoadSave(savedata, savelen);
}
void EjectCart()
{
NDSCart::EjectCart();

View File

@ -238,13 +238,10 @@ void SetARM7RegionTimings(u32 addrstart, u32 addrend, u32 region, int buswidth,
// 0=DS 1=DSi
void SetConsoleType(int type);
/*bool LoadROM(const char* path, const char* sram, bool direct);
bool LoadROM(const u8* romdata, u32 filelength, const char *sram, bool direct);
bool LoadGBAROM(const char* path, const char* sram);
bool LoadGBAROM(const u8* romdata, u32 filelength, const char *filename, const char *sram);*/
void LoadBIOS();
bool LoadCart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen);
void LoadSave(const u8* savedata, u32 savelen);
void EjectCart();
bool CartInserted();
@ -255,8 +252,6 @@ bool LoadGBACart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen)
void LoadGBAAddon(int type);
void EjectGBACart();
//void RelocateSave(const char* path, bool write);
u32 RunFrame();
void TouchScreen(u16 x, u16 y);
@ -269,8 +264,6 @@ void SetLidClosed(bool closed);
void MicInputFrame(s16* data, int samples);
//int ImportSRAM(u8* data, u32 length);
void ScheduleEvent(u32 id, bool periodic, s32 delay, void (*func)(u32), u32 param);
void CancelEvent(u32 id);

View File

@ -473,7 +473,9 @@ void CartRetail::LoadSave(const u8* savedata, u32 savelen)
{
if (!SRAM) return;
memcpy(SRAM, savedata, std::min(savelen, SRAMLength));
u32 len = std::min(savelen, SRAMLength);
memcpy(SRAM, savedata, len);
Platform::WriteNDSSave(savedata, len, 0, len);
}
int CartRetail::ROMCommandStart(u8* cmd, u8* data, u32 len)

View File

@ -1862,6 +1862,7 @@ void MainWindow::dropEvent(QDropEvent* event)
actCurrentCart->setText("DS slot: " + ROMManager::CartLabel());
actEjectCart->setEnabled(true);
actImportSavefile->setEnabled(true);
}
}
@ -1929,6 +1930,7 @@ bool MainWindow::preloadROMs(QString filename, QString gbafilename)
actCurrentCart->setText("DS slot: " + ROMManager::CartLabel());
actEjectCart->setEnabled(true);
actImportSavefile->setEnabled(true);
if (gbaloaded)
{
@ -2071,6 +2073,7 @@ void MainWindow::onOpenFile()
actCurrentCart->setText("DS slot: " + ROMManager::CartLabel());
actEjectCart->setEnabled(true);
actImportSavefile->setEnabled(true);
}
void MainWindow::onClearRecentFiles()
@ -2163,6 +2166,7 @@ void MainWindow::onClickRecentFile()
actCurrentCart->setText("DS slot: " + ROMManager::CartLabel());
actEjectCart->setEnabled(true);
actImportSavefile->setEnabled(true);
}
void MainWindow::onBootFirmware()
@ -2210,6 +2214,7 @@ void MainWindow::onInsertCart()
actCurrentCart->setText("DS slot: " + ROMManager::CartLabel());
actEjectCart->setEnabled(true);
actImportSavefile->setEnabled(true);
}
void MainWindow::onEjectCart()
@ -2222,6 +2227,7 @@ void MainWindow::onEjectCart()
actCurrentCart->setText("DS slot: " + ROMManager::CartLabel());
actEjectCart->setEnabled(false);
actImportSavefile->setEnabled(false);
}
void MainWindow::onInsertGBACart()
@ -2386,37 +2392,52 @@ void MainWindow::onUndoStateLoad()
void MainWindow::onImportSavefile()
{
if (!RunningSomething) return;
/*emuThread->emuPause();
emuThread->emuPause();
QString path = QFileDialog::getOpenFileName(this,
"Select savefile",
QString::fromStdString(Config::LastROMFolder),
"Savefiles (*.sav *.bin *.dsv);;Any file (*.*)");
if (!path.isEmpty())
if (path.isEmpty())
{
emuThread->emuUnpause();
return;
}
FILE* f = Platform::OpenFile(path.toStdString(), "rb", true);
if (!f)
{
QMessageBox::critical(this, "melonDS", "Could not open the given savefile.");
emuThread->emuUnpause();
return;
}
if (RunningSomething)
{
if (QMessageBox::warning(this,
"Emulation will be reset and data overwritten",
"melonDS",
"The emulation will be reset and the current savefile overwritten.",
QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok)
{
int res = Frontend::Reset();
if (res != Frontend::Load_OK)
{
QMessageBox::critical(this, "melonDS", "Reset failed\n" + loadErrorStr(res));
}
else
{
int diff = Frontend::ImportSRAM(path.toStdString().c_str());
if (diff > 0)
OSD::AddMessage(0, "Trimmed savefile");
else if (diff < 0)
OSD::AddMessage(0, "Savefile shorter than SRAM");
}
emuThread->emuUnpause();
return;
}
ROMManager::Reset();
}
emuThread->emuUnpause();*/
u32 len;
fseek(f, 0, SEEK_END);
len = (u32)ftell(f);
u8* data = new u8[len];
fseek(f, 0, SEEK_SET);
fread(data, len, 1, f);
NDS::LoadSave(data, len);
fclose(f);
emuThread->emuUnpause();
}
void MainWindow::onQuit()
@ -2806,7 +2827,6 @@ void MainWindow::onEmuStart()
actReset->setEnabled(true);
actStop->setEnabled(true);
actFrameStep->setEnabled(true);
actImportSavefile->setEnabled(true);
actSetupCheats->setEnabled(true);
actTitleManager->setEnabled(false);
@ -2824,7 +2844,6 @@ void MainWindow::onEmuStop()
actLoadState[i]->setEnabled(false);
}
actUndoStateLoad->setEnabled(false);
actImportSavefile->setEnabled(false);
actPause->setEnabled(false);
actReset->setEnabled(false);