@@ -49,10 +49,14 @@ static u32 status_message_start_time = 0;
4949static u32 status_message_duration = 0 ;
5050static bool error_window_active = false ;
5151static char error_message[4096 ] = " " ;
52+ static bool loading_rom_active = false ;
53+ static char loading_rom_path[4096 ] = " " ;
5254static void main_window (void );
5355static void push_recent_rom (std::string path);
5456static void show_status_message (void );
5557static void show_error_window (void );
58+ static void show_loading_popup (void );
59+ static void finish_loading_rom (void );
5660static void set_style (void );
5761static void load_custom_palette_from_settings (void );
5862static ImVec4 lerp (const ImVec4& a, const ImVec4& b, float t);
@@ -207,6 +211,7 @@ void gui_render(void)
207211 if (config_emulator.show_info )
208212 gui_show_info ();
209213
214+ show_loading_popup ();
210215 show_status_message ();
211216 show_error_window ();
212217
@@ -414,64 +419,18 @@ void gui_load_palette(const char* path)
414419
415420void gui_load_rom (const char * path)
416421{
417- using namespace std ;
422+ if (loading_rom_active)
423+ return ;
418424
419- string message (" Loading ROM " );
420- message += path;
421- gui_set_status_message (message.c_str (), 3000 );
422425 gui_debug_auto_save_settings ();
423-
424426 push_recent_rom (path);
425427 emu_resume ();
426428
427- if (!emu_load_media (path))
428- {
429- string message (" Error loading ROM:\n " );
430- message += path;
431- gui_set_error_message (message.c_str ());
432-
433- emu_get_core ()->GetMedia ()->Reset ();
434- gui_action_reset ();
435- return ;
436- }
437-
438- if (emu_get_core ()->GetMedia ()->IsCDROM () && !emu_get_core ()->GetMedia ()->IsLoadedBios ())
439- {
440- bool is_gameexpress = emu_get_core ()->GetMedia ()->IsGameExpress ();
441- string bios_name = is_gameexpress ? " Game Express BIOS" : " System Card BIOS" ;
442-
443- std::string message;
444- message += bios_name;
445- message += " is required to run this ROM!!\n " ;
446- message += " Make sure you have a valid BIOS file in 'Menu->Emulator->BIOS'." ;
447- gui_set_error_message (message.c_str ());
448-
449- emu_get_core ()->GetMedia ()->Reset ();
450- gui_action_reset ();
451- return ;
452- }
453-
454- gui_debug_reset ();
455-
456- std::string str (path);
457- str = str.substr (0 , str.find_last_of (" ." ));
458- str += " .sym" ;
459- gui_debug_load_symbols_file (str.c_str ());
460-
461- gui_debug_auto_load_settings ();
429+ strncpy (loading_rom_path, path, sizeof (loading_rom_path) - 1 );
430+ loading_rom_path[sizeof (loading_rom_path) - 1 ] = ' \0 ' ;
431+ loading_rom_active = true ;
462432
463- if (config_emulator.start_paused )
464- {
465- emu_pause ();
466-
467- for (int i=0 ; i < (HUC6270_MAX_RESOLUTION_WIDTH * HUC6270_MAX_RESOLUTION_HEIGHT); i++)
468- {
469- emu_frame_buffer[i] = 0 ;
470- }
471- }
472-
473- if (!emu_is_empty ())
474- application_update_title_with_rom (emu_get_core ()->GetMedia ()->GetFileName ());
433+ emu_load_media_async (path);
475434}
476435
477436void gui_set_status_message (const char * message, u32 milliseconds)
@@ -686,6 +645,105 @@ static void show_status_message(void)
686645 }
687646}
688647
648+ static void show_loading_popup (void )
649+ {
650+ if (!loading_rom_active)
651+ return ;
652+
653+ if (!emu_is_media_loading ())
654+ {
655+ loading_rom_active = false ;
656+ gui_dialog_in_use = false ;
657+ bool success = emu_finish_media_loading ();
658+
659+ if (success)
660+ {
661+ finish_loading_rom ();
662+ }
663+ else
664+ {
665+ std::string message (" Error loading ROM:\n " );
666+ message += loading_rom_path;
667+ gui_set_error_message (message.c_str ());
668+
669+ emu_get_core ()->GetMedia ()->Reset ();
670+ gui_action_reset ();
671+ }
672+ return ;
673+ }
674+
675+ gui_dialog_in_use = true ;
676+
677+ ImVec2 center = ImGui::GetMainViewport ()->GetCenter ();
678+ ImGui::SetNextWindowPos (center, ImGuiCond_Always, ImVec2 (0 .5f , 0 .5f ));
679+ ImGui::SetNextWindowSize (ImVec2 (0 .0f , 0 .0f ));
680+ ImGui::PushStyleVar (ImGuiStyleVar_WindowPadding, ImVec2 (30 .0f , 20 .0f ));
681+ ImGui::PushStyleVar (ImGuiStyleVar_WindowRounding, 8 .0f );
682+ ImGui::PushStyleVar (ImGuiStyleVar_ItemSpacing, ImVec2 (10 .0f , 12 .0f ));
683+ ImGui::PushStyleColor (ImGuiCol_PopupBg, ImVec4 (0 .10f , 0 .10f , 0 .10f , 0 .95f ));
684+ ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0 .87f , 0 .01f , 0 .39f , 0 .80f ));
685+ ImGui::OpenPopup (" ##loading" );
686+
687+ if (ImGui::BeginPopupModal (" ##loading" , NULL , ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove))
688+ {
689+ ImGui::PushFont (gui_roboto_font);
690+
691+ ImGui::PushStyleColor (ImGuiCol_Text, ImVec4 (0 .87f , 0 .01f , 0 .39f , 1 .0f ));
692+ ImGui::TextUnformatted (ICON_MD_HOURGLASS_EMPTY);
693+ ImGui::PopStyleColor ();
694+
695+ ImGui::SameLine ();
696+ ImGui::Text (" LOADING..." );
697+
698+ ImGui::PopFont ();
699+ ImGui::EndPopup ();
700+ }
701+
702+ ImGui::PopStyleColor (2 );
703+ ImGui::PopStyleVar (3 );
704+ }
705+
706+ static void finish_loading_rom (void )
707+ {
708+ if (emu_get_core ()->GetMedia ()->IsCDROM () && !emu_get_core ()->GetMedia ()->IsLoadedBios ())
709+ {
710+ bool is_gameexpress = emu_get_core ()->GetMedia ()->IsGameExpress ();
711+ std::string bios_name = is_gameexpress ? " Game Express BIOS" : " System Card BIOS" ;
712+
713+ std::string message;
714+ message += bios_name;
715+ message += " is required to run this ROM!!\n " ;
716+ message += " Make sure you have a valid BIOS file in 'Menu->Emulator->BIOS'." ;
717+ gui_set_error_message (message.c_str ());
718+
719+ emu_get_core ()->GetMedia ()->Reset ();
720+ gui_action_reset ();
721+ return ;
722+ }
723+
724+ gui_debug_reset ();
725+
726+ std::string str (loading_rom_path);
727+ str = str.substr (0 , str.find_last_of (" ." ));
728+ str += " .sym" ;
729+ gui_debug_load_symbols_file (str.c_str ());
730+
731+ gui_debug_auto_load_settings ();
732+
733+ if (config_emulator.start_paused )
734+ {
735+ emu_pause ();
736+
737+ for (int i = 0 ; i < (HUC6270_MAX_RESOLUTION_WIDTH * HUC6270_MAX_RESOLUTION_HEIGHT); i++)
738+ {
739+ emu_frame_buffer[i] = 0 ;
740+ }
741+ }
742+
743+ if (!emu_is_empty ())
744+ application_update_title_with_rom (emu_get_core ()->GetMedia ()->GetFileName ());
745+ }
746+
689747static void show_error_window (void )
690748{
691749 if (error_window_active)
0 commit comments