mirror of
https://github.com/libretro/Mu.git
synced 2026-09-24 07:35:55 +00:00
Automatic RAM handling, load on start, save on exit
This will be useful for those who dont use savestates. Something similar will need to be added for the sd card.
This commit is contained in:
@@ -101,7 +101,7 @@ void EmuWrapper::emuThreadRun(){
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t EmuWrapper::init(QString romPath, QString bootloaderPath, uint32_t features){
|
||||
uint32_t EmuWrapper::init(QString romPath, QString bootloaderPath, QString ramPath, uint32_t features){
|
||||
if(!emuRunning && !emuInited){
|
||||
//start emu
|
||||
uint32_t error;
|
||||
@@ -112,7 +112,7 @@ uint32_t EmuWrapper::init(QString romPath, QString bootloaderPath, uint32_t feat
|
||||
buffer_t romBuff;
|
||||
buffer_t bootloaderBuff;
|
||||
|
||||
if(romFile.open(QFile::ReadOnly)){
|
||||
if(romFile.open(QFile::ReadOnly | QFile::ExistingOnly)){
|
||||
romData = romFile.readAll();
|
||||
romFile.close();
|
||||
|
||||
@@ -123,8 +123,8 @@ uint32_t EmuWrapper::init(QString romPath, QString bootloaderPath, uint32_t feat
|
||||
return EMU_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if(bootloaderPath != "" && bootloaderFile.exists()){
|
||||
if(bootloaderFile.open(QFile::ReadOnly)){
|
||||
if(bootloaderPath != ""){
|
||||
if(bootloaderFile.open(QFile::ReadOnly | QFile::ExistingOnly)){
|
||||
bootloaderData = bootloaderFile.readAll();
|
||||
bootloaderFile.close();
|
||||
|
||||
@@ -142,6 +142,25 @@ uint32_t EmuWrapper::init(QString romPath, QString bootloaderPath, uint32_t feat
|
||||
|
||||
error = emulatorInit(romBuff, bootloaderBuff, features);
|
||||
if(error == EMU_ERROR_NONE){
|
||||
if(ramPath != ""){
|
||||
QFile ramFile(ramPath);
|
||||
|
||||
if(ramFile.exists()){
|
||||
if(ramFile.open(QFile::ReadOnly | QFile::ExistingOnly)){
|
||||
QByteArray ramData;
|
||||
buffer_t emuRam = emulatorGetRamBuffer();
|
||||
|
||||
ramData = ramFile.readAll();
|
||||
ramFile.close();
|
||||
|
||||
//only copy in data if its the correct size, the file will be overwritten on exit with the devices RAM either way
|
||||
//(changing RAM size requires a factory reset for now and always will when going from 128mb back to 16mb)
|
||||
if(ramData.size() == emuRam.size)
|
||||
memcpy(emuRam.data, ramData.data(), emuRam.size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(features & FEATURE_320x320){
|
||||
emuVideoWidth = 320;
|
||||
emuVideoHeight = 320 + 120;
|
||||
@@ -152,6 +171,7 @@ uint32_t EmuWrapper::init(QString romPath, QString bootloaderPath, uint32_t feat
|
||||
}
|
||||
|
||||
emuInput = palmInput;
|
||||
emuRamFilePath = ramPath;
|
||||
|
||||
emuThreadJoin = false;
|
||||
emuInited = true;
|
||||
@@ -175,6 +195,16 @@ void EmuWrapper::exit(){
|
||||
if(emuThread.joinable())
|
||||
emuThread.join();
|
||||
if(emuInited){
|
||||
if(emuRamFilePath != ""){
|
||||
QFile ramFile(emuRamFilePath);
|
||||
buffer_t emuRam = emulatorGetRamBuffer();
|
||||
|
||||
//save out RAM before exit
|
||||
if(ramFile.open(QFile::WriteOnly | QFile::Truncate)){
|
||||
ramFile.write((const char*)emuRam.data, emuRam.size);
|
||||
ramFile.close();
|
||||
}
|
||||
}
|
||||
emulatorExit();
|
||||
delete[] emuDoubleBuffer;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ private:
|
||||
uint16_t emuVideoHeight;
|
||||
std::atomic<bool> emuNewFrameReady;
|
||||
uint16_t* emuDoubleBuffer;
|
||||
QString emuRamFilePath;
|
||||
|
||||
void emuThreadRun();
|
||||
|
||||
@@ -34,7 +35,7 @@ public:
|
||||
EmuWrapper();
|
||||
~EmuWrapper();
|
||||
|
||||
uint32_t init(QString romPath, QString bootloaderPath, uint32_t features);
|
||||
uint32_t init(QString romPath, QString bootloaderPath, QString ramPath, uint32_t features);
|
||||
void exit();
|
||||
void pause();
|
||||
void resume();
|
||||
|
||||
@@ -238,7 +238,8 @@ void MainWindow::on_right_released(){
|
||||
//emu control
|
||||
void MainWindow::on_ctrlBtn_clicked(){
|
||||
if(!emu.isInited()){
|
||||
uint32_t error = emu.init(settings.value("resourceDirectory", "").toString() + "/palmos41-en-m515.rom", settings.value("resourceDirectory", "").toString() + "/bootloader-en-m515.rom", FEATURE_DEBUG);
|
||||
QString systemDirectory = settings.value("resourceDirectory", "").toString();
|
||||
uint32_t error = emu.init(systemDirectory + "/palmos41-en-m515.rom", systemDirectory + "/bootloader-en-m515.rom", systemDirectory + "/userdata-en-m515.ram", FEATURE_DEBUG);
|
||||
if(error == EMU_ERROR_NONE){
|
||||
ui->calendar->setEnabled(true);
|
||||
ui->addressBook->setEnabled(true);
|
||||
|
||||
Reference in New Issue
Block a user