diff gst.c @ 1019:e34334e6c682

Fix GST savestate loading to deal with SAT cache to fix sprite corruption on savestate load. Clear out Z80 native_pc so the Z80 state does not get hosed when loading a savestate while the emulator is already running
author Michael Pavone <pavone@retrodev.com>
date Mon, 02 May 2016 23:08:20 -0700
parents f52cb02a1466
children 1a66d5165ea7
line wrap: on
line diff
--- a/gst.c	Mon May 02 22:20:19 2016 -0700
+++ b/gst.c	Mon May 02 23:08:20 2016 -0700
@@ -211,12 +211,13 @@
 			z80_handle_code_write(i, context);
 		}
 	}
+	context->native_pc = NULL;
 	return 1;
 }
 
 uint8_t vdp_load_gst(vdp_context * context, FILE * state_file)
 {
-	uint8_t tmp_buf[CRAM_SIZE*2];
+	uint8_t tmp_buf[VRAM_SIZE];
 	fseek(state_file, GST_VDP_REGS, SEEK_SET);
 	if (fread(context->regs, 1, VDP_REGS, state_file) != VDP_REGS) {
 		fputs("Failed to read VDP registers from savestate\n", stderr);
@@ -227,7 +228,7 @@
 		context->framebuf = context->oddbuf;
 	}
 	latch_mode(context);
-	if (fread(tmp_buf, 1, sizeof(tmp_buf), state_file) != sizeof(tmp_buf)) {
+	if (fread(tmp_buf, 1, CRAM_SIZE*2, state_file) != CRAM_SIZE*2) {
 		fputs("Failed to read CRAM from savestate\n", stderr);
 		return 0;
 	}
@@ -246,10 +247,13 @@
 		context->vsram[i] = (tmp_buf[i*2+1] << 8) | tmp_buf[i*2];
 	}
 	fseek(state_file, GST_VDP_MEM, SEEK_SET);
-	if (fread(context->vdpmem, 1, VRAM_SIZE, state_file) != VRAM_SIZE) {
+	if (fread(tmp_buf, 1, VRAM_SIZE, state_file) != VRAM_SIZE) {
 		fputs("Failed to read VRAM from savestate\n", stderr);
 		return 0;
 	}
+	for (int i = 0; i < VRAM_SIZE; i++) {
+		write_vram_byte(context, i, tmp_buf[i]);
+	}
 	return 1;
 }