# HG changeset patch # User Michael Pavone # Date 1697696834 25200 # Node ID 76dfad6a53b59483b27d0a3b793d71efc4967071 # Parent 8f3cfb77f1e3ccecca9bd6a959013a5392e68b5a Fix bug in CD-ROM scrambling algorithm diff -r 8f3cfb77f1e3 -r 76dfad6a53b5 cdimage.c --- 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; }