From 7172e6428cf6c880ae2c70ca35cfaf237e58cd7f Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 19 Jul 2014 17:48:37 -0700 Subject: [PATCH] Create concept of state directory --- src/gba/gba-thread.c | 34 ++++++++++++++++++++++------------ src/gba/gba-thread.h | 3 ++- src/platform/sdl/sdl-events.c | 8 ++++---- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/gba/gba-thread.c b/src/gba/gba-thread.c index d46710017..9029ba9b0 100644 --- a/src/gba/gba-thread.c +++ b/src/gba/gba-thread.c @@ -170,11 +170,12 @@ static THREAD_ENTRY _GBAThreadRun(void* context) { void GBAMapOptionsToContext(struct StartupOptions* opts, struct GBAThread* threadContext) { if (opts->dirmode) { - threadContext->gamedir = VDirOpen(opts->fname); + threadContext->gameDir = VDirOpen(opts->fname); + threadContext->stateDir = threadContext->gameDir; } else { threadContext->rom = VFileOpen(opts->fname, O_RDONLY); #if ENABLE_LIBZIP - threadContext->gamedir = VDirOpenZip(opts->fname, 0); + threadContext->gameDir = VDirOpenZip(opts->fname, 0); #endif } threadContext->fname = opts->fname; @@ -206,12 +207,12 @@ bool GBAThreadStart(struct GBAThread* threadContext) { threadContext->rom = 0; } - if (threadContext->gamedir) { - threadContext->gamedir->rewind(threadContext->gamedir); - struct VDirEntry* dirent = threadContext->gamedir->listNext(threadContext->gamedir); + if (threadContext->gameDir) { + threadContext->gameDir->rewind(threadContext->gameDir); + struct VDirEntry* dirent = threadContext->gameDir->listNext(threadContext->gameDir); while (dirent) { struct Patch patchTemp; - struct VFile* vf = threadContext->gamedir->openFile(threadContext->gamedir, dirent->name(dirent), O_RDONLY); + struct VFile* vf = threadContext->gameDir->openFile(threadContext->gameDir, dirent->name(dirent), O_RDONLY); if (!vf) { continue; } @@ -222,11 +223,12 @@ bool GBAThreadStart(struct GBAThread* threadContext) { } else { vf->close(vf); } - dirent = threadContext->gamedir->listNext(threadContext->gamedir); + dirent = threadContext->gameDir->listNext(threadContext->gameDir); } - // TODO: Differentiate ZIPs and filesystem directories - threadContext->save = threadContext->gamedir->openFile(threadContext->gamedir, "sram.sav", O_RDWR | O_CREAT); + } + if (threadContext->stateDir) { + threadContext->save = threadContext->stateDir->openFile(threadContext->stateDir, "sram.sav", O_RDWR | O_CREAT); } if (!threadContext->rom) { @@ -360,9 +362,17 @@ void GBAThreadJoin(struct GBAThread* threadContext) { threadContext->patch = 0; } - if (threadContext->gamedir) { - threadContext->gamedir->close(threadContext->gamedir); - threadContext->gamedir = 0; + if (threadContext->gameDir) { + if (threadContext->stateDir == threadContext->gameDir) { + threadContext->stateDir = 0; + } + threadContext->gameDir->close(threadContext->gameDir); + threadContext->gameDir = 0; + } + + if (threadContext->stateDir) { + threadContext->stateDir->close(threadContext->stateDir); + threadContext->stateDir = 0; } } diff --git a/src/gba/gba-thread.h b/src/gba/gba-thread.h index 4b2484d70..a870b9610 100644 --- a/src/gba/gba-thread.h +++ b/src/gba/gba-thread.h @@ -47,7 +47,8 @@ struct GBAThread { struct GBAVideoRenderer* renderer; struct GBASIODriverSet sioDrivers; struct ARMDebugger* debugger; - struct VDir* gamedir; + struct VDir* gameDir; + struct VDir* stateDir; struct VFile* rom; struct VFile* save; struct VFile* bios; diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index d0844a6b5..aa2b2ef2b 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -149,21 +149,21 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents GBAThreadContinue(context); break; case SDLK_t: - if (context->gamedir) { + if (context->stateDir) { GBAThreadInterrupt(context); GBARRStopPlaying(context->gba); - GBARRSave(context->gba->rr, context->gamedir); + GBARRSave(context->gba->rr, context->stateDir); GBAThreadContinue(context); } break; case SDLK_y: - if (context->gamedir) { + if (context->stateDir) { GBAThreadReset(context); GBAThreadInterrupt(context); GBARRStopRecording(context->gba); GBARRContextDestroy(context->gba); GBARRContextCreate(context->gba); - if (GBARRLoad(context->gba->rr, context->gamedir)) { + if (GBARRLoad(context->gba->rr, context->stateDir)) { GBARRStartPlaying(context->gba); } GBAThreadContinue(context);