mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-19 08:31:11 +00:00
Merge pull request #1094 from TomHarte/AppleIIDecoding
Resolve off-by-one error in Apple II sector decoding.
This commit is contained in:
commit
1ba4363802
@ -100,8 +100,8 @@ void AppleDSK::set_tracks(const std::map<Track::Address, std::shared_ptr<Track>>
|
||||
std::map<Track::Address, std::vector<uint8_t>> 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<uint8_t> track_contents(size_t(bytes_per_sector * sectors_per_track_));
|
||||
|
@ -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(
|
||||
|
@ -175,11 +175,12 @@ std::unique_ptr<Sector> decode_appleii_sector(const std::array<uint_fast8_t, 8>
|
||||
}
|
||||
}
|
||||
|
||||
// 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<std::size_t, Sector> 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<std::size_t, Sector> 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user