summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2016-05-02 23:08:20 -0700
committerMichael Pavone <pavone@retrodev.com>2016-05-02 23:08:20 -0700
commitdd54326136cdefda96bce7cdff31d0938162377b (patch)
tree4457090807eeef5faee0cdf50ab988ef750b3644
parentf6a58778f9123e15c17defe09423c40642b1cc7e (diff)
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
-rw-r--r--gst.c10
-rw-r--r--vdp.c2
-rw-r--r--vdp.h1
3 files changed, 9 insertions, 4 deletions
diff --git a/gst.c b/gst.c
index 01a8c19..7fadc18 100644
--- a/gst.c
+++ b/gst.c
@@ -211,12 +211,13 @@ uint8_t z80_load_gst(z80_context * context, FILE * gstfile)
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 @@ uint8_t vdp_load_gst(vdp_context * context, FILE * state_file)
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 @@ uint8_t vdp_load_gst(vdp_context * context, FILE * state_file)
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;
}
diff --git a/vdp.c b/vdp.c
index e86407e..2e35afe 100644
--- a/vdp.c
+++ b/vdp.c
@@ -518,7 +518,7 @@ void vdp_advance_dma(vdp_context * context)
context->cd &= 0xF;
}
}
-#include <assert.h>
+
void write_vram_byte(vdp_context *context, uint16_t address, uint8_t value)
{
if (!(address & 4)) {
diff --git a/vdp.h b/vdp.h
index 59b8b0b..7812ee1 100644
--- a/vdp.h
+++ b/vdp.h
@@ -204,6 +204,7 @@ void vdp_print_reg_explain(vdp_context * context);
void latch_mode(vdp_context * context);
uint32_t vdp_cycles_to_frame_end(vdp_context * context);
uint32_t vdp_frame_end_line(vdp_context *context);
+void write_vram_byte(vdp_context *context, uint16_t address, uint8_t value);
extern int32_t color_map[1 << 12];