changeset 2348:2025ba21026a

Fix backwards seek calculation
author Michael Pavone <pavone@retrodev.com>
date Wed, 11 Oct 2023 23:18:16 -0700
parents 047253715fd8
children f0fc6c09517d
files cdd_mcu.c
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/cdd_mcu.c	Wed Oct 11 11:36:18 2023 -0700
+++ b/cdd_mcu.c	Wed Oct 11 23:18:16 2023 -0700
@@ -125,13 +125,15 @@
 				}
 			} else {
 				uint32_t seek_amount;
-				for (seek_amount = max_seek; seek_amount >= min_seek; seek_amount >>= 1)
+				for (seek_amount = max_seek; seek_amount >= min_seek;)
 				{
-					if (context->head_pba - context->seek_pba >= seek_amount) {
+					uint32_t next_seek = seek_amount >> 1;
+					if (context->head_pba - context->seek_pba > next_seek) {
 						break;
 					}
+					seek_amount = next_seek;
 				}
-				if (seek_amount >= min_seek) {
+				if (seek_amount >= min_seek && context->head_pba >= seek_amount) {
 					context->head_pba -= seek_amount;
 				} else if (context->head_pba >= min_seek){
 					context->head_pba -= min_seek;