forge Documentation

sio-operations

SIO Operations

The Atari Serial Input Output interface is the low-level interface between the Atari 8-bit computers and the serial peripherals, like disk-drives and modems.

Overview

SIO (Serial Input/Output) is the protocol used by the Atari 8-bit computers to communicate with peripheral devices such as:

  • Disk drives
  • Modems
  • Printers
  • Network adapters (FujiNet)
  • Other serial devices

SIO Statement

SIO ddevic, dunit, dcomnd, dstats, dbuf, dtimlo, dbyt, daux1, daux2

Send Any Command Over SIO

This function can be used to send any SIO command to any SIO device. For example, this command is used to read or write one sector in a floppy disk, or send special commands to a FujiNet network device.

Parameters

ParameterDescription
DDEVICDevice # (e.g. $71)
DUNITUnit #
DCOMNDCommand # ($00-$FF)
DSTATSRead($40) / Write($80)
DBUFTarget buffer address
DTIMLOTimeout value
DBYT# of bytes in payload
DAUX1First Aux parameter
DAUX2Second Aux parameter

The meanings of each of these is highly dependent on the target device.

Example: Reading a Disk Sector

DIM sector(128) BYTE
' Read sector 360 from drive 1
SIO $31, 1, $52, $40, ADR(sector), 64, 128, 360, 0
IF SERR() <> 1 THEN ? "Error reading sector"

Example: Writing a Disk Sector

DIM sector(128) BYTE
' Write sector 360 to drive 1
SIO $31, 1, $57, $80, ADR(sector), 64, 128, 360, 0
IF SERR() <> 1 THEN ? "Error writing sector"

SERR() Function

SERR() / SE.

Get Last SIO Error Function

This function returns the value in DSTATS, which contains the error of the last SIO operation from the device.

In the context of the FujiNet device, can be used, along with DVSTAT+4 to determine any error from a network operation.

Example:

SIO $71, 1, $FF, $40, ADR(buffer), 64, 0, 0, 0
IF SERR() <> 1 THEN
  ? "SIO error: "; SERR()
ENDIF

Common SIO Commands

Disk Drive Commands

CommandValueDescription
Get Status$53Read drive status
Read Sector$52Read a sector
Write Sector$57Write a sector
Write Sector with Verify$57Write and verify

Device IDs

Common device IDs:

  • $31 - Disk drive (D1:)
  • $71 - FujiNet device
  • $50 - Printer
  • $60 - Modem

Error Handling

Always check SERR() after an SIO operation:

SIO $31, 1, $52, $40, ADR(buffer), 64, 128, 360, 0
IF SERR() <> 1 THEN
  ? "SIO Error: "; SERR()
  ' Handle error
ENDIF

Timeout Values

The DTIMLO parameter specifies the timeout value. Common values:

  • 64 - Standard timeout
  • 128 - Longer timeout for slow devices
  • 32 - Shorter timeout for fast operations

Buffer Management

The DBUF parameter must point to a valid memory buffer. Use ADR() to get the address of arrays:

DIM buffer(256) BYTE
SIO $31, 1, $52, $40, ADR(buffer), 64, 256, 0, 0

Advanced Usage

Sector Addressing

For disk drives, sectors are typically addressed using:

  • DAUX1 - Sector number (low byte)
  • DAUX2 - Sector number (high byte) or additional parameter

Example:

' Read sector 720 (high byte = 2, low byte = 208)
SIO $31, 1, $52, $40, ADR(buffer), 64, 128, 208, 2

Multiple Sector Operations

For reading/writing multiple sectors, you may need to call SIO multiple times or use device-specific commands.

FujiNet Integration

SIO is heavily used with FujiNet devices. See FujiNet for more details on network operations.

Example:

' FujiNet status command
SIO $71, 1, $E0, $40, ADR(status), 64, 4, 0, 0

Best Practices

  1. Always check errors - Use SERR() after every SIO call
  2. Use appropriate timeouts - Adjust DTIMLO for your device
  3. Validate buffer sizes - Ensure DBYT matches your buffer
  4. Handle device-specific behavior - Different devices interpret parameters differently
  5. Test thoroughly - SIO operations can be device-dependent

Troubleshooting

SIO fails immediately:

  • Check device ID is correct
  • Verify device is connected and powered
  • Check unit number is valid

Timeout errors:

  • Increase DTIMLO value
  • Check device is responding
  • Verify cable connections

Data corruption:

  • Verify buffer address is correct
  • Check buffer size matches DBYT
  • Ensure buffer is not overwritten during operation

Related Topics