mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-28 16:50:15 -06:00
* proper check for whether direct boot is required
* proof-of-concept cart insert/eject. it works!
This commit is contained in:
21
src/NDS.cpp
21
src/NDS.cpp
@ -353,6 +353,27 @@ void InitTimings()
|
|||||||
// handled later: GBA slot, wifi
|
// handled later: GBA slot, wifi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NeedsDirectBoot()
|
||||||
|
{
|
||||||
|
if (ConsoleType == 1)
|
||||||
|
{
|
||||||
|
// for now, DSi mode requires original BIOS/NAND
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// internal BIOS does not support direct boot
|
||||||
|
if (!Platform::GetConfigBool(Platform::ExternalBIOSEnable))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// DSi/3DS firmwares aren't bootable
|
||||||
|
if (SPI_Firmware::GetFirmwareLength() == 0x20000)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SetupDirectBoot(std::string romname)
|
void SetupDirectBoot(std::string romname)
|
||||||
{
|
{
|
||||||
if (ConsoleType == 1)
|
if (ConsoleType == 1)
|
||||||
|
@ -240,6 +240,8 @@ void LoadBIOS();
|
|||||||
|
|
||||||
bool LoadCart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen);
|
bool LoadCart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen);
|
||||||
void EjectCart();
|
void EjectCart();
|
||||||
|
|
||||||
|
bool NeedsDirectBoot();
|
||||||
void SetupDirectBoot(std::string romname);
|
void SetupDirectBoot(std::string romname);
|
||||||
|
|
||||||
bool LoadGBACart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen);
|
bool LoadGBACart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen);
|
||||||
|
@ -463,6 +463,7 @@ void SetupDirectBoot(bool dsi)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 GetFirmwareLength() { return FirmwareLength; }
|
||||||
u8 GetConsoleType() { return Firmware[0x1D]; }
|
u8 GetConsoleType() { return Firmware[0x1D]; }
|
||||||
u8 GetWifiVersion() { return Firmware[0x2F]; }
|
u8 GetWifiVersion() { return Firmware[0x2F]; }
|
||||||
u8 GetNWifiVersion() { return Firmware[0x1FD]; } // for DSi; will return 0xFF on a DS
|
u8 GetNWifiVersion() { return Firmware[0x1FD]; } // for DSi; will return 0xFF on a DS
|
||||||
|
@ -28,6 +28,7 @@ void SetupDirectBoot(bool dsi);
|
|||||||
|
|
||||||
u32 FixFirmwareLength(u32 originalLength);
|
u32 FixFirmwareLength(u32 originalLength);
|
||||||
|
|
||||||
|
u32 GetFirmwareLength();
|
||||||
u8 GetConsoleType();
|
u8 GetConsoleType();
|
||||||
u8 GetWifiVersion();
|
u8 GetWifiVersion();
|
||||||
u8 GetNWifiVersion();
|
u8 GetNWifiVersion();
|
||||||
|
@ -255,6 +255,19 @@ QString VerifySetup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool LoadBIOS()
|
||||||
|
{
|
||||||
|
if (NDS::NeedsDirectBoot())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
FullROMPath = "";
|
||||||
|
BaseROMDir = "";
|
||||||
|
BaseROMName = "";
|
||||||
|
|
||||||
|
NDS::Reset();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool LoadROM(QStringList filepath, bool reset)
|
bool LoadROM(QStringList filepath, bool reset)
|
||||||
{
|
{
|
||||||
if (filepath.empty()) return false;
|
if (filepath.empty()) return false;
|
||||||
@ -262,6 +275,7 @@ bool LoadROM(QStringList filepath, bool reset)
|
|||||||
u8* filedata;
|
u8* filedata;
|
||||||
u32 filelen;
|
u32 filelen;
|
||||||
|
|
||||||
|
std::string fullpath;
|
||||||
std::string basepath;
|
std::string basepath;
|
||||||
std::string romname;
|
std::string romname;
|
||||||
|
|
||||||
@ -295,6 +309,8 @@ bool LoadROM(QStringList filepath, bool reset)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
filelen = (u32)len;
|
filelen = (u32)len;
|
||||||
|
|
||||||
|
fullpath = filename;
|
||||||
|
|
||||||
int pos = LastSep(filename);
|
int pos = LastSep(filename);
|
||||||
basepath = filename.substr(0, pos);
|
basepath = filename.substr(0, pos);
|
||||||
romname = filename.substr(pos+1);
|
romname = filename.substr(pos+1);
|
||||||
@ -304,9 +320,7 @@ bool LoadROM(QStringList filepath, bool reset)
|
|||||||
{
|
{
|
||||||
// file inside archive
|
// file inside archive
|
||||||
|
|
||||||
QString archivepath = filepath.at(0);
|
u32 lenread = Archive::ExtractFileFromArchive(filepath.at(0), filepath.at(1), &filedata, &filelen);
|
||||||
|
|
||||||
u32 lenread = Archive::ExtractFileFromArchive(archivepath, filepath.at(1), &filedata, &filelen);
|
|
||||||
if (lenread < 0) return false;
|
if (lenread < 0) return false;
|
||||||
if (!filedata) return false;
|
if (!filedata) return false;
|
||||||
if (lenread != filelen)
|
if (lenread != filelen)
|
||||||
@ -315,21 +329,20 @@ bool LoadROM(QStringList filepath, bool reset)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string std_archivepath = archivepath.toStdString();
|
std::string std_archivepath = filepath.at(0).toStdString();
|
||||||
basepath = std_archivepath.substr(0, LastSep(std_archivepath));
|
basepath = std_archivepath.substr(0, LastSep(std_archivepath));
|
||||||
|
|
||||||
std::string std_romname = filepath.at(1).toStdString();
|
std::string std_romname = filepath.at(1).toStdString();
|
||||||
romname = std_romname.substr(LastSep(std_romname)+1);
|
romname = std_romname.substr(LastSep(std_romname)+1);
|
||||||
|
|
||||||
|
fullpath = std_archivepath + "//" + std_romname;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//
|
FullROMPath = fullpath;
|
||||||
printf("BASE PATH IS %s\n", basepath.c_str());
|
|
||||||
printf("ROM NAME IS %s\n", romname.c_str());
|
|
||||||
BaseROMDir = basepath;
|
BaseROMDir = basepath;
|
||||||
|
|
||||||
BaseROMName = romname.substr(0, romname.rfind('.'));
|
BaseROMName = romname.substr(0, romname.rfind('.'));
|
||||||
|
|
||||||
if (reset)
|
if (reset)
|
||||||
@ -356,7 +369,7 @@ bool LoadROM(QStringList filepath, bool reset)
|
|||||||
bool res = NDS::LoadCart(filedata, filelen, savedata, savelen);
|
bool res = NDS::LoadCart(filedata, filelen, savedata, savelen);
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
if (Config::DirectBoot)
|
if (Config::DirectBoot || NDS::NeedsDirectBoot())
|
||||||
{
|
{
|
||||||
NDS::SetupDirectBoot(romname);
|
NDS::SetupDirectBoot(romname);
|
||||||
}
|
}
|
||||||
@ -367,6 +380,15 @@ bool LoadROM(QStringList filepath, bool reset)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EjectCart()
|
||||||
|
{
|
||||||
|
NDS::EjectCart();
|
||||||
|
|
||||||
|
FullROMPath = "";
|
||||||
|
BaseROMDir = "";
|
||||||
|
BaseROMName = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +28,9 @@ namespace ROMLoader
|
|||||||
{
|
{
|
||||||
|
|
||||||
QString VerifySetup();
|
QString VerifySetup();
|
||||||
|
bool LoadBIOS();
|
||||||
bool LoadROM(QStringList filepath, bool reset);
|
bool LoadROM(QStringList filepath, bool reset);
|
||||||
|
void EjectCart();
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -65,58 +67,7 @@ enum
|
|||||||
Load_ROMLoadError,
|
Load_ROMLoadError,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::string ROMPath [ROMSlot_MAX];
|
|
||||||
extern std::string SRAMPath[ROMSlot_MAX];
|
|
||||||
extern bool SavestateLoaded;
|
|
||||||
|
|
||||||
// Stores type of nds rom i.e. nds/srl/dsi. Should be updated everytime an NDS rom is loaded from an archive
|
|
||||||
extern std::string NDSROMExtension;
|
|
||||||
|
|
||||||
// initialize the ROM handling utility
|
|
||||||
void Init_ROM();
|
|
||||||
|
|
||||||
// deinitialize the ROM handling utility
|
|
||||||
void DeInit_ROM();
|
|
||||||
|
|
||||||
// load the BIOS/firmware and boot from it
|
|
||||||
int LoadBIOS();
|
|
||||||
|
|
||||||
// load a ROM file to the specified cart slot
|
|
||||||
// note: loading a ROM to the NDS slot resets emulation
|
|
||||||
int LoadROM(const char* file, int slot);
|
|
||||||
int LoadROM(const u8 *romdata, u32 romlength, const char *archivefilename, const char *romfilename, const char *sramfilename, int slot);
|
|
||||||
|
|
||||||
// unload the ROM loaded in the specified cart slot
|
|
||||||
// simulating ejection of the cartridge
|
|
||||||
void UnloadROM(int slot);
|
|
||||||
|
|
||||||
void ROMIcon(u8 (&data)[512], u16 (&palette)[16], u32* iconRef);
|
|
||||||
void AnimatedROMIcon(u8 (&data)[8][512], u16 (&palette)[8][16], u16 (&sequence)[64], u32 (&animatedTexRef)[32 * 32 * 64], std::vector<int> &animatedSequenceRef);
|
|
||||||
|
|
||||||
// reset execution of the current ROM
|
|
||||||
int Reset();
|
|
||||||
|
|
||||||
// get the filename associated with the given savestate slot (1-8)
|
|
||||||
std::string GetSavestateName(int slot);
|
|
||||||
|
|
||||||
// determine whether the given savestate slot does contain a savestate
|
|
||||||
bool SavestateExists(int slot);
|
|
||||||
|
|
||||||
// load the given savestate file
|
|
||||||
// if successful, emulation will continue from the savestate's point
|
|
||||||
bool LoadState(std::string filename);
|
|
||||||
|
|
||||||
// save the current emulator state to the given file
|
|
||||||
bool SaveState(std::string filename);
|
|
||||||
|
|
||||||
// undo the latest savestate load
|
|
||||||
void UndoStateLoad();
|
|
||||||
|
|
||||||
// imports savedata from an external file. Returns the difference between the filesize and the SRAM size
|
|
||||||
int ImportSRAM(const char* filename);
|
|
||||||
|
|
||||||
// enable or disable cheats
|
|
||||||
void EnableCheats(bool enable);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1312,8 +1312,10 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
|||||||
actCurrentCart->setEnabled(false);
|
actCurrentCart->setEnabled(false);
|
||||||
|
|
||||||
actInsertCart = menu->addAction("Insert cart...");
|
actInsertCart = menu->addAction("Insert cart...");
|
||||||
|
connect(actInsertCart, &QAction::triggered, this, &MainWindow::onInsertCart);
|
||||||
|
|
||||||
actEjectCart = menu->addAction("Eject cart");
|
actEjectCart = menu->addAction("Eject cart");
|
||||||
|
connect(actEjectCart, &QAction::triggered, this, &MainWindow::onEjectCart);
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
@ -2122,15 +2124,6 @@ void MainWindow::onOpenFile()
|
|||||||
{
|
{
|
||||||
emuThread->emuPause();
|
emuThread->emuPause();
|
||||||
|
|
||||||
// stock path/archivepath in this module, alongside recent ROM list
|
|
||||||
// update them at the same time?
|
|
||||||
//
|
|
||||||
// 1. verify BIOS/firm/etc
|
|
||||||
// 2. pick ROM
|
|
||||||
// 3. set recent ROM, last folder, etc
|
|
||||||
// 4. reset system (if need be)
|
|
||||||
// 5. load ROM/SRAM into core
|
|
||||||
// 6. boot
|
|
||||||
if (!verifySetup())
|
if (!verifySetup())
|
||||||
{
|
{
|
||||||
emuThread->emuUnpause();
|
emuThread->emuUnpause();
|
||||||
@ -2153,31 +2146,9 @@ void MainWindow::onOpenFile()
|
|||||||
emuThread->emuUnpause();
|
emuThread->emuUnpause();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("PROEUPRAON\n");
|
|
||||||
NDS::Start();printf("PROOT\n");
|
|
||||||
emuThread->emuRun();printf("ASSFAZIL\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onOpenFileArchive()
|
NDS::Start();
|
||||||
{
|
emuThread->emuRun();
|
||||||
/*emuThread->emuPause();
|
|
||||||
|
|
||||||
QString archiveFileName = QFileDialog::getOpenFileName(this,
|
|
||||||
"Open ROM Archive",
|
|
||||||
QString::fromStdString(Config::LastROMFolder),
|
|
||||||
"Archived ROMs (*.zip *.7z *.rar *.tar *.tar.gz *.tar.xz *.tar.bz2);;Any file (*.*)");
|
|
||||||
if (archiveFileName.isEmpty())
|
|
||||||
{
|
|
||||||
emuThread->emuUnpause();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray romBuffer;
|
|
||||||
QString romFileName = pickAndExtractFileFromArchive(archiveFileName, &romBuffer);
|
|
||||||
if(!romFileName.isEmpty())
|
|
||||||
{
|
|
||||||
loadROM(&romBuffer, archiveFileName, romFileName);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*QString MainWindow::pickAndExtractFileFromArchive(QString archiveFileName, QByteArray *romBuffer)
|
/*QString MainWindow::pickAndExtractFileFromArchive(QString archiveFileName, QByteArray *romBuffer)
|
||||||
@ -2322,18 +2293,55 @@ void MainWindow::onBootFirmware()
|
|||||||
|
|
||||||
emuThread->emuPause();
|
emuThread->emuPause();
|
||||||
|
|
||||||
int res = Frontend::LoadBIOS();
|
if (!verifySetup())
|
||||||
if (res != Frontend::Load_OK)
|
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this,
|
|
||||||
"melonDS",
|
|
||||||
loadErrorStr(res));
|
|
||||||
emuThread->emuUnpause();
|
emuThread->emuUnpause();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (!ROMLoader::LoadBIOS())
|
||||||
{
|
{
|
||||||
emuThread->emuRun();
|
// TODO: better error reporting?
|
||||||
|
QMessageBox::critical(this, "melonDS", "This firmware is not bootable.");
|
||||||
|
emuThread->emuUnpause();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NDS::Start();
|
||||||
|
emuThread->emuRun();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onInsertCart()
|
||||||
|
{
|
||||||
|
emuThread->emuPause();
|
||||||
|
|
||||||
|
QStringList file = pickROM(false);
|
||||||
|
if (file.isEmpty())
|
||||||
|
{
|
||||||
|
emuThread->emuUnpause();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add to recent ROM list??
|
||||||
|
|
||||||
|
if (!ROMLoader::LoadROM(file, false))
|
||||||
|
{
|
||||||
|
// TODO: better error reporting?
|
||||||
|
QMessageBox::critical(this, "melonDS", "Failed to load the ROM.");
|
||||||
|
emuThread->emuUnpause();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emuThread->emuUnpause();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onEjectCart()
|
||||||
|
{
|
||||||
|
emuThread->emuPause();
|
||||||
|
|
||||||
|
ROMLoader::EjectCart();
|
||||||
|
|
||||||
|
emuThread->emuUnpause();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onSaveState()
|
void MainWindow::onSaveState()
|
||||||
|
@ -230,10 +230,11 @@ signals:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onOpenFile();
|
void onOpenFile();
|
||||||
void onOpenFileArchive();
|
|
||||||
void onClickRecentFile();
|
void onClickRecentFile();
|
||||||
void onClearRecentFiles();
|
void onClearRecentFiles();
|
||||||
void onBootFirmware();
|
void onBootFirmware();
|
||||||
|
void onInsertCart();
|
||||||
|
void onEjectCart();
|
||||||
void onSaveState();
|
void onSaveState();
|
||||||
void onLoadState();
|
void onLoadState();
|
||||||
void onUndoStateLoad();
|
void onUndoStateLoad();
|
||||||
|
Reference in New Issue
Block a user