mirror of https://github.com/mgba-emu/mgba.git
Feature: Move command-line patch/cheats argument handling
This commit is contained in:
parent
3e47da2e18
commit
18a35b3928
|
@ -60,6 +60,7 @@ void version(const char* arg0);
|
||||||
bool mArgumentsParse(struct mArguments* args, int argc, char* const* argv, struct mSubParser* subparsers, int nSubparsers);
|
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);
|
void mArgumentsApply(const struct mArguments* args, struct mSubParser* subparsers, int nSubparsers, struct mCoreConfig* config);
|
||||||
bool mArgumentsApplyDebugger(const struct mArguments*, struct mCore*, struct mDebugger*);
|
bool mArgumentsApplyDebugger(const struct mArguments*, struct mCore*, struct mDebugger*);
|
||||||
|
void mArgumentsApplyFileLoads(const struct mArguments*, struct mCore*);
|
||||||
void mArgumentsDeinit(struct mArguments* args);
|
void mArgumentsDeinit(struct mArguments* args);
|
||||||
|
|
||||||
void mSubParserGraphicsInit(struct mSubParser* parser, struct mGraphicsOpts* opts);
|
void mSubParserGraphicsInit(struct mSubParser* parser, struct mGraphicsOpts* opts);
|
||||||
|
|
|
@ -5,9 +5,12 @@
|
||||||
* 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 <mgba/feature/commandline.h>
|
#include <mgba/feature/commandline.h>
|
||||||
|
|
||||||
|
#include <mgba/core/cheats.h>
|
||||||
#include <mgba/core/config.h>
|
#include <mgba/core/config.h>
|
||||||
|
#include <mgba/core/core.h>
|
||||||
#include <mgba/core/version.h>
|
#include <mgba/core/version.h>
|
||||||
#include <mgba-util/string.h>
|
#include <mgba-util/string.h>
|
||||||
|
#include <mgba-util/vfs.h>
|
||||||
|
|
||||||
#ifdef USE_GDB_STUB
|
#ifdef USE_GDB_STUB
|
||||||
#include <mgba/internal/debugger/gdb-stub.h>
|
#include <mgba/internal/debugger/gdb-stub.h>
|
||||||
|
@ -241,6 +244,30 @@ bool mArgumentsApplyDebugger(const struct mArguments* args, struct mCore* core,
|
||||||
return hasDebugger;
|
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) {
|
void mArgumentsDeinit(struct mArguments* args) {
|
||||||
free(args->fname);
|
free(args->fname);
|
||||||
args->fname = 0;
|
args->fname = 0;
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <mgba/core/cheats.h>
|
|
||||||
#include <mgba/core/core.h>
|
#include <mgba/core/core.h>
|
||||||
#include <mgba/core/config.h>
|
#include <mgba/core/config.h>
|
||||||
#include <mgba/core/input.h>
|
#include <mgba/core/input.h>
|
||||||
|
@ -110,16 +109,6 @@ int main(int argc, char** argv) {
|
||||||
opts.width = renderer.width * renderer.ratio;
|
opts.width = renderer.width * renderer.ratio;
|
||||||
opts.height = renderer.height * 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);
|
mInputMapInit(&renderer.core->inputMap, &GBAInputInfo);
|
||||||
mCoreInitConfig(renderer.core, PORT);
|
mCoreInitConfig(renderer.core, PORT);
|
||||||
mArgumentsApply(&args, &subparser, 1, &renderer.core->config);
|
mArgumentsApply(&args, &subparser, 1, &renderer.core->config);
|
||||||
|
@ -183,10 +172,6 @@ int main(int argc, char** argv) {
|
||||||
mSDLDetachPlayer(&renderer.events, &renderer.player);
|
mSDLDetachPlayer(&renderer.events, &renderer.player);
|
||||||
mInputMapDeinit(&renderer.core->inputMap);
|
mInputMapDeinit(&renderer.core->inputMap);
|
||||||
|
|
||||||
if (device) {
|
|
||||||
mCheatDeviceDestroy(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
mSDLDeinit(&renderer);
|
mSDLDeinit(&renderer);
|
||||||
mStandardLoggerDeinit(&_logger);
|
mStandardLoggerDeinit(&_logger);
|
||||||
|
|
||||||
|
@ -225,7 +210,7 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
mCoreAutoloadSave(renderer->core);
|
mCoreAutoloadSave(renderer->core);
|
||||||
mCoreAutoloadCheats(renderer->core);
|
mArgumentsApplyFileLoads(args, renderer->core);
|
||||||
#ifdef ENABLE_SCRIPTING
|
#ifdef ENABLE_SCRIPTING
|
||||||
struct mScriptBridge* bridge = mScriptBridgeCreate();
|
struct mScriptBridge* bridge = mScriptBridgeCreate();
|
||||||
#ifdef ENABLE_PYTHON
|
#ifdef ENABLE_PYTHON
|
||||||
|
@ -252,15 +237,6 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) {
|
||||||
}
|
}
|
||||||
#endif
|
#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.samples = renderer->core->opts.audioBuffers;
|
||||||
renderer->audio.sampleRate = 44100;
|
renderer->audio.sampleRate = 44100;
|
||||||
thread.logger.logger = &_logger.d;
|
thread.logger.logger = &_logger.d;
|
||||||
|
|
Loading…
Reference in New Issue