Create concept of state directory
Jeffrey Pfau jeffrey@endrift.com
Sat, 19 Jul 2014 17:48:37 -0700
3 files changed,
28 insertions(+),
17 deletions(-)
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -170,11 +170,12 @@ }
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 @@ threadContext->rom->close(threadContext->rom);
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 @@ threadContext->patch = vf;
} 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 @@ threadContext->patch->close(threadContext->patch);
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; } }
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -47,7 +47,8 @@ // Input
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;
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -149,21 +149,21 @@ GBASaveState(context->gba, event->keysym.sym - SDLK_F1);
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);