forge Documentation

xio-reference

XIO Reference

XIO (eXtended Input/Output) commands provide access to device-specific CIO operations beyond the standard open, close, get, put, and print commands.

Overview

XIO allows you to execute special device-specific commands that are not available through standard CIO operations. Each device handler can implement its own set of XIO commands.

Syntax

XIO #iochn, cmd, aux1, aux2, dev / X.

Performs a general input/output operation on device dev, over channel iochn, with the command cmd and auxiliary bytes aux1 and aux2.

Note: The arguments of XIO statements are in different order than Atari BASIC, for consistency with other statements the iochn is the first argument.

Example:

XIO #1, 33, 0, 0, "D:FILE.TXT"  ' Delete file

Standard XIO Command Codes

These commands are supported by most device handlers:

CodeOperationDescription
3OPENOpen a channel (same as OPEN statement)
5GET RECORDGet a record (same as INPUT)
7GET CHARACTERSGet characters (same as GET)
8PUT RECORDPut a record
11PUT CHARACTERSPut characters (same as PUT)
12CLOSEClose a channel (same as CLOSE statement)
13STATUS REQUESTGet device status (same as STATUS statement)
17DRAW LINEDraw a line (graphics)
18FILLFill area (graphics)

Disk File Operations

These commands are typically used with disk drives (D: device):

CodeOperationDescription
32RENAMERename a file
33DELETEDelete a file
35LOCK FILELock a file (prevent deletion)
36UNLOCK FILEUnlock a file
37POINTSet file position
38NOTEGet file position
40LOAD BINARY FILELoad binary file
41SAVE BINARY FILESave binary file (Atari DOS, SpartaDOS 2.3/3.2)

Example - Delete a file:

XIO #1, 33, 0, 0, "D:OLD.TXT"
IF ERR() <> 1 THEN ? "Error deleting file"

Example - Rename a file:

XIO #1, 32, 0, 0, "D:OLD.TXT,D:NEW.TXT"
IF ERR() <> 1 THEN ? "Error renaming file"

Directory Operations

Directory operations vary by DOS version:

MyDOS

CodeOperation
34CREATE DIRECTORY
41CHANGE DIRECTORY

SpartaDOS

CodeOperation
34LOCK DISK (SpartaDOS 2.3/3.2)
39GET FILE LENGTH
41SAVE BINARY FILE (SpartaDOS 2.3/3.2)
42CREATE DIRECTORY
43DELETE DIRECTORY
44CHANGE DIRECTORY
45SET BOOT FILE
46UNLOCK DISK (SpartaDOS 2.3/3.2)
49SET FILE ATTRIBUTES (SpartaDOS X)

Disk Formatting

CodeOperationDescription
253FORMAT SINGLE DENSITYFormat disk (DOS 2.5)
254FORMAT DISKFormat disk (default format)

Warning: Formatting operations will erase all data on the disk!

NOTE and POINT

While NOTE and POINT are available as XIO commands (codes 38 and 37), FORGE provides built-in NOTE and POINT statements that are safer and easier to use:

XIO method (not recommended):

' Get file position
XIO #1, 38, 0, 0, "D:FILE.TXT"
SEC = PEEK(ICBLL)  ' Low byte
BYT = PEEK(ICBLH)  ' High byte (actually byte offset)

FORGE method (recommended):

NOTE #1, SEC, BYT  ' Much simpler and safer!

See NOTE/POINT for complete documentation.

Device-Specific Commands

Different devices may support additional XIO commands. Consult the device documentation for specific commands.

R: Device Commands

R: devices (serial ports) may support additional commands for:

  • Setting baud rate
  • Configuring serial parameters
  • Controlling modem functions

See R: Handler for details.

Graphics Commands

Graphics devices support commands like:

  • DRAW LINE (17)
  • FILL (18)

Error Handling

Always check ERR() after XIO operations:

XIO #1, 33, 0, 0, "D:FILE.TXT"
IF ERR() <> 1 THEN
  ? "XIO Error: "; ERR()
ENDIF

Common Patterns

Delete a File

XIO #1, 33, 0, 0, "D:FILE.TXT"
IF ERR() = 1 THEN
  ? "File deleted"
ELSE
  ? "Error: "; ERR()
ENDIF

Rename a File

XIO #1, 32, 0, 0, "D:OLD.TXT,D:NEW.TXT"
IF ERR() = 1 THEN
  ? "File renamed"
ELSE
  ? "Error: "; ERR()
ENDIF

Lock/Unlock a File

' Lock file
XIO #1, 35, 0, 0, "D:IMPORTANT.TXT"

' Later, unlock file
XIO #1, 36, 0, 0, "D:IMPORTANT.TXT"

Best Practices

  1. Use FORGE statements when available - NOTE/POINT statements are safer than XIO
  2. Always check errors - Use ERR() after every XIO call
  3. Document device-specific commands - Different devices support different commands
  4. Test thoroughly - XIO commands can have device-specific behavior
  5. Handle errors gracefully - Some commands may fail on certain devices

Troubleshooting

XIO fails:

  • Check channel is open (if required)
  • Verify command code is supported by device
  • Check device name is correct
  • Verify aux parameters are correct

Unexpected behavior:

  • Consult device-specific documentation
  • Check DOS version compatibility
  • Verify command parameters

Related Topics