@@ -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 > -1 ) // -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,7 +395,7 @@ 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 ,
398+ .sampleRate = 0 ,
412399 .tickRate = 60 ,
413400 .tickTimeout = 3000000 ,
414401 .frameTime = 1000000 / 60 ,
@@ -498,20 +485,40 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, void *_u
498485 app .romPath = app .bootArgs ?: "" ; // For whatever reason some of our code isn't NULL-aware, sigh..
499486
500487 rg_gui_draw_hourglass ();
501- rg_audio_init (sampleRate );
502488
503- rg_system_set_timezone (rg_settings_get_string (NS_GLOBAL , SETTING_TIMEZONE , "EST+5" ));
504- rg_system_load_time ();
489+ if (config )
490+ {
491+ app .sampleRate = config -> sampleRate ;
492+ app .tickRate = config -> frameRate ;
493+ // app.frameskip = config->frameSkip;
494+ if (config -> mallocAlwaysInternal > 0 )
495+ {
496+ #ifdef ESP_PLATFORM
497+ heap_caps_malloc_extmem_enable (config -> mallocAlwaysInternal );
498+ #endif
499+ }
500+ if (config -> storageRequired && !rg_storage_ready ())
501+ {
502+ rg_display_clear (C_SKY_BLUE );
503+ rg_gui_alert (_ ("SD Card Error" ), _ ("Storage mount failed.\nMake sure the card is FAT32." ));
504+ rg_system_exit ();
505+ }
506+ if (config -> romRequired && !app .romPath && !* app .romPath )
507+ {
508+ // show rom picking dialog
509+ }
510+ app .isLauncher = config -> isLauncher ;
511+ app .handlers = config -> handlers ;
512+ }
505513
506- // Do these last to not interfere with panic handling above
507- if (handlers )
508- app .handlers = * handlers ;
514+ if (app .sampleRate > 0 )
515+ {
516+ rg_audio_init (app .sampleRate );
517+ }
509518
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
519+ rg_system_set_tick_rate (app .tickRate );
520+ rg_system_set_timezone (rg_settings_get_string (NS_GLOBAL , SETTING_TIMEZONE , "EST+5" ));
521+ rg_system_load_time ();
515522
516523 if (app .lowMemoryMode )
517524 rg_gui_alert ("External memory not detected" , "Boot will continue but it will surely crash..." );
@@ -522,6 +529,12 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, void *_u
522529 rg_task_create ("rg_sysmon" , & system_monitor_task , NULL , 3 * 1024 , RG_TASK_PRIORITY_5 , -1 );
523530 app .initialized = true;
524531
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+
525538 update_memory_statistics ();
526539 RG_LOGI ("Available memory: %d/%d + %d/%d" , statistics .freeMemoryInt / 1024 , statistics .totalMemoryInt / 1024 ,
527540 statistics .freeMemoryExt / 1024 , statistics .totalMemoryExt / 1024 );
@@ -530,6 +543,16 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, void *_u
530543 return & app ;
531544}
532545
546+ rg_app_t * rg_system_reinit (int sampleRate , const rg_handlers_t * handlers , void * _unused )
547+ {
548+ RG_ASSERT (app .initialized , "App not initialized" );
549+ rg_audio_set_sample_rate (app .sampleRate );
550+ app .sampleRate = sampleRate ;
551+ if (handlers )
552+ app .handlers = * handlers ;
553+ return & app ;
554+ }
555+
533556// FIXME: None of this is threadsafe. It works for now, but eventually it needs fixing...
534557
535558#ifdef ESP_PLATFORM
@@ -810,7 +833,10 @@ rg_stats_t rg_system_get_stats(void)
810833void rg_system_set_tick_rate (int tickRate )
811834{
812835 app .tickRate = tickRate ;
813- app .frameTime = 1000000 / (app .tickRate * app .speed );
836+ if (tickRate > 0 )
837+ app .frameTime = 1000000 / (app .tickRate * app .speed );
838+ else
839+ app .frameTime = 1000000 ;
814840}
815841
816842int rg_system_get_tick_rate (void )
0 commit comments