diff jag_video.c @ 1097:faa3a4617f62

Get Jaguar video interrupt working
author Michael Pavone <pavone@retrodev.com>
date Sat, 05 Nov 2016 00:23:11 -0700
parents a68274a25e2f
children 4a726e339d6f
line wrap: on
line diff
--- a/jag_video.c	Mon Oct 31 18:41:42 2016 -0700
+++ b/jag_video.c	Sat Nov 05 00:23:11 2016 -0700
@@ -187,6 +187,27 @@
 	OBJ_STOP
 };
 
+uint32_t jag_cycles_to_halfline(jag_video *context, uint32_t target)
+{
+	uint32_t cycles = context->regs[VID_HPERIOD] - (context->regs[VID_HCOUNT & 0x3FF]);
+	uint32_t num_lines;
+	if (context->regs[VID_VCOUNT] < target) {
+		num_lines = target - 1 - context->regs[VID_VCOUNT];
+	} else {
+		num_lines = target + context->regs[VID_VPERIOD] - context->regs[VID_VCOUNT];
+	}
+	cycles += num_lines * context->regs[VID_HPERIOD];
+	return cycles;
+}
+
+uint32_t jag_next_vid_interrupt(jag_video *context)
+{
+	if (context->regs[VID_VINT] > context->regs[VID_VPERIOD]) {
+		return 0xFFFFFFF;
+	}
+	return context->cycles + jag_cycles_to_halfline(context, context->regs[VID_VINT]);
+}
+
 void op_run(jag_video *context)
 {
 	while (context->op.cycles < context->cycles)
@@ -547,6 +568,9 @@
 					context->regs[VID_VCOUNT] = 0;
 				} else {
 					context->regs[VID_VCOUNT]++;
+					if (context->regs[VID_VCOUNT] == context->regs[VID_VINT]) {
+						context->cpu_int_pending |= BIT_CPU_VID_INT_ENABLED;
+					}
 				}
 			} else {
 				context->regs[VID_HCOUNT]++;