mirror of https://github.com/mgba-emu/mgba.git
GBA Config: Begin refactor of separating out command line args from settings
This commit is contained in:
parent
5607a13039
commit
f36a74759a
|
@ -45,7 +45,7 @@ bool GBAConfigLoad(struct Configuration* config) {
|
|||
return ConfigurationRead(config, BINARY_NAME ".ini");
|
||||
}
|
||||
|
||||
void GBAConfigMapStartupOpts(const struct Configuration* config, const char* port, struct StartupOptions* opts) {
|
||||
void GBAConfigMapGeneralOpts(const struct Configuration* config, const char* port, struct GBAOptions* opts) {
|
||||
_lookupCharValue(config, "bios", port, &opts->bios);
|
||||
_lookupIntValue(config, "logLevel", port, &opts->logLevel);
|
||||
_lookupIntValue(config, "frameskip", port, &opts->frameskip);
|
||||
|
@ -53,8 +53,13 @@ void GBAConfigMapStartupOpts(const struct Configuration* config, const char* por
|
|||
_lookupIntValue(config, "rewindBufferInterval", port, &opts->rewindBufferInterval);
|
||||
}
|
||||
|
||||
void GBAConfigMapGraphicsOpts(const struct Configuration* config, const char* port, struct GraphicsOpts* opts) {
|
||||
void GBAConfigMapGraphicsOpts(const struct Configuration* config, const char* port, struct GBAOptions* opts) {
|
||||
_lookupIntValue(config, "fullscreen", port, &opts->fullscreen);
|
||||
_lookupIntValue(config, "width", port, &opts->width);
|
||||
_lookupIntValue(config, "height", port, &opts->height);
|
||||
}
|
||||
|
||||
void GBAConfigFreeOpts(struct GBAOptions* opts) {
|
||||
free(opts->bios);
|
||||
opts->bios = 0;
|
||||
}
|
||||
|
|
|
@ -4,12 +4,23 @@
|
|||
#include "util/common.h"
|
||||
|
||||
struct Configuration;
|
||||
struct StartupOptions;
|
||||
struct GraphicsOpts;
|
||||
|
||||
struct GBAOptions {
|
||||
char* bios;
|
||||
int logLevel;
|
||||
int frameskip;
|
||||
int rewindBufferCapacity;
|
||||
int rewindBufferInterval;
|
||||
|
||||
int fullscreen;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
bool GBAConfigLoad(struct Configuration*);
|
||||
|
||||
void GBAConfigMapStartupOpts(const struct Configuration*, const char* port, struct StartupOptions*);
|
||||
void GBAConfigMapGraphicsOpts(const struct Configuration*, const char* port, struct GraphicsOpts*);
|
||||
void GBAConfigMapGeneralOpts(const struct Configuration*, const char* port, struct GBAOptions*);
|
||||
void GBAConfigMapGraphicsOpts(const struct Configuration*, const char* port, struct GBAOptions*);
|
||||
void GBAConfigFreeOpts(struct GBAOptions*);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -217,7 +217,15 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void GBAMapOptionsToContext(struct StartupOptions* opts, struct GBAThread* threadContext) {
|
||||
void GBAMapOptionsToContext(struct GBAOptions* opts, struct GBAThread* threadContext) {
|
||||
threadContext->bios = VFileOpen(opts->bios, O_RDONLY);
|
||||
threadContext->frameskip = opts->frameskip;
|
||||
threadContext->logLevel = opts->logLevel;
|
||||
threadContext->rewindBufferCapacity = opts->rewindBufferCapacity;
|
||||
threadContext->rewindBufferInterval = opts->rewindBufferInterval;
|
||||
}
|
||||
|
||||
void GBAMapStartupOptionsToContext(struct StartupOptions* opts, struct GBAThread* threadContext) {
|
||||
if (opts->dirmode) {
|
||||
threadContext->gameDir = VDirOpen(opts->fname);
|
||||
threadContext->stateDir = threadContext->gameDir;
|
||||
|
@ -228,12 +236,7 @@ void GBAMapOptionsToContext(struct StartupOptions* opts, struct GBAThread* threa
|
|||
#endif
|
||||
}
|
||||
threadContext->fname = opts->fname;
|
||||
threadContext->bios = VFileOpen(opts->bios, O_RDONLY);
|
||||
threadContext->patch = VFileOpen(opts->patch, O_RDONLY);
|
||||
threadContext->frameskip = opts->frameskip;
|
||||
threadContext->logLevel = opts->logLevel;
|
||||
threadContext->rewindBufferCapacity = opts->rewindBufferCapacity;
|
||||
threadContext->rewindBufferInterval = opts->rewindBufferInterval;
|
||||
}
|
||||
|
||||
bool GBAThreadStart(struct GBAThread* threadContext) {
|
||||
|
|
|
@ -94,7 +94,8 @@ struct GBAThread {
|
|||
int rewindBufferWriteOffset;
|
||||
};
|
||||
|
||||
void GBAMapOptionsToContext(struct StartupOptions*, struct GBAThread*);
|
||||
void GBAMapOptionsToContext(struct GBAOptions*, struct GBAThread*);
|
||||
void GBAMapStartupOptionsToContext(struct StartupOptions*, struct GBAThread*);
|
||||
|
||||
bool GBAThreadStart(struct GBAThread* threadContext);
|
||||
bool GBAThreadHasStarted(struct GBAThread* threadContext);
|
||||
|
|
|
@ -38,9 +38,9 @@ static const struct option _options[] = {
|
|||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
bool _parseGraphicsArg(struct SubParser* parser, int option, const char* arg);
|
||||
bool _parseGraphicsArg(struct SubParser* parser, struct GBAOptions* gbaOpts, int option, const char* arg);
|
||||
|
||||
bool parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, struct SubParser* subparser) {
|
||||
bool parseCommandArgs(struct StartupOptions* opts, struct GBAOptions* gbaOpts, int argc, char* const* argv, struct SubParser* subparser) {
|
||||
int ch;
|
||||
char options[64] =
|
||||
"b:Dl:p:s:"
|
||||
|
@ -58,7 +58,10 @@ bool parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv,
|
|||
while ((ch = getopt_long(argc, argv, options, _options, 0)) != -1) {
|
||||
switch (ch) {
|
||||
case 'b':
|
||||
opts->bios = strdup(optarg);
|
||||
if (gbaOpts->bios) {
|
||||
free(gbaOpts->bios);
|
||||
}
|
||||
gbaOpts->bios = strdup(optarg);
|
||||
break;
|
||||
case 'D':
|
||||
opts->dirmode = true;
|
||||
|
@ -80,17 +83,17 @@ bool parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv,
|
|||
break;
|
||||
#endif
|
||||
case 'l':
|
||||
opts->logLevel = atoi(optarg);
|
||||
gbaOpts->logLevel = atoi(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
opts->patch = strdup(optarg);
|
||||
break;
|
||||
case 's':
|
||||
opts->frameskip = atoi(optarg);
|
||||
gbaOpts->frameskip = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
if (subparser) {
|
||||
if (!subparser->parse(subparser, ch, optarg)) {
|
||||
if (!subparser->parse(subparser, gbaOpts, ch, optarg)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -110,9 +113,6 @@ void freeOptions(struct StartupOptions* opts) {
|
|||
free(opts->fname);
|
||||
opts->fname = 0;
|
||||
|
||||
free(opts->bios);
|
||||
opts->bios = 0;
|
||||
|
||||
free(opts->patch);
|
||||
opts->patch = 0;
|
||||
}
|
||||
|
@ -125,12 +125,12 @@ void initParserForGraphics(struct SubParser* parser, struct GraphicsOpts* opts)
|
|||
opts->multiplier = 0;
|
||||
}
|
||||
|
||||
bool _parseGraphicsArg(struct SubParser* parser, int option, const char* arg) {
|
||||
bool _parseGraphicsArg(struct SubParser* parser, struct GBAOptions* gbaOpts, int option, const char* arg) {
|
||||
UNUSED(arg);
|
||||
struct GraphicsOpts* graphicsOpts = parser->opts;
|
||||
switch (option) {
|
||||
case 'f':
|
||||
graphicsOpts->fullscreen = 1;
|
||||
gbaOpts->fullscreen = 1;
|
||||
return true;
|
||||
case '1':
|
||||
case '2':
|
||||
|
@ -140,8 +140,8 @@ bool _parseGraphicsArg(struct SubParser* parser, int option, const char* arg) {
|
|||
return false;
|
||||
}
|
||||
graphicsOpts->multiplier = option - '0';
|
||||
graphicsOpts->width = VIDEO_HORIZONTAL_PIXELS * graphicsOpts->multiplier;
|
||||
graphicsOpts->height = VIDEO_VERTICAL_PIXELS * graphicsOpts->multiplier;
|
||||
gbaOpts->width = VIDEO_HORIZONTAL_PIXELS * graphicsOpts->multiplier;
|
||||
gbaOpts->height = VIDEO_VERTICAL_PIXELS * graphicsOpts->multiplier;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "util/common.h"
|
||||
|
||||
#include "gba-config.h"
|
||||
|
||||
enum DebuggerType {
|
||||
DEBUGGER_NONE = 0,
|
||||
#ifdef USE_CLI_DEBUGGER
|
||||
|
@ -15,40 +17,26 @@ enum DebuggerType {
|
|||
};
|
||||
|
||||
struct StartupOptions {
|
||||
// Passed only
|
||||
char* fname;
|
||||
char* patch;
|
||||
bool dirmode;
|
||||
|
||||
enum DebuggerType debuggerType;
|
||||
bool debugAtStart;
|
||||
|
||||
// Configurable
|
||||
char* bios;
|
||||
int logLevel;
|
||||
int frameskip;
|
||||
int rewindBufferCapacity;
|
||||
int rewindBufferInterval;
|
||||
};
|
||||
|
||||
struct SubParser {
|
||||
const char* usage;
|
||||
bool (*parse)(struct SubParser* parser, int option, const char* arg);
|
||||
bool (*parse)(struct SubParser* parser, struct GBAOptions* gbaOpts, int option, const char* arg);
|
||||
const char* extraOptions;
|
||||
void* opts;
|
||||
};
|
||||
|
||||
struct GraphicsOpts {
|
||||
// Passed only
|
||||
int multiplier;
|
||||
|
||||
// Configurable
|
||||
int fullscreen;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
bool parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, struct SubParser* subparser);
|
||||
bool parseCommandArgs(struct StartupOptions* opts, struct GBAOptions* gbaOpts, int argc, char* const* argv, struct SubParser* subparser);
|
||||
void freeOptions(struct StartupOptions* opts);
|
||||
|
||||
void usage(const char* arg0, const char* extraOptions);
|
||||
|
|
|
@ -25,7 +25,7 @@ struct PerfOpts {
|
|||
|
||||
static void _GBAPerfRunloop(struct GBAThread* context, int* frames, bool quiet);
|
||||
static void _GBAPerfShutdown(int signal);
|
||||
static bool _parsePerfOpts(struct SubParser* parser, int option, const char* arg);
|
||||
static bool _parsePerfOpts(struct SubParser* parser, struct GBAOptions* gbaOpts, int option, const char* arg);
|
||||
|
||||
static struct GBAThread* _thread;
|
||||
|
||||
|
@ -43,8 +43,9 @@ int main(int argc, char** argv) {
|
|||
.opts = &perfOpts
|
||||
};
|
||||
|
||||
struct GBAOptions gbaOpts = {};
|
||||
struct StartupOptions opts = {};
|
||||
if (!parseCommandArgs(&opts, argc, argv, &subparser)) {
|
||||
if (!parseCommandArgs(&opts, &gbaOpts, argc, argv, &subparser)) {
|
||||
usage(argv[0], PERF_USAGE);
|
||||
return 1;
|
||||
}
|
||||
|
@ -65,7 +66,8 @@ int main(int argc, char** argv) {
|
|||
context.debugger = createDebugger(&opts);
|
||||
char gameCode[5] = { 0 };
|
||||
|
||||
GBAMapOptionsToContext(&opts, &context);
|
||||
GBAMapStartupOptionsToContext(&opts, &context);
|
||||
GBAMapOptionsToContext(&gbaOpts, &context);
|
||||
|
||||
GBAThreadStart(&context);
|
||||
GBAGetGameCode(context.gba, gameCode);
|
||||
|
@ -147,7 +149,8 @@ static void _GBAPerfShutdown(int signal) {
|
|||
pthread_mutex_unlock(&_thread->stateMutex);
|
||||
}
|
||||
|
||||
static bool _parsePerfOpts(struct SubParser* parser, int option, const char* arg) {
|
||||
static bool _parsePerfOpts(struct SubParser* parser, struct GBAOptions* gbaOpts, int option, const char* arg) {
|
||||
UNUSED(gbaOpts);
|
||||
struct PerfOpts* opts = parser->opts;
|
||||
errno = 0;
|
||||
switch (option) {
|
||||
|
|
|
@ -12,8 +12,11 @@ GBAApp::GBAApp(int& argc, char* argv[])
|
|||
QApplication::setApplicationName(PROJECT_NAME);
|
||||
QApplication::setApplicationVersion(PROJECT_VERSION);
|
||||
|
||||
if (parseCommandArgs(&m_opts, argc, argv, 0)) {
|
||||
if (parseCommandArgs(&m_opts, &m_gbaOpts, argc, argv, 0)) {
|
||||
m_window.setOptions(&m_gbaOpts);
|
||||
m_window.optionsPassed(&m_opts);
|
||||
} else {
|
||||
m_window.setOptions(&m_gbaOpts);
|
||||
}
|
||||
|
||||
m_window.show();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
extern "C" {
|
||||
#include "platform/commandline.h"
|
||||
#include "util/configuration.h"
|
||||
}
|
||||
|
||||
namespace QGBA {
|
||||
|
@ -27,6 +28,8 @@ private:
|
|||
Window m_window;
|
||||
|
||||
StartupOptions m_opts;
|
||||
GBAOptions m_gbaOpts;
|
||||
Configuration m_config;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -102,18 +102,6 @@ GBAKey Window::mapKey(int qtKey) {
|
|||
}
|
||||
|
||||
void Window::optionsPassed(StartupOptions* opts) {
|
||||
if (opts->logLevel) {
|
||||
m_logView->setLevels(opts->logLevel);
|
||||
}
|
||||
|
||||
if (opts->frameskip) {
|
||||
m_controller->setFrameskip(opts->frameskip);
|
||||
}
|
||||
|
||||
if (opts->bios) {
|
||||
m_controller->loadBIOS(opts->bios);
|
||||
}
|
||||
|
||||
if (opts->patch) {
|
||||
m_controller->loadPatch(opts->patch);
|
||||
}
|
||||
|
@ -123,6 +111,15 @@ void Window::optionsPassed(StartupOptions* opts) {
|
|||
}
|
||||
}
|
||||
|
||||
void Window::setOptions(GBAOptions* opts) {
|
||||
m_logView->setLevels(opts->logLevel);
|
||||
m_controller->setFrameskip(opts->frameskip);
|
||||
|
||||
if (opts->bios) {
|
||||
m_controller->loadBIOS(opts->bios);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::selectROM() {
|
||||
QString filename = QFileDialog::getOpenFileName(this, tr("Select ROM"));
|
||||
if (!filename.isEmpty()) {
|
||||
|
|
|
@ -12,6 +12,7 @@ extern "C" {
|
|||
#include "Display.h"
|
||||
#include "LoadSaveState.h"
|
||||
|
||||
struct GBAOptions;
|
||||
struct StartupOptions;
|
||||
|
||||
namespace QGBA {
|
||||
|
@ -32,6 +33,7 @@ public:
|
|||
|
||||
static GBAKey mapKey(int qtKey);
|
||||
|
||||
void setOptions(GBAOptions*);
|
||||
void optionsPassed(StartupOptions*);
|
||||
|
||||
signals:
|
||||
|
|
|
@ -69,25 +69,26 @@ int main(int argc, char** argv) {
|
|||
ConfigurationInit(&config);
|
||||
GBAConfigLoad(&config);
|
||||
|
||||
struct StartupOptions opts = { };
|
||||
struct GraphicsOpts graphicsOpts = { };
|
||||
struct GBAOptions gbaOpts = {};
|
||||
struct StartupOptions opts = {};
|
||||
struct GraphicsOpts graphicsOpts = {};
|
||||
|
||||
struct SubParser subparser;
|
||||
|
||||
GBAConfigMapStartupOpts(&config, PORT, &opts);
|
||||
GBAConfigMapGraphicsOpts(&config, PORT, &graphicsOpts);
|
||||
GBAConfigMapGeneralOpts(&config, PORT, &gbaOpts);
|
||||
GBAConfigMapGraphicsOpts(&config, PORT, &gbaOpts);
|
||||
|
||||
initParserForGraphics(&subparser, &graphicsOpts);
|
||||
if (!parseCommandArgs(&opts, argc, argv, &subparser)) {
|
||||
if (!parseCommandArgs(&opts, &gbaOpts, argc, argv, &subparser)) {
|
||||
usage(argv[0], subparser.usage);
|
||||
freeOptions(&opts);
|
||||
return 1;
|
||||
}
|
||||
|
||||
renderer.viewportWidth = graphicsOpts.width;
|
||||
renderer.viewportHeight = graphicsOpts.height;
|
||||
renderer.viewportWidth = gbaOpts.width;
|
||||
renderer.viewportHeight = gbaOpts.height;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
renderer.events.fullscreen = graphicsOpts.fullscreen;
|
||||
renderer.events.fullscreen = gbaOpts.fullscreen;
|
||||
renderer.events.windowUpdated = 0;
|
||||
#endif
|
||||
|
||||
|
@ -108,7 +109,8 @@ int main(int argc, char** argv) {
|
|||
|
||||
context.debugger = createDebugger(&opts);
|
||||
|
||||
GBAMapOptionsToContext(&opts, &context);
|
||||
GBAMapOptionsToContext(&gbaOpts, &context);
|
||||
GBAMapStartupOptionsToContext(&opts, &context);
|
||||
|
||||
renderer.audio.samples = context.audioBuffers;
|
||||
GBASDLInitAudio(&renderer.audio);
|
||||
|
|
Loading…
Reference in New Issue