headless.patch (4432B)
1diff --git a/platforms/audio-shared/Sound_Queue.cpp b/platforms/audio-shared/Sound_Queue.cpp 2index 4dd4fb1..9a4402e 100644 3--- a/platforms/audio-shared/Sound_Queue.cpp 4+++ b/platforms/audio-shared/Sound_Queue.cpp 5@@ -144,9 +144,9 @@ void Sound_Queue::write( const sample_t* in, int count, bool sync ) 6 { 7 write_pos = 0; 8 write_buf = (write_buf + 1) % buf_count; 9- 10- if (sync_output) 11- SDL_SemWait( free_sem ); 12+ // We don't like deadlocks in SDL_SemWait, remove them 13+ //if (sync_output) 14+ // SDL_SemWait( free_sem ); 15 } 16 } 17 } 18diff --git a/platforms/desktop-shared/application.cpp b/platforms/desktop-shared/application.cpp 19index d39cf93..d75be4d 100644 20--- a/platforms/desktop-shared/application.cpp 21+++ b/platforms/desktop-shared/application.cpp 22@@ -44,17 +44,10 @@ static void run_emulator(void); 23 static void render(void); 24 static void frame_throttle(void); 25 26-int application_init(const char* arg) 27+int application_init(const char* rom, const char* state) 28 { 29 Log ("<·> %s %s Desktop App <·>", GEARBOY_TITLE, GEARBOY_VERSION); 30 31- if (IsValidPointer(arg) && (strlen(arg) > 0)) 32- { 33- Log ("Loading with argv: %s"); 34- } 35- 36- int ret = sdl_init(); 37- 38 application_fullscreen = false; 39 40 config_init(); 41@@ -67,42 +60,39 @@ int application_init(const char* arg) 42 emu_savefiles_dir_option = config_emulator.savefiles_dir_option; 43 emu_savestates_dir_option = config_emulator.savestates_dir_option; 44 45- gui_init(); 46+ // We need no renderer and no SDL, remove those functions 47 48- ImGui_ImplSDL2_InitForOpenGL(sdl_window, gl_context); 49- 50- renderer_init(); 51 52 SDL_GL_SetSwapInterval(config_video.sync ? 1 : 0); 53 54- if (IsValidPointer(arg) && (strlen(arg) > 0)) 55- { 56- gui_load_rom(arg); 57- } 58+ 59+ printf("Loading rom: %s\n", rom); 60+ gui_load_rom(rom); 61+ printf("Loading state: %s\n", state); 62+ emu_load_state_file(state); 63 64- return ret; 65+ return 0x00; 66 } 67 68 void application_destroy(void) 69 { 70 config_write(); 71 config_destroy(); 72- renderer_destroy(); 73- gui_destroy(); 74+ // We can't destroy objects we did not create. We remove them 75+ //renderer_destroy(); 76+ //gui_destroy(); 77 emu_destroy(); 78- sdl_destroy(); 79+ //sdl_destroy(); 80 } 81 82 void application_mainloop(void) 83 { 84- while (running) 85- { 86+ // Only 100 ticks for emulation. No crypto-mining on gearboy! 87+ for (int i = 0; i < 100; i++) { 88 frame_time_start = SDL_GetPerformanceCounter(); 89 sdl_events(); 90 run_emulator(); 91- render(); 92 frame_time_end = SDL_GetPerformanceCounter(); 93- frame_throttle(); 94 } 95 } 96 97@@ -466,20 +456,7 @@ static void sdl_shortcuts_gui(const SDL_Event* event) 98 99 static void run_emulator(void) 100 { 101- if (!emu_is_empty()) 102- { 103- static int i = 0; 104- i++; 105- 106- if (i > 20) 107- { 108- i = 0; 109- 110- char title[256]; 111- sprintf(title, "%s %s - %s", GEARBOY_TITLE, GEARBOY_VERSION, emu_get_core()->GetCartridge()->GetFileName()); 112- SDL_SetWindowTitle(sdl_window, title); 113- } 114- } 115+ // We removed stuff like window titles here 116 config_emulator.paused = emu_is_paused(); 117 emu_audio_sync = config_audio.sync; 118 emu_update(); 119diff --git a/platforms/desktop-shared/application.h b/platforms/desktop-shared/application.h 120index 74a8c9e..ebbd3cb 100644 121--- a/platforms/desktop-shared/application.h 122+++ b/platforms/desktop-shared/application.h 123@@ -35,7 +35,7 @@ EXTERN SDL_version application_sdl_build_version; 124 EXTERN SDL_version application_sdl_link_version; 125 EXTERN bool application_fullscreen; 126 127-EXTERN int application_init(const char* arg); 128+EXTERN int application_init(const char* rom, const char* state); 129 EXTERN void application_destroy(void); 130 EXTERN void application_mainloop(void); 131 EXTERN void application_trigger_quit(void); 132diff --git a/platforms/desktop-shared/main.cpp b/platforms/desktop-shared/main.cpp 133index 161eb9e..37e842e 100644 134--- a/platforms/desktop-shared/main.cpp 135+++ b/platforms/desktop-shared/main.cpp 136@@ -21,7 +21,11 @@ 137 138 int main(int argc, char* argv[]) 139 { 140- int ret = application_init((argc == 2) ? argv[1] : NULL); 141+ if (argc < 3) { 142+ printf("Usage: gearboy [rom] [state]\n"); 143+ return -1; 144+ } 145+ int ret = application_init(argv[1], argv[2]); 146 147 if (ret >= 0) 148 application_mainloop();