From 015104bd573ae3b52d6ec6cd40960a42d319cb3c Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sun, 18 Feb 2018 23:46:48 -0600 Subject: [PATCH] Self-sync bytes should be written after a sector header Not after the data field marker, where the controller/RWTS don't expect to find them. --- src/apple2.enc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/apple2.enc.c b/src/apple2.enc.c index b7ee937..032d0c9 100644 --- a/src/apple2.enc.c +++ b/src/apple2.enc.c @@ -22,6 +22,8 @@ * different byte value that would be literally written to and read from * the disk media. Apple II's RWTS subroutine would then translate them * back into data that is useful to the software being run. + * + * Also, since I forget: gcr is short for "group coded recording" */ static vm_8bit gcr62[] = { // 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f @@ -219,11 +221,6 @@ apple2_enc_sector(vm_segment *dest, vm_segment *src, vm_segment_set(dest, doff++, 0xaa); vm_segment_set(dest, doff++, 0xad); - // Sure... let's just toss in a few self-sync bytes - for (i = 0; i < 6; i++) { - vm_segment_set(dest, doff++, 0xff); - } - // Now we use the gcr table for 6-and-2 encoding to take the XOR'd // values and represent them as they should be in the destination // segment. This constitutes the data field of the sector. @@ -292,5 +289,11 @@ apple2_enc_sector_header(vm_segment *seg, int off, vm_segment_set(seg, off++, 0xaa); vm_segment_set(seg, off++, 0xeb); + // Write six (exactly six!) self-sync bytes following the epilogue, + // because the Disk II controller/RWTS method expect to find it. + for (int i = 0; i < 6; i++) { + vm_segment_set(seg, off++, 0xff); + } + return off - orig; }