@@ -456,6 +456,9 @@ static void on_rom_load(App* app) {
456456
457457 // reset speed to default.
458458 on_set_speed (app , SPEED_DEFAULT_INDEX );
459+
460+ // reset runahead buffer.
461+ runahead_clear_frames (app );
459462}
460463
461464static void mgb_on_file_callback (void * user , const char * file_name , enum CallbackType type , bool result ) {
@@ -490,6 +493,7 @@ static void mgb_on_file_callback(void* user, const char* file_name, enum Callbac
490493 case CallbackType_LOAD_STATE :
491494 if (result ) {
492495 on_set_rewind (app , false);
496+ runahead_clear_frames (app );
493497 text_popup_push (TextPopupType_INFO , "Loaded State" );
494498 } else {
495499 text_popup_push (TextPopupType_ERROR , "Failed to load state" );
@@ -618,6 +622,10 @@ static uint32_t core_colour_callback(void* user, uint8_t r, uint8_t g, uint8_t b
618622static void core_vblank_callback (void * user , uint32_t overscan_colour ) {
619623 App * app = user ;
620624
625+ if (SMS_get_skip_frame (& app -> sms )) {
626+ return ;
627+ }
628+
621629 SDL_LockMutex (app -> timer_shared_data .mutex );
622630 app -> timer_shared_data .vblank_counter ++ ;
623631 SDL_UnlockMutex (app -> timer_shared_data .mutex );
@@ -629,10 +637,6 @@ static void core_vblank_callback(void* user, uint32_t overscan_colour) {
629637 app -> rewind_counter -- ;
630638 }
631639
632- if (SMS_get_skip_frame (& app -> sms )) {
633- return ;
634- }
635-
636640 if (app -> pending_frame && app -> speed_index == SPEED_DEFAULT_INDEX ) {
637641 SDL_Log ("dropping frame\n" );
638642 }
@@ -1168,7 +1172,7 @@ static bool runahead_is_enabled(const App* app) {
11681172
11691173// clears frame count so that all new frames must be generated.
11701174// this should be called on input change, loadstate and loadrom.
1171- static void runahead_clear_frames (App * app ) {
1175+ void runahead_clear_frames (App * app ) {
11721176 app -> runahead .count = 0 ;
11731177}
11741178
@@ -1355,6 +1359,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
13551359 bool fullscreen = false;
13561360 bool loadstate = false;
13571361 bool overscan_fill = true;
1362+ bool runahead_lazy = false;
13581363
13591364 int arg_index = 1 ;
13601365 for (;;) {
@@ -1396,7 +1401,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
13961401 }
13971402 }
13981403 else {
1399- // while (!(arg_result = args_parse(&arg_index, argc, argv, ARGS_META, SDL_arraysize(ARGS_META), &arg_data))) {
14001404 switch (ARGS_META [arg_data .meta_index ].id ) {
14011405 case ArgsId_help :
14021406 show_help = true;
@@ -1446,6 +1450,9 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
14461450 case ArgsId_runahead :
14471451 runahead = arg_data .value .i ;
14481452 break ;
1453+ case ArgsId_runahead_lazy :
1454+ runahead_lazy = true;
1455+ break ;
14491456 }
14501457 }
14511458 }
@@ -1644,6 +1651,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
16441651 text_popup_push (TextPopupType_INFO , "Press CTRL+O to load ROM" );
16451652 }
16461653
1654+ app -> runahead .lazy = runahead_lazy ;
16471655 runahead_init (app , runahead );
16481656
16491657 app -> focus = SDL_GetWindowFlags (app -> window ) & SDL_WINDOW_INPUT_FOCUS ;
0 commit comments