Create concept of state directory

This commit is contained in:
Jeffrey Pfau 2014-07-19 17:48:37 -07:00
parent e8a78c9547
commit 7172e6428c
3 changed files with 28 additions and 17 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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);