GBA: Begin STORE_32/16-izing serialization

This commit is contained in:
Jeffrey Pfau 2015-10-19 21:10:26 -07:00
parent 9e5070acf8
commit c5ed4cb9af
2 changed files with 36 additions and 24 deletions

View File

@ -25,9 +25,9 @@
const uint32_t GBA_SAVESTATE_MAGIC = 0x01000000;
void GBASerialize(struct GBA* gba, struct GBASerializedState* state) {
state->versionMagic = GBA_SAVESTATE_MAGIC;
state->biosChecksum = gba->biosChecksum;
state->romCrc32 = gba->romCrc32;
STORE_32(GBA_SAVESTATE_MAGIC, 0, &state->versionMagic);
STORE_32(gba->biosChecksum, 0, &state->biosChecksum);
STORE_32(gba->romCrc32, 0, &state->romCrc32);
if (gba->memory.rom) {
state->id = ((struct GBACartridge*) gba->memory.rom)->id;
@ -37,17 +37,25 @@ void GBASerialize(struct GBA* gba, struct GBASerializedState* state) {
memset(state->title, 0, sizeof(state->title));
}
memcpy(state->cpu.gprs, gba->cpu->gprs, sizeof(state->cpu.gprs));
state->cpu.cpsr = gba->cpu->cpsr;
state->cpu.spsr = gba->cpu->spsr;
state->cpu.cycles = gba->cpu->cycles;
state->cpu.nextEvent = gba->cpu->nextEvent;
memcpy(state->cpu.bankedRegisters, gba->cpu->bankedRegisters, 6 * 7 * sizeof(int32_t));
memcpy(state->cpu.bankedSPSRs, gba->cpu->bankedSPSRs, 6 * sizeof(int32_t));
int i;
for (i = 0; i < 16; ++i) {
STORE_32(gba->cpu->gprs[i], i * sizeof(state->cpu.gprs[0]), state->cpu.gprs);
}
STORE_32(gba->cpu->cpsr.packed, 0, &state->cpu.cpsr.packed);
STORE_32(gba->cpu->spsr.packed, 0, &state->cpu.spsr.packed);
STORE_32(gba->cpu->cycles, 0, &state->cpu.cycles);
STORE_32(gba->cpu->nextEvent, 0, &state->cpu.nextEvent);
for (i = 0; i < 6; ++i) {
int j;
for (j = 0; j < 7; ++j) {
STORE_32(gba->cpu->bankedRegisters[i][j], (i * 7 + j) * sizeof(gba->cpu->bankedRegisters[0][0]), state->cpu.bankedRegisters);
}
STORE_32(gba->cpu->bankedSPSRs[i], i * sizeof(gba->cpu->bankedSPSRs[0]), state->cpu.bankedSPSRs);
}
state->biosPrefetch = gba->memory.biosPrefetch;
state->cpuPrefetch[0] = gba->cpu->prefetch[0];
state->cpuPrefetch[1] = gba->cpu->prefetch[1];
STORE_32(gba->cpu->prefetch[0], 0, state->cpuPrefetch);
STORE_32(gba->cpu->prefetch[1], 4, state->cpuPrefetch);
GBAMemorySerialize(&gba->memory, state);
GBAIOSerialize(gba, state);
@ -137,7 +145,7 @@ bool GBADeserialize(struct GBA* gba, const struct GBASerializedState* state) {
gba->cpu->executionMode = MODE_THUMB;
if (state->cpuPrefetch[0] && state->cpuPrefetch[1]) {
LOAD_32(gba->cpu->prefetch[0], 0, state->cpuPrefetch);
LOAD_32(gba->cpu->prefetch[1], 2, state->cpuPrefetch);
LOAD_32(gba->cpu->prefetch[1], 4, state->cpuPrefetch);
gba->cpu->prefetch[0] &= 0xFFFF;
gba->cpu->prefetch[1] &= 0xFFFF;
} else {
@ -149,7 +157,7 @@ bool GBADeserialize(struct GBA* gba, const struct GBASerializedState* state) {
gba->cpu->executionMode = MODE_ARM;
if (state->cpuPrefetch[0] && state->cpuPrefetch[1]) {
LOAD_32(gba->cpu->prefetch[0], 0, state->cpuPrefetch);
LOAD_32(gba->cpu->prefetch[1], 2, state->cpuPrefetch);
LOAD_32(gba->cpu->prefetch[1], 4, state->cpuPrefetch);
} else {
// Maintain backwards compat
LOAD_32(gba->cpu->prefetch[0], (gba->cpu->gprs[ARM_PC] - WORD_SIZE_ARM) & gba->cpu->memory.activeMask, gba->cpu->memory.activeRegion);

View File

@ -272,16 +272,20 @@ static void GBAVideoDummyRendererGetPixels(struct GBAVideoRenderer* renderer, un
void GBAVideoSerialize(const struct GBAVideo* video, struct GBASerializedState* state) {
memcpy(state->vram, video->renderer->vram, SIZE_VRAM);
memcpy(state->oam, video->oam.raw, SIZE_OAM);
memcpy(state->pram, video->palette, SIZE_PALETTE_RAM);
state->video.nextEvent = video->nextEvent;
state->video.eventDiff = video->eventDiff;
state->video.lastHblank = video->nextHblank - VIDEO_HBLANK_LENGTH;
state->video.nextHblank = video->nextHblank;
state->video.nextHblankIRQ = video->nextHblankIRQ;
state->video.nextVblankIRQ = video->nextVblankIRQ;
state->video.nextVcounterIRQ = video->nextVcounterIRQ;
state->video.frameCounter = video->frameCounter;
int i;
for (i = 0; i < SIZE_OAM; i += 2) {
STORE_16(video->oam.raw[i >> 1], i, state->oam);
}
for (i = 0; i < SIZE_PALETTE_RAM; i += 2) {
STORE_16(video->palette[i >> 1], i, state->pram);
}
STORE_32(video->nextEvent, 0, &state->video.nextEvent);
STORE_32(video->eventDiff, 0, &state->video.eventDiff);
STORE_32(video->nextHblank, 0, &state->video.nextHblank);
STORE_32(video->nextHblankIRQ, 0, &state->video.nextHblankIRQ);
STORE_32(video->nextVblankIRQ, 0, &state->video.nextVblankIRQ);
STORE_32(video->nextVcounterIRQ, 0, &state->video.nextVcounterIRQ);
STORE_32(video->frameCounter, 0, &state->video.frameCounter);
}
void GBAVideoDeserialize(struct GBAVideo* video, const struct GBASerializedState* state) {