changeset 56:a28b1dfe1af2

Fix CRAM and possibly VSRAM writes
author Mike Pavone <pavone@retrodev.com>
date Tue, 18 Dec 2012 19:51:33 -0800
parents 8317f174d916
children bc3bc7a60c4e
files vdp.c vdp.h
diffstat 2 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/vdp.c	Tue Dec 18 19:51:17 2012 -0800
+++ b/vdp.c	Tue Dec 18 19:51:33 2012 -0800
@@ -203,12 +203,12 @@
 			break;
 		case CRAM_WRITE:
 			printf("CRAM Write: %X to %X\n", start->value, context->address);
-			context->cram[context->address & (CRAM_SIZE-1)] = start->value;
+			context->cram[(context->address/2) & (CRAM_SIZE-1)] = start->value;
 			break;
 		case VSRAM_WRITE:
-			if ((context->address & 63) < VSRAM_SIZE) {
+			if (((context->address/2) & 63) < VSRAM_SIZE) {
 				printf("VSRAM Write: %X to %X\n", start->value, context->address);
-				context->vsram[context->address & 63] = start->value;
+				context->vsram[(context->address/2) & 63] = start->value;
 			}
 			break;
 		}
@@ -994,3 +994,22 @@
 	fread(context->vdpmem, 1, VRAM_SIZE, state_file);
 }
 
+void vdp_save_state(vdp_context * context, FILE * outfile)
+{
+	uint8_t tmp_buf[CRAM_SIZE*2];
+	fseek(outfile, GST_VDP_REGS, SEEK_SET);
+	fwrite(context->regs, 1, VDP_REGS, outfile);
+	for (int i = 0; i < CRAM_SIZE; i++) {
+		tmp_buf[i*2] = context->cram[i];
+		tmp_buf[i*2+1] = context->cram[i] >> 8;
+	}
+	fwrite(tmp_buf, 1, sizeof(tmp_buf), outfile);
+	for (int i = 0; i < VSRAM_SIZE; i++) {
+		tmp_buf[i*2] = context->vsram[i];
+		tmp_buf[i*2+1] = context->vsram[i] >> 8;
+	}
+	fwrite(tmp_buf, 2, VSRAM_SIZE, outfile);
+	fseek(outfile, GST_VDP_MEM, SEEK_SET);
+	fwrite(context->vdpmem, 1, VRAM_SIZE, outfile);
+}
+
--- a/vdp.h	Tue Dec 18 19:51:17 2012 -0800
+++ b/vdp.h	Tue Dec 18 19:51:33 2012 -0800
@@ -70,7 +70,7 @@
 	fifo_entry  *fifo_end;
 	uint16_t    address;
 	uint8_t     cd;
-	uint8_t		flags;
+	uint8_t	    flags;
 	//cycle count in MCLKs
 	uint32_t    cycles;
 	uint8_t     *vdpmem;
@@ -102,6 +102,7 @@
 //runs from current cycle count to VBLANK for the current mode, returns ending cycle count
 uint32_t vdp_run_to_vblank(vdp_context * context);
 void vdp_load_savestate(vdp_context * context, FILE * state_file);
+void vdp_save_state(vdp_context * context, FILE * outfile);
 void vdp_control_port_write(vdp_context * context, uint16_t value);
 void vdp_data_port_write(vdp_context * context, uint16_t value);
 uint16_t vdp_control_port_read(vdp_context * context);