SIO Explained: How the Atari Serial Bus Talks to Drives and Devices

Disk drives, printers, the 850 interface, modems, and today's SIO2PC adapters, SD-card drives and FujiNet all hang off one daisy-chained cable: the Atari serial I/O bus, usually called SIO. The protocol is simple and well documented. Once you understand it, a lot of Atari behaviour makes sense: the beeps during disk access, the "ERROR 138", why disk emulators work at all, and how high-speed drives get their speed. This guide walks through the physical bus, the protocol, the OS interface and a hands-on sector reader you can run from BASIC.

You need: nothing beyond curiosity. For the examples: Atari BASIC, any disk drive or emulated drive (Altirra, SIO2PC/RespeQt, FujiNet), and optionally an assembler.

1. The connector

Every Atari and every SIO peripheral uses the same 13-pin plug. The pinout:

Pin Signal Pin Signal
1 Clock input (POKEY) 8 Motor control (PIA): cassette motor
2 Clock output (POKEY) 9 /Proceed (PIA)
3 Data input (POKEY) 10 +5 V / Ready (1200XL: Ready only)
4 Ground 11 Audio input
5 Data output (POKEY) 12 +12 V (400/800 only)
6 Ground 13 /Interrupt (PIA)
7 /Command (PIA)

Data goes out on pin 5 and comes back on pin 3, using POKEY's serial port. The computer is wired as the host, and peripherals the other way round. Peripherals therefore cannot talk to each other. This is why an ordinary SIO2PC cable, wired as a peripheral, cannot drive a real disk drive: that needs a reverse-wired "1050-2-PC" adapter. The audio-in line lets a cassette's audio track or an SIO device's sound play through the TV speaker.

2. Bytes on the wire

The format is standard asynchronous serial: one start bit, eight data bits sent LSB first, one stop bit, no parity. The normal speed is about 19,200 baud. The OS drives the transfer with three POKEY interrupts: serial input ready (VSERIN, $020A), output needed (VSEROR, $020C) and transmission complete (VSEROC, $020E). The main SIO routine simply waits in a loop until the interrupt handlers signal that the buffer is done, so all other program execution halts during a transfer: SIO simply wastes time waiting for POKEY. The beeps you hear are SIO echoing the data to the speaker. POKE 65,0 silences them.

3. The protocol, step by step

Every intelligent SIO device (anything except the cassette recorder) follows the same sequence, with these timings:

  1. Command frame. The computer pulls the /COMMAND line low and sends five bytes at 19,200 baud: device ID, command, AUX1, AUX2, checksum. Then it raises /COMMAND again.
  2. Acknowledge. The addressed device replies 'A' ($41) if the command is valid, or 'N' ($4E, NAK) if it is not. It must answer within about 16 ms, and devices ignore frames meant for other IDs or with bad checksums.
  3. Data to the device (write commands only). The computer sends the data frame plus a checksum, and the device ACKs or NAKs it.
  4. Execution. The device does the work: milliseconds for a status request, hundreds of milliseconds for a sector, a minute or more for a format.
  5. Result. The device sends 'C' ($43, Complete) or 'E' ($45, Error).
  6. Data to the computer (read commands only). The device sends the data frame plus a checksum. It does this even after an 'E'.

The checksum is an 8-bit sum with end-around carry. Add each byte with ADC and fold the carry back in with ADC #0.

Common device IDs:

ID Device
$31–$3F Disk drives D1:–D15:
$40 Printer P:
$50–$53 850 serial ports R1:–R4:
$58 1030 modem T:
$70 / $71–$74 / $72 SIO2USB / SDrive / SIO2SD
$46 AspeQt
$6F DOS2DOS (PCLink)

Standard disk commands, from De Re Atari and cc65's atari.inc: $52 'R' read sector, $57 'W' write with verify, $50 'P' put (write without verify), $53 'S' status, $21 '!' format. The four-byte status reply is the same idea on every device. Byte 1 holds error flags (bit 0 command error, bit 1 data error; for disks, bit 3 means write-protected). Byte 3 is the device's recommended timeout.

4. The OS interface: the DCB and SIOV

Programs normally reach SIO through CIO and a device handler (see CIO and IOCBs). You can also call it directly. Fill in the Device Control Block at $0300 and JSR SIOV ($E459):

Address Name Contents
$0300 (768) DDEVIC Device ID ($31 for disks)
$0301 (769) DUNIT Unit number (1 = D1:)
$0302 (770) DCOMND Command byte
$0303 (771) DSTATS In: direction ($40 receive, $80 send, $00 none). Out: status
$0304–05 (772–773) DBUFLO/HI Buffer address
$0306 (774) DTIMLO Timeout (units of 64 frames, roughly one second each)
$0308–09 (776–777) DBYTLO/HI Number of bytes to transfer
$030A–0B (778–779) DAUX1/2 Command parameters (sector number for disks)

SIO returns with the status in DSTATS and in Y, and the N flag set on error: 1 = success, 138 = timeout, 139 = NAK, 144 = device error, as in BASIC.

