changeset 2231:8e6fb2c06024

Fix CDC transfer regression
author Michael Pavone <pavone@retrodev.com>
date Thu, 08 Sep 2022 18:56:34 -0700
parents 3888c7ed4e36
children 0c42982dd4d8
files lc8951.c lc8951.h
diffstat 2 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/lc8951.c	Wed Sep 07 23:19:29 2022 -0700
+++ b/lc8951.c	Thu Sep 08 18:56:34 2022 -0700
@@ -143,6 +143,7 @@
 			uint16_t transfer_size = context->regs[DBCL] | (context->regs[DBCH] << 8);
 			context->transfer_end = context->cycle + transfer_size * context->cycles_per_byte;
 			context->next_byte_cycle = context->cycle;
+			context->triggered = 1;
 			printf("DTTRG: size %u, cycle %u, end %u\n", transfer_size, context->cycle, context->transfer_end);
 		}
 		break;
@@ -278,6 +279,7 @@
 						}
 						context->transfer_end = CYCLE_NEVER;
 						context->next_byte_cycle = CYCLE_NEVER;
+						context->triggered = 0;
 					}
 				}
 			} else {
@@ -291,19 +293,17 @@
 
 void lc8951_resume_transfer(lc8951 *context, uint32_t cycle)
 {
-	if (context->transfer_end == CYCLE_NEVER && (context->ifctrl & BIT_DOUTEN)) {
+	if (context->triggered && context->transfer_end == CYCLE_NEVER && (context->ifctrl & BIT_DOUTEN)) {
 		uint16_t transfer_size = context->regs[DBCL] | (context->regs[DBCH] << 8);
-		if (transfer_size != 0xFFFF) {
-			//HACK!!! Work around Sub CPU running longer than we would like and dragging other components with it
-			uint32_t step_diff = (context->cycle - cycle) / context->clock_step;
-			if (step_diff) {
-				context->cycle -= step_diff * context->clock_step;
-			}
-			context->transfer_end = context->cycle + transfer_size * context->cycles_per_byte;
-			context->next_byte_cycle = context->cycle;
-			if (step_diff) {
-				lc8951_run(context, cycle);
-			}
+		//HACK!!! Work around Sub CPU running longer than we would like and dragging other components with it
+		uint32_t step_diff = (context->cycle - cycle) / context->clock_step;
+		if (step_diff) {
+			context->cycle -= step_diff * context->clock_step;
+		}
+		context->transfer_end = context->cycle + transfer_size * context->cycles_per_byte;
+		context->next_byte_cycle = context->cycle;
+		if (step_diff) {
+			lc8951_run(context, cycle);
 		}
 	}
 }
--- a/lc8951.h	Wed Sep 07 23:19:29 2022 -0700
+++ b/lc8951.h	Thu Sep 08 18:56:34 2022 -0700
@@ -29,6 +29,7 @@
 	uint8_t  ctrl1;
 	uint8_t  ar;
 	uint8_t  ar_mask;
+	uint8_t  triggered;
 	uint8_t  sync_counter;
 } lc8951;