@@ -278,7 +278,7 @@ static void system_monitor_task(void *arg)
278278
279279 // Auto frameskip
280280 // TODO: Use a rolling average of frameTimes instead of this mess
281- if (app .tickRate > 0 && statistics .ticks > app .tickRate * 2 )
281+ if (app .tickRate > 0 && statistics .ticks > app .tickRate * 2 && app . frameskip >= 0 ) // -1 disables auto frameskip
282282 {
283283 float speed = statistics .speedPercent / app .speed ;
284284 // We don't fully go back to 0 frameskip because if we dip below 95% once, we're clearly
@@ -379,20 +379,7 @@ static void platform_init(void)
379379#endif
380380}
381381
382- rg_app_t * rg_system_reinit (int sampleRate , const rg_handlers_t * handlers , void * _unused )
383- {
384- if (!app .initialized )
385- return rg_system_init (sampleRate , handlers , NULL );
386-
387- app .sampleRate = sampleRate ;
388- if (handlers )
389- app .handlers = * handlers ;
390- rg_audio_set_sample_rate (app .sampleRate );
391-
392- return & app ;
393- }
394-
395- rg_app_t * rg_system_init (int sampleRate , const rg_handlers_t * handlers , void * _unused )
382+ rg_app_t * rg_system_init (const rg_config_t * config )
396383{
397384 RG_ASSERT (app .initialized == false, "rg_system_init() was already called." );
398385 bool enterRecoveryMode = false;
@@ -408,10 +395,10 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, void *_u
408395 .bootFlags = 0 ,
409396 .indicatorsMask = (1 << RG_INDICATOR_POWER_LOW ),
410397 .speed = 1.f ,
411- .sampleRate = sampleRate ,
412- .tickRate = 60 ,
398+ .sampleRate = 0 ,
399+ .tickRate = 0 ,
413400 .tickTimeout = 3000000 ,
414- .frameTime = 1000000 / 60 ,
401+ .frameTime = 1000000 ,
415402 .frameskip = 1 , // This can be overriden on a per-app basis if needed, do not set 0 here!
416403 .lowMemoryMode = false,
417404 .enWatchdog = true,
@@ -491,30 +478,44 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, void *_u
491478 memset (& panicTrace , 0 , sizeof (panicTrace ));
492479 panicTraceCleared = true;
493480
494- update_memory_statistics ();
495- app .lowMemoryMode = statistics .totalMemoryExt == 0 ;
496-
497481 app .indicatorsMask = rg_settings_get_number (NS_GLOBAL , SETTING_INDICATOR_MASK , app .indicatorsMask );
498482 app .romPath = app .bootArgs ?: "" ; // For whatever reason some of our code isn't NULL-aware, sigh..
499483
500484 rg_gui_draw_hourglass ();
501- rg_audio_init (sampleRate );
502485
503- rg_system_set_timezone (rg_settings_get_string (NS_GLOBAL , SETTING_TIMEZONE , "EST+5" ));
504- rg_system_load_time ();
505-
506- // Do these last to not interfere with panic handling above
507- if (handlers )
508- app .handlers = * handlers ;
486+ if (config )
487+ {
488+ app .sampleRate = config -> sampleRate ;
489+ app .tickRate = config -> frameRate ;
490+ // app.frameskip = config->frameSkip;
491+ if (config -> mallocAlwaysInternal > 0 )
492+ {
493+ #ifdef ESP_PLATFORM
494+ heap_caps_malloc_extmem_enable (config -> mallocAlwaysInternal );
495+ #endif
496+ }
497+ if (config -> storageRequired && !rg_storage_ready ())
498+ {
499+ rg_display_clear (C_SKY_BLUE );
500+ rg_gui_alert (_ ("SD Card Error" ), _ ("Storage mount failed.\nMake sure the card is FAT32." ));
501+ rg_system_exit ();
502+ }
503+ if (config -> romRequired && !app .romPath && !* app .romPath )
504+ {
505+ // show rom picking dialog
506+ }
507+ app .isLauncher = config -> isLauncher ;
508+ app .handlers = config -> handlers ;
509+ }
509510
510- #ifdef RG_ENABLE_PROFILING
511- RG_LOGI ("Profiling has been enabled at compile time!\n" );
512- profile = rg_alloc (sizeof (* profile ), MEM_SLOW );
513- profile -> lock = rg_mutex_create ();
514- #endif
511+ if (app .sampleRate > 0 )
512+ {
513+ rg_audio_init (app .sampleRate );
514+ }
515515
516- if (app .lowMemoryMode )
517- rg_gui_alert ("External memory not detected" , "Boot will continue but it will surely crash..." );
516+ rg_system_set_tick_rate (app .tickRate );
517+ rg_system_set_timezone (rg_settings_get_string (NS_GLOBAL , SETTING_TIMEZONE , "EST+5" ));
518+ rg_system_load_time ();
518519
519520 if (app .bootFlags & RG_BOOT_ONCE )
520521 update_boot_config (RG_APP_LAUNCHER , NULL , NULL , 0 , 0 );
@@ -523,13 +524,34 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, void *_u
523524 app .initialized = true;
524525
525526 update_memory_statistics ();
527+
528+ app .lowMemoryMode = statistics .totalMemoryExt == 0 ;
529+ if (app .lowMemoryMode )
530+ rg_gui_alert ("External memory not detected" , "Boot will continue but it will surely crash..." );
531+
532+ #ifdef RG_ENABLE_PROFILING
533+ RG_LOGI ("Profiling has been enabled at compile time!" );
534+ profile = rg_alloc (sizeof (* profile ), MEM_SLOW );
535+ profile -> lock = rg_mutex_create ();
536+ #endif
537+
526538 RG_LOGI ("Available memory: %d/%d + %d/%d" , statistics .freeMemoryInt / 1024 , statistics .totalMemoryInt / 1024 ,
527539 statistics .freeMemoryExt / 1024 , statistics .totalMemoryExt / 1024 );
528540 RG_LOGI ("Retro-Go ready.\n\n" );
529541
530542 return & app ;
531543}
532544
545+ rg_app_t * rg_system_reinit (int sampleRate , const rg_handlers_t * handlers , void * _unused )
546+ {
547+ RG_ASSERT (app .initialized , "App not initialized" );
548+ rg_audio_set_sample_rate (app .sampleRate );
549+ app .sampleRate = sampleRate ;
550+ if (handlers )
551+ app .handlers = * handlers ;
552+ return & app ;
553+ }
554+
533555// FIXME: None of this is threadsafe. It works for now, but eventually it needs fixing...
534556
535557#ifdef ESP_PLATFORM
@@ -810,7 +832,10 @@ rg_stats_t rg_system_get_stats(void)
810832void rg_system_set_tick_rate (int tickRate )
811833{
812834 app .tickRate = tickRate ;
813- app .frameTime = 1000000 / (app .tickRate * app .speed );
835+ if (tickRate > 0 )
836+ app .frameTime = 1000000 / (app .tickRate * app .speed );
837+ else
838+ app .frameTime = 1000000 ;
814839}
815840
816841int rg_system_get_tick_rate (void )
0 commit comments