Test: Move to mCoreThread

This commit is contained in:
Jeffrey Pfau 2016-02-07 14:26:59 -08:00
parent f0af862475
commit e775c5900d
1 changed files with 36 additions and 40 deletions

View File

@ -4,7 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "core/config.h" #include "core/config.h"
#include "gba/supervisor/thread.h" #include "core/thread.h"
#include "gba/core.h"
#include "gba/gba.h" #include "gba/gba.h"
#include "gba/renderers/video-software.h" #include "gba/renderers/video-software.h"
#include "gba/serialize.h" #include "gba/serialize.h"
@ -36,21 +37,18 @@ struct PerfOpts {
char* savestate; 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 void _GBAPerfShutdown(int signal);
static bool _parsePerfOpts(struct mSubParser* parser, int option, const char* arg); 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 bool _dispatchExiting = false;
static struct VFile* _savestate = 0; static struct VFile* _savestate = 0;
int main(int argc, char** argv) { int main(int argc, char** argv) {
signal(SIGINT, _GBAPerfShutdown); signal(SIGINT, _GBAPerfShutdown);
struct GBAVideoSoftwareRenderer renderer;
GBAVideoSoftwareRendererCreate(&renderer);
struct PerfOpts perfOpts = { false, false, 0, 0, 0 }; struct PerfOpts perfOpts = { false, false, 0, 0, 0 };
struct mSubParser subparser = { struct mSubParser subparser = {
.usage = PERF_USAGE, .usage = PERF_USAGE,
@ -59,36 +57,29 @@ int main(int argc, char** argv) {
.opts = &perfOpts .opts = &perfOpts
}; };
struct mCoreConfig config;
mCoreConfigInit(&config, "perf");
mCoreConfigLoad(&config);
mCoreConfigSetDefaultIntValue(&config, "idleOptimization", IDLE_LOOP_REMOVE);
struct mArguments args; struct mArguments args;
bool parsed = parseArguments(&args, argc, argv, &subparser); bool parsed = parseArguments(&args, argc, argv, &subparser);
if (!parsed || args.showHelp) { if (!parsed || args.showHelp) {
usage(argv[0], PERF_USAGE); usage(argv[0], PERF_USAGE);
freeArguments(&args); freeArguments(&args);
mCoreConfigDeinit(&config);
return !parsed; return !parsed;
} }
if (args.showVersion) { if (args.showVersion) {
version(argv[0]); version(argv[0]);
freeArguments(&args); freeArguments(&args);
mCoreConfigDeinit(&config);
return 0; return 0;
} }
applyArguments(&args, NULL, &config);
renderer.outputBuffer = malloc(256 * 256 * 4); void* outputBuffer = malloc(256 * 256 * 4);
renderer.outputBufferStride = 256;
struct GBAThread context = {}; struct mCore* core = GBACoreCreate();
struct mCoreThread context = {
.core = core
};
_thread = &context; _thread = &context;
if (!perfOpts.noVideo) { if (!perfOpts.noVideo) {
context.renderer = &renderer.d; core->setVideoBuffer(core, outputBuffer, 256);
} }
if (perfOpts.savestate) { if (perfOpts.savestate) {
_savestate = VFileOpen(perfOpts.savestate, O_RDONLY); _savestate = VFileOpen(perfOpts.savestate, O_RDONLY);
@ -98,30 +89,36 @@ int main(int argc, char** argv) {
context.startCallback = _loadSavestate; context.startCallback = _loadSavestate;
} }
context.debugger = createDebugger(&args, &context); // TODO: Put back debugger
context.overrides = mCoreConfigGetOverrides(&config);
char gameCode[5] = { 0 }; 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; struct mCoreOptions opts;
mCoreConfigMap(&config, &opts); mCoreConfigMap(&core->config, &opts);
opts.audioSync = false; opts.audioSync = false;
opts.videoSync = false; opts.videoSync = false;
GBAMapArgumentsToContext(&args, &context); applyArguments(&args, NULL, &core->config);
GBAMapOptionsToContext(&opts, &context); mCoreConfigLoadDefaults(&core->config, &opts);
mCoreLoadConfig(core);
int didStart = GBAThreadStart(&context); int didStart = mCoreThreadStart(&context);
if (!didStart) { if (!didStart) {
goto cleanup; goto cleanup;
} }
GBAThreadInterrupt(&context); mCoreThreadInterrupt(&context);
if (GBAThreadHasCrashed(&context)) { if (mCoreThreadHasCrashed(&context)) {
GBAThreadJoin(&context); mCoreThreadJoin(&context);
goto cleanup; goto cleanup;
} }
GBAGetGameCode(context.gba, gameCode); GBAGetGameCode(core->board, gameCode);
GBAThreadContinue(&context); mCoreThreadContinue(&context);
int frames = perfOpts.frames; int frames = perfOpts.frames;
if (!frames) { if (!frames) {
@ -135,7 +132,7 @@ int main(int argc, char** argv) {
uint64_t end = 1000000LL * tv.tv_sec + tv.tv_usec; uint64_t end = 1000000LL * tv.tv_sec + tv.tv_usec;
uint64_t duration = end - start; uint64_t duration = end - start;
GBAThreadJoin(&context); mCoreThreadJoin(&context);
float scaledFrames = frames * 1000000.f; float scaledFrames = frames * 1000000.f;
if (perfOpts.csv) { if (perfOpts.csv) {
@ -157,14 +154,13 @@ cleanup:
} }
mCoreConfigFreeOpts(&opts); mCoreConfigFreeOpts(&opts);
freeArguments(&args); freeArguments(&args);
mCoreConfigDeinit(&config); mCoreConfigDeinit(&core->config);
free(context.debugger); free(outputBuffer);
free(renderer.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; struct timeval lastEcho;
gettimeofday(&lastEcho, 0); gettimeofday(&lastEcho, 0);
int duration = *frames; int duration = *frames;
@ -194,7 +190,7 @@ static void _GBAPerfRunloop(struct GBAThread* context, int* frames, bool quiet)
_GBAPerfShutdown(0); _GBAPerfShutdown(0);
} }
if (_dispatchExiting) { if (_dispatchExiting) {
GBAThreadEnd(context); mCoreThreadEnd(context);
} }
} }
if (!quiet) { if (!quiet) {
@ -233,8 +229,8 @@ static bool _parsePerfOpts(struct mSubParser* parser, int option, const char* ar
} }
} }
static void _loadSavestate(struct GBAThread* context) { static void _loadSavestate(struct mCoreThread* context) {
GBALoadStateNamed(context->gba, _savestate, 0); context->core->loadState(context->core, _savestate, 0);
_savestate->close(_savestate); _savestate->close(_savestate);
_savestate = 0; _savestate = 0;
} }