all repos — mgba @ 2a926e8dd50658b1761abb6f7f51f7a92fdd2696

mGBA Game Boy Advance Emulator

GBA Test: Disuse GBAContext
Jeffrey Pfau jeffrey@endrift.com
Sun, 07 Feb 2016 13:59:47 -0800
commit

2a926e8dd50658b1761abb6f7f51f7a92fdd2696

parent

7a1f8ec86f3f9ef4cca6353a2ceb6ccbcaa4ed45

2 files changed, 30 insertions(+), 40 deletions(-)

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

@@ -4,9 +4,9 @@ * 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/context/context.h" +#include "core/core.h" +#include "gba/core.h" #include "gba/gba.h" -#include "gba/renderers/video-software.h" #include "gba/serialize.h" #include "platform/commandline.h"

@@ -34,7 +34,7 @@ char* savestate;

char* ssOverlay; }; -static void _GBAFuzzRunloop(struct GBAContext* context, int frames); +static void _GBAFuzzRunloop(struct mCore* core, int frames); static void _GBAFuzzShutdown(int signal); static bool _parseFuzzOpts(struct mSubParser* parser, int option, const char* arg);

@@ -51,50 +51,43 @@ .extraOptions = FUZZ_OPTIONS,

.opts = &fuzzOpts }; - struct GBAContext context; - GBAContextInit(&context, "fuzz"); - struct mCoreOptions opts = {}; // TODO: Put back idle loops - mCoreConfigLoadDefaults(&context.config, &opts); - mCoreConfigFreeOpts(&opts); + struct mCore* core = GBACoreCreate(); + core->init(core); + mCoreInitConfig(core, "fuzz"); + mCoreConfigSetDefaultIntValue(&core->config, "idleOptimization", IDLE_LOOP_REMOVE); struct mArguments args; bool parsed = parseArguments(&args, argc, argv, &subparser); if (!parsed || args.showHelp) { usage(argv[0], FUZZ_USAGE); - GBAContextDeinit(&context); + core->deinit(core); return !parsed; } if (args.showVersion) { version(argv[0]); - GBAContextDeinit(&context); + core->deinit(core); return 0; } - applyArguments(&args, NULL, &context.config); + applyArguments(&args, NULL, &core->config); - struct GBAVideoSoftwareRenderer renderer; - renderer.outputBuffer = 0; + void* outputBuffer; + outputBuffer = 0; if (!fuzzOpts.noVideo) { - GBAVideoSoftwareRendererCreate(&renderer); - renderer.outputBuffer = malloc(256 * 256 * 4); - renderer.outputBufferStride = 256; - context.renderer = &renderer.d; + outputBuffer = malloc(256 * 256 * 4); + core->setVideoBuffer(core, outputBuffer, 256); } #ifdef __AFL_HAVE_MANUAL_CONTROL __AFL_INIT(); #endif - struct VFile* rom = VFileOpen(args.fname, O_RDONLY); - - context.gba->hardCrash = false; - GBAContextLoadROMFromVFile(&context, rom, 0); + ((struct GBA*) core->board)->hardCrash = false; + mCoreLoadFile(core, args.fname); struct VFile* savestate = 0; struct VFile* savestateOverlay = 0; size_t overlayOffset; - - GBAContextStart(&context); if (fuzzOpts.savestate) { savestate = VFileOpen(fuzzOpts.savestate, O_RDONLY);

@@ -109,12 +102,12 @@ free(fuzzOpts.ssOverlay);

} if (savestate) { if (!savestateOverlay) { - GBALoadStateNamed(context.gba, savestate, 0); + core->loadState(core, savestate, 0); } else { struct GBASerializedState* state = GBAAllocateState(); savestate->read(savestate, state, sizeof(*state)); savestateOverlay->read(savestateOverlay, (uint8_t*) state + overlayOffset, sizeof(*state) - overlayOffset); - GBADeserialize(context.gba, state); + GBADeserialize(core->board, state); GBADeallocateState(state); savestateOverlay->close(savestateOverlay); savestateOverlay = 0;

@@ -123,13 +116,12 @@ savestate->close(savestate);

savestate = 0; } - blip_set_rates(context.gba->audio.psg.left, GBA_ARM7TDMI_FREQUENCY, 0x8000); - blip_set_rates(context.gba->audio.psg.right, GBA_ARM7TDMI_FREQUENCY, 0x8000); + blip_set_rates(core->getAudioChannel(core, 0), GBA_ARM7TDMI_FREQUENCY, 0x8000); + blip_set_rates(core->getAudioChannel(core, 1), GBA_ARM7TDMI_FREQUENCY, 0x8000); - _GBAFuzzRunloop(&context, fuzzOpts.frames); + _GBAFuzzRunloop(core, fuzzOpts.frames); - GBAContextStop(&context); - GBAContextUnloadROM(&context); + core->unloadROM(core); if (savestate) { savestate->close(savestate);

@@ -139,18 +131,18 @@ savestateOverlay->close(savestateOverlay);

} freeArguments(&args); - if (renderer.outputBuffer) { - free(renderer.outputBuffer); + if (outputBuffer) { + free(outputBuffer); } - GBAContextDeinit(&context); + core->deinit(core); return 0; } -static void _GBAFuzzRunloop(struct GBAContext* context, int frames) { +static void _GBAFuzzRunloop(struct mCore* core, int frames) { do { - GBAContextFrame(context, 0); - } while (context->gba->video.frameCounter < frames && !_dispatchExiting); + core->runFrame(core); + } while (core->frameCounter(core) < frames && !_dispatchExiting); } static void _GBAFuzzShutdown(int signal) {
M src/platform/test/perf-main.csrc/platform/test/perf-main.c

@@ -63,22 +63,19 @@ struct mCoreConfig config;

mCoreConfigInit(&config, "perf"); mCoreConfigLoad(&config); - struct mCoreOptions opts = {}; // TODO: Put back idle loops - mCoreConfigLoadDefaults(&config, &opts); + 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); - mCoreConfigFreeOpts(&opts); mCoreConfigDeinit(&config); return !parsed; } if (args.showVersion) { version(argv[0]); freeArguments(&args); - mCoreConfigFreeOpts(&opts); mCoreConfigDeinit(&config); return 0; }

@@ -105,6 +102,7 @@ context.debugger = createDebugger(&args, &context);

context.overrides = mCoreConfigGetOverrides(&config); char gameCode[5] = { 0 }; + struct mCoreOptions opts; mCoreConfigMap(&config, &opts); opts.audioSync = false; opts.videoSync = false;