Copy Protection and ATX Disk Images: Bad Sectors, Phantoms and Timing

BASIC screen listing sectors 1 to 8 and four re-reads of sector 4, each with status 1 and a read time of 4 or 5 jiffies (14 for the first)

Plenty of original Atari disks refuse to run from an ordinary ATR image. They boot, check something about the disk, and crash or hang when the answer is wrong. That something is the copy protection: the disk was recorded so that a stock 810 or 1050 could read it but not write an identical copy. This guide explains the tricks at the level of the drive, why ATR can't represent them, and how the ATX format from Jorge Cwik's VAPI preservation project captures them.

What you'll learn: how sectors are laid out on a track, the main protection techniques and how a loader detects them, what an ATX file contains, which emulators and devices run ATX, and how protected disks are imaged today.

What you need: Atari BASIC (emulated or real), Python 3 for the ATX lister, and Altirra for running ATX images. Atari 8-bit File Formats Explained covers ATR and the other everyday formats.

1. What a real track holds

An 810 or 1050 spins the disk at 288 RPM, so one revolution takes about 208 ms. In single density each track is recorded in FM encoding, giving room for roughly 3,250 raw bytes. Each of the 18 sectors on a track has two parts:

  • an address field: a sync mark, the track number, side, sector number (1–18), a size code (0 = 128 bytes, 1 = 256, 2 = 512, 3 = 1024) and a CRC;
  • a data field: a data address mark, the sector data, and another CRC.

The drive's floppy disk controller (FDC) finds the address field with the right numbers, reads the data field after it, and the firmware passes the data and the controller's status to the computer.

Standard Atari formats put the sectors in an interleaved order so the drive is ready when the next one arrives: 9:1 for single density, giving the order 1, 10, 2, 11, 3, 12 and so on.

An ATR image stores none of this. It is just the 128-byte payload of sectors 1 to 720, in numerical order. Anything that lives in the layout of a track, in the errors the controller reports, or in when a sector passes under the head is gone.

2. The protection toolbox

The tricks below all exploit things that a stock drive reads faithfully but cannot write through the normal Put and Write commands. Status values are the second byte of the four-byte drive status. The 810 inverts the FDC status, so a cleared bit means an error.

Technique How it is made What the loader sees
Bad (missing) sector No address field for that number Error, "record not found"; 810 status $EF
CRC error Data deliberately corrupted after the CRC was written Error plus the data anyway; status $F7
Deleted sector Data mark $F8 instead of $FB Error; 810 returns $9F, 1050 $DF
Long sector Address field says 256+ bytes Error; 810 $FC/$FE, 1050 $F9
Weak sector Unrecorded or weakly recorded area Different data on every read, always with a CRC error
Phantom (duplicate) sectors Two or more sectors with the same ID on one track Which copy you get depends on when you ask
Overlapped track Clock bits left out so one sector's data overlaps the next address field More sectors than should fit, as many as 36 on one track

The loader's check is simple. It reads the protected sector, expects an Error result rather than Complete, and often also checks the status byte or the returned data. A copy made with an ordinary sector copier turns the bad sector into a good one full of zeros, so the check fails.

Phantoms go further, because they involve time. Reading a sector on an 810 takes at least 90 ms end to end: about 2.6 ms to send the command, 9.7 ms to read the physical sector, and 74 ms to checksum and send it to the computer. Which of two duplicate sectors comes back therefore depends on exactly where the disk was when the command arrived. Some loaders also time their reads with the real-time clock, which can trip over speed-ups in emulators and modern drives, or depend on the video standard: Penguin Software's Transylvania and The Quest are known to load on NTSC machines but not on PAL ones because of timing-based protection.

Not every drive answers the same way. The Indus GT and Percom RFD-40S1 read long sectors without reporting an error, so a long-sector check gets a different answer on those drives. There was a home-brew arms race too: CSS sold its Protector bad-sector generator in 1983, Computer Support its Bad Sector in 1985, and CSS its Electronic Phantom Sector Maker hardware in 1987.

3. Hands-on: measuring sector timing

This probe reads sectors through the OS SIO routine and times each read with the real-time clock (RTCLOK, 18–20). It uses the same PLA : JSR $E459 : RTS stub in page 6 as SIO Explained. Line 70 picks sectors 1 to 8, then sector 4 four more times.

