I converted my disk image to a .nib with Ciderpress. It turns out my nibble generator is failing for offsets 0x55 and 0x56 in a nibblized sector. Some poking with it showed that my routine that accounts for the rollover of the low bits isn't working right. In the encoded buffer, $100 isn't being set properly because I'm missing the checksum byte.
I'm confused about the encoding process though, specifically the checksum byte. I'm looking at a text file on DOS 3.3 encoding (
http://mirrors.apple2.org.za/ground.icaen.uiowa.edu/MiscInfo/Dos33/dos.encoding). It says:
---
Suppose that you have read in (and translated) the 343 bytes (data
field + checksum) of a sector into a buffer with the beginning of the
buffer being represented by byte position HEX $000 and the end being
represented by byte position HEX $156. The buffer would have the
following appearance:
$000: 0 0 a7 a6 a5 a4 a3 a2
$001: 0 0 b7 b6 b5 b4 b3 b2
$002: 0 0 c7 c6 c5 c4 c3 c2
$003: 0 0 | | | | | |
$004: 0 0 | | | | | |
$005: 0 0 v v v v v v
$100: 0 0 < <
$150: 0 0 ^ ^ ^ ^ ^ ^
$151: 0 0 | | | | | |
$152: 0 0 | | | | | |
$153: 0 0 | | | | | |
$154: 0 0 | | | | c0 c1
$155: 0 0 | | | | b0 b1
$156: 0 0 | | | | a0 a1
---
256 / 3 = 85 1/3... but we have 86 low bytes to store. Where does the checksum bit specifically fit into this? That seems to be the missing piece.
The source code in question is here:
https://github.com/Luigi30/FruitMachine-Swift/blob/master/FruitMachine/AppleII/Peripherals/DiskII/DiskImage.swift
It's kind of a mess since I'm actively writing the disk image handler. encodeDos33Track() takes in a .do/.dsk disk image and a track number and encodes the data for the Disk II controller, creating an encoded track as described in Beneath Apple DOS. EncodeSectorSixAndTwo takes in the raw binary data and spits out the 342-byte encoded sector to be inserted into the track.