

Software decoding of the 1541 disk drive GCR data in realtime - draugadrotten
http://www.linusakesson.net/programming/gcr-decoding/index.php
The code solves a real, practical problem that people have been struggling with for 30 years.<p>The 1541 contains a single 6502 CPU clocked at 1 MHz, 2 kB of RAM and 16 kB of ROM. With such modest specifications, Commodore concluded that the 1541 was not capable of decoding the GCR data in realtime. Commodore compatible 5.25" floppy disks store data as magnetic polarity reversals along 35 concentric tracks on the surface.  The key to the solution lies in looking at the problem from a novel angle. We'll use plenty of self-modifying code. This is not really a trick, but an established technique on the 6502 processor. The sax instruction is a mix of sta and stx; it tries to write the contents of both A and X to memory, and due to the NMOS process used to manufacture the 6502, zeroes are stronger than ones, so bus contentions resolve into bitwise-and operations. Thus, we can use sax to store a subset of the bits in A (or X) to memory without clobbering the rest of the register. Furthermore, we can perform a bitwise-and operation using the sbx instruction (a mix of cpx and tax) with an operand of zero, which will leave the result in X.
======
gbaygon
previous discussion (4 days ago):
<https://news.ycombinator.com/item?id=5504910>