For disks there is also DSKINV ($E453), the resident disk handler. The handler sets DDEVIC itself and supports read, put, write-with-verify, status and format. SIO also has a small bug: it misbehaves when the last byte of a buffer sits at an address ending in $FF. DOS 2.0S contains its own disk routine partly to avoid it.

5. Hands-on: reading a sector from BASIC

This program reads any sector of the disk in D1: and shows its first 64 bytes. The USR routine is just PLA : JSR $E459 : RTS, stored in page 6:

10 REM READ A DISK SECTOR VIA SIOV
20 DIM B$(128)
30 POKE 1664,104:POKE 1665,32:POKE 1666,89:POKE 1667,228:POKE 1668,96
40 PRINT "SECTOR NUMBER";:INPUT SEC
50 A=ADR(B$)
60 POKE 768,49:POKE 769,1:REM DEVICE $31, UNIT 1
70 POKE 770,82:POKE 771,64:REM 'R' READ, RECEIVE DATA
80 POKE 772,A-INT(A/256)*256:POKE 773,INT(A/256)
90 POKE 774,15:POKE 776,128:POKE 777,0
100 POKE 778,SEC-INT(SEC/256)*256:POKE 779,INT(SEC/256)
110 X=USR(1664):ST=PEEK(771)
120 PRINT "STATUS ";ST
130 IF ST<>1 THEN 40
140 FOR I=0 TO 63:PRINT PEEK(A+I);" ";:NEXT I
150 PRINT :GOTO 40

Try sector 1, the boot sector. It starts with the same six-byte boot header used by cassette boot files: a flag byte, the number of sectors to load, the load address and the initialisation address. Sector 360 is the DOS 2 VTOC (volume table of contents), and 361–368 hold the directory, each entry 16 bytes with the filename starting at offset 5. Notes:

  • 128 bytes is right for single and enhanced density. For double-density disks, set DBYT to 256 for sectors 4 and up. The first three sectors are always 128 bytes.
  • Never point a write command at a disk you care about while experimenting. A wrong sector number in a write ($57) can destroy the directory.
  • The status 138 (timeout) means nothing answered at that ID. Check the drive number and power.

6. Cassette: the odd one out

The cassette recorder has no intelligence at all. It uses only the motor-control line and the data lines. The OS routes requests with DDEVIC = $5F to special cassette code inside SIO, so the ID $5F never appears on the bus. Tape data is sent as two-tone audio at about 600 baud. The OS measures the speed from the two $55 bytes at the start of each block and corrects for tape stretch.

7. Faster than 19,200 baud

Stock drives always use 19,200 baud. Enhanced drives speed things up in different, incompatible ways:

  • XF551 style: the command goes at normal speed, and bit 7 of the command byte asks for a high-speed data frame (38,400 baud).
  • US Doubler style: the computer sends the whole command frame at high speed. The drive notices and answers at the same rate. A "get high speed index" command lets software ask the drive which speed to use, which makes this the most standardised scheme.

Speeds are often quoted as a POKEY divisor, the value loaded into AUDF3/AUDF4 to clock the serial port. The US Doubler's divisor 10 gives about 52,600 baud. Divisor 0, about 127 kbaud, is the limit of stock hardware, but around 60–70 kbaud is the practical maximum while the screen is on, because display DMA and the VBI steal cycles. High-speed SIO patches in modern OSes and DOSes, and devices such as SIO2PC/RespeQt and FujiNet, use these protocols.

8. Why disk emulators work

Because the protocol is just bytes and timings, any microcontroller or PC that answers command frames for ID $31 with the right ACK/Complete/data sequence is a disk drive as far as the Atari is concerned. SIO2PC adapters with RespeQt or AspeQt on a PC, SDrive and SIO2SD on SD cards, and FujiNet over Wi-Fi all work this way. FujiNet also adds new device IDs and handlers for network access. The main catch is the tight 16 ms acknowledge window, which is hardest to meet for device emulators running on a PC with a heavily buffered serial port, particularly a USB serial adapter. If a PC-based emulator gives intermittent timeouts, try a different USB serial adapter or the software's latency settings.

Troubleshooting

  • ERROR 138 (timeout): no device answered. Check that it is powered, on the right drive number, and that every cable in the chain is seated. A device at the end of the chain with only one SIO port must be last.
  • ERROR 139 (NAK): the device rejected the command. Typical causes are a sector number out of range for the disk's density, or no disk inserted on some drives.
  • ERROR 144: the device reported an error, such as a write-protected disk or an unreadable sector.
  • Odd sounds or silence after I/O in your own program: SIO leaves POKEY in serial mode. Execute SOUND 0,0,0,0 (see POKEY sound basics).

Further reading

  • Altirra Hardware Reference Manual (Avery Lee), Chapters 9 and 10: the definitive modern description of SIO timing, polling and drive protocols.
  • De Re Atari (Atari, Inc., 1982), Chapter 8, including Figure 8-15, which prints a line by calling SIO directly.
  • Mapping the Atari by Ian Chadwick (Small System Services, 1983), page three (768–831).
  • Technical Manual: 850 Interface Module (Atari, Inc., 1982), for concurrent serial I/O.

Credits