mirror of https://github.com/mgba-emu/mgba.git
Create concept of state directory
This commit is contained in:
parent
e8a78c9547
commit
7172e6428c
|
@ -170,11 +170,12 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
|
||||||
|
|
||||||
void GBAMapOptionsToContext(struct StartupOptions* opts, struct GBAThread* threadContext) {
|
void GBAMapOptionsToContext(struct StartupOptions* opts, struct GBAThread* threadContext) {
|
||||||
if (opts->dirmode) {
|
if (opts->dirmode) {
|
||||||
threadContext->gamedir = VDirOpen(opts->fname);
|
threadContext->gameDir = VDirOpen(opts->fname);
|
||||||
|
threadContext->stateDir = threadContext->gameDir;
|
||||||
} else {
|
} else {
|
||||||
threadContext->rom = VFileOpen(opts->fname, O_RDONLY);
|
threadContext->rom = VFileOpen(opts->fname, O_RDONLY);
|
||||||
#if ENABLE_LIBZIP
|
#if ENABLE_LIBZIP
|
||||||
threadContext->gamedir = VDirOpenZip(opts->fname, 0);
|
threadContext->gameDir = VDirOpenZip(opts->fname, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
threadContext->fname = opts->fname;
|
threadContext->fname = opts->fname;
|
||||||
|
@ -206,12 +207,12 @@ bool GBAThreadStart(struct GBAThread* threadContext) {
|
||||||
threadContext->rom = 0;
|
threadContext->rom = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (threadContext->gamedir) {
|
if (threadContext->gameDir) {
|
||||||
threadContext->gamedir->rewind(threadContext->gamedir);
|
threadContext->gameDir->rewind(threadContext->gameDir);
|
||||||
struct VDirEntry* dirent = threadContext->gamedir->listNext(threadContext->gamedir);
|
struct VDirEntry* dirent = threadContext->gameDir->listNext(threadContext->gameDir);
|
||||||
while (dirent) {
|
while (dirent) {
|
||||||
struct Patch patchTemp;
|
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) {
|
if (!vf) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -222,11 +223,12 @@ bool GBAThreadStart(struct GBAThread* threadContext) {
|
||||||
} else {
|
} else {
|
||||||
vf->close(vf);
|
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) {
|
if (!threadContext->rom) {
|
||||||
|
@ -360,9 +362,17 @@ void GBAThreadJoin(struct GBAThread* threadContext) {
|
||||||
threadContext->patch = 0;
|
threadContext->patch = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (threadContext->gamedir) {
|
if (threadContext->gameDir) {
|
||||||
threadContext->gamedir->close(threadContext->gamedir);
|
if (threadContext->stateDir == threadContext->gameDir) {
|
||||||
threadContext->gamedir = 0;
|
threadContext->stateDir = 0;
|
||||||
|
}
|
||||||
|
threadContext->gameDir->close(threadContext->gameDir);
|
||||||
|
threadContext->gameDir = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (threadContext->stateDir) {
|
||||||
|
threadContext->stateDir->close(threadContext->stateDir);
|
||||||
|
threadContext->stateDir = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,8 @@ struct GBAThread {
|
||||||
struct GBAVideoRenderer* renderer;
|
struct GBAVideoRenderer* renderer;
|
||||||
struct GBASIODriverSet sioDrivers;
|
struct GBASIODriverSet sioDrivers;
|
||||||
struct ARMDebugger* debugger;
|
struct ARMDebugger* debugger;
|
||||||
struct VDir* gamedir;
|
struct VDir* gameDir;
|
||||||
|
struct VDir* stateDir;
|
||||||
struct VFile* rom;
|
struct VFile* rom;
|
||||||
struct VFile* save;
|
struct VFile* save;
|
||||||
struct VFile* bios;
|
struct VFile* bios;
|
||||||
|
|
|
@ -149,21 +149,21 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents
|
||||||
GBAThreadContinue(context);
|
GBAThreadContinue(context);
|
||||||
break;
|
break;
|
||||||
case SDLK_t:
|
case SDLK_t:
|
||||||
if (context->gamedir) {
|
if (context->stateDir) {
|
||||||
GBAThreadInterrupt(context);
|
GBAThreadInterrupt(context);
|
||||||
GBARRStopPlaying(context->gba);
|
GBARRStopPlaying(context->gba);
|
||||||
GBARRSave(context->gba->rr, context->gamedir);
|
GBARRSave(context->gba->rr, context->stateDir);
|
||||||
GBAThreadContinue(context);
|
GBAThreadContinue(context);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_y:
|
case SDLK_y:
|
||||||
if (context->gamedir) {
|
if (context->stateDir) {
|
||||||
GBAThreadReset(context);
|
GBAThreadReset(context);
|
||||||
GBAThreadInterrupt(context);
|
GBAThreadInterrupt(context);
|
||||||
GBARRStopRecording(context->gba);
|
GBARRStopRecording(context->gba);
|
||||||
GBARRContextDestroy(context->gba);
|
GBARRContextDestroy(context->gba);
|
||||||
GBARRContextCreate(context->gba);
|
GBARRContextCreate(context->gba);
|
||||||
if (GBARRLoad(context->gba->rr, context->gamedir)) {
|
if (GBARRLoad(context->gba->rr, context->stateDir)) {
|
||||||
GBARRStartPlaying(context->gba);
|
GBARRStartPlaying(context->gba);
|
||||||
}
|
}
|
||||||
GBAThreadContinue(context);
|
GBAThreadContinue(context);
|
||||||
|
|
Loading…
Reference in New Issue