Plumb through filename for proper saves
Jeffrey Pfau jeffrey@endrift.com
Sun, 22 Sep 2013 16:45:19 -0700
6 files changed,
35 insertions(+),
6 deletions(-)
M
src/gba/gba-memory.c
→
src/gba/gba-memory.c
@@ -43,8 +43,6 @@ memory->p->errno = GBA_OUT_OF_MEMORY;
memory->p->errstr = GBA_CANNOT_MMAP; } - GBASavedataInit(&memory->savedata, "test.sav"); - int i; for (i = 0; i < 16; ++i) { memory->waitstates16[i] = GBA_BASE_WAITSTATES[i];@@ -272,6 +270,7 @@ break;
case BASE_CART_SRAM: wait = gbaMemory->waitstates16[address >> BASE_OFFSET]; if (gbaMemory->savedata.type == SAVEDATA_NONE) { + GBASavedataInit(&gbaMemory->savedata, gbaMemory->p->savefile); GBASavedataInitSRAM(&gbaMemory->savedata); } value = gbaMemory->savedata.data[address & (SIZE_CART_SRAM - 1)];@@ -360,6 +359,7 @@ case BASE_CART0:
break; case BASE_CART2_EX: if (gbaMemory->savedata.type == SAVEDATA_NONE) { + GBASavedataInit(&gbaMemory->savedata, gbaMemory->p->savefile); GBASavedataInitEEPROM(&gbaMemory->savedata); } GBASavedataWriteEEPROM(&gbaMemory->savedata, value, 1);@@ -400,6 +400,7 @@ case BASE_CART0:
break; case BASE_CART_SRAM: if (gbaMemory->savedata.type == SAVEDATA_NONE) { + GBASavedataInit(&gbaMemory->savedata, gbaMemory->p->savefile); if (address == SAVEDATA_FLASH_BASE) { GBASavedataInitFlash(&gbaMemory->savedata); } else {
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -4,12 +4,14 @@ #include "arm.h"
#include "debugger.h" #include "gba.h" +#include <stdlib.h> #include <signal.h> static void* _GBAThreadRun(void* context) { struct ARMDebugger debugger; struct GBA gba; struct GBAThread* threadContext = context; + char* savedata = 0; sigset_t signals; sigfillset(&signals);@@ -22,7 +24,27 @@ }
threadContext->gba = &gba; if (threadContext->fd >= 0) { - GBALoadROM(&gba, threadContext->fd); + if (threadContext->fname) { + char* dotPoint = strrchr(threadContext->fname, '.'); + if (dotPoint > strrchr(threadContext->fname, '/') && dotPoint[1] && dotPoint[2] && dotPoint[3]) { + savedata = strdup(threadContext->fname); + dotPoint = strrchr(savedata, '.'); + dotPoint[1] = 's'; + dotPoint[2] = 'a'; + dotPoint[3] = 'v'; + dotPoint[4] = '\0'; + } else if (dotPoint) { + savedata = malloc((dotPoint - threadContext->fname + 5) * sizeof(char)); + strncpy(savedata, threadContext->fname, dotPoint - threadContext->fname + 1); + strcat(savedata, "sav"); + } else { + savedata = malloc(strlen(threadContext->fname + 5)); + strcpy(savedata, threadContext->fname); + strcat(savedata, "sav"); + } + } + GBALoadROM(&gba, threadContext->fd, threadContext->fname); + gba.savefile = savedata; } if (threadContext->useDebugger) { threadContext->debugger = &debugger;@@ -46,6 +68,7 @@ ARMRun(&gba.cpu);
} } GBADeinit(&gba); + free(savedata); return 0; }
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -13,6 +13,7 @@
// Input struct GBAVideoRenderer* renderer; int fd; + const char* fname; int activeKeys; // Threading state
M
src/gba/gba.c
→
src/gba/gba.c
@@ -231,9 +231,10 @@ ARMDebuggerInit(debugger, &gba->cpu);
gba->debugger = debugger; } -void GBALoadROM(struct GBA* gba, int fd) { +void GBALoadROM(struct GBA* gba, int fd, const char* fname) { struct stat info; gba->memory.rom = mmap(0, SIZE_CART0, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + gba->activeFile = fname; fstat(fd, &info); gba->memory.romSize = info.st_size; // TODO: error check
M
src/gba/gba.h
→
src/gba/gba.h
@@ -78,6 +78,8 @@
int springIRQ; int* keySource; + const char* activeFile; + const char* savefile; enum GBAError errno; const char* errstr; enum GBALogLevel logLevel;@@ -105,7 +107,7 @@ int GBAHalt(struct GBA* gba);
void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger); -void GBALoadROM(struct GBA* gba, int fd); +void GBALoadROM(struct GBA* gba, int fd, const char* fname); __attribute__((format (printf, 3, 4))) void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...);
M
src/gl-main.c
→
src/gl-main.c
@@ -65,7 +65,8 @@ return 1;
} context.fd = fd; - context.useDebugger = 0; + context.fname = fname; + context.useDebugger = 1; context.renderer = &renderer.d.d; GBAThreadStart(&context);