From 4b4ea4a103bcc108c4097fd251ad80e8b587d0c0 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 2 May 2018 21:06:18 -0400 Subject: [PATCH] Corrects final two bytes of Apple GCR low nibble encoding. --- Storage/Disk/Encodings/AppleGCR.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Storage/Disk/Encodings/AppleGCR.cpp b/Storage/Disk/Encodings/AppleGCR.cpp index 3843859c1..5702d9239 100644 --- a/Storage/Disk/Encodings/AppleGCR.cpp +++ b/Storage/Disk/Encodings/AppleGCR.cpp @@ -156,13 +156,26 @@ Storage::Disk::PCMSegment AppleGCR::six_and_two_data(const uint8_t *source) { // six bits. const uint8_t bit_shuffle[] = {0, 2, 1, 3}; for(std::size_t c = 0; c < 84; ++c) { - segment.data[3 + c] = bit_shuffle[source[c]&3]; - if(c + 86 < 256) segment.data[3 + c] |= bit_shuffle[source[c + 86]&3] << 2; - if(c + 172 < 256) segment.data[3 + c] |= bit_shuffle[source[c + 172]&3] << 4; + segment.data[3 + c] = + static_cast( + bit_shuffle[source[c]&3] | + (bit_shuffle[source[c + 86]&3] << 2) | + (bit_shuffle[source[c + 172]&3] << 4) + ); } + segment.data[87] = + static_cast( + (bit_shuffle[source[84]&3] << 0) | + (bit_shuffle[source[170]&3] << 2) + ); + segment.data[88] = + static_cast( + (bit_shuffle[source[85]&3] << 0) | + (bit_shuffle[source[171]&3] << 2) + ); for(std::size_t c = 0; c < 256; ++c) { - segment.data[3 + 85 + 1 + c] = source[c] >> 2; + segment.data[3 + 86 + c] = source[c] >> 2; } // Exclusive OR each byte with the one before it.