mirror of https://github.com/mgba-emu/mgba.git
Disentagle graphics flags from global flags
This commit is contained in:
parent
5b300bbcff
commit
810c35c318
|
@ -24,7 +24,7 @@ static const struct option _options[] = {
|
||||||
{ 0, 0, 0, 0 }
|
{ 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));
|
memset(opts, 0, sizeof(*opts));
|
||||||
opts->fd = -1;
|
opts->fd = -1;
|
||||||
opts->biosFd = -1;
|
opts->biosFd = -1;
|
||||||
|
@ -43,8 +43,8 @@ int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, i
|
||||||
"g"
|
"g"
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
if (hasGraphics) {
|
if (extraOptions) {
|
||||||
strncat(options, "234f", sizeof(options) - strlen(options) - 1);
|
strncat(options, extraOptions, sizeof(options) - strlen(options) - 1);
|
||||||
}
|
}
|
||||||
while ((ch = getopt_long(argc, argv, options, _options, 0)) != -1) {
|
while ((ch = getopt_long(argc, argv, options, _options, 0)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
|
@ -142,18 +142,17 @@ struct ARMDebugger* createDebugger(struct StartupOptions* opts) {
|
||||||
return &debugger->d;
|
return &debugger->d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(const char* arg0) {
|
void usage(const char* arg0, const char* extraOptions) {
|
||||||
printf("usage: %s [option ...] file\n", arg0);
|
printf("usage: %s [option ...] file\n", arg0);
|
||||||
printf("\nOptions:\n");
|
puts("\nGeneric options:");
|
||||||
printf(" -2 2x viewport\n");
|
puts(" -b, --bios FILE GBA BIOS file to use");
|
||||||
printf(" -3 3x viewport\n");
|
|
||||||
printf(" -4 4x viewport\n");
|
|
||||||
printf(" -b, --bios FILE GBA BIOS file to use\n");
|
|
||||||
#ifdef USE_CLI_DEBUGGER
|
#ifdef USE_CLI_DEBUGGER
|
||||||
printf(" -d, --debug Use command-line debugger\n");
|
puts(" -d, --debug Use command-line debugger");
|
||||||
#endif
|
#endif
|
||||||
printf(" -f Sart full-screen\n");
|
|
||||||
#ifdef USE_GDB_STUB
|
#ifdef USE_GDB_STUB
|
||||||
printf(" -g, --gdb Start GDB session (default port 2345)\n");
|
puts(" -g, --gdb Start GDB session (default port 2345)");
|
||||||
#endif
|
#endif
|
||||||
|
if (extraOptions) {
|
||||||
|
puts(extraOptions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,14 @@ enum DebuggerType {
|
||||||
DEBUGGER_MAX
|
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 {
|
struct StartupOptions {
|
||||||
int fd;
|
int fd;
|
||||||
const char* fname;
|
const char* fname;
|
||||||
|
@ -30,8 +38,9 @@ struct StartupOptions {
|
||||||
int debugAtStart;
|
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);
|
struct ARMDebugger* createDebugger(struct StartupOptions* opts);
|
||||||
void usage(const char* arg0);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,33 +12,32 @@ static void _GBAPerfShutdown(int signal);
|
||||||
static struct GBAThread* _thread;
|
static struct GBAThread* _thread;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
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);
|
signal(SIGINT, _GBAPerfShutdown);
|
||||||
|
|
||||||
struct GBAVideoSoftwareRenderer renderer;
|
struct GBAVideoSoftwareRenderer renderer;
|
||||||
GBAVideoSoftwareRendererCreate(&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.outputBuffer = malloc(256 * 256 * 4);
|
||||||
renderer.outputBufferStride = 256;
|
renderer.outputBufferStride = 256;
|
||||||
|
|
||||||
struct GBAThread context = {
|
struct GBAThread context = {
|
||||||
.fd = fd,
|
|
||||||
.fname = fname,
|
|
||||||
.biosFd = -1,
|
|
||||||
.renderer = &renderer.d,
|
.renderer = &renderer.d,
|
||||||
.frameskip = 0,
|
.frameskip = 0,
|
||||||
.sync.videoFrameWait = 0,
|
.sync.videoFrameWait = 0,
|
||||||
.sync.audioWait = 0
|
.sync.audioWait = 0
|
||||||
};
|
};
|
||||||
_thread = &context;
|
_thread = &context;
|
||||||
|
|
||||||
|
context.debugger = createDebugger(&opts);
|
||||||
|
|
||||||
|
GBAMapOptionsToContext(&opts, &context);
|
||||||
|
|
||||||
GBAThreadStart(&context);
|
GBAThreadStart(&context);
|
||||||
|
|
||||||
int frames = 0;
|
int frames = 0;
|
||||||
|
@ -48,7 +47,11 @@ int main(int argc, char** argv) {
|
||||||
int duration = end - start;
|
int duration = end - start;
|
||||||
|
|
||||||
GBAThreadJoin(&context);
|
GBAThreadJoin(&context);
|
||||||
close(fd);
|
close(opts.fd);
|
||||||
|
if (opts.biosFd >= 0) {
|
||||||
|
close(opts.biosFd);
|
||||||
|
}
|
||||||
|
free(context.debugger);
|
||||||
|
|
||||||
free(renderer.outputBuffer);
|
free(renderer.outputBuffer);
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,8 @@ int main(int argc, char** argv) {
|
||||||
GBAVideoSoftwareRendererCreate(&renderer.d);
|
GBAVideoSoftwareRendererCreate(&renderer.d);
|
||||||
|
|
||||||
struct StartupOptions opts;
|
struct StartupOptions opts;
|
||||||
if (!parseCommandArgs(&opts, argc, argv, 1)) {
|
if (!parseCommandArgs(&opts, argc, argv, GRAPHICS_OPTIONS)) {
|
||||||
usage(argv[0]);
|
usage(argv[0], GRAPHICS_USAGE);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue