changeset 699:d8a1fdec68fc

Fix frame counter increment and VINT cycle time calculation
author Michael Pavone <pavone@retrodev.com>
date Mon, 11 May 2015 20:30:35 -0700
parents 0a86e81fa87d
children 72ab94527a8a
files vdp.c
diffstat 1 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/vdp.c	Mon May 11 20:30:13 2015 -0700
+++ b/vdp.c	Mon May 11 20:30:35 2015 -0700
@@ -1456,9 +1456,6 @@
 		}
 		if (is_h40 && slot == LINE_CHANGE_H40 || !is_h40 && slot == LINE_CHANGE_H32) {
 			if (line >= inactive_start) {
-				if (line == (inactive_start + 8)) {
-					context->frame++;
-				}
 				context->hint_counter = context->regs[REG_HINT];
 			} else if (context->hint_counter) {
 				context->hint_counter--;
@@ -1524,12 +1521,18 @@
 			if (is_h40) {
 				if (context->hslot == LINE_CHANGE_H40) {
 					context->vcounter++;
+					if (context->vcounter == (inactive_start + 8)) {
+						context->frame++;
+					}
 				} else if (context->hslot == 183) {
 					context->hslot = 229;
 				}
 			} else {
 				if (context->hslot == LINE_CHANGE_H32) {
 					context->vcounter++;
+					if (context->vcounter == (inactive_start + 8)) {
+						context->frame++;
+					}
 				} else if (context->hslot == 148) {
 					context->hslot = 233;
 				}
@@ -1957,7 +1960,7 @@
 	uint32_t inactive_start = context->latched_mode & BIT_PAL ? PAL_INACTIVE_START : NTSC_INACTIVE_START;
 	if (context->vcounter == inactive_start) {
 		if (context->regs[REG_MODE_4] & BIT_H40) {
-			if (context->hslot >= HBLANK_START_H40) {
+			if (context->hslot >= LINE_CHANGE_H40) {
 				if (context->hslot < 183) {
 					return context->cycles + (VINT_SLOT_H40 + 183 - context->hslot + 256 - 229) * MCLKS_SLOT_H40;
 				} else {
@@ -1967,7 +1970,7 @@
 				return context->cycles + (VINT_SLOT_H40 - context->hslot) * MCLKS_SLOT_H40;
 			}
 		} else {
-			if (context->hslot >= HBLANK_START_H32) {
+			if (context->hslot >= LINE_CHANGE_H32) {
 				if (context->hslot < 148) {
 					return context->cycles + (VINT_SLOT_H32 + 148 - context->hslot + 256 - 233) * MCLKS_SLOT_H32;
 				} else {
@@ -1980,9 +1983,9 @@
 	}
 	int32_t cycles_to_vint = vdp_cycles_to_line(context, inactive_start);
 	if (context->regs[REG_MODE_4] & BIT_H40) {
-		cycles_to_vint += (VINT_SLOT_H40 + 183 - HBLANK_START_H40 + 256 - 229) * MCLKS_SLOT_H40;
+		cycles_to_vint += (VINT_SLOT_H40 + 183 - LINE_CHANGE_H40 + 256 - 229) * MCLKS_SLOT_H40;
 	} else {
-		cycles_to_vint += (VINT_SLOT_H32 + 148 - HBLANK_START_H32 + 256 - 233) * MCLKS_SLOT_H32;
+		cycles_to_vint += (VINT_SLOT_H32 + 148 - LINE_CHANGE_H32 + 256 - 233) * MCLKS_SLOT_H32;
 	}
 	return context->cycles + cycles_to_vint;
 }