mirror of https://github.com/mgba-emu/mgba.git
GBA Config: Further separate arguments from options, renaming things in the process
This commit is contained in:
parent
f36a74759a
commit
6afa678a41
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "arm.h"
|
||||
#include "gba.h"
|
||||
#include "gba-config.h"
|
||||
#include "gba-serialize.h"
|
||||
|
||||
#include "debugger/debugger.h"
|
||||
|
@ -10,6 +11,8 @@
|
|||
#include "util/png-io.h"
|
||||
#include "util/vfs.h"
|
||||
|
||||
#include "platform/commandline.h"
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
static const float _defaultFPSTarget = 60.f;
|
||||
|
@ -225,18 +228,18 @@ void GBAMapOptionsToContext(struct GBAOptions* opts, struct GBAThread* threadCon
|
|||
threadContext->rewindBufferInterval = opts->rewindBufferInterval;
|
||||
}
|
||||
|
||||
void GBAMapStartupOptionsToContext(struct StartupOptions* opts, struct GBAThread* threadContext) {
|
||||
if (opts->dirmode) {
|
||||
threadContext->gameDir = VDirOpen(opts->fname);
|
||||
void GBAMapArgumentsToContext(struct GBAArguments* args, struct GBAThread* threadContext) {
|
||||
if (args->dirmode) {
|
||||
threadContext->gameDir = VDirOpen(args->fname);
|
||||
threadContext->stateDir = threadContext->gameDir;
|
||||
} else {
|
||||
threadContext->rom = VFileOpen(opts->fname, O_RDONLY);
|
||||
threadContext->rom = VFileOpen(args->fname, O_RDONLY);
|
||||
#if ENABLE_LIBZIP
|
||||
threadContext->gameDir = VDirOpenZip(opts->fname, 0);
|
||||
threadContext->gameDir = VDirOpenZip(args->fname, 0);
|
||||
#endif
|
||||
}
|
||||
threadContext->fname = opts->fname;
|
||||
threadContext->patch = VFileOpen(opts->patch, O_RDONLY);
|
||||
threadContext->fname = args->fname;
|
||||
threadContext->patch = VFileOpen(args->patch, O_RDONLY);
|
||||
}
|
||||
|
||||
bool GBAThreadStart(struct GBAThread* threadContext) {
|
||||
|
|
|
@ -7,9 +7,10 @@
|
|||
#include "gba-input.h"
|
||||
|
||||
#include "util/threading.h"
|
||||
#include "platform/commandline.h"
|
||||
|
||||
struct GBAThread;
|
||||
struct GBAArguments;
|
||||
struct GBAOptions;
|
||||
typedef void (*ThreadCallback)(struct GBAThread* threadContext);
|
||||
typedef void (*LogHandler)(struct GBAThread*, enum GBALogLevel, const char* format, va_list args);
|
||||
|
||||
|
@ -95,7 +96,7 @@ struct GBAThread {
|
|||
};
|
||||
|
||||
void GBAMapOptionsToContext(struct GBAOptions*, struct GBAThread*);
|
||||
void GBAMapStartupOptionsToContext(struct StartupOptions*, struct GBAThread*);
|
||||
void GBAMapArgumentsToContext(struct GBAArguments*, struct GBAThread*);
|
||||
|
||||
bool GBAThreadStart(struct GBAThread* threadContext);
|
||||
bool GBAThreadHasStarted(struct GBAThread* threadContext);
|
||||
|
|
|
@ -40,7 +40,7 @@ static const struct option _options[] = {
|
|||
|
||||
bool _parseGraphicsArg(struct SubParser* parser, struct GBAOptions* gbaOpts, int option, const char* arg);
|
||||
|
||||
bool parseCommandArgs(struct StartupOptions* opts, struct GBAOptions* gbaOpts, int argc, char* const* argv, struct SubParser* subparser) {
|
||||
bool parseArguments(struct GBAArguments* opts, struct GBAOptions* gbaOpts, int argc, char* const* argv, struct SubParser* subparser) {
|
||||
int ch;
|
||||
char options[64] =
|
||||
"b:Dl:p:s:"
|
||||
|
@ -109,7 +109,7 @@ bool parseCommandArgs(struct StartupOptions* opts, struct GBAOptions* gbaOpts, i
|
|||
return true;
|
||||
}
|
||||
|
||||
void freeOptions(struct StartupOptions* opts) {
|
||||
void freeArguments(struct GBAArguments* opts) {
|
||||
free(opts->fname);
|
||||
opts->fname = 0;
|
||||
|
||||
|
@ -148,7 +148,7 @@ bool _parseGraphicsArg(struct SubParser* parser, struct GBAOptions* gbaOpts, int
|
|||
}
|
||||
}
|
||||
|
||||
struct ARMDebugger* createDebugger(struct StartupOptions* opts) {
|
||||
struct ARMDebugger* createDebugger(struct GBAArguments* opts) {
|
||||
union DebugUnion {
|
||||
struct ARMDebugger d;
|
||||
#ifdef USE_CLI_DEBUGGER
|
||||
|
|
|
@ -16,7 +16,7 @@ enum DebuggerType {
|
|||
DEBUGGER_MAX
|
||||
};
|
||||
|
||||
struct StartupOptions {
|
||||
struct GBAArguments {
|
||||
char* fname;
|
||||
char* patch;
|
||||
bool dirmode;
|
||||
|
@ -36,12 +36,12 @@ struct GraphicsOpts {
|
|||
int multiplier;
|
||||
};
|
||||
|
||||
bool parseCommandArgs(struct StartupOptions* opts, struct GBAOptions* gbaOpts, int argc, char* const* argv, struct SubParser* subparser);
|
||||
void freeOptions(struct StartupOptions* opts);
|
||||
bool parseArguments(struct GBAArguments* opts, struct GBAOptions* gbaOpts, int argc, char* const* argv, struct SubParser* subparser);
|
||||
void freeArguments(struct GBAArguments* opts);
|
||||
|
||||
void usage(const char* arg0, const char* extraOptions);
|
||||
|
||||
void initParserForGraphics(struct SubParser* parser, struct GraphicsOpts* opts);
|
||||
struct ARMDebugger* createDebugger(struct StartupOptions* opts);
|
||||
struct ARMDebugger* createDebugger(struct GBAArguments* opts);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#include "gba-thread.h"
|
||||
#include "gba-config.h"
|
||||
#include "gba.h"
|
||||
#include "renderers/video-software.h"
|
||||
|
||||
#include "platform/commandline.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
|
@ -43,9 +46,9 @@ int main(int argc, char** argv) {
|
|||
.opts = &perfOpts
|
||||
};
|
||||
|
||||
struct GBAOptions gbaOpts = {};
|
||||
struct StartupOptions opts = {};
|
||||
if (!parseCommandArgs(&opts, &gbaOpts, argc, argv, &subparser)) {
|
||||
struct GBAOptions opts = {};
|
||||
struct GBAArguments args = {};
|
||||
if (!parseArguments(&args, &opts, argc, argv, &subparser)) {
|
||||
usage(argv[0], PERF_USAGE);
|
||||
return 1;
|
||||
}
|
||||
|
@ -63,11 +66,11 @@ int main(int argc, char** argv) {
|
|||
context.renderer = &renderer.d;
|
||||
}
|
||||
|
||||
context.debugger = createDebugger(&opts);
|
||||
context.debugger = createDebugger(&args);
|
||||
char gameCode[5] = { 0 };
|
||||
|
||||
GBAMapStartupOptionsToContext(&opts, &context);
|
||||
GBAMapOptionsToContext(&gbaOpts, &context);
|
||||
GBAMapArgumentsToContext(&args, &context);
|
||||
GBAMapOptionsToContext(&opts, &context);
|
||||
|
||||
GBAThreadStart(&context);
|
||||
GBAGetGameCode(context.gba, gameCode);
|
||||
|
@ -85,7 +88,8 @@ int main(int argc, char** argv) {
|
|||
uint64_t duration = end - start;
|
||||
|
||||
GBAThreadJoin(&context);
|
||||
freeOptions(&opts);
|
||||
GBAConfigFreeOpts(&opts);
|
||||
freeArguments(&args);
|
||||
free(context.debugger);
|
||||
|
||||
free(renderer.outputBuffer);
|
||||
|
|
|
@ -12,18 +12,19 @@ GBAApp::GBAApp(int& argc, char* argv[])
|
|||
QApplication::setApplicationName(PROJECT_NAME);
|
||||
QApplication::setApplicationVersion(PROJECT_VERSION);
|
||||
|
||||
if (parseCommandArgs(&m_opts, &m_gbaOpts, argc, argv, 0)) {
|
||||
m_window.setOptions(&m_gbaOpts);
|
||||
m_window.optionsPassed(&m_opts);
|
||||
if (parseArguments(&m_args, &m_opts, argc, argv, 0)) {
|
||||
m_window.setOptions(&m_opts);
|
||||
m_window.argumentsPassed(&m_args);
|
||||
} else {
|
||||
m_window.setOptions(&m_gbaOpts);
|
||||
m_window.setOptions(&m_opts);
|
||||
}
|
||||
|
||||
m_window.show();
|
||||
}
|
||||
|
||||
GBAApp::~GBAApp() {
|
||||
freeOptions(&m_opts);
|
||||
freeArguments(&m_args);
|
||||
GBAConfigFreeOpts(&m_opts);
|
||||
}
|
||||
|
||||
bool GBAApp::event(QEvent* event) {
|
||||
|
|
|
@ -27,8 +27,8 @@ protected:
|
|||
private:
|
||||
Window m_window;
|
||||
|
||||
StartupOptions m_opts;
|
||||
GBAOptions m_gbaOpts;
|
||||
GBAArguments m_args;
|
||||
GBAOptions m_opts;
|
||||
Configuration m_config;
|
||||
};
|
||||
|
||||
|
|
|
@ -101,13 +101,13 @@ GBAKey Window::mapKey(int qtKey) {
|
|||
}
|
||||
}
|
||||
|
||||
void Window::optionsPassed(StartupOptions* opts) {
|
||||
if (opts->patch) {
|
||||
m_controller->loadPatch(opts->patch);
|
||||
void Window::argumentsPassed(GBAArguments* args) {
|
||||
if (args->patch) {
|
||||
m_controller->loadPatch(args->patch);
|
||||
}
|
||||
|
||||
if (opts->fname) {
|
||||
m_controller->loadGame(opts->fname, opts->dirmode);
|
||||
if (args->fname) {
|
||||
m_controller->loadGame(args->fname, args->dirmode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ extern "C" {
|
|||
#include "LoadSaveState.h"
|
||||
|
||||
struct GBAOptions;
|
||||
struct StartupOptions;
|
||||
struct GBAArguments;
|
||||
|
||||
namespace QGBA {
|
||||
|
||||
|
@ -34,7 +34,7 @@ public:
|
|||
static GBAKey mapKey(int qtKey);
|
||||
|
||||
void setOptions(GBAOptions*);
|
||||
void optionsPassed(StartupOptions*);
|
||||
void argumentsPassed(GBAArguments*);
|
||||
|
||||
signals:
|
||||
void startDrawing(const uint32_t*, GBAThread*);
|
||||
|
|
|
@ -69,31 +69,33 @@ int main(int argc, char** argv) {
|
|||
ConfigurationInit(&config);
|
||||
GBAConfigLoad(&config);
|
||||
|
||||
struct GBAOptions gbaOpts = {};
|
||||
struct StartupOptions opts = {};
|
||||
struct GBAOptions opts = {};
|
||||
struct GBAArguments args = {};
|
||||
struct GraphicsOpts graphicsOpts = {};
|
||||
|
||||
struct SubParser subparser;
|
||||
|
||||
GBAConfigMapGeneralOpts(&config, PORT, &gbaOpts);
|
||||
GBAConfigMapGraphicsOpts(&config, PORT, &gbaOpts);
|
||||
GBAConfigMapGeneralOpts(&config, PORT, &opts);
|
||||
GBAConfigMapGraphicsOpts(&config, PORT, &opts);
|
||||
|
||||
initParserForGraphics(&subparser, &graphicsOpts);
|
||||
if (!parseCommandArgs(&opts, &gbaOpts, argc, argv, &subparser)) {
|
||||
if (!parseArguments(&args, &opts, argc, argv, &subparser)) {
|
||||
usage(argv[0], subparser.usage);
|
||||
freeOptions(&opts);
|
||||
freeArguments(&args);
|
||||
GBAConfigFreeOpts(&opts);
|
||||
return 1;
|
||||
}
|
||||
|
||||
renderer.viewportWidth = gbaOpts.width;
|
||||
renderer.viewportHeight = gbaOpts.height;
|
||||
renderer.viewportWidth = opts.width;
|
||||
renderer.viewportHeight = opts.height;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
renderer.events.fullscreen = gbaOpts.fullscreen;
|
||||
renderer.events.fullscreen = opts.fullscreen;
|
||||
renderer.events.windowUpdated = 0;
|
||||
#endif
|
||||
|
||||
if (!_GBASDLInit(&renderer)) {
|
||||
freeOptions(&opts);
|
||||
freeArguments(&args);
|
||||
GBAConfigFreeOpts(&opts);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -107,10 +109,10 @@ int main(int argc, char** argv) {
|
|||
.userData = &renderer
|
||||
};
|
||||
|
||||
context.debugger = createDebugger(&opts);
|
||||
context.debugger = createDebugger(&args);
|
||||
|
||||
GBAMapOptionsToContext(&gbaOpts, &context);
|
||||
GBAMapStartupOptionsToContext(&opts, &context);
|
||||
GBAMapOptionsToContext(&opts, &context);
|
||||
GBAMapArgumentsToContext(&args, &context);
|
||||
|
||||
renderer.audio.samples = context.audioBuffers;
|
||||
GBASDLInitAudio(&renderer.audio);
|
||||
|
@ -123,7 +125,8 @@ int main(int argc, char** argv) {
|
|||
_GBASDLRunloop(&context, &renderer);
|
||||
|
||||
GBAThreadJoin(&context);
|
||||
freeOptions(&opts);
|
||||
freeArguments(&args);
|
||||
GBAConfigFreeOpts(&opts);
|
||||
free(context.debugger);
|
||||
|
||||
_GBASDLDeinit(&renderer);
|
||||
|
|
Loading…
Reference in New Issue