Disentagle graphics flags from global flags

This commit is contained in:
Jeffrey Pfau 2014-04-20 21:54:05 -07:00
parent 5b300bbcff
commit 810c35c318
4 changed files with 40 additions and 29 deletions

View File

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

View File

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

View File

@ -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);

View File

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