Mercurial > repos > blastem
diff vdp.c @ 424:7e8e179116af
Add support for loading GST format savestates
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 29 Jun 2013 17:15:08 -0700 |
parents | acdd6c5240fe |
children | add9e2f5c0e3 |
line wrap: on
line diff
--- a/vdp.c Tue Jun 25 23:18:57 2013 -0700 +++ b/vdp.c Sat Jun 29 17:15:08 2013 -0700 @@ -1653,22 +1653,39 @@ #define GST_VDP_REGS 0xFA #define GST_VDP_MEM 0x12478 -void vdp_load_savestate(vdp_context * context, FILE * state_file) +uint8_t vdp_load_gst(vdp_context * context, FILE * state_file) { uint8_t tmp_buf[CRAM_SIZE*2]; fseek(state_file, GST_VDP_REGS, SEEK_SET); - fread(context->regs, 1, VDP_REGS, state_file); + if (fread(context->regs, 1, VDP_REGS, state_file) != VDP_REGS) { + fputs("Failed to read VDP registers from savestate\n", stderr); + return 0; + } + context->double_res = (context->regs[REG_MODE_4] & (BIT_INTERLACE | BIT_DOUBLE_RES)) == (BIT_INTERLACE | BIT_DOUBLE_RES); + if (!context->double_res) { + context->framebuf = context->oddbuf; + } latch_mode(context); - fread(tmp_buf, 1, sizeof(tmp_buf), state_file); + if (fread(tmp_buf, 1, sizeof(tmp_buf), state_file) != sizeof(tmp_buf)) { + fputs("Failed to read CRAM from savestate\n", stderr); + return 0; + } for (int i = 0; i < CRAM_SIZE; i++) { context->cram[i] = (tmp_buf[i*2+1] << 8) | tmp_buf[i*2]; } - fread(tmp_buf, 2, VSRAM_SIZE, state_file); + if (fread(tmp_buf, 2, VSRAM_SIZE, state_file) != VSRAM_SIZE) { + fputs("Failed to read VSRAM from savestate\n", stderr); + return 0; + } for (int i = 0; i < VSRAM_SIZE; i++) { context->vsram[i] = (tmp_buf[i*2+1] << 8) | tmp_buf[i*2]; } fseek(state_file, GST_VDP_MEM, SEEK_SET); - fread(context->vdpmem, 1, VRAM_SIZE, state_file); + if (fread(context->vdpmem, 1, VRAM_SIZE, state_file) != VRAM_SIZE) { + fputs("Failed to read VRAM from savestate\n", stderr); + return 0; + } + return 1; } void vdp_save_state(vdp_context * context, FILE * outfile)