comparison 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
comparison
equal deleted inserted replaced
1018:dba8c630bdbf 1019:e34334e6c682
209 if (context->mem_pointers[0][i] != buffer[i]) { 209 if (context->mem_pointers[0][i] != buffer[i]) {
210 context->mem_pointers[0][i] = buffer[i]; 210 context->mem_pointers[0][i] = buffer[i];
211 z80_handle_code_write(i, context); 211 z80_handle_code_write(i, context);
212 } 212 }
213 } 213 }
214 context->native_pc = NULL;
214 return 1; 215 return 1;
215 } 216 }
216 217
217 uint8_t vdp_load_gst(vdp_context * context, FILE * state_file) 218 uint8_t vdp_load_gst(vdp_context * context, FILE * state_file)
218 { 219 {
219 uint8_t tmp_buf[CRAM_SIZE*2]; 220 uint8_t tmp_buf[VRAM_SIZE];
220 fseek(state_file, GST_VDP_REGS, SEEK_SET); 221 fseek(state_file, GST_VDP_REGS, SEEK_SET);
221 if (fread(context->regs, 1, VDP_REGS, state_file) != VDP_REGS) { 222 if (fread(context->regs, 1, VDP_REGS, state_file) != VDP_REGS) {
222 fputs("Failed to read VDP registers from savestate\n", stderr); 223 fputs("Failed to read VDP registers from savestate\n", stderr);
223 return 0; 224 return 0;
224 } 225 }
225 context->double_res = (context->regs[REG_MODE_4] & (BIT_INTERLACE | BIT_DOUBLE_RES)) == (BIT_INTERLACE | BIT_DOUBLE_RES); 226 context->double_res = (context->regs[REG_MODE_4] & (BIT_INTERLACE | BIT_DOUBLE_RES)) == (BIT_INTERLACE | BIT_DOUBLE_RES);
226 if (!context->double_res) { 227 if (!context->double_res) {
227 context->framebuf = context->oddbuf; 228 context->framebuf = context->oddbuf;
228 } 229 }
229 latch_mode(context); 230 latch_mode(context);
230 if (fread(tmp_buf, 1, sizeof(tmp_buf), state_file) != sizeof(tmp_buf)) { 231 if (fread(tmp_buf, 1, CRAM_SIZE*2, state_file) != CRAM_SIZE*2) {
231 fputs("Failed to read CRAM from savestate\n", stderr); 232 fputs("Failed to read CRAM from savestate\n", stderr);
232 return 0; 233 return 0;
233 } 234 }
234 for (int i = 0; i < CRAM_SIZE; i++) { 235 for (int i = 0; i < CRAM_SIZE; i++) {
235 uint16_t value; 236 uint16_t value;
244 } 245 }
245 for (int i = 0; i < VSRAM_SIZE; i++) { 246 for (int i = 0; i < VSRAM_SIZE; i++) {
246 context->vsram[i] = (tmp_buf[i*2+1] << 8) | tmp_buf[i*2]; 247 context->vsram[i] = (tmp_buf[i*2+1] << 8) | tmp_buf[i*2];
247 } 248 }
248 fseek(state_file, GST_VDP_MEM, SEEK_SET); 249 fseek(state_file, GST_VDP_MEM, SEEK_SET);
249 if (fread(context->vdpmem, 1, VRAM_SIZE, state_file) != VRAM_SIZE) { 250 if (fread(tmp_buf, 1, VRAM_SIZE, state_file) != VRAM_SIZE) {
250 fputs("Failed to read VRAM from savestate\n", stderr); 251 fputs("Failed to read VRAM from savestate\n", stderr);
251 return 0; 252 return 0;
253 }
254 for (int i = 0; i < VRAM_SIZE; i++) {
255 write_vram_byte(context, i, tmp_buf[i]);
252 } 256 }
253 return 1; 257 return 1;
254 } 258 }
255 259
256 uint8_t vdp_save_gst(vdp_context * context, FILE * outfile) 260 uint8_t vdp_save_gst(vdp_context * context, FILE * outfile)