GBA Config: Further separate arguments from options, renaming things in the process

This commit is contained in:
Jeffrey Pfau 2014-11-02 02:19:57 -08:00
parent f36a74759a
commit 6afa678a41
10 changed files with 63 additions and 51 deletions

View File

@ -2,6 +2,7 @@
#include "arm.h" #include "arm.h"
#include "gba.h" #include "gba.h"
#include "gba-config.h"
#include "gba-serialize.h" #include "gba-serialize.h"
#include "debugger/debugger.h" #include "debugger/debugger.h"
@ -10,6 +11,8 @@
#include "util/png-io.h" #include "util/png-io.h"
#include "util/vfs.h" #include "util/vfs.h"
#include "platform/commandline.h"
#include <signal.h> #include <signal.h>
static const float _defaultFPSTarget = 60.f; static const float _defaultFPSTarget = 60.f;
@ -225,18 +228,18 @@ void GBAMapOptionsToContext(struct GBAOptions* opts, struct GBAThread* threadCon
threadContext->rewindBufferInterval = opts->rewindBufferInterval; threadContext->rewindBufferInterval = opts->rewindBufferInterval;
} }
void GBAMapStartupOptionsToContext(struct StartupOptions* opts, struct GBAThread* threadContext) { void GBAMapArgumentsToContext(struct GBAArguments* args, struct GBAThread* threadContext) {
if (opts->dirmode) { if (args->dirmode) {
threadContext->gameDir = VDirOpen(opts->fname); threadContext->gameDir = VDirOpen(args->fname);
threadContext->stateDir = threadContext->gameDir; threadContext->stateDir = threadContext->gameDir;
} else { } else {
threadContext->rom = VFileOpen(opts->fname, O_RDONLY); threadContext->rom = VFileOpen(args->fname, O_RDONLY);
#if ENABLE_LIBZIP #if ENABLE_LIBZIP
threadContext->gameDir = VDirOpenZip(opts->fname, 0); threadContext->gameDir = VDirOpenZip(args->fname, 0);
#endif #endif
} }
threadContext->fname = opts->fname; threadContext->fname = args->fname;
threadContext->patch = VFileOpen(opts->patch, O_RDONLY); threadContext->patch = VFileOpen(args->patch, O_RDONLY);
} }
bool GBAThreadStart(struct GBAThread* threadContext) { bool GBAThreadStart(struct GBAThread* threadContext) {

View File

@ -7,9 +7,10 @@
#include "gba-input.h" #include "gba-input.h"
#include "util/threading.h" #include "util/threading.h"
#include "platform/commandline.h"
struct GBAThread; struct GBAThread;
struct GBAArguments;
struct GBAOptions;
typedef void (*ThreadCallback)(struct GBAThread* threadContext); typedef void (*ThreadCallback)(struct GBAThread* threadContext);
typedef void (*LogHandler)(struct GBAThread*, enum GBALogLevel, const char* format, va_list args); 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 GBAMapOptionsToContext(struct GBAOptions*, struct GBAThread*);
void GBAMapStartupOptionsToContext(struct StartupOptions*, struct GBAThread*); void GBAMapArgumentsToContext(struct GBAArguments*, struct GBAThread*);
bool GBAThreadStart(struct GBAThread* threadContext); bool GBAThreadStart(struct GBAThread* threadContext);
bool GBAThreadHasStarted(struct GBAThread* threadContext); bool GBAThreadHasStarted(struct GBAThread* threadContext);

View File

@ -40,7 +40,7 @@ static const struct option _options[] = {
bool _parseGraphicsArg(struct SubParser* parser, struct GBAOptions* gbaOpts, int option, const char* arg); 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; int ch;
char options[64] = char options[64] =
"b:Dl:p:s:" "b:Dl:p:s:"
@ -109,7 +109,7 @@ bool parseCommandArgs(struct StartupOptions* opts, struct GBAOptions* gbaOpts, i
return true; return true;
} }
void freeOptions(struct StartupOptions* opts) { void freeArguments(struct GBAArguments* opts) {
free(opts->fname); free(opts->fname);
opts->fname = 0; 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 { union DebugUnion {
struct ARMDebugger d; struct ARMDebugger d;
#ifdef USE_CLI_DEBUGGER #ifdef USE_CLI_DEBUGGER

View File

@ -16,7 +16,7 @@ enum DebuggerType {
DEBUGGER_MAX DEBUGGER_MAX
}; };
struct StartupOptions { struct GBAArguments {
char* fname; char* fname;
char* patch; char* patch;
bool dirmode; bool dirmode;
@ -36,12 +36,12 @@ struct GraphicsOpts {
int multiplier; int multiplier;
}; };
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);
void freeOptions(struct StartupOptions* opts); void freeArguments(struct GBAArguments* opts);
void usage(const char* arg0, const char* extraOptions); void usage(const char* arg0, const char* extraOptions);
void initParserForGraphics(struct SubParser* parser, struct GraphicsOpts* opts); void initParserForGraphics(struct SubParser* parser, struct GraphicsOpts* opts);
struct ARMDebugger* createDebugger(struct StartupOptions* opts); struct ARMDebugger* createDebugger(struct GBAArguments* opts);
#endif #endif

View File

@ -1,7 +1,10 @@
#include "gba-thread.h" #include "gba-thread.h"
#include "gba-config.h"
#include "gba.h" #include "gba.h"
#include "renderers/video-software.h" #include "renderers/video-software.h"
#include "platform/commandline.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
@ -43,9 +46,9 @@ int main(int argc, char** argv) {
.opts = &perfOpts .opts = &perfOpts
}; };
struct GBAOptions gbaOpts = {}; struct GBAOptions opts = {};
struct StartupOptions opts = {}; struct GBAArguments args = {};
if (!parseCommandArgs(&opts, &gbaOpts, argc, argv, &subparser)) { if (!parseArguments(&args, &opts, argc, argv, &subparser)) {
usage(argv[0], PERF_USAGE); usage(argv[0], PERF_USAGE);
return 1; return 1;
} }
@ -63,11 +66,11 @@ int main(int argc, char** argv) {
context.renderer = &renderer.d; context.renderer = &renderer.d;
} }
context.debugger = createDebugger(&opts); context.debugger = createDebugger(&args);
char gameCode[5] = { 0 }; char gameCode[5] = { 0 };
GBAMapStartupOptionsToContext(&opts, &context); GBAMapArgumentsToContext(&args, &context);
GBAMapOptionsToContext(&gbaOpts, &context); GBAMapOptionsToContext(&opts, &context);
GBAThreadStart(&context); GBAThreadStart(&context);
GBAGetGameCode(context.gba, gameCode); GBAGetGameCode(context.gba, gameCode);
@ -85,7 +88,8 @@ int main(int argc, char** argv) {
uint64_t duration = end - start; uint64_t duration = end - start;
GBAThreadJoin(&context); GBAThreadJoin(&context);
freeOptions(&opts); GBAConfigFreeOpts(&opts);
freeArguments(&args);
free(context.debugger); free(context.debugger);
free(renderer.outputBuffer); free(renderer.outputBuffer);

View File

@ -12,18 +12,19 @@ GBAApp::GBAApp(int& argc, char* argv[])
QApplication::setApplicationName(PROJECT_NAME); QApplication::setApplicationName(PROJECT_NAME);
QApplication::setApplicationVersion(PROJECT_VERSION); QApplication::setApplicationVersion(PROJECT_VERSION);
if (parseCommandArgs(&m_opts, &m_gbaOpts, argc, argv, 0)) { if (parseArguments(&m_args, &m_opts, argc, argv, 0)) {
m_window.setOptions(&m_gbaOpts); m_window.setOptions(&m_opts);
m_window.optionsPassed(&m_opts); m_window.argumentsPassed(&m_args);
} else { } else {
m_window.setOptions(&m_gbaOpts); m_window.setOptions(&m_opts);
} }
m_window.show(); m_window.show();
} }
GBAApp::~GBAApp() { GBAApp::~GBAApp() {
freeOptions(&m_opts); freeArguments(&m_args);
GBAConfigFreeOpts(&m_opts);
} }
bool GBAApp::event(QEvent* event) { bool GBAApp::event(QEvent* event) {

View File

@ -27,8 +27,8 @@ protected:
private: private:
Window m_window; Window m_window;
StartupOptions m_opts; GBAArguments m_args;
GBAOptions m_gbaOpts; GBAOptions m_opts;
Configuration m_config; Configuration m_config;
}; };

View File

@ -101,13 +101,13 @@ GBAKey Window::mapKey(int qtKey) {
} }
} }
void Window::optionsPassed(StartupOptions* opts) { void Window::argumentsPassed(GBAArguments* args) {
if (opts->patch) { if (args->patch) {
m_controller->loadPatch(opts->patch); m_controller->loadPatch(args->patch);
} }
if (opts->fname) { if (args->fname) {
m_controller->loadGame(opts->fname, opts->dirmode); m_controller->loadGame(args->fname, args->dirmode);
} }
} }

View File

@ -13,7 +13,7 @@ extern "C" {
#include "LoadSaveState.h" #include "LoadSaveState.h"
struct GBAOptions; struct GBAOptions;
struct StartupOptions; struct GBAArguments;
namespace QGBA { namespace QGBA {
@ -34,7 +34,7 @@ public:
static GBAKey mapKey(int qtKey); static GBAKey mapKey(int qtKey);
void setOptions(GBAOptions*); void setOptions(GBAOptions*);
void optionsPassed(StartupOptions*); void argumentsPassed(GBAArguments*);
signals: signals:
void startDrawing(const uint32_t*, GBAThread*); void startDrawing(const uint32_t*, GBAThread*);

View File

@ -69,31 +69,33 @@ int main(int argc, char** argv) {
ConfigurationInit(&config); ConfigurationInit(&config);
GBAConfigLoad(&config); GBAConfigLoad(&config);
struct GBAOptions gbaOpts = {}; struct GBAOptions opts = {};
struct StartupOptions opts = {}; struct GBAArguments args = {};
struct GraphicsOpts graphicsOpts = {}; struct GraphicsOpts graphicsOpts = {};
struct SubParser subparser; struct SubParser subparser;
GBAConfigMapGeneralOpts(&config, PORT, &gbaOpts); GBAConfigMapGeneralOpts(&config, PORT, &opts);
GBAConfigMapGraphicsOpts(&config, PORT, &gbaOpts); GBAConfigMapGraphicsOpts(&config, PORT, &opts);
initParserForGraphics(&subparser, &graphicsOpts); initParserForGraphics(&subparser, &graphicsOpts);
if (!parseCommandArgs(&opts, &gbaOpts, argc, argv, &subparser)) { if (!parseArguments(&args, &opts, argc, argv, &subparser)) {
usage(argv[0], subparser.usage); usage(argv[0], subparser.usage);
freeOptions(&opts); freeArguments(&args);
GBAConfigFreeOpts(&opts);
return 1; return 1;
} }
renderer.viewportWidth = gbaOpts.width; renderer.viewportWidth = opts.width;
renderer.viewportHeight = gbaOpts.height; renderer.viewportHeight = opts.height;
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
renderer.events.fullscreen = gbaOpts.fullscreen; renderer.events.fullscreen = opts.fullscreen;
renderer.events.windowUpdated = 0; renderer.events.windowUpdated = 0;
#endif #endif
if (!_GBASDLInit(&renderer)) { if (!_GBASDLInit(&renderer)) {
freeOptions(&opts); freeArguments(&args);
GBAConfigFreeOpts(&opts);
return 1; return 1;
} }
@ -107,10 +109,10 @@ int main(int argc, char** argv) {
.userData = &renderer .userData = &renderer
}; };
context.debugger = createDebugger(&opts); context.debugger = createDebugger(&args);
GBAMapOptionsToContext(&gbaOpts, &context); GBAMapOptionsToContext(&opts, &context);
GBAMapStartupOptionsToContext(&opts, &context); GBAMapArgumentsToContext(&args, &context);
renderer.audio.samples = context.audioBuffers; renderer.audio.samples = context.audioBuffers;
GBASDLInitAudio(&renderer.audio); GBASDLInitAudio(&renderer.audio);
@ -123,7 +125,8 @@ int main(int argc, char** argv) {
_GBASDLRunloop(&context, &renderer); _GBASDLRunloop(&context, &renderer);
GBAThreadJoin(&context); GBAThreadJoin(&context);
freeOptions(&opts); freeArguments(&args);
GBAConfigFreeOpts(&opts);
free(context.debugger); free(context.debugger);
_GBASDLDeinit(&renderer); _GBASDLDeinit(&renderer);