GB: Save support
Jeffrey Pfau jeffrey@endrift.com
Fri, 22 Jan 2016 20:22:34 -0800
3 files changed,
15 insertions(+),
5 deletions(-)
M
src/gb/gb.c
→
src/gb/gb.c
@@ -44,6 +44,7 @@
gb->timer.p = gb; gb->romVf = 0; + gb->sramVf = 0; gb->pristineRom = 0; gb->pristineRomSize = 0;@@ -72,6 +73,12 @@ gb->memory.rom = gb->pristineRom;
gb->activeFile = fname; gb->memory.romSize = gb->pristineRomSize; gb->romCrc32 = doCrc32(gb->memory.rom, gb->memory.romSize); + gb->sramVf = sav; + if (sav) { + gb->memory.sram = sav->map(sav, 0x8000, MAP_WRITE); + } else { + gb->memory.sram = anonymousMemoryMap(0x8000); + } return true; // TODO: error check }@@ -93,6 +100,13 @@ #endif
gb->pristineRom = 0; gb->romVf = 0; } + + if (gb->sramVf) { + gb->sramVf->unmap(gb->sramVf, gb->memory.sram, 0x8000); + } else if (gb->memory.sram) { + mappedMemoryFree(gb->memory.sram, 0x8000); + } + gb->memory.sram = 0; } void GBDestroy(struct GB* gb) {@@ -209,7 +223,6 @@ GBUpdateIRQs(gb);
} void GBHalt(struct LR35902Core* cpu) { - struct GB* gb = (struct GB*) cpu->master; cpu->cycles = cpu->nextEvent; cpu->halted = true; }
M
src/gb/gb.h
→
src/gb/gb.h
@@ -50,6 +50,7 @@ size_t pristineRomSize;
size_t yankedRomSize; uint32_t romCrc32; struct VFile* romVf; + struct VFile* sramVf; const char* activeFile; };
M
src/gb/memory.c
→
src/gb/memory.c
@@ -57,9 +57,6 @@ mappedMemoryFree(gb->memory.wram, GB_SIZE_WORKING_RAM);
if (gb->memory.rom) { mappedMemoryFree(gb->memory.rom, gb->memory.romSize); } - if (gb->memory.sram) { - mappedMemoryFree(gb->memory.sram, 0x8000); - } } void GBMemoryReset(struct GB* gb) {@@ -70,7 +67,6 @@ gb->memory.wram = anonymousMemoryMap(GB_SIZE_WORKING_RAM);
gb->memory.wramBank = &gb->memory.wram[GB_SIZE_WORKING_RAM_BANK0]; gb->memory.romBank = &gb->memory.rom[GB_SIZE_CART_BANK0]; gb->memory.currentBank = 1; - gb->memory.sram = anonymousMemoryMap(0x8000); // TODO: Persist gb->memory.sramCurrentBank = 0; memset(&gb->video.oam, 0, sizeof(gb->video.oam));