Clean up GBAThread variables
Jeffrey Pfau jeffrey@endrift.com
Wed, 16 Jul 2014 23:53:11 -0700
2 files changed,
34 insertions(+),
14 deletions(-)
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -88,13 +88,13 @@ if (threadContext->renderer) {
GBAVideoAssociateRenderer(&gba.video, threadContext->renderer); } - if (threadContext->fd) { - GBALoadROM(&gba, threadContext->fd, threadContext->saveFd, threadContext->fname); - if (threadContext->biosFd) { - GBALoadBIOS(&gba, threadContext->biosFd); + if (threadContext->rom) { + GBALoadROM(&gba, threadContext->rom, threadContext->save, threadContext->fname); + if (threadContext->bios) { + GBALoadBIOS(&gba, threadContext->bios); } - if (threadContext->patchFd && loadPatch(threadContext->patchFd, &patch)) { + if (threadContext->patch && loadPatch(threadContext->patch, &patch)) { GBAApplyPatch(&gba, &patch); } }@@ -169,10 +169,10 @@ return 0;
} void GBAMapOptionsToContext(struct StartupOptions* opts, struct GBAThread* threadContext) { - threadContext->fd = VFileOpen(opts->fname, O_RDONLY); + threadContext->rom = VFileOpen(opts->fname, O_RDONLY); threadContext->fname = opts->fname; - threadContext->biosFd = VFileOpen(opts->bios, O_RDONLY); - threadContext->patchFd = VFileOpen(opts->patch, O_RDONLY); + threadContext->bios = VFileOpen(opts->bios, O_RDONLY); + threadContext->patch = VFileOpen(opts->patch, O_RDONLY); threadContext->frameskip = opts->frameskip; threadContext->logLevel = opts->logLevel; threadContext->rewindBufferCapacity = opts->rewindBufferCapacity;@@ -194,7 +194,7 @@ } else {
threadContext->rewindBuffer = 0; } - if (threadContext->fname && !threadContext->saveFd) { + if (threadContext->fname && !threadContext->save) { char* savedata = 0; char* dotPoint = strrchr(threadContext->fname, '.'); if (dotPoint > strrchr(threadContext->fname, '/') && dotPoint[1] && dotPoint[2] && dotPoint[3]) {@@ -213,7 +213,7 @@ savedata = malloc(strlen(threadContext->fname + 5));
strcpy(savedata, threadContext->fname); strcat(savedata, "sav"); } - threadContext->saveFd = VFileOpen(savedata, O_RDWR | O_CREAT); + threadContext->save = VFileOpen(savedata, O_RDWR | O_CREAT); free(savedata); }@@ -301,6 +301,26 @@ GBADeallocateState(threadContext->rewindBuffer[i]);
} } free(threadContext->rewindBuffer); + + if (threadContext->rom) { + threadContext->rom->close(threadContext->rom); + threadContext->rom = 0; + } + + if (threadContext->save) { + threadContext->save->close(threadContext->save); + threadContext->save = 0; + } + + if (threadContext->bios) { + threadContext->bios->close(threadContext->bios); + threadContext->bios = 0; + } + + if (threadContext->patch) { + threadContext->patch->close(threadContext->patch); + threadContext->patch = 0; + } } void GBAThreadInterrupt(struct GBAThread* threadContext) {
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -47,10 +47,10 @@ // Input
struct GBAVideoRenderer* renderer; struct GBASIODriverSet sioDrivers; struct ARMDebugger* debugger; - struct VFile* fd; - struct VFile* saveFd; - struct VFile* biosFd; - struct VFile* patchFd; + struct VFile* rom; + struct VFile* save; + struct VFile* bios; + struct VFile* patch; const char* fname; int activeKeys; int frameskip;