Commodore‎ > ‎BASIC‎ > ‎

Disk Commands

I am not going to try to describe all the possible disk commands here; this page is about something more focused.  In version 3.5+ of CBM BASIC, there are many commands and statements (and a few reserved variables) that were designed to work with CBM's disk drives.  Their devices are (were) "smart", containing their own CPU and memory.  CBM was ahead of its time in this area, as this is a thing you find in modern devices like USB 'thumb drives', optical discs, hard drives, etc.  (Most other disk drives of the time were "stupid" requiring most of the work to be done by the host computer).
Anyway, these devices work by receiving "commands" from the host computer, doing some action, and generating a status/error code.  The device commands can be rather archaic so the BASIC disk commands help the programmer by allowing English words and flexible parameter passing.  Just as important (for debugging in direct mode, more important) is the easy way you can read the error/status channel of the device: just use PRINT DS$ (for example)... this is a royal pain in older versions of BASIC because you have to use INPUT# to read from the device, but INPUT# is not allowed in direct mode!
Now, the main reason for this page: below are all the "disk commands" that set the "DosFA" secret variable.  This variable controls which device will be read to get the error/status message.  Normally I wouldn't bother to report on such things (BASIC has many internal/secret variables that you don't need [and probably don't want] to know about).  However, all I/O commands (not just the disk commands listed below) that refer to a "disk device" (any device number 8 to 11) will clear the reserved variable DS$; thus when you read DS$, BASIC will need to refer to the secret "DosFA" in order to querry the device... but only the commands listed below actually update "DosFA"!
If that doesn't seem important, you are not alone... the designers of CBM BASIC never realized the problem (it is a problem)... or at least they never fixed it, and to my knoweldge, never documented it either!  The problem is that if you use an I/O command not listed below (and it refers to a "disk device") then DS$ will be cleared (which is appropriate).  Because the other commands ("non-disk commands") do not update the secret "DosFA", then trying to get the error/status using DS or DS$ may report on the wrong device!  This is true when the last "disk command" referred to a device different from the most-recent "non-disk command".
In short, you can avoid the problem if you can avoid using other "non-disk commands" before testing the error/status with DS or DS$.  However, there are several commands supported by CBM disk devices not  present in any version of BASIC (and even more when you count non-CBM hardware).  These require using "non-disk commands" (in particular PRINT#).  An alternative work-around for the bug is to use a machine-specific POKE to manually set the secret "DosFA" (or else, pretty lame, rely on old BASIC 2.0 commands completely).
So here is a list of "disk commands" which update the secret "DosFA":
I guess I should point out, in case it isn't obvious, that the reserved variables DS and DS$ implicitly refer to the secret "DosFA", but they do not update it.  Here is a list of the I/O commands that reset DS$ (if they refer to device number 8 to 11) but fail to update "DosFA": CLOSE, CMD, GET#, INPUT#, OPEN, PRINT#SAVE, VERIFY.  Note that CLR and RUN (without filename) both unconditionally reset DS$ (they do not use a device number).

© H2Obsession, 2014