mirror of https://github.com/mgba-emu/mgba.git
Plumb through filename for proper saves
This commit is contained in:
parent
388dbc0851
commit
34ddb09516
|
@ -43,8 +43,6 @@ void GBAMemoryInit(struct GBAMemory* memory) {
|
||||||
memory->p->errstr = GBA_CANNOT_MMAP;
|
memory->p->errstr = GBA_CANNOT_MMAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
GBASavedataInit(&memory->savedata, "test.sav");
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 16; ++i) {
|
for (i = 0; i < 16; ++i) {
|
||||||
memory->waitstates16[i] = GBA_BASE_WAITSTATES[i];
|
memory->waitstates16[i] = GBA_BASE_WAITSTATES[i];
|
||||||
|
@ -272,6 +270,7 @@ int8_t GBALoad8(struct ARMMemory* memory, uint32_t address, int* cycleCounter) {
|
||||||
case BASE_CART_SRAM:
|
case BASE_CART_SRAM:
|
||||||
wait = gbaMemory->waitstates16[address >> BASE_OFFSET];
|
wait = gbaMemory->waitstates16[address >> BASE_OFFSET];
|
||||||
if (gbaMemory->savedata.type == SAVEDATA_NONE) {
|
if (gbaMemory->savedata.type == SAVEDATA_NONE) {
|
||||||
|
GBASavedataInit(&gbaMemory->savedata, gbaMemory->p->savefile);
|
||||||
GBASavedataInitSRAM(&gbaMemory->savedata);
|
GBASavedataInitSRAM(&gbaMemory->savedata);
|
||||||
}
|
}
|
||||||
value = gbaMemory->savedata.data[address & (SIZE_CART_SRAM - 1)];
|
value = gbaMemory->savedata.data[address & (SIZE_CART_SRAM - 1)];
|
||||||
|
@ -360,6 +359,7 @@ void GBAStore16(struct ARMMemory* memory, uint32_t address, int16_t value, int*
|
||||||
break;
|
break;
|
||||||
case BASE_CART2_EX:
|
case BASE_CART2_EX:
|
||||||
if (gbaMemory->savedata.type == SAVEDATA_NONE) {
|
if (gbaMemory->savedata.type == SAVEDATA_NONE) {
|
||||||
|
GBASavedataInit(&gbaMemory->savedata, gbaMemory->p->savefile);
|
||||||
GBASavedataInitEEPROM(&gbaMemory->savedata);
|
GBASavedataInitEEPROM(&gbaMemory->savedata);
|
||||||
}
|
}
|
||||||
GBASavedataWriteEEPROM(&gbaMemory->savedata, value, 1);
|
GBASavedataWriteEEPROM(&gbaMemory->savedata, value, 1);
|
||||||
|
@ -400,6 +400,7 @@ void GBAStore8(struct ARMMemory* memory, uint32_t address, int8_t value, int* cy
|
||||||
break;
|
break;
|
||||||
case BASE_CART_SRAM:
|
case BASE_CART_SRAM:
|
||||||
if (gbaMemory->savedata.type == SAVEDATA_NONE) {
|
if (gbaMemory->savedata.type == SAVEDATA_NONE) {
|
||||||
|
GBASavedataInit(&gbaMemory->savedata, gbaMemory->p->savefile);
|
||||||
if (address == SAVEDATA_FLASH_BASE) {
|
if (address == SAVEDATA_FLASH_BASE) {
|
||||||
GBASavedataInitFlash(&gbaMemory->savedata);
|
GBASavedataInitFlash(&gbaMemory->savedata);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,12 +4,14 @@
|
||||||
#include "debugger.h"
|
#include "debugger.h"
|
||||||
#include "gba.h"
|
#include "gba.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
static void* _GBAThreadRun(void* context) {
|
static void* _GBAThreadRun(void* context) {
|
||||||
struct ARMDebugger debugger;
|
struct ARMDebugger debugger;
|
||||||
struct GBA gba;
|
struct GBA gba;
|
||||||
struct GBAThread* threadContext = context;
|
struct GBAThread* threadContext = context;
|
||||||
|
char* savedata = 0;
|
||||||
|
|
||||||
sigset_t signals;
|
sigset_t signals;
|
||||||
sigfillset(&signals);
|
sigfillset(&signals);
|
||||||
|
@ -22,7 +24,27 @@ static void* _GBAThreadRun(void* context) {
|
||||||
|
|
||||||
threadContext->gba = &gba;
|
threadContext->gba = &gba;
|
||||||
if (threadContext->fd >= 0) {
|
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) {
|
if (threadContext->useDebugger) {
|
||||||
threadContext->debugger = &debugger;
|
threadContext->debugger = &debugger;
|
||||||
|
@ -46,6 +68,7 @@ static void* _GBAThreadRun(void* context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GBADeinit(&gba);
|
GBADeinit(&gba);
|
||||||
|
free(savedata);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ struct GBAThread {
|
||||||
// Input
|
// Input
|
||||||
struct GBAVideoRenderer* renderer;
|
struct GBAVideoRenderer* renderer;
|
||||||
int fd;
|
int fd;
|
||||||
|
const char* fname;
|
||||||
int activeKeys;
|
int activeKeys;
|
||||||
|
|
||||||
// Threading state
|
// Threading state
|
||||||
|
|
|
@ -231,9 +231,10 @@ void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger) {
|
||||||
gba->debugger = debugger;
|
gba->debugger = debugger;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBALoadROM(struct GBA* gba, int fd) {
|
void GBALoadROM(struct GBA* gba, int fd, const char* fname) {
|
||||||
struct stat info;
|
struct stat info;
|
||||||
gba->memory.rom = mmap(0, SIZE_CART0, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
|
gba->memory.rom = mmap(0, SIZE_CART0, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||||
|
gba->activeFile = fname;
|
||||||
fstat(fd, &info);
|
fstat(fd, &info);
|
||||||
gba->memory.romSize = info.st_size;
|
gba->memory.romSize = info.st_size;
|
||||||
// TODO: error check
|
// TODO: error check
|
||||||
|
|
|
@ -78,6 +78,8 @@ struct GBA {
|
||||||
int springIRQ;
|
int springIRQ;
|
||||||
int* keySource;
|
int* keySource;
|
||||||
|
|
||||||
|
const char* activeFile;
|
||||||
|
const char* savefile;
|
||||||
enum GBAError errno;
|
enum GBAError errno;
|
||||||
const char* errstr;
|
const char* errstr;
|
||||||
enum GBALogLevel logLevel;
|
enum GBALogLevel logLevel;
|
||||||
|
@ -105,7 +107,7 @@ int GBAHalt(struct GBA* gba);
|
||||||
|
|
||||||
void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);
|
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)))
|
__attribute__((format (printf, 3, 4)))
|
||||||
void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...);
|
void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...);
|
||||||
|
|
|
@ -65,7 +65,8 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
context.fd = fd;
|
context.fd = fd;
|
||||||
context.useDebugger = 0;
|
context.fname = fname;
|
||||||
|
context.useDebugger = 1;
|
||||||
context.renderer = &renderer.d.d;
|
context.renderer = &renderer.d.d;
|
||||||
GBAThreadStart(&context);
|
GBAThreadStart(&context);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue