1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-05 10:28:58 +00:00

Fixed: the sector number also goes into sector bodies.

Also the checksum is written in the other order, and the final byte of data isn't output.
This commit is contained in:
Thomas Harte 2019-06-18 10:34:10 -04:00
parent 756641e837
commit df56e6fe53
4 changed files with 24 additions and 16 deletions

View File

@ -127,7 +127,7 @@
0x09, 0x64, 0x18, 0x6e, 0x66, 0xd5, 0x32, 0x6f, 0xc2, 0x1e, 0x69, 0x75, 0x80, 0x4d, 0x9e, 0x92,
0x5a, 0xee, 0xc1, 0x29, 0x41, 0xae, 0x47, 0xbd, 0x3b, 0x13, 0x46, 0xa1,
};
const auto data = Storage::Encodings::AppleGCR::Macintosh::data(source_data);
const auto data = Storage::Encodings::AppleGCR::Macintosh::data(0, source_data);
const auto expected = Storage::Disk::PCMSegment(expected_data);
XCTAssertEqual(data.data, expected.data);
}

View File

@ -136,6 +136,9 @@ std::shared_ptr<::Storage::Disk::Track> DiskCopy42::get_track_at_position(::Stor
segment += Encodings::AppleGCR::six_and_two_sync(24);
for(int c = 0; c < included_sectors.length; ++c) {
// const int interleave_scale = ((format_ & 0x1f) == 4) ? 8 : 4;
uint8_t sector_id = uint8_t(c);//uint8_t((c == included_sectors.length - 1) ? c : (c * interleave_scale)%included_sectors.length);
uint8_t sector_plus_tags[524];
// Copy in the tags, if provided; otherwise generate them.
@ -155,12 +158,9 @@ std::shared_ptr<::Storage::Disk::Track> DiskCopy42::get_track_at_position(::Stor
// the Apple II, as I have no idea whatsoever what they
// should be.
// const int interleave_scale = ((format_ & 0x1f) == 4) ? 8 : 4;
uint8_t sector_id = uint8_t(c);//uint8_t((c == included_sectors.length - 1) ? c : (c * interleave_scale)%included_sectors.length);
segment += Encodings::AppleGCR::Macintosh::header(0x22, uint8_t(address.position.as_int()), sector_id, !!address.head);
segment += Encodings::AppleGCR::six_and_two_sync(7);
segment += Encodings::AppleGCR::Macintosh::data(sector_plus_tags);
segment += Encodings::AppleGCR::Macintosh::data(sector_id, sector_plus_tags);
segment += Encodings::AppleGCR::six_and_two_sync(20);
}

View File

@ -232,7 +232,7 @@ Storage::Disk::PCMSegment AppleGCR::Macintosh::header(uint8_t type, uint8_t trac
return Storage::Disk::PCMSegment(data);
}
Storage::Disk::PCMSegment AppleGCR::Macintosh::data(const uint8_t *source) {
Storage::Disk::PCMSegment AppleGCR::Macintosh::data(uint8_t sector, const uint8_t *source) {
std::vector<uint8_t> output(710);
int checksum[3] = {0, 0, 0};
@ -241,6 +241,9 @@ Storage::Disk::PCMSegment AppleGCR::Macintosh::data(const uint8_t *source) {
output[1] = data_prologue[1];
output[2] = data_prologue[2];
// Add the sector number.
output[3] = six_and_two_mapping[sector & 0x3f];
// The Macintosh has a similar checksum-as-it-goes approach to encoding
// to the Apple II, but works entirely differently. Each three bytes of
// input are individually encoded to four GCR bytes, their output values
@ -284,10 +287,10 @@ Storage::Disk::PCMSegment AppleGCR::Macintosh::data(const uint8_t *source) {
// Having mutated those three bytes according to the current checksum,
// and the checksum according to those bytes, run them through the
// GCR conversion table.
output[3 + c*4 + 1] = six_and_two_mapping[values[0] & 0x3f];
output[3 + c*4 + 2] = six_and_two_mapping[values[1] & 0x3f];
output[3 + c*4 + 3] = six_and_two_mapping[values[2] & 0x3f];
output[3 + c*4 + 0] = six_and_two_mapping[
output[4 + c*4 + 1] = six_and_two_mapping[values[0] & 0x3f];
output[4 + c*4 + 2] = six_and_two_mapping[values[1] & 0x3f];
output[4 + c*4 + 3] = six_and_two_mapping[values[2] & 0x3f];
output[4 + c*4 + 0] = six_and_two_mapping[
((values[0] >> 2) & 0x30) |
((values[1] >> 4) & 0x0c) |
((values[2] >> 6) & 0x03)
@ -295,13 +298,18 @@ Storage::Disk::PCMSegment AppleGCR::Macintosh::data(const uint8_t *source) {
}
// Also write the checksum.
output[704] = six_and_two_mapping[checksum[0] & 0x3f];
//
// Caveat: the first byte written here will overwrite the final byte that
// was deposited in the loop above. That's deliberate. The final byte from
// the loop above doesn't contain any useful content, and isn't actually
// included on disk.
output[704] = six_and_two_mapping[checksum[2] & 0x3f];
output[705] = six_and_two_mapping[checksum[1] & 0x3f];
output[706] = six_and_two_mapping[checksum[2] & 0x3f];
output[706] = six_and_two_mapping[checksum[0] & 0x3f];
output[703] = six_and_two_mapping[
((checksum[0] >> 2) & 0x30) |
((checksum[2] >> 2) & 0x30) |
((checksum[1] >> 4) & 0x0c) |
((checksum[2] >> 6) & 0x03)
((checksum[0] >> 6) & 0x03)
];
// Write epilogue.

View File

@ -55,9 +55,9 @@ SectorSpan sectors_in_track(int track);
/*!
Produces the data section of a Macintosh-format sector;
the segment returned will be 5680 bits long, encoding the first 524 bytes
from @c source.
from @c source and including a record of the @c sector.
*/
Storage::Disk::PCMSegment data(const uint8_t *source);
Storage::Disk::PCMSegment data(uint8_t sector, const uint8_t *source);
/*!
Produces the Mac-standard header. This is the same