Skip to content

Commit

Permalink
Move initialization of the firmware flush task into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTG committed Sep 19, 2023
1 parent ce460bd commit 60086d9
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace melonds {
static bool isUnloading = false;
static bool deferred_initialization_pending = false;
static bool first_frame_run = false;
static uint32_t flushTaskId = 0;
static std::unique_ptr<NdsCart> _loaded_nds_cart;
static std::unique_ptr<GbaCart> _loaded_gba_cart;
static const char *const INTERNAL_ERROR_MESSAGE =
Expand Down Expand Up @@ -103,6 +104,17 @@ namespace melonds {
// functions for running games
static void read_microphone(melonds::InputState& inputState) noexcept;
static void render_audio();
static void InitFlushFirmwareTask() noexcept
{
string_view firmwareName = config::system::FirmwarePath(config::system::ConsoleType());
if (TaskSpec flushTask = sram::FlushFirmwareTask(firmwareName)) {
flushTaskId = flushTask.Identifier();
retro::task::push(std::move(flushTask));
}
else {
retro::set_error_message("System path not found, changes to firmware settings won't be saved.");
}
}


bool IsUnloadingGame() noexcept
Expand Down Expand Up @@ -131,6 +143,7 @@ PUBLIC_SYMBOL void retro_init(void) {
retro_assert(!melonds::isInDeinit);
retro_assert(!melonds::isUnloading);
retro_assert(!melonds::mic_state_toggled);
retro_assert(melonds::flushTaskId == 0);
srand(time(nullptr));
melonds::input_state = melonds::InputState();
melonds::sram::init();
Expand Down Expand Up @@ -495,6 +508,7 @@ PUBLIC_SYMBOL void retro_deinit(void) {
melonds::deferred_initialization_pending = false;
melonds::first_frame_run = false;
melonds::isInDeinit = false;
melonds::flushTaskId = 0;
retro::env::deinit();
}

Expand Down Expand Up @@ -637,13 +651,7 @@ static void melonds::load_games(
retro::task::push(file::FlushTask());
}

string_view firmwareName = config::system::FirmwarePath(config::system::ConsoleType());
if (TaskSpec flushTask = sram::FlushFirmwareTask(firmwareName)) {
retro::task::push(std::move(flushTask));
}
else {
retro::set_error_message("System path not found, changes to firmware settings won't be saved.");
}
InitFlushFirmwareTask();

if (_loaded_gba_cart && (NDS::IsLoadedARM9BIOSBuiltIn() || NDS::IsLoadedARM7BIOSBuiltIn() || SPI_Firmware::IsLoadedFirmwareBuiltIn())) {
// If we're using FreeBIOS and are trying to load a GBA cart...
Expand Down

0 comments on commit 60086d9

Please sign in to comment.