From 810c35c318c4457b40c17dbe91a19b536bc99e8b Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 20 Apr 2014 21:54:05 -0700 Subject: [PATCH] Disentagle graphics flags from global flags --- src/platform/commandline.c | 23 +++++++++++------------ src/platform/commandline.h | 13 +++++++++++-- src/platform/perf-main.c | 29 ++++++++++++++++------------- src/platform/sdl/gl-main.c | 4 ++-- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/platform/commandline.c b/src/platform/commandline.c index 7dadfed71..89789e5fe 100644 --- a/src/platform/commandline.c +++ b/src/platform/commandline.c @@ -24,7 +24,7 @@ static const struct option _options[] = { { 0, 0, 0, 0 } }; -int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, int hasGraphics) { +int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, const char* extraOptions) { memset(opts, 0, sizeof(*opts)); opts->fd = -1; opts->biosFd = -1; @@ -43,8 +43,8 @@ int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, i "g" #endif ; - if (hasGraphics) { - strncat(options, "234f", sizeof(options) - strlen(options) - 1); + if (extraOptions) { + strncat(options, extraOptions, sizeof(options) - strlen(options) - 1); } while ((ch = getopt_long(argc, argv, options, _options, 0)) != -1) { switch (ch) { @@ -142,18 +142,17 @@ struct ARMDebugger* createDebugger(struct StartupOptions* opts) { return &debugger->d; } -void usage(const char* arg0) { +void usage(const char* arg0, const char* extraOptions) { printf("usage: %s [option ...] file\n", arg0); - printf("\nOptions:\n"); - printf(" -2 2x viewport\n"); - printf(" -3 3x viewport\n"); - printf(" -4 4x viewport\n"); - printf(" -b, --bios FILE GBA BIOS file to use\n"); + puts("\nGeneric options:"); + puts(" -b, --bios FILE GBA BIOS file to use"); #ifdef USE_CLI_DEBUGGER - printf(" -d, --debug Use command-line debugger\n"); + puts(" -d, --debug Use command-line debugger"); #endif - printf(" -f Sart full-screen\n"); #ifdef USE_GDB_STUB - printf(" -g, --gdb Start GDB session (default port 2345)\n"); + puts(" -g, --gdb Start GDB session (default port 2345)"); #endif + if (extraOptions) { + puts(extraOptions); + } } diff --git a/src/platform/commandline.h b/src/platform/commandline.h index 2e1bf0f8b..d91adbf0a 100644 --- a/src/platform/commandline.h +++ b/src/platform/commandline.h @@ -14,6 +14,14 @@ enum DebuggerType { DEBUGGER_MAX }; +#define GRAPHICS_OPTIONS "234f" +#define GRAPHICS_USAGE \ + "\nGraphics options:\n" \ + " -2 2x viewport\n" \ + " -3 3x viewport\n" \ + " -4 4x viewport\n" \ + " -f Sart full-screen" + struct StartupOptions { int fd; const char* fname; @@ -30,8 +38,9 @@ struct StartupOptions { int debugAtStart; }; -int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, int hasGraphics); +int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, const char* extraOptions); +void usage(const char* arg0, const char* extraOptions); + struct ARMDebugger* createDebugger(struct StartupOptions* opts); -void usage(const char* arg0); #endif diff --git a/src/platform/perf-main.c b/src/platform/perf-main.c index 144128a3d..521e276e6 100644 --- a/src/platform/perf-main.c +++ b/src/platform/perf-main.c @@ -12,33 +12,32 @@ static void _GBAPerfShutdown(int signal); static struct GBAThread* _thread; int main(int argc, char** argv) { - const char* fname = "test.rom"; - if (argc > 1) { - fname = argv[1]; - } - int fd = open(fname, O_RDONLY); - if (fd < 0) { - return 1; - } - signal(SIGINT, _GBAPerfShutdown); struct GBAVideoSoftwareRenderer renderer; GBAVideoSoftwareRendererCreate(&renderer); + struct StartupOptions opts; + if (!parseCommandArgs(&opts, argc, argv, 0)) { + usage(argv[0], 0); + return 1; + } + renderer.outputBuffer = malloc(256 * 256 * 4); renderer.outputBufferStride = 256; struct GBAThread context = { - .fd = fd, - .fname = fname, - .biosFd = -1, .renderer = &renderer.d, .frameskip = 0, .sync.videoFrameWait = 0, .sync.audioWait = 0 }; _thread = &context; + + context.debugger = createDebugger(&opts); + + GBAMapOptionsToContext(&opts, &context); + GBAThreadStart(&context); int frames = 0; @@ -48,7 +47,11 @@ int main(int argc, char** argv) { int duration = end - start; GBAThreadJoin(&context); - close(fd); + close(opts.fd); + if (opts.biosFd >= 0) { + close(opts.biosFd); + } + free(context.debugger); free(renderer.outputBuffer); diff --git a/src/platform/sdl/gl-main.c b/src/platform/sdl/gl-main.c index c21359ccd..42ef29f6c 100644 --- a/src/platform/sdl/gl-main.c +++ b/src/platform/sdl/gl-main.c @@ -62,8 +62,8 @@ int main(int argc, char** argv) { GBAVideoSoftwareRendererCreate(&renderer.d); struct StartupOptions opts; - if (!parseCommandArgs(&opts, argc, argv, 1)) { - usage(argv[0]); + if (!parseCommandArgs(&opts, argc, argv, GRAPHICS_OPTIONS)) { + usage(argv[0], GRAPHICS_USAGE); return 1; }