Skip to content

Commit

Permalink
Merge pull request #782 from Daft-Freak/game-switch-fix
Browse files Browse the repository at this point in the history
Fix delayed game switch
  • Loading branch information
Gadgetoid authored Sep 27, 2022
2 parents 74b5936 + b1973b2 commit 65d0bfd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions 32blit-stm32/Src/32blit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static int (*user_tick)(uint32_t time) = nullptr;
static void (*user_render)(uint32_t time) = nullptr;
static bool user_code_disabled = false;

static bool in_user_code = false;
static bool game_switch_requested = false;

// flash cache, most of this is hanlded by the firmware. This needs to be here so switch_execution can reset it
Expand Down Expand Up @@ -210,11 +211,12 @@ void blit_tick() {
fs_mounted = false;
}

in_user_code = do_tick == user_tick;
auto time_to_next_tick = do_tick(blit::now());
in_user_code = false;

// handle delayed switch
if(game_switch_requested) {
user_tick = nullptr;
if(!blit_switch_execution(persist.last_game_offset, true)) {
// new game failed and old game will now be broken
// reset and let the firmware show the error
Expand Down Expand Up @@ -660,8 +662,8 @@ bool blit_switch_execution(uint32_t address, bool force_game)

persist.last_game_offset = address;

// game possibly running, wait until it isn't
if(user_tick && !user_code_disabled) {
// game running, wait until it isn't
if(in_user_code) {
game_switch_requested = true;
return true;
}
Expand Down

0 comments on commit 65d0bfd

Please sign in to comment.