10 REM SECTOR TIMING PROBE
20 FOR I=0 TO 4:READ B:POKE 1536+I,B:NEXT I
30 DATA 104,32,89,228,96
40 DIM B$(128):A=ADR(B$)
50 PRINT "SECTOR","STATUS","JIFFIES"
60 FOR K=1 TO 12
70 S=K:IF K>8 THEN S=4
80 POKE 768,49:POKE 769,1:POKE 770,82:POKE 771,64
90 POKE 772,A-INT(A/256)*256:POKE 773,INT(A/256)
100 POKE 774,7:POKE 776,128:POKE 777,0
110 POKE 778,S:POKE 779,0
120 T0=PEEK(19)*256+PEEK(20)
130 X=USR(1536)
140 T=PEEK(19)*256+PEEK(20)-T0
150 PRINT S,PEEK(771),T
160 NEXT K

Line 80 sets DSTATS back to $40 (receive) on every pass, because SIO overwrites it with the result. In atari800 with its SIO patch turned off (-nopatch), every read takes the same 4 jiffies, including the four repeats of sector 4: that emulator does not model rotation. A real drive cannot do that. After reading sector 4 it has to wait for the sector to come round again, and a full revolution is 208 ms, about 12 to 13 NTSC jiffies. A loader that times its reads can tell the difference, and so can one that relies on getting a particular phantom.

4. Why ATR fails, and what PRO and ATX add

Because an ATR is only a list of sector contents, it has nowhere to record a missing sector, a CRC error, a deleted mark, a second copy of sector 7 or the angle at which a sector sits. Protected software in ATR, DCM or XFD form has either had the protection removed or won't work, apart from the odd scheme that passes by luck because of how an emulator lays out the sectors.

Two formats were designed to fix this:

  • PRO, from Steven Tucker's APE ProSystem, records protection features. APE, Altirra and RespeQt support it, but it captures less than ATX.
  • ATX, created by Jorge Cwik (ijor) for VAPI, a project to preserve Atari software in its original form, protection included. As first defined it covered 90K single-density disks only. The format has since been extended: Altirra reads ATX images with MFM (enhanced- and double-density) tracks, and has had double-density ATX support on by default since version 4.30.

An ATX file is a 48-byte header starting with the signature AT8X, then one record per track. Each track record has a 32-byte header (track number, sector count, flags such as "MFM") and a chain of chunks. The sector list chunk gives, for every physical sector on the track in the order found:

  • its sector number, so duplicates simply appear twice;
  • the FDC status it produced: CRC error, missing data, deleted, long;
  • its position on the track, in units of 8 µs, with 26,042 units to a revolution;
  • where its data is stored.

Optional chunks mark a weak-data offset, from which an emulator should return random bytes, and an extended sector header for long sectors.

This short Python lister walks the structure and prints each track's physical sectors as number@angle, with a ! and the status byte for any abnormal sector:

import struct, sys

data = open(sys.argv[1], "rb").read()
if data[:4] != b"AT8X":
    sys.exit("not an ATX image")
ver, = struct.unpack_from("<H", data, 4)
density = data[18]                       # 0=SD, 1=ED, 2=DD
pos, = struct.unpack_from("<I", data, 28)   # first track record
print(f"ATX version {ver}, density code {density}")
while pos + 32 <= len(data):
    size, rtype = struct.unpack_from("<IH", data, pos)
    if size == 0:
        break
    if rtype == 0:                       # a track record
        track, nsec = data[pos + 8], struct.unpack_from("<H", data, pos + 10)[0]
        flags, first = struct.unpack_from("<II", data, pos + 16)
        chunk = pos + first
        while True:                      # walk the chunks to find the sector list
            csize, ctype = struct.unpack_from("<IB", data, chunk)
            if csize == 0 or ctype == 1:
                break
            chunk += csize
        line = []
        for i in range(nsec if csize else 0):
            num, fdc, when = struct.unpack_from("<BBH", data, chunk + 8 + i * 8)
            mark = "" if fdc == 0 else f"!{fdc:02X}"
            line.append(f"{num}@{when * 360 // 26042}{mark}")
        print(f"T{track:02d} {'MFM' if flags & 2 else 'FM '} {nsec:2d}: " + " ".join(line))
    pos += size

A line such as T01 FM 19: … 7@40 … 7@220!08 … shows a duplicate sector 7 half a turn from the first, with a CRC error: a phantom-sector check. The status bits are stored uninverted: 08 CRC error, 10 record not found, 20 deleted, 04 long.

5. Running ATX images

Altirra loads ATX directly (also from inside .zip files) and emulates weak bits, phantoms and sector positions. Since 2.60 it can also write ATX, PRO, DCM and XFD images. The settings that matter:

  • Accurate sector timing. This returns sectors with real rotational and seek delays. It is the slowest mode, but it loads almost anything. With it off, Altirra still tracks disk rotation and "warps" the disk position to keep most protections happy at higher speed.
  • SIO patch and burst transfers. The burst I/O option is the one most likely to break a protected loader, because it can engage with any loader. Turn it off first, then the SIO patch if necessary.
  • Write mode. The default Virtual read/write safe mode lets the disk be modified in memory but blocks format commands. This matters because some protection checks try to format the disk.
  • Drive type. Altirra emulates 810, 1050, XF551 and several enhanced drives, but extended commands, including the drives' own copy-protection features, are only modelled for the 1050 and XF551.

On real hardware, ATX needs a device that reproduces the timing:

  • FujiNet serves ATX as well as ATR and XEX, from its SD card or a TNFS server.
  • RespeQt reads and writes PRO and ATX with protection emulation.
  • A8PicoSIO (Raspberry Pi Pico) reads ATX and can write to sectors that already exist. It can behave as an "accurate" 1050 or 810.
  • AVGCART, with its optional SIO cable, adds ATX support. SIO2Arduino runs many PRO and ATX images.
  • On Windows, APE runs ATX through the VAPI.DLL plug-in, and Cwik's own VAPI2SIO serves ATX images over an SIO2PC cable.

6. Making ATX images

The preservation-grade route is a flux-level capture. A KryoFlux, SuperCard Pro or the open-source Greaseweazle records the magnetic transitions using a PC 5.25" drive. Avery Lee's a8rawconv then decodes the RAW or SCP capture into ATR or ATX (version 0.94 dates from August 2020). The same tool converts between ATR and ATX and can drive a SuperCard Pro directly, including writing images back to disk.

The other route uses an enhanced Atari drive as the reader. RespeQt emulates a Super Archiver (and The Chip) on a virtual drive, so archiver software can copy straight into an image:

  1. Load Super Archiver on the Atari, with the archiver-equipped drive as D1:.
  2. In RespeQt, create a new disk image, save it with an .atx extension, and put it in slot 2.
  3. Switch on the Super Archiver button in that slot's toolbar.
  4. Set Super Archiver's destination to D2:, insert the original, and copy.

If Super Archiver can't make a working copy, the ATX won't work either. Jorge Cwik's advice is that drive enhancements such as the Happy or the Archiver are fine for personal backups but are not preservation tools: they are less precise, and they need more revolutions per track, which wears fragile originals.

Troubleshooting

  • ATX boots in Altirra, then crashes: turn off burst I/O, then the SIO patch, then switch on accurate sector timing.
  • Game reformats or "repairs" its disk: use the Virtual read/write safe mode so formats are refused.
  • Works on NTSC, not PAL (or the reverse): some checks are tuned to one video standard. Try the other machine type in the emulator.
  • ATX won't mount on an SD device: check that its firmware supports ATX. Many SD drives handle only ATR and XEX.

Further reading

  • Altirra Hardware Reference Manual (Avery Lee), Chapter 10 Disk drives and Appendix B Physical Disk Format: drive behaviour on every kind of abnormal sector.
  • Altirra's help file, Disk drives: Copy-protected disks.
  • The comp.sys.atari.8bit FAQ, sections 9.1 (image formats) and 10.1–10.3 (imaging hardware and software).
  • The a8preservation.com disk-dumping guides.
  • Our guides Atari 8-bit File Formats Explained, SIO Explained and SIO2PC and RespeQt.

Credits