all repos — mgba @ e775c5900de2975e89f39dcf10593fd076f7bfae

mGBA Game Boy Advance Emulator

Test: Move to mCoreThread
Jeffrey Pfau jeffrey@endrift.com
Sun, 07 Feb 2016 14:26:59 -0800
commit

e775c5900de2975e89f39dcf10593fd076f7bfae

parent

f0af8624752111835b90770434ada62c6433e405

1 files changed, 36 insertions(+), 40 deletions(-)

jump to
M src/platform/test/perf-main.csrc/platform/test/perf-main.c

@@ -4,7 +4,8 @@ * This Source Code Form is subject to the terms of the Mozilla Public

* License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "core/config.h" -#include "gba/supervisor/thread.h" +#include "core/thread.h" +#include "gba/core.h" #include "gba/gba.h" #include "gba/renderers/video-software.h" #include "gba/serialize.h"

@@ -36,21 +37,18 @@ unsigned frames;

char* savestate; }; -static void _GBAPerfRunloop(struct GBAThread* context, int* frames, bool quiet); +static void _GBAPerfRunloop(struct mCoreThread* context, int* frames, bool quiet); static void _GBAPerfShutdown(int signal); static bool _parsePerfOpts(struct mSubParser* parser, int option, const char* arg); -static void _loadSavestate(struct GBAThread* context); +static void _loadSavestate(struct mCoreThread* context); -static struct GBAThread* _thread; +static struct mCoreThread* _thread; static bool _dispatchExiting = false; static struct VFile* _savestate = 0; int main(int argc, char** argv) { signal(SIGINT, _GBAPerfShutdown); - struct GBAVideoSoftwareRenderer renderer; - GBAVideoSoftwareRendererCreate(&renderer); - struct PerfOpts perfOpts = { false, false, 0, 0, 0 }; struct mSubParser subparser = { .usage = PERF_USAGE,

@@ -59,36 +57,29 @@ .extraOptions = PERF_OPTIONS,

.opts = &perfOpts }; - struct mCoreConfig config; - mCoreConfigInit(&config, "perf"); - mCoreConfigLoad(&config); - - mCoreConfigSetDefaultIntValue(&config, "idleOptimization", IDLE_LOOP_REMOVE); - struct mArguments args; bool parsed = parseArguments(&args, argc, argv, &subparser); if (!parsed || args.showHelp) { usage(argv[0], PERF_USAGE); freeArguments(&args); - mCoreConfigDeinit(&config); return !parsed; } if (args.showVersion) { version(argv[0]); freeArguments(&args); - mCoreConfigDeinit(&config); return 0; } - applyArguments(&args, NULL, &config); - renderer.outputBuffer = malloc(256 * 256 * 4); - renderer.outputBufferStride = 256; + void* outputBuffer = malloc(256 * 256 * 4); - struct GBAThread context = {}; + struct mCore* core = GBACoreCreate(); + struct mCoreThread context = { + .core = core + }; _thread = &context; if (!perfOpts.noVideo) { - context.renderer = &renderer.d; + core->setVideoBuffer(core, outputBuffer, 256); } if (perfOpts.savestate) { _savestate = VFileOpen(perfOpts.savestate, O_RDONLY);

@@ -98,30 +89,36 @@ if (_savestate) {

context.startCallback = _loadSavestate; } - context.debugger = createDebugger(&args, &context); - context.overrides = mCoreConfigGetOverrides(&config); + // TODO: Put back debugger char gameCode[5] = { 0 }; + core->init(core); + mCoreLoadFile(core, args.fname); + mCoreConfigInit(&core->config, "perf"); + mCoreConfigLoad(&core->config); + + mCoreConfigSetDefaultIntValue(&core->config, "idleOptimization", IDLE_LOOP_REMOVE); struct mCoreOptions opts; - mCoreConfigMap(&config, &opts); + mCoreConfigMap(&core->config, &opts); opts.audioSync = false; opts.videoSync = false; - GBAMapArgumentsToContext(&args, &context); - GBAMapOptionsToContext(&opts, &context); + applyArguments(&args, NULL, &core->config); + mCoreConfigLoadDefaults(&core->config, &opts); + mCoreLoadConfig(core); - int didStart = GBAThreadStart(&context); + int didStart = mCoreThreadStart(&context); if (!didStart) { goto cleanup; } - GBAThreadInterrupt(&context); - if (GBAThreadHasCrashed(&context)) { - GBAThreadJoin(&context); + mCoreThreadInterrupt(&context); + if (mCoreThreadHasCrashed(&context)) { + mCoreThreadJoin(&context); goto cleanup; } - GBAGetGameCode(context.gba, gameCode); - GBAThreadContinue(&context); + GBAGetGameCode(core->board, gameCode); + mCoreThreadContinue(&context); int frames = perfOpts.frames; if (!frames) {

@@ -135,7 +132,7 @@ gettimeofday(&tv, 0);

uint64_t end = 1000000LL * tv.tv_sec + tv.tv_usec; uint64_t duration = end - start; - GBAThreadJoin(&context); + mCoreThreadJoin(&context); float scaledFrames = frames * 1000000.f; if (perfOpts.csv) {

@@ -157,14 +154,13 @@ _savestate->close(_savestate);

} mCoreConfigFreeOpts(&opts); freeArguments(&args); - mCoreConfigDeinit(&config); - free(context.debugger); - free(renderer.outputBuffer); + mCoreConfigDeinit(&core->config); + free(outputBuffer); - return !didStart || GBAThreadHasCrashed(&context); + return !didStart || mCoreThreadHasCrashed(&context); } -static void _GBAPerfRunloop(struct GBAThread* context, int* frames, bool quiet) { +static void _GBAPerfRunloop(struct mCoreThread* context, int* frames, bool quiet) { struct timeval lastEcho; gettimeofday(&lastEcho, 0); int duration = *frames;

@@ -194,7 +190,7 @@ if (duration > 0 && *frames == duration) {

_GBAPerfShutdown(0); } if (_dispatchExiting) { - GBAThreadEnd(context); + mCoreThreadEnd(context); } } if (!quiet) {

@@ -233,8 +229,8 @@ return false;

} } -static void _loadSavestate(struct GBAThread* context) { - GBALoadStateNamed(context->gba, _savestate, 0); +static void _loadSavestate(struct mCoreThread* context) { + context->core->loadState(context->core, _savestate, 0); _savestate->close(_savestate); _savestate = 0; }