changeset 2352:76dfad6a53b5

Fix bug in CD-ROM scrambling algorithm
author Michael Pavone <pavone@retrodev.com>
date Wed, 18 Oct 2023 23:27:14 -0700
parents 8f3cfb77f1e3
children c66e051de8a6
files cdimage.c
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/cdimage.c	Wed Oct 18 23:26:51 2023 -0700
+++ b/cdimage.c	Wed Oct 18 23:27:14 2023 -0700
@@ -9,10 +9,13 @@
 uint8_t cdrom_scramble(uint16_t *lsfr, uint8_t data)
 {
 	data ^= *lsfr;
-	uint16_t new_bit = *lsfr;
-	*lsfr >>= 1;
-	new_bit = (new_bit ^ *lsfr) & 1;
-	*lsfr |= new_bit << 14;
+	for (int i = 0; i < 8; i++)
+	{
+		uint16_t new_bit = *lsfr;
+		*lsfr >>= 1;
+		new_bit = (new_bit ^ *lsfr) & 1;
+		*lsfr |= new_bit << 14;
+	}
 	return data;
 }