STATUS: Your I/O Report Card

STATUS: Your I/O Report Card

Ever wondered if your Commodore 64 successfully read that data from tape, or if the printer ran out of paper? Look no further than the STATUS command and variable! This dynamic duo gives you valuable insights into the outcome of your input/output (I/O) operations with devices like the cassette drive, disk drive, and printer. Think of it as your I/O report card, telling you how your C64 performed!

The STATUS Variable

ST

In Commodore 64 BASIC V2, ST (short for STATUS) is a special system variable that holds a numeric value representing the result of the most recent I/O operation. You can examine this value to determine if the operation was successful or if any errors occurred.

The STATUS Command

PRINT ST

or simply

?ST

This command simply prints the current value of the ST variable to the screen, allowing you to see the I/O status.

Common STATUS Values

STATUS Bit Value Datasette Serial Bus (RS-232)
0 1 indicates data direction if a timeout occurred
(0 = reading, 1 = writing)
parity error
2 4 timeout error framing error
3 8 block was too short (less than 192 bytes) recieve buffer overrun
4 16 block was too long (greater than 192 bytes) recieve buffer empty
5 32 VERIFY error (errornous read bytes from pass 1 could not read correctly even in pass 2) VERIFY error
6 64 checksum error CTS signal missing
7 128 end of file has been reached (only while reading) end of file has been reached
RTS signal missing
device not present error
BREAK detected

Note: These are just a few common values; other values may have different meanings depending on the device and operation. (https://www.c64-wiki.com/wiki/STATUS)

Applications

The STATUS command and variable are invaluable for:

  • Error handling: Detect and respond to I/O errors like "FILE NOT FOUND" or "DEVICE NOT PRESENT."
  • End-of-file detection: Determine when you've reached the end of a file while reading data.
  • Device status checks: Verify if a device is ready before attempting to read or write.

Code Example

10 OPEN 1,8,15,"myfile,S,R"  :rem Open a file for reading
20 INPUT#1, A$               :rem Read a line from the file
30 IF ST=64 THEN GOTO 100    :rem Check if end of file reached
40 PRINT A$                  :rem If not, print the line
50 GOTO 20                   :rem Read the next line
100 CLOSE 1                  :rem Close the file

This example reads a text file line by line, using ST to detect the end of the file and stop the loop.

STATUS in the Wild: The Data Recovery Specialist

Imagine you're trying to recover data from an old, damaged floppy disk. By checking the ST variable after each read operation, you can identify errors and potentially salvage valuable information that would otherwise be lost.

Don't leave your I/O operations to chance! With STATUS, you can gain valuable insights into how your Commodore 64 interacts with files and devices, allowing you to write more robust and error-resistant programs. It's like having a built-in diagnostic tool for your I/O operations, helping you troubleshoot problems and ensure smooth data flow. So embrace the power of STATUS and make it an integral part of your Commodore 64 programming toolkit!


Privacy Policy

Let's be honest, we collect some data. But we promise not to sell it, we'll mostly use it to improve our service. You can read the nitty-gritty details below, but be warned, it uses big words that lawyers like (we don't judge).

By using our service, you agree to this privacy policy. This disclaimer strikes a balance between lightheartedness and informing users that they should still read the full privacy policy if they choose.