From c1652c34b0acd551850936b82ff42f3ab2db5367 Mon Sep 17 00:00:00 2001 From: jn Date: Thu, 26 Jan 2023 22:21:35 +0100 Subject: [PATCH 1/2] Initialize VM state and scan arguments before initializing SDL --- src/main.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 68878e2..ad74fe9 100644 --- a/src/main.c +++ b/src/main.c @@ -40,13 +40,6 @@ void main_loop(void); void load_rom(const char *filename); int main(int argc, char *argv[]) { - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - fprintf(stderr, "unable to initialize SDL: %s", SDL_GetError()); - return 1; - } - - SDL_ShowCursor(SDL_DISABLE); - fox32_init(&vm); vm.io_read = bus_io_read; vm.io_write = bus_io_write; @@ -90,6 +83,12 @@ int main(int argc, char *argv[]) { return 1; } } + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + fprintf(stderr, "unable to initialize SDL: %s", SDL_GetError()); + return 1; + } + + SDL_ShowCursor(SDL_DISABLE); ScreenCreate( FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT, From 17f452bacf8092e98e1f08bd352822bac62c87a6 Mon Sep 17 00:00:00 2001 From: jn Date: Fri, 20 Jan 2023 20:07:34 +0100 Subject: [PATCH 2/2] Add headless mode --- src/cpu.h | 1 + src/main.c | 47 +++++++++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/cpu.h b/src/cpu.h index ce9874d..edb3c2c 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -58,6 +58,7 @@ typedef struct { bool halted; bool debug; + bool headless; bool mmu_enabled; diff --git a/src/main.c b/src/main.c index ad74fe9..d08e84a 100644 --- a/src/main.c +++ b/src/main.c @@ -58,6 +58,7 @@ int main(int argc, char *argv[]) { " --disk DISK Specify a disk image to use\n" " --rom ROM Specify a ROM image to use\n" " --debug Enable debug output\n" + " --headless Headless mode: don't open a window\n" , argv[0]); return 0; } else if (strcmp(argv[i], "--disk") == 0) { @@ -78,32 +79,37 @@ int main(int argc, char *argv[]) { } } else if (strcmp(argv[i], "--debug") == 0) { vm.debug = true; + } else if (strcmp(argv[i], "--headless") == 0) { + vm.headless = true; } else { fprintf(stderr, "unrecognized option %s\n", argv[i]); return 1; } } - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - fprintf(stderr, "unable to initialize SDL: %s", SDL_GetError()); - return 1; + + if (!vm.headless) { + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + fprintf(stderr, "unable to initialize SDL: %s", SDL_GetError()); + return 1; + } + + SDL_ShowCursor(SDL_DISABLE); + + ScreenCreate( + FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT, + draw_framebuffer, + key_pressed, + key_released, + mouse_pressed, + mouse_released, + mouse_moved, + drop_file + ); + + ScreenInit(); + ScreenDraw(); } - SDL_ShowCursor(SDL_DISABLE); - - ScreenCreate( - FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT, - draw_framebuffer, - key_pressed, - key_released, - mouse_pressed, - mouse_released, - mouse_moved, - drop_file - ); - - ScreenInit(); - ScreenDraw(); - tick_start = SDL_GetTicks(); tick_end = SDL_GetTicks(); @@ -158,7 +164,8 @@ void main_loop(void) { } if ((ticks % TPF) == 0) { - ScreenDraw(); + if (!vm.headless) + ScreenDraw(); fox32_raise(&vm, VSYNC_INTERRUPT_VECTOR); vm.halted = false; }