changeset 480:0737953132ad

Implement HV counter latch
author Mike Pavone <pavone@retrodev.com>
date Tue, 17 Sep 2013 09:45:14 -0700
parents 863e868752cf
children 1f3450d1129f
files vdp.c vdp.h
diffstat 2 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/vdp.c	Tue Sep 17 00:42:49 2013 -0700
+++ b/vdp.c	Tue Sep 17 09:45:14 2013 -0700
@@ -1467,10 +1467,10 @@
 			uint8_t reg = (value >> 8) & 0x1F;
 			if (reg < (context->regs[REG_MODE_2] & BIT_MODE_5 ? VDP_REGS : 0xA)) {
 				//printf("register %d set to %X\n", reg, value & 0xFF);
+				if (reg == REG_MODE_1 && (value & BIT_HVC_LATCH) && !(context->regs[reg] & BIT_HVC_LATCH)) {
+					context->hv_latch = vdp_hv_counter_read(context);
+				}
 				context->regs[reg] = value;
-				if (reg == REG_MODE_2) {
-					//printf("Display is now %s\n", (context->regs[REG_MODE_2] & DISPLAY_ENABLE) ? "enabled" : "disabled");
-				}
 				if (reg == REG_MODE_4) {
 					context->double_res = (value & (BIT_INTERLACE | BIT_DOUBLE_RES)) == (BIT_INTERLACE | BIT_DOUBLE_RES);
 					if (!context->double_res) {
@@ -1613,7 +1613,9 @@
 
 uint16_t vdp_hv_counter_read(vdp_context * context)
 {
-	//TODO: deal with clock adjustemnts handled in vdp_run_context
+	if (context->regs[REG_MODE_1] & BIT_HVC_LATCH) {
+		return context->hv_latch;
+	}
 	uint32_t line= context->cycles / MCLKS_LINE;
 	if (!line) {
 		line = 0xFF;
--- a/vdp.h	Tue Sep 17 00:42:49 2013 -0700
+++ b/vdp.h	Tue Sep 17 09:45:14 2013 -0700
@@ -152,6 +152,7 @@
 	sprite_info sprite_info_list[MAX_SPRITES_LINE];
 	uint16_t    col_1;
 	uint16_t    col_2;
+	uint16_t    hv_latch;
 	uint8_t     v_offset;
 	uint8_t     dma_cd;
 	uint8_t     hint_counter;