diff --git a/Storage/Disk/DiskImage/Formats/AppleDSK.cpp b/Storage/Disk/DiskImage/Formats/AppleDSK.cpp index 699da7ecc..0d4a2fa5e 100644 --- a/Storage/Disk/DiskImage/Formats/AppleDSK.cpp +++ b/Storage/Disk/DiskImage/Formats/AppleDSK.cpp @@ -100,8 +100,8 @@ void AppleDSK::set_tracks(const std::map> std::map> tracks_by_address; for(const auto &pair: tracks) { // Decode the track. - const auto sector_map = Storage::Encodings::AppleGCR::sectors_from_segment( - Storage::Disk::track_serialisation(*pair.second, Storage::Time(1, 50000))); + const auto serialistion = Storage::Disk::track_serialisation(*pair.second, Storage::Time(1, 50000)); + const auto sector_map = Storage::Encodings::AppleGCR::sectors_from_segment(serialistion); // Rearrange sectors into Apple DOS or Pro-DOS order. std::vector track_contents(size_t(bytes_per_sector * sectors_per_track_)); diff --git a/Storage/Disk/Encodings/AppleGCR/Encoder.cpp b/Storage/Disk/Encodings/AppleGCR/Encoder.cpp index fc9308d3b..0fa51e366 100644 --- a/Storage/Disk/Encodings/AppleGCR/Encoder.cpp +++ b/Storage/Disk/Encodings/AppleGCR/Encoder.cpp @@ -141,7 +141,7 @@ Storage::Disk::PCMSegment AppleGCR::AppleII::six_and_two_data(const uint8_t *sou // and combined copies of the bottom two bits of the sector // contents; the 256 bytes afterwards are the remaining // six bits. - const uint8_t bit_reverse[] = {0, 2, 1, 3}; + constexpr uint8_t bit_reverse[] = {0, 2, 1, 3}; for(std::size_t c = 0; c < 84; ++c) { data[3 + c] = uint8_t( diff --git a/Storage/Disk/Encodings/AppleGCR/SegmentParser.cpp b/Storage/Disk/Encodings/AppleGCR/SegmentParser.cpp index d68be8d7e..8df9d09ca 100644 --- a/Storage/Disk/Encodings/AppleGCR/SegmentParser.cpp +++ b/Storage/Disk/Encodings/AppleGCR/SegmentParser.cpp @@ -175,11 +175,12 @@ std::unique_ptr decode_appleii_sector(const std::array } } - // Undo the XOR step on sector contents and check that checksum. + // Undo the XOR step on sector contents, then check and discard the checksum. for(std::size_t c = 1; c < sector->data.size(); ++c) { sector->data[c] ^= sector->data[c-1]; } if(sector->data.back()) return nullptr; + sector->data.resize(sector->data.size() - 1); if(is_five_and_three) { // TODO: the below is almost certainly incorrect; Beneath Apple DOS partly documents @@ -275,7 +276,8 @@ std::map Storage::Encodings::AppleGCR::sectors_from_segment scanner[2] == five_and_three_header_prologue[2] || scanner[2] == header_prologue[2] || scanner[2] == data_prologue[2] - )) { + ) + ) { pointer = 0; if(scanner[2] != data_prologue[2]) { @@ -309,20 +311,21 @@ std::map Storage::Encodings::AppleGCR::sectors_from_segment new_sector.reset(); pointer = scanning_sentinel; + const bool had_header = has_header; + has_header = false; + // Potentially this is a Macintosh sector. - auto macintosh_sector = decode_macintosh_sector(has_header ? &header : nullptr, sector); + auto macintosh_sector = decode_macintosh_sector(had_header ? &header : nullptr, sector); if(macintosh_sector) { result.insert(std::make_pair(sector_location, std::move(*macintosh_sector))); continue; } // Apple II then? - auto appleii_sector = decode_appleii_sector(has_header ? &header : nullptr, sector, is_five_and_three); + auto appleii_sector = decode_appleii_sector(had_header ? &header : nullptr, sector, is_five_and_three); if(appleii_sector) { result.insert(std::make_pair(sector_location, std::move(*appleii_sector))); } - - has_header = false; } else { new_sector->data.push_back(value); }