mirror of https://github.com/mgba-emu/mgba.git
Add more command line options and perf-main duration
This commit is contained in:
parent
810c35c318
commit
53389684db
|
@ -15,6 +15,7 @@ static const char* _defaultFilename = "test.rom";
|
|||
|
||||
static const struct option _options[] = {
|
||||
{ "bios", 1, 0, 'b' },
|
||||
{ "frameskip", 1, 0, 's' },
|
||||
#ifdef USE_CLI_DEBUGGER
|
||||
{ "debug", 1, 0, 'd' },
|
||||
#endif
|
||||
|
@ -30,12 +31,11 @@ int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, c
|
|||
opts->biosFd = -1;
|
||||
opts->width = 240;
|
||||
opts->height = 160;
|
||||
opts->fullscreen = 0;
|
||||
|
||||
int multiplier = 1;
|
||||
int ch;
|
||||
char options[64] =
|
||||
"b:"
|
||||
"b:s:"
|
||||
#ifdef USE_CLI_DEBUGGER
|
||||
"d"
|
||||
#endif
|
||||
|
@ -44,6 +44,7 @@ int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, c
|
|||
#endif
|
||||
;
|
||||
if (extraOptions) {
|
||||
// TODO: modularize options to subparsers
|
||||
strncat(options, extraOptions, sizeof(options) - strlen(options) - 1);
|
||||
}
|
||||
while ((ch = getopt_long(argc, argv, options, _options, 0)) != -1) {
|
||||
|
@ -70,6 +71,12 @@ int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, c
|
|||
opts->debuggerType = DEBUGGER_GDB;
|
||||
break;
|
||||
#endif
|
||||
case 's':
|
||||
opts->frameskip = atoi(optarg);
|
||||
break;
|
||||
case 'S':
|
||||
opts->perfDuration = atoi(optarg);
|
||||
break;
|
||||
case '2':
|
||||
if (multiplier != 1) {
|
||||
return 0;
|
||||
|
|
|
@ -22,6 +22,11 @@ enum DebuggerType {
|
|||
" -4 4x viewport\n" \
|
||||
" -f Sart full-screen"
|
||||
|
||||
#define PERF_OPTIONS "S:"
|
||||
#define PERF_USAGE \
|
||||
"\nBenchmark options:\n" \
|
||||
" -S SEC Run for SEC in-game seconds before exiting"
|
||||
|
||||
struct StartupOptions {
|
||||
int fd;
|
||||
const char* fname;
|
||||
|
@ -34,6 +39,8 @@ struct StartupOptions {
|
|||
int height;
|
||||
int fullscreen;
|
||||
|
||||
int perfDuration;
|
||||
|
||||
enum DebuggerType debuggerType;
|
||||
int debugAtStart;
|
||||
};
|
||||
|
|
|
@ -18,8 +18,8 @@ int main(int argc, char** argv) {
|
|||
GBAVideoSoftwareRendererCreate(&renderer);
|
||||
|
||||
struct StartupOptions opts;
|
||||
if (!parseCommandArgs(&opts, argc, argv, 0)) {
|
||||
usage(argv[0], 0);
|
||||
if (!parseCommandArgs(&opts, argc, argv, PERF_OPTIONS)) {
|
||||
usage(argv[0], PERF_USAGE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,6 @@ int main(int argc, char** argv) {
|
|||
|
||||
struct GBAThread context = {
|
||||
.renderer = &renderer.d,
|
||||
.frameskip = 0,
|
||||
.sync.videoFrameWait = 0,
|
||||
.sync.audioWait = 0
|
||||
};
|
||||
|
@ -40,7 +39,7 @@ int main(int argc, char** argv) {
|
|||
|
||||
GBAThreadStart(&context);
|
||||
|
||||
int frames = 0;
|
||||
int frames = opts.perfDuration;
|
||||
time_t start = time(0);
|
||||
_GBAPerfRunloop(&context, &frames);
|
||||
time_t end = time(0);
|
||||
|
@ -63,6 +62,8 @@ int main(int argc, char** argv) {
|
|||
static void _GBAPerfRunloop(struct GBAThread* context, int* frames) {
|
||||
struct timeval lastEcho;
|
||||
gettimeofday(&lastEcho, 0);
|
||||
int duration = *frames;
|
||||
*frames = 0;
|
||||
int lastFrames = 0;
|
||||
while (context->state < THREAD_EXITING) {
|
||||
if (GBASyncWaitFrameStart(&context->sync, 0)) {
|
||||
|
@ -82,7 +83,11 @@ static void _GBAPerfRunloop(struct GBAThread* context, int* frames) {
|
|||
}
|
||||
}
|
||||
GBASyncWaitFrameEnd(&context->sync);
|
||||
if (*frames == duration * 60) {
|
||||
_GBAPerfShutdown(0);
|
||||
}
|
||||
}
|
||||
printf("\033[2K\r");
|
||||
}
|
||||
|
||||
static void _GBAPerfShutdown(int signal) {
|
||||
|
|
Loading…
Reference in New Issue