all repos — mgba @ 810c35c318c4457b40c17dbe91a19b536bc99e8b

mGBA Game Boy Advance Emulator

Disentagle graphics flags from global flags
Jeffrey Pfau jeffrey@endrift.com
Sun, 20 Apr 2014 21:54:05 -0700
commit

810c35c318c4457b40c17dbe91a19b536bc99e8b

parent

5b300bbcff5d2dfb43671c203647ce78cd605465

M src/platform/commandline.csrc/platform/commandline.c

@@ -24,7 +24,7 @@ #endif

{ 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 @@ #ifdef USE_GDB_STUB

"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 @@

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); + } }
M src/platform/commandline.hsrc/platform/commandline.h

@@ -14,6 +14,14 @@ #endif

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 @@ enum DebuggerType debuggerType;

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
M src/platform/perf-main.csrc/platform/perf-main.c

@@ -12,33 +12,32 @@

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 @@ time_t end = time(0);

int duration = end - start; GBAThreadJoin(&context); - close(fd); + close(opts.fd); + if (opts.biosFd >= 0) { + close(opts.biosFd); + } + free(context.debugger); free(renderer.outputBuffer);
M src/platform/sdl/gl-main.csrc/platform/sdl/gl-main.c

@@ -62,8 +62,8 @@ struct GLSoftwareRenderer renderer;

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; }