Feature: Move command-line patch/cheats argument handling

This commit is contained in:
Vicki Pfau 2023-11-24 22:12:40 -08:00
parent 3e47da2e18
commit 18a35b3928
3 changed files with 29 additions and 25 deletions

View File

@ -60,6 +60,7 @@ void version(const char* arg0);
bool mArgumentsParse(struct mArguments* args, int argc, char* const* argv, struct mSubParser* subparsers, int nSubparsers);
void mArgumentsApply(const struct mArguments* args, struct mSubParser* subparsers, int nSubparsers, struct mCoreConfig* config);
bool mArgumentsApplyDebugger(const struct mArguments*, struct mCore*, struct mDebugger*);
void mArgumentsApplyFileLoads(const struct mArguments*, struct mCore*);
void mArgumentsDeinit(struct mArguments* args);
void mSubParserGraphicsInit(struct mSubParser* parser, struct mGraphicsOpts* opts);

View File

@ -5,9 +5,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <mgba/feature/commandline.h>
#include <mgba/core/cheats.h>
#include <mgba/core/config.h>
#include <mgba/core/core.h>
#include <mgba/core/version.h>
#include <mgba-util/string.h>
#include <mgba-util/vfs.h>
#ifdef USE_GDB_STUB
#include <mgba/internal/debugger/gdb-stub.h>
@ -241,6 +244,30 @@ bool mArgumentsApplyDebugger(const struct mArguments* args, struct mCore* core,
return hasDebugger;
}
void mArgumentsApplyFileLoads(const struct mArguments* args, struct mCore* core) {
if (args->patch) {
struct VFile* patch = VFileOpen(args->patch, O_RDONLY);
if (patch) {
core->loadPatch(core, patch);
patch->close(patch);
}
} else {
mCoreAutoloadPatch(core);
}
struct mCheatDevice* device = NULL;
if (args->cheatsFile && (device = core->cheatDevice(core))) {
struct VFile* vf = VFileOpen(args->cheatsFile, O_RDONLY);
if (vf) {
mCheatDeviceClear(device);
mCheatParseFile(device, vf);
vf->close(vf);
}
} else {
mCoreAutoloadCheats(core);
}
}
void mArgumentsDeinit(struct mArguments* args) {
free(args->fname);
args->fname = 0;

View File

@ -15,7 +15,6 @@
#endif
#endif
#include <mgba/core/cheats.h>
#include <mgba/core/core.h>
#include <mgba/core/config.h>
#include <mgba/core/input.h>
@ -110,16 +109,6 @@ int main(int argc, char** argv) {
opts.width = renderer.width * renderer.ratio;
opts.height = renderer.height * renderer.ratio;
struct mCheatDevice* device = NULL;
if (args.cheatsFile && (device = renderer.core->cheatDevice(renderer.core))) {
struct VFile* vf = VFileOpen(args.cheatsFile, O_RDONLY);
if (vf) {
mCheatDeviceClear(device);
mCheatParseFile(device, vf);
vf->close(vf);
}
}
mInputMapInit(&renderer.core->inputMap, &GBAInputInfo);
mCoreInitConfig(renderer.core, PORT);
mArgumentsApply(&args, &subparser, 1, &renderer.core->config);
@ -183,10 +172,6 @@ int main(int argc, char** argv) {
mSDLDetachPlayer(&renderer.events, &renderer.player);
mInputMapDeinit(&renderer.core->inputMap);
if (device) {
mCheatDeviceDestroy(device);
}
mSDLDeinit(&renderer);
mStandardLoggerDeinit(&_logger);
@ -225,7 +210,7 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) {
return 1;
}
mCoreAutoloadSave(renderer->core);
mCoreAutoloadCheats(renderer->core);
mArgumentsApplyFileLoads(args, renderer->core);
#ifdef ENABLE_SCRIPTING
struct mScriptBridge* bridge = mScriptBridgeCreate();
#ifdef ENABLE_PYTHON
@ -252,15 +237,6 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) {
}
#endif
if (args->patch) {
struct VFile* patch = VFileOpen(args->patch, O_RDONLY);
if (patch) {
renderer->core->loadPatch(renderer->core, patch);
}
} else {
mCoreAutoloadPatch(renderer->core);
}
renderer->audio.samples = renderer->core->opts.audioBuffers;
renderer->audio.sampleRate = 44100;
thread.logger.logger = &_logger.d;