Core: Add option to allow preloading the entire ROM before running
@@ -13,6 +13,7 @@ - Add option for whether rewinding restores save games
- Qt: German translation (by Lothar Serra Mari) - Savestates now contain any RTC override data - Command line ability to override configuration values + - Add option to allow preloading the entire ROM before running Bugfixes: - LR35902: Fix core never exiting with certain event patterns - GB Timer: Improve DIV reset behavior
@@ -151,6 +151,9 @@ #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
struct mCore* mCoreFind(const char* path); bool mCoreLoadFile(struct mCore* core, const char* path); +bool mCorePreloadVF(struct mCore* core, struct VFile* vf); +bool mCorePreloadFile(struct mCore* core, const char* path); + bool mCoreAutoloadSave(struct mCore* core); bool mCoreAutoloadPatch(struct mCore* core);
@@ -115,6 +115,35 @@ }
return ret; } +bool mCorePreloadVF(struct mCore* core, struct VFile* vf) { + struct VFile* vfm = VFileMemChunk(NULL, vf->size(vf)); + uint8_t buffer[2048]; + ssize_t read; + vf->seek(vf, 0, SEEK_SET); + while ((read = vf->read(vf, buffer, sizeof(buffer))) > 0) { + vfm->write(vfm, buffer, read); + } + vf->close(vf); + bool ret = core->loadROM(core, vfm); + if (!ret) { + vfm->close(vfm); + } + return ret; +} + +bool mCorePreloadFile(struct mCore* core, const char* path) { + struct VFile* rom = mDirectorySetOpenPath(&core->dirs, path, core->isROM); + if (!rom) { + return false; + } + + bool ret = mCorePreloadVF(core, rom); + if (!ret) { + rom->close(rom); + } + return ret; +} + bool mCoreAutoloadSave(struct mCore* core) { return core->loadSave(core, mDirectorySetOpenSuffix(&core->dirs, core->dirs.save, ".sav", O_CREAT | O_RDWR)); }
@@ -69,6 +69,7 @@ , m_backupLoadState(nullptr)
, m_backupSaveState(nullptr) , m_saveStateFlags(SAVESTATE_SCREENSHOT | SAVESTATE_SAVEDATA | SAVESTATE_CHEATS | SAVESTATE_RTC) , m_loadStateFlags(SAVESTATE_SCREENSHOT | SAVESTATE_RTC) + , m_preload(false) , m_override(nullptr) { #ifdef M_CORE_GBA@@ -458,11 +459,20 @@
QByteArray bytes; if (!biosOnly) { bytes = m_fname.toUtf8(); - if (m_vf) { - m_threadContext.core->loadROM(m_threadContext.core, m_vf); + if (m_preload) { + if (m_vf) { + mCorePreloadVF(m_threadContext.core, m_vf); + } else { + mCorePreloadFile(m_threadContext.core, bytes.constData()); + mDirectorySetDetachBase(&m_threadContext.core->dirs); + } } else { - mCoreLoadFile(m_threadContext.core, bytes.constData()); - mDirectorySetDetachBase(&m_threadContext.core->dirs); + if (m_vf) { + m_threadContext.core->loadROM(m_threadContext.core, m_vf); + } else { + mCoreLoadFile(m_threadContext.core, bytes.constData()); + mDirectorySetDetachBase(&m_threadContext.core->dirs); + } } } else { bytes = m_bios.toUtf8();@@ -1105,6 +1115,10 @@ }
void GameController::setLoadStateExtdata(int flags) { m_loadStateFlags = flags; +} + +void GameController::setPreload(bool preload) { + m_preload = preload; } void GameController::setLuminanceValue(uint8_t value) {
@@ -154,6 +154,7 @@ void clearAVStream();
void reloadAudioDriver(); void setSaveStateExtdata(int flags); void setLoadStateExtdata(int flags); + void setPreload(bool); #ifdef USE_PNG void screenshot();@@ -233,6 +234,8 @@ struct VFile* m_backupLoadState;
QByteArray m_backupSaveState; int m_saveStateFlags; int m_loadStateFlags; + + bool m_preload; InputController* m_inputController; MultiplayerController* m_multiplayer;
@@ -204,6 +204,7 @@ saveSetting("savestatePath", m_ui.savestatePath);
saveSetting("screenshotPath", m_ui.screenshotPath); saveSetting("patchPath", m_ui.patchPath); saveSetting("showLibrary", m_ui.showLibrary); + saveSetting("preload", m_ui.preload); if (m_ui.fastForwardUnbounded->isChecked()) { saveSetting("fastForwardRatio", "-1");@@ -283,6 +284,7 @@ loadSetting("savestatePath", m_ui.savestatePath);
loadSetting("screenshotPath", m_ui.screenshotPath); loadSetting("patchPath", m_ui.patchPath); loadSetting("showLibrary", m_ui.showLibrary); + loadSetting("preload", m_ui.preload); double fastForwardRatio = loadSetting("fastForwardRatio").toDouble(); if (fastForwardRatio <= 0) {
@@ -568,21 +568,21 @@ </property>
</item> </widget> </item> - <item row="7" column="0" colspan="2"> + <item row="8" column="0" colspan="2"> <widget class="Line" name="line_2"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> </widget> </item> - <item row="8" column="0"> + <item row="9" column="0"> <widget class="QLabel" name="label_24"> <property name="text"> <string>Savestate extra data:</string> </property> </widget> </item> - <item row="8" column="1"> + <item row="9" column="1"> <widget class="QCheckBox" name="saveStateScreenshot"> <property name="text"> <string>Screenshot</string>@@ -592,7 +592,7 @@ <bool>true</bool>
</property> </widget> </item> - <item row="9" column="1"> + <item row="10" column="1"> <widget class="QCheckBox" name="saveStateSave"> <property name="text"> <string>Save data</string>@@ -602,7 +602,7 @@ <bool>true</bool>
</property> </widget> </item> - <item row="10" column="1"> + <item row="11" column="1"> <widget class="QCheckBox" name="saveStateCheats"> <property name="text"> <string>Cheat codes</string>@@ -612,14 +612,14 @@ <bool>true</bool>
</property> </widget> </item> - <item row="12" column="0"> + <item row="13" column="0"> <widget class="QLabel" name="label_25"> <property name="text"> <string>Load extra data:</string> </property> </widget> </item> - <item row="12" column="1"> + <item row="13" column="1"> <widget class="QCheckBox" name="loadStateScreenshot"> <property name="text"> <string>Screenshot</string>@@ -629,21 +629,21 @@ <bool>true</bool>
</property> </widget> </item> - <item row="13" column="1"> + <item row="14" column="1"> <widget class="QCheckBox" name="loadStateSave"> <property name="text"> <string>Save data</string> </property> </widget> </item> - <item row="14" column="1"> + <item row="15" column="1"> <widget class="QCheckBox" name="loadStateCheats"> <property name="text"> <string>Cheat codes</string> </property> </widget> </item> - <item row="11" column="0" colspan="2"> + <item row="12" column="0" colspan="2"> <widget class="Line" name="line_9"> <property name="orientation"> <enum>Qt::Horizontal</enum>@@ -657,6 +657,13 @@ <string>Rewind affects save data</string>
</property> <property name="checked"> <bool>true</bool> + </property> + </widget> + </item> + <item row="7" column="1"> + <widget class="QCheckBox" name="preload"> + <property name="text"> + <string>Preload entire ROM into memory</string> </property> </widget> </item>
@@ -1476,6 +1476,12 @@ loadStateExtdata->connect([this](const QVariant& value) {
m_controller->setLoadStateExtdata(value.toInt()); }, this); + ConfigOption* preload = m_config->addOption("preload"); + preload->connect([this](const QVariant& value) { + m_controller->setPreload(value.toBool()); + }, this); + m_config->updateOption("preload"); + QAction* exitFullScreen = new QAction(tr("Exit fullscreen"), frameMenu); connect(exitFullScreen, SIGNAL(triggered()), this, SLOT(exitFullScreen())); exitFullScreen->setShortcut(QKeySequence("Esc"));