keirf / disk-utilities

The Unlicense
235 stars 50 forks source link

Support for Commodore 1581? #74

Open tokudan opened 4 years ago

tokudan commented 4 years ago

I've got a 1581 with a couple of disks and can provide an image from the 1581 Demo Disk and maybe other disks. Are you interested in adding support for this format?

keirf commented 4 years ago

Probably already supported: Try passing a dump into disk-analyse with --format=ibm_mfm_dd

tokudan commented 4 years ago

That produces an image that is exactly the correct size and I'm able to find some strings from the BASIC programs stored on the disk. I'm unable to find the directory track, which should be at track 40 (starting at position 0005f000 in the resulting image) and I cannot find the usual "BLOCKS FREE" text anywhere on the disk It's quite possible that the d81 format has some quirks that I don't know about yet, so I'll have a closer look probably during the upcoming weekend.

tokudan commented 4 years ago

I think I've managed to make sense of the issues I have with the disk image produced by the disk analyzer. The commodore 64 and it's 1581 uses 256 byte "sectors", with 80 tracks (1 to 80) and 40 sectors (0 to 39) per track. Renaming the .img file to .d81 results int the sectors being offset by exactly half a track (20 256-byte sectors or 10 512-byte sectors). For example (using Commodore 1581 tracks,sectors in decimal numbers): Expected location of directory blocks: 40,0 disk header 40,1-2 block allocation map 40,3 start of directory Actual location in the image: 40,20 disk header 40,23 start of directory

Same for a random file that I tried to read, according to the directory and the linked blocks: 47,28 to 39 PARTITION AID Actual locations on the image: 47,08 to 19 PARTITION AID

I used some basic shell scripting to swap the two halves of each track:

source=converted-ibm_mfm_dd.img
target=converted-ibm_mfm_dd_fixed.d81
halftracks=160
halftracksize=$((20*256))
rc=0;
t=0
while [ $t -lt $halftracks ]; do
dd if=${source} ibs=$(($halftracksize)) of=${target} obs=$(($halftracksize)) conv=notrunc skip=$(($t +1)) seek=$(($t)) count=1
dd if=${source} ibs=$(($halftracksize)) of=${target} obs=$(($halftracksize)) conv=notrunc skip=$(($t)) seek=$(($t +1)) count=1
t=$(($t + 2))
done

As a result the image loads fine now. I haven't verified this completely yet, so there may still be some hidden issues.

So adding the d81 as an output format would basically mean to swap around the two halves of the tracks. I want to verify this with a couple other disks first, though.

tokudan commented 4 years ago

I've created a basic test disk on my 1581 that contains the logical track and sector numbers. The tests show that the two halves of each track are swapped. I'm not sure if that means that e.g. the top and bottom side of the disk are swapped on a 1581 or if there's something else going on. Are you interested in having d81 as a supported output format? Would you need me to write a pull request?

keirf commented 4 years ago

Yes disk sides are swapped on d81 images. That's the only oddity (I know as I support this image format in Flashfloppy).