diff --git a/Storage/Disk/DiskImage/Formats/AppleDSK.cpp b/Storage/Disk/DiskImage/Formats/AppleDSK.cpp index a3c86c2e7..afc0d06c9 100644 --- a/Storage/Disk/DiskImage/Formats/AppleDSK.cpp +++ b/Storage/Disk/DiskImage/Formats/AppleDSK.cpp @@ -53,12 +53,12 @@ std::shared_ptr AppleDSK::get_track_at_position(Track::Address address) { // In either case below, the code aims for exactly 50,000 bits per track. if(sectors_per_track_ == 16) { // Write the sectors. - uint8_t sector_number_ = 0; - for(std::size_t c = 0; c < 16; ++c) { + std::size_t sector_number_ = 0; + for(uint8_t c = 0; c < 16; ++c) { segment += Encodings::AppleGCR::six_and_two_sync(10); - segment += Encodings::AppleGCR::header(0, track, sector_number_); + segment += Encodings::AppleGCR::header(0, track, c); segment += Encodings::AppleGCR::six_and_two_sync(10); - segment += Encodings::AppleGCR::six_and_two_data(&track_data[c * 256]); + segment += Encodings::AppleGCR::six_and_two_data(&track_data[sector_number_ * 256]); // DOS and Pro DOS interleave sectors on disk, and they're represented in a disk // image in physical order rather than logical. So that skew needs to be applied here. diff --git a/Storage/Disk/Drive.cpp b/Storage/Disk/Drive.cpp index 5ef0dac5f..f1de0609c 100644 --- a/Storage/Disk/Drive.cpp +++ b/Storage/Disk/Drive.cpp @@ -205,9 +205,14 @@ void Drive::setup_track() { assert(track_time_now >= Time(0) && current_event_.length <= Time(1)); Time time_found = track_->seek_to(track_time_now); - assert(time_found >= Time(0) && time_found < Time(1) && time_found <= track_time_now); - offset = track_time_now - time_found; + // time_found can be greater than track_time_now if limited precision caused rounding + if(time_found <= track_time_now) { + offset = track_time_now - time_found; + } else { + offset.set_zero(); + } + get_next_event(offset); } 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.