Make various apple2 parameters configurable. Change the way sync bytes are

written to more match the way real hardware does it.
This commit is contained in:
David Given
2024-02-02 22:52:44 +01:00
parent df83b558bf
commit 8863bda0d0
3 changed files with 17 additions and 11 deletions

View File

@@ -29,6 +29,7 @@ IncludeBlocks: Preserve
IndentCaseLabels: 'true' IndentCaseLabels: 'true'
IndentWidth: '4' IndentWidth: '4'
IndentWrappedFunctionNames: 'false' IndentWrappedFunctionNames: 'false'
IndentPPDirectives: BeforeHash
KeepEmptyLinesAtTheStartOfBlocks: 'true' KeepEmptyLinesAtTheStartOfBlocks: 'true'
NamespaceIndentation: All NamespaceIndentation: All
PointerAlignment: Left PointerAlignment: Left

View File

@@ -19,4 +19,13 @@ message Apple2EncoderProto
optional uint32 side_one_track_offset = 3 optional uint32 side_one_track_offset = 3
[ default = 0, (help) = "offset to apply to track numbers on side 1" ]; [ default = 0, (help) = "offset to apply to track numbers on side 1" ];
optional uint32 post_index_gap_bytes = 4
[ default = 32, (help) = "the number of resync bytes to write after the index mark" ];
optional uint32 post_address_gap_bytes = 5
[ default = 6, (help) = "the number of resync bytes to write after the address gap" ];
optional uint32 post_data_gap_bytes = 6
[ default = 8, (help) = "the number of resync bytes to write after each sector" ];
} }

View File

@@ -79,18 +79,14 @@ private:
auto write_bit = [&](bool val) auto write_bit = [&](bool val)
{ {
if (cursor <= bits.size()) if (cursor <= bits.size())
{
bits[cursor] = val; bits[cursor] = val;
}
cursor++; cursor++;
}; };
auto write_bits = [&](uint32_t bits, int width) auto write_bits = [&](uint32_t bits, int width)
{ {
for (int i = width; i--;) for (int i = width; i--;)
{
write_bit(bits & (1u << i)); write_bit(bits & (1u << i));
}
}; };
auto write_gcr44 = [&](uint8_t value) auto write_gcr44 = [&](uint8_t value)
@@ -104,15 +100,13 @@ private:
}; };
// The special "FF40" sequence is used to synchronize the receiving // The special "FF40" sequence is used to synchronize the receiving
// shift register. It's written as "1111 1111 00"; FF indicates the // shift register. It's written as "0 1111 1111 0"; FF indicates the
// 8 consecutive 1-bits, while "40" indicates the total number of // 8 consecutive 1-bits, while "40" indicaes the total number of
// microseconds. // microseconds.
auto write_ff40 = [&](int n = 1) auto write_ff40 = [&](int n = 1)
{ {
for (; n--;) for (; n--;)
{ write_bits(0xff << 1, 10);
write_bits(0xff << 2, 10);
}
}; };
// There is data to encode to disk. // There is data to encode to disk.
@@ -127,7 +121,9 @@ private:
// //
// In standard formatting, the first logical sector apparently gets // In standard formatting, the first logical sector apparently gets
// extra padding. // extra padding.
write_ff40(sector.logicalSector == 0 ? 32 : 8); write_ff40(sector.logicalSector == 0
? _config.post_index_gap_bytes()
: _config.post_data_gap_bytes());
int track = sector.logicalTrack; int track = sector.logicalTrack;
if (sector.logicalSide == 1) if (sector.logicalSide == 1)
@@ -144,7 +140,7 @@ private:
// Write data syncing leader: FF40 + APPLE2_DATA_RECORD + sector // Write data syncing leader: FF40 + APPLE2_DATA_RECORD + sector
// data + sum + DE AA EB (+ mystery bits cut off of the scan?) // data + sum + DE AA EB (+ mystery bits cut off of the scan?)
write_ff40(8); write_ff40(_config.post_address_gap_bytes());
write_bits(APPLE2_DATA_RECORD, 24); write_bits(APPLE2_DATA_RECORD, 24);
// Convert the sector data to GCR, append the checksum, and write it // Convert the sector data to GCR, append the checksum, and write it