changeset 65:aef6302770c2

Fix issue in which VDP would have trouble emptying FIFO because the VDP cycle count got reset at end of frame.
author Mike Pavone <pavone@retrodev.com>
date Wed, 19 Dec 2012 22:15:16 -0800
parents 2b1a65f4b85d
children 7a22a0e6c004
files vdp.c vdp.h
diffstat 2 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/vdp.c	Wed Dec 19 21:25:39 2012 -0800
+++ b/vdp.c	Wed Dec 19 22:15:16 2012 -0800
@@ -195,7 +195,7 @@
 				//printf("VRAM Write: %X to %X\n", start->value, context->address ^ 1);
 				context->vdpmem[context->address ^ 1] = start->value;
 			} else {
-				//printf("VRAM Write: %X to %X\n", start->value >> 8, context->address);
+				//printf("VRAM Write High: %X to %X\n", start->value >> 8, context->address);
 				context->vdpmem[context->address] = start->value >> 8;
 				start->partial = 1;
 				//skip auto-increment and removal of entry from fifo
@@ -920,9 +920,9 @@
 {
 	//printf("data port write: %X\n", value);
 	context->flags &= ~FLAG_PENDING;
-	/*if (context->fifo_cur == context->fifo_end) {
+	if (context->fifo_cur == context->fifo_end) {
 		printf("FIFO full, waiting for space before next write at cycle %X\n", context->cycles);
-	}*/
+	}
 	while (context->fifo_cur == context->fifo_end) {
 		vdp_run_context(context, context->cycles + ((context->latched_mode & BIT_H40) ? 16 : 20));
 	}
@@ -981,6 +981,18 @@
 	return value;
 }
 
+void vdp_adjust_cycles(vdp_context * context, uint32_t deduction)
+{
+	context->cycles -= deduction;
+	for(fifo_entry * start = (context->fifo_end - FIFO_SIZE); start < context->fifo_cur; start++) {
+		if (start->cycle >= deduction) {
+			start->cycle -= deduction;
+		} else {
+			start->cycle = 0;
+		}
+	}
+}
+
 #define GST_VDP_REGS 0xFA
 #define GST_VDP_MEM 0x12478
 
--- a/vdp.h	Wed Dec 19 21:25:39 2012 -0800
+++ b/vdp.h	Wed Dec 19 22:15:16 2012 -0800
@@ -107,5 +107,6 @@
 void vdp_data_port_write(vdp_context * context, uint16_t value);
 uint16_t vdp_control_port_read(vdp_context * context);
 uint16_t vdp_data_port_read(vdp_context * context);
+void vdp_adjust_cycles(vdp_context * context, uint32_t deduction);
 
 #endif //VDP_H_