mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-21 05:09:46 -06:00
add a bunch of code
This commit is contained in:
@ -26,6 +26,8 @@ add_library(core STATIC
|
|||||||
Savestate.cpp
|
Savestate.cpp
|
||||||
SPI.cpp
|
SPI.cpp
|
||||||
SPU.cpp
|
SPU.cpp
|
||||||
|
types.h
|
||||||
|
version.h
|
||||||
Wifi.cpp
|
Wifi.cpp
|
||||||
WifiAP.cpp
|
WifiAP.cpp
|
||||||
)
|
)
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
namespace Config
|
namespace Config
|
||||||
|
@ -21,10 +21,44 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
namespace FrontendUtil
|
namespace Frontend
|
||||||
{
|
{
|
||||||
|
|
||||||
//
|
enum
|
||||||
|
{
|
||||||
|
ROMSlot_NDS = 0,
|
||||||
|
ROMSlot_GBA,
|
||||||
|
|
||||||
|
ROMSlot_MAX
|
||||||
|
};
|
||||||
|
|
||||||
|
extern char ROMPath [ROMSlot_MAX][1024];
|
||||||
|
extern char SRAMPath[ROMSlot_MAX][1024];
|
||||||
|
extern bool SavestateLoaded;
|
||||||
|
|
||||||
|
|
||||||
|
// initialize the ROM handling utility
|
||||||
|
void Init_ROM();
|
||||||
|
|
||||||
|
// load a ROM file to the specified cart slot
|
||||||
|
// note: loading a ROM to the NDS slot resets emulation
|
||||||
|
bool LoadROM(char* file, int slot);
|
||||||
|
|
||||||
|
// get the filename associated with the given savestate slot
|
||||||
|
void GetSavestateName(int slot, char* filename, int len);
|
||||||
|
|
||||||
|
// 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(const char* filename);
|
||||||
|
|
||||||
|
// save the current emulator state to the given file
|
||||||
|
bool SaveState(const char* filename);
|
||||||
|
|
||||||
|
// undo the latest savestate load
|
||||||
|
void UndoStateLoad();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,3 +15,239 @@
|
|||||||
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU General Public License along
|
||||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "FrontendUtil.h"
|
||||||
|
#include "Config.h"
|
||||||
|
#include "qt_sdl/PlatformConfig.h" // FIXME!!!
|
||||||
|
#include "Platform.h"
|
||||||
|
|
||||||
|
#include "NDS.h"
|
||||||
|
#include "GBACart.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Frontend
|
||||||
|
{
|
||||||
|
|
||||||
|
char ROMPath [ROMSlot_MAX][1024];
|
||||||
|
char SRAMPath [ROMSlot_MAX][1024];
|
||||||
|
char PrevSRAMPath[ROMSlot_MAX][1024]; // for savestate 'undo load'
|
||||||
|
|
||||||
|
bool SavestateLoaded;
|
||||||
|
|
||||||
|
|
||||||
|
void Init_ROM()
|
||||||
|
{
|
||||||
|
SavestateLoaded = false;
|
||||||
|
|
||||||
|
memset(ROMPath[ROMSlot_NDS], 0, 1024);
|
||||||
|
memset(ROMPath[ROMSlot_GBA], 0, 1024);
|
||||||
|
memset(SRAMPath[ROMSlot_NDS], 0, 1024);
|
||||||
|
memset(SRAMPath[ROMSlot_GBA], 0, 1024);
|
||||||
|
memset(PrevSRAMPath[ROMSlot_NDS], 0, 1024);
|
||||||
|
memset(PrevSRAMPath[ROMSlot_GBA], 0, 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetupSRAMPath(int slot)
|
||||||
|
{
|
||||||
|
strncpy(SRAMPath[slot], ROMPath[slot], 1023);
|
||||||
|
SRAMPath[slot][1023] = '\0';
|
||||||
|
strncpy(SRAMPath[slot] + strlen(ROMPath[slot]) - 3, "sav", 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LoadROM(char* file, int slot)
|
||||||
|
{
|
||||||
|
char oldpath[1024];
|
||||||
|
char oldsram[1024];
|
||||||
|
strncpy(oldpath, ROMPath[slot], 1024);
|
||||||
|
strncpy(oldsram, SRAMPath[slot], 1024);
|
||||||
|
|
||||||
|
strncpy(ROMPath[slot], file, 1023);
|
||||||
|
ROMPath[slot][1023] = '\0';
|
||||||
|
|
||||||
|
SetupSRAMPath(0);
|
||||||
|
SetupSRAMPath(1);
|
||||||
|
|
||||||
|
if (slot == ROMSlot_NDS && NDS::LoadROM(ROMPath[slot], SRAMPath[slot], Config::DirectBoot))
|
||||||
|
{
|
||||||
|
SavestateLoaded = false;
|
||||||
|
|
||||||
|
// Reload the inserted GBA cartridge (if any)
|
||||||
|
if (ROMPath[ROMSlot_GBA][0] != '\0') NDS::LoadGBAROM(ROMPath[ROMSlot_GBA], SRAMPath[ROMSlot_GBA]);
|
||||||
|
|
||||||
|
strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (slot == ROMSlot_GBA && NDS::LoadGBAROM(ROMPath[slot], SRAMPath[slot]))
|
||||||
|
{
|
||||||
|
SavestateLoaded = false;
|
||||||
|
|
||||||
|
strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strncpy(ROMPath[slot], oldpath, 1024);
|
||||||
|
strncpy(SRAMPath[slot], oldsram, 1024);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// SAVESTATE TODO
|
||||||
|
// * configurable paths. not everyone wants their ROM directory to be polluted, I guess.
|
||||||
|
|
||||||
|
void GetSavestateName(int slot, char* filename, int len)
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
if (ROMPath[ROMSlot_NDS][0] == '\0') // running firmware, no ROM
|
||||||
|
{
|
||||||
|
strcpy(filename, "firmware");
|
||||||
|
pos = 8;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int l = strlen(ROMPath[ROMSlot_NDS]);
|
||||||
|
pos = l;
|
||||||
|
while (ROMPath[ROMSlot_NDS][pos] != '.' && pos > 0) pos--;
|
||||||
|
if (pos == 0) pos = l;
|
||||||
|
|
||||||
|
// avoid buffer overflow. shoddy
|
||||||
|
if (pos > len-5) pos = len-5;
|
||||||
|
|
||||||
|
strncpy(&filename[0], ROMPath[ROMSlot_NDS], pos);
|
||||||
|
}
|
||||||
|
strcpy(&filename[pos], ".ml");
|
||||||
|
filename[pos+3] = '0'+slot;
|
||||||
|
filename[pos+4] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SavestateExists(int slot)
|
||||||
|
{
|
||||||
|
char ssfile[1024];
|
||||||
|
GetSavestateName(slot, ssfile, 1024);
|
||||||
|
return Platform::FileExists(ssfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LoadState(const char* filename)
|
||||||
|
{
|
||||||
|
u32 oldGBACartCRC = GBACart::CartCRC;
|
||||||
|
|
||||||
|
// backup
|
||||||
|
Savestate* backup = new Savestate("timewarp.mln", true);
|
||||||
|
NDS::DoSavestate(backup);
|
||||||
|
delete backup;
|
||||||
|
|
||||||
|
bool failed = false;
|
||||||
|
|
||||||
|
Savestate* state = new Savestate(filename, false);
|
||||||
|
if (state->Error)
|
||||||
|
{
|
||||||
|
delete state;
|
||||||
|
|
||||||
|
//uiMsgBoxError(MainWindow, "Error", "Could not load savestate file.");
|
||||||
|
|
||||||
|
// current state might be crapoed, so restore from sane backup
|
||||||
|
state = new Savestate("timewarp.mln", false);
|
||||||
|
failed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
NDS::DoSavestate(state);
|
||||||
|
delete state;
|
||||||
|
|
||||||
|
if (!failed)
|
||||||
|
{
|
||||||
|
if (Config::SavestateRelocSRAM && ROMPath[ROMSlot_NDS][0]!='\0')
|
||||||
|
{
|
||||||
|
strncpy(PrevSRAMPath[ROMSlot_NDS], SRAMPath[0], 1024);
|
||||||
|
|
||||||
|
strncpy(SRAMPath[ROMSlot_NDS], filename, 1019);
|
||||||
|
int len = strlen(SRAMPath[ROMSlot_NDS]);
|
||||||
|
strcpy(&SRAMPath[ROMSlot_NDS][len], ".sav");
|
||||||
|
SRAMPath[ROMSlot_NDS][len+4] = '\0';
|
||||||
|
|
||||||
|
NDS::RelocateSave(SRAMPath[ROMSlot_NDS], false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool loadedPartialGBAROM = false;
|
||||||
|
|
||||||
|
// in case we have a GBA cart inserted, and the GBA ROM changes
|
||||||
|
// due to having loaded a save state, we do not want to reload
|
||||||
|
// the previous cartridge on reset, or commit writes to any
|
||||||
|
// loaded save file. therefore, their paths are "nulled".
|
||||||
|
if (GBACart::CartInserted && GBACart::CartCRC != oldGBACartCRC)
|
||||||
|
{
|
||||||
|
ROMPath[ROMSlot_GBA][0] = '\0';
|
||||||
|
SRAMPath[ROMSlot_GBA][0] = '\0';
|
||||||
|
loadedPartialGBAROM = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO forward this to user in a meaningful way!!
|
||||||
|
/*char msg[64];
|
||||||
|
if (slot > 0) sprintf(msg, "State loaded from slot %d%s",
|
||||||
|
slot, loadedPartialGBAROM ? " (GBA ROM header only)" : "");
|
||||||
|
else sprintf(msg, "State loaded from file%s",
|
||||||
|
loadedPartialGBAROM ? " (GBA ROM header only)" : "");
|
||||||
|
OSD::AddMessage(0, msg);*/
|
||||||
|
|
||||||
|
SavestateLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SaveState(const char* filename)
|
||||||
|
{
|
||||||
|
Savestate* state = new Savestate(filename, true);
|
||||||
|
if (state->Error)
|
||||||
|
{
|
||||||
|
delete state;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NDS::DoSavestate(state);
|
||||||
|
delete state;
|
||||||
|
|
||||||
|
if (Config::SavestateRelocSRAM && ROMPath[ROMSlot_NDS][0]!='\0')
|
||||||
|
{
|
||||||
|
strncpy(SRAMPath[ROMSlot_NDS], filename, 1019);
|
||||||
|
int len = strlen(SRAMPath[ROMSlot_NDS]);
|
||||||
|
strcpy(&SRAMPath[ROMSlot_NDS][len], ".sav");
|
||||||
|
SRAMPath[ROMSlot_NDS][len+4] = '\0';
|
||||||
|
|
||||||
|
NDS::RelocateSave(SRAMPath[ROMSlot_NDS], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*char msg[64];
|
||||||
|
if (slot > 0) sprintf(msg, "State saved to slot %d", slot);
|
||||||
|
else sprintf(msg, "State saved to file");
|
||||||
|
OSD::AddMessage(0, msg);*/
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UndoStateLoad()
|
||||||
|
{
|
||||||
|
if (!SavestateLoaded) return;
|
||||||
|
|
||||||
|
// pray that this works
|
||||||
|
// what do we do if it doesn't???
|
||||||
|
// but it should work.
|
||||||
|
Savestate* backup = new Savestate("timewarp.mln", false);
|
||||||
|
NDS::DoSavestate(backup);
|
||||||
|
delete backup;
|
||||||
|
|
||||||
|
if (ROMPath[ROMSlot_NDS][0]!='\0')
|
||||||
|
{
|
||||||
|
strncpy(SRAMPath[ROMSlot_NDS], PrevSRAMPath[ROMSlot_NDS], 1024);
|
||||||
|
NDS::RelocateSave(SRAMPath[ROMSlot_NDS], false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//OSD::AddMessage(0, "State load undone");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -49,11 +49,6 @@
|
|||||||
char* EmuDirectory;
|
char* EmuDirectory;
|
||||||
|
|
||||||
bool RunningSomething;
|
bool RunningSomething;
|
||||||
char ROMPath[2][1024];
|
|
||||||
char SRAMPath[2][1024];
|
|
||||||
char PrevSRAMPath[2][1024]; // for savestate 'undo load'
|
|
||||||
|
|
||||||
bool SavestateLoaded;
|
|
||||||
|
|
||||||
MainWindow* mainWindow;
|
MainWindow* mainWindow;
|
||||||
EmuThread* emuThread;
|
EmuThread* emuThread;
|
||||||
@ -334,8 +329,8 @@ void EmuThread::emuPause(bool refresh)
|
|||||||
{
|
{
|
||||||
int status = refresh ? 2:3;
|
int status = refresh ? 2:3;
|
||||||
PrevEmuStatus = EmuRunning;
|
PrevEmuStatus = EmuRunning;
|
||||||
EmuRunning = status;printf("emuPause %d -> %d %d\n", PrevEmuStatus, EmuRunning, EmuStatus);
|
EmuRunning = status;
|
||||||
while (EmuStatus != status);printf("wait done\n");
|
while (EmuStatus != status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::emuUnpause()
|
void EmuThread::emuUnpause()
|
||||||
@ -370,7 +365,7 @@ void MainWindowPanel::paintEvent(QPaintEvent* event)
|
|||||||
|
|
||||||
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||||
{
|
{
|
||||||
setWindowTitle("melonDS - assfucking Qt version");
|
setWindowTitle("melonDS " MELONDS_VERSION);
|
||||||
|
|
||||||
QMenuBar* menubar = new QMenuBar();
|
QMenuBar* menubar = new QMenuBar();
|
||||||
{
|
{
|
||||||
@ -569,6 +564,7 @@ int main(int argc, char** argv)
|
|||||||
emuThread->start();
|
emuThread->start();
|
||||||
emuThread->emuPause(true);
|
emuThread->emuPause(true);
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
char* file = argv[1];
|
char* file = argv[1];
|
||||||
@ -601,11 +597,12 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int ret = melon.exec();
|
int ret = melon.exec();
|
||||||
printf("melon over\n");
|
|
||||||
emuThread->emuStop();printf("STOP\n");
|
emuThread->emuStop();
|
||||||
emuThread->wait();printf("farked\n");
|
emuThread->wait();
|
||||||
|
|
||||||
Config::Save();
|
Config::Save();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user