Skip to content

SDCopy

A floppy disk imager in the style of HD-COPY

C++AssemblyDOSCompleted

Part 8 of 9 · Early Work

Written in 2000 for my Computer Architecture course with Borland C/C++ 3.1 and Turbo Assembler 5.0, SDCopy reads a floppy sector by sector into memory or an image file, then formats, writes and verifies it back onto another disk. It borrows its look from HD-COPY, the tool everyone used for that at the time.

SDCopy reading a 1.44 MB disk: the source track map filling with Rs, a buffer bar, an empty destination map, and a menu of read, write, verify and format commands.

Its images start with an eight-byte header (the letters GMB, a disk type, then tracks, heads and sectors per track), so changing the header is enough to write an image onto a disk of a different geometry. With an image in hand, the boot sector and FAT were mine to edit.

Reading it again

The disk loop does what floppies demand: when a read or write fails it resets the controller and tries again, up to three times, and both operations share one short assembly routine that does it. That part I would keep.

A track that still fails after three tries is reported on screen and then left out of the image file. Every track after it shifts back into its place, so the image is corrupt, and you find out only when you write it back to a disk. Today it would write filler for the unreadable sectors and keep a list of them. I tested it with good disks; a bad one would have shown me.

Floppies read through DMA, and the PC’s DMA controller can’t cross a 64K boundary in physical memory. The track buffer is 10,752 bytes from the heap, put wherever the heap had room, so whenever it happens to straddle such a boundary, every track fails with the same error, three times each. The funny part is that my own error table has the message for exactly that error, “El DMA sobrepasó los 64K bytes” (“DMA crossed the 64K boundary”). The usual trick is to allocate twice the size and use the half that doesn’t straddle.

My drive-type constants don’t match the BIOS’s numbering either, so a 5¼-inch 1.2 MB drive is shown as a 3½-inch 720K one, and refused for 1.2 MB disks.

None of this was obscure in 2000. The 64K DMA boundary was the best-known trap in floppy programming, documented everywhere floppies were, and I knew it well enough to put its message in my error table. I just never connected the message to my own buffer, which is the difference between knowing a fact and having been bitten by it.

The boot sector it writes onto every disk is assembled by hand, as a byte array with its disassembly in the comments, and signs itself GMBSoft!.

Downloads: SDCopy with its source.

Source and history on GitHub: Kronuz/SDCopy, with the source and a few typos fixed.