mirror of https://github.com/mgba-emu/mgba.git
GBA Test: Disuse GBAContext
This commit is contained in:
parent
7a1f8ec86f
commit
2a926e8dd5
|
@ -4,9 +4,9 @@
|
||||||
* 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/context/context.h"
|
#include "core/core.h"
|
||||||
|
#include "gba/core.h"
|
||||||
#include "gba/gba.h"
|
#include "gba/gba.h"
|
||||||
#include "gba/renderers/video-software.h"
|
|
||||||
#include "gba/serialize.h"
|
#include "gba/serialize.h"
|
||||||
|
|
||||||
#include "platform/commandline.h"
|
#include "platform/commandline.h"
|
||||||
|
@ -34,7 +34,7 @@ struct FuzzOpts {
|
||||||
char* ssOverlay;
|
char* ssOverlay;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void _GBAFuzzRunloop(struct GBAContext* context, int frames);
|
static void _GBAFuzzRunloop(struct mCore* core, int frames);
|
||||||
static void _GBAFuzzShutdown(int signal);
|
static void _GBAFuzzShutdown(int signal);
|
||||||
static bool _parseFuzzOpts(struct mSubParser* parser, int option, const char* arg);
|
static bool _parseFuzzOpts(struct mSubParser* parser, int option, const char* arg);
|
||||||
|
|
||||||
|
@ -51,51 +51,44 @@ int main(int argc, char** argv) {
|
||||||
.opts = &fuzzOpts
|
.opts = &fuzzOpts
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GBAContext context;
|
struct mCore* core = GBACoreCreate();
|
||||||
GBAContextInit(&context, "fuzz");
|
core->init(core);
|
||||||
struct mCoreOptions opts = {}; // TODO: Put back idle loops
|
mCoreInitConfig(core, "fuzz");
|
||||||
mCoreConfigLoadDefaults(&context.config, &opts);
|
mCoreConfigSetDefaultIntValue(&core->config, "idleOptimization", IDLE_LOOP_REMOVE);
|
||||||
mCoreConfigFreeOpts(&opts);
|
|
||||||
|
|
||||||
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], FUZZ_USAGE);
|
usage(argv[0], FUZZ_USAGE);
|
||||||
GBAContextDeinit(&context);
|
core->deinit(core);
|
||||||
return !parsed;
|
return !parsed;
|
||||||
}
|
}
|
||||||
if (args.showVersion) {
|
if (args.showVersion) {
|
||||||
version(argv[0]);
|
version(argv[0]);
|
||||||
GBAContextDeinit(&context);
|
core->deinit(core);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
applyArguments(&args, NULL, &context.config);
|
applyArguments(&args, NULL, &core->config);
|
||||||
|
|
||||||
struct GBAVideoSoftwareRenderer renderer;
|
void* outputBuffer;
|
||||||
renderer.outputBuffer = 0;
|
outputBuffer = 0;
|
||||||
|
|
||||||
if (!fuzzOpts.noVideo) {
|
if (!fuzzOpts.noVideo) {
|
||||||
GBAVideoSoftwareRendererCreate(&renderer);
|
outputBuffer = malloc(256 * 256 * 4);
|
||||||
renderer.outputBuffer = malloc(256 * 256 * 4);
|
core->setVideoBuffer(core, outputBuffer, 256);
|
||||||
renderer.outputBufferStride = 256;
|
|
||||||
context.renderer = &renderer.d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __AFL_HAVE_MANUAL_CONTROL
|
#ifdef __AFL_HAVE_MANUAL_CONTROL
|
||||||
__AFL_INIT();
|
__AFL_INIT();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct VFile* rom = VFileOpen(args.fname, O_RDONLY);
|
((struct GBA*) core->board)->hardCrash = false;
|
||||||
|
mCoreLoadFile(core, args.fname);
|
||||||
context.gba->hardCrash = false;
|
|
||||||
GBAContextLoadROMFromVFile(&context, rom, 0);
|
|
||||||
|
|
||||||
struct VFile* savestate = 0;
|
struct VFile* savestate = 0;
|
||||||
struct VFile* savestateOverlay = 0;
|
struct VFile* savestateOverlay = 0;
|
||||||
size_t overlayOffset;
|
size_t overlayOffset;
|
||||||
|
|
||||||
GBAContextStart(&context);
|
|
||||||
|
|
||||||
if (fuzzOpts.savestate) {
|
if (fuzzOpts.savestate) {
|
||||||
savestate = VFileOpen(fuzzOpts.savestate, O_RDONLY);
|
savestate = VFileOpen(fuzzOpts.savestate, O_RDONLY);
|
||||||
free(fuzzOpts.savestate);
|
free(fuzzOpts.savestate);
|
||||||
|
@ -109,12 +102,12 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
if (savestate) {
|
if (savestate) {
|
||||||
if (!savestateOverlay) {
|
if (!savestateOverlay) {
|
||||||
GBALoadStateNamed(context.gba, savestate, 0);
|
core->loadState(core, savestate, 0);
|
||||||
} else {
|
} else {
|
||||||
struct GBASerializedState* state = GBAAllocateState();
|
struct GBASerializedState* state = GBAAllocateState();
|
||||||
savestate->read(savestate, state, sizeof(*state));
|
savestate->read(savestate, state, sizeof(*state));
|
||||||
savestateOverlay->read(savestateOverlay, (uint8_t*) state + overlayOffset, sizeof(*state) - overlayOffset);
|
savestateOverlay->read(savestateOverlay, (uint8_t*) state + overlayOffset, sizeof(*state) - overlayOffset);
|
||||||
GBADeserialize(context.gba, state);
|
GBADeserialize(core->board, state);
|
||||||
GBADeallocateState(state);
|
GBADeallocateState(state);
|
||||||
savestateOverlay->close(savestateOverlay);
|
savestateOverlay->close(savestateOverlay);
|
||||||
savestateOverlay = 0;
|
savestateOverlay = 0;
|
||||||
|
@ -123,13 +116,12 @@ int main(int argc, char** argv) {
|
||||||
savestate = 0;
|
savestate = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
blip_set_rates(context.gba->audio.psg.left, GBA_ARM7TDMI_FREQUENCY, 0x8000);
|
blip_set_rates(core->getAudioChannel(core, 0), GBA_ARM7TDMI_FREQUENCY, 0x8000);
|
||||||
blip_set_rates(context.gba->audio.psg.right, 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);
|
core->unloadROM(core);
|
||||||
GBAContextUnloadROM(&context);
|
|
||||||
|
|
||||||
if (savestate) {
|
if (savestate) {
|
||||||
savestate->close(savestate);
|
savestate->close(savestate);
|
||||||
|
@ -139,18 +131,18 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
freeArguments(&args);
|
freeArguments(&args);
|
||||||
if (renderer.outputBuffer) {
|
if (outputBuffer) {
|
||||||
free(renderer.outputBuffer);
|
free(outputBuffer);
|
||||||
}
|
}
|
||||||
GBAContextDeinit(&context);
|
core->deinit(core);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _GBAFuzzRunloop(struct GBAContext* context, int frames) {
|
static void _GBAFuzzRunloop(struct mCore* core, int frames) {
|
||||||
do {
|
do {
|
||||||
GBAContextFrame(context, 0);
|
core->runFrame(core);
|
||||||
} while (context->gba->video.frameCounter < frames && !_dispatchExiting);
|
} while (core->frameCounter(core) < frames && !_dispatchExiting);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _GBAFuzzShutdown(int signal) {
|
static void _GBAFuzzShutdown(int signal) {
|
||||||
|
|
|
@ -63,22 +63,19 @@ int main(int argc, char** argv) {
|
||||||
mCoreConfigInit(&config, "perf");
|
mCoreConfigInit(&config, "perf");
|
||||||
mCoreConfigLoad(&config);
|
mCoreConfigLoad(&config);
|
||||||
|
|
||||||
struct mCoreOptions opts = {}; // TODO: Put back idle loops
|
mCoreConfigSetDefaultIntValue(&config, "idleOptimization", IDLE_LOOP_REMOVE);
|
||||||
mCoreConfigLoadDefaults(&config, &opts);
|
|
||||||
|
|
||||||
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);
|
||||||
mCoreConfigFreeOpts(&opts);
|
|
||||||
mCoreConfigDeinit(&config);
|
mCoreConfigDeinit(&config);
|
||||||
return !parsed;
|
return !parsed;
|
||||||
}
|
}
|
||||||
if (args.showVersion) {
|
if (args.showVersion) {
|
||||||
version(argv[0]);
|
version(argv[0]);
|
||||||
freeArguments(&args);
|
freeArguments(&args);
|
||||||
mCoreConfigFreeOpts(&opts);
|
|
||||||
mCoreConfigDeinit(&config);
|
mCoreConfigDeinit(&config);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -105,6 +102,7 @@ int main(int argc, char** argv) {
|
||||||
context.overrides = mCoreConfigGetOverrides(&config);
|
context.overrides = mCoreConfigGetOverrides(&config);
|
||||||
char gameCode[5] = { 0 };
|
char gameCode[5] = { 0 };
|
||||||
|
|
||||||
|
struct mCoreOptions opts;
|
||||||
mCoreConfigMap(&config, &opts);
|
mCoreConfigMap(&config, &opts);
|
||||||
opts.audioSync = false;
|
opts.audioSync = false;
|
||||||
opts.videoSync = false;
|
opts.videoSync = false;
|
||||||
|
|
Loading…
Reference in New Issue