Home
CBM
  ASCII-X
  BASIC
    Disk Commands
    Enter RUN mode
    Program Format
    Secret Variables
    Variable Format
    Expressions
    Keywords
      (divide)
      (equal)
      (less)
      (minus)
      (more)
      (multiply)
      (plus)
      (power)
      Abs
      And
      Append
      Asc
      Atn
      Auto
      Backup
      Bank
      Begin
      Bend
      Bload
      Boot
      Box
      Bsave
      Bump
      Catalog
      Char
      Chr
      Circle
      Close
      Clr
      Cmd
      Collect
      Collision
      Color
      Concat
      Cont
      Copy
      Cos
      Data
      Dclear
      Dclose
      Dec
      Def
      Delete
      Dim
      Directory
      Dispose
      Dload
      Do
      Dopen
      Draw
      Ds
      Ds string
      Dsave
      Dverify
      El
      Else
      End
      Envelope
      Er
      Err
      Exit
      Exp
      Fast
      Fetch
      Filter
      Fn
      For
      Fre
      Get
      Get num
      Getkey
      Go
      Gosub
      Goto
      Graphic
      Gshape
      Header
      Help
      Hex
      If
      Input
      Input num
      Instr
      Int
      Joy
      Key
      Left
      Len
      Let
      List
      Load
      Locate
      Log
      Loop
      Mid
      Monitor
      Movspr
      New
      Next
      Not
      Off
      On
      Open
      Or
      Paint
      Peek
      Pen
      Pi
      Play
      Pointer
      Poke
      Pos
      Pot
      Print
      Print num
      Pudef
      Quit
      Rclr
      Rdot
      Read
      Record
      Rem
      Rename
      Renumber
      Restore
      Resume
      Return
      Rgr
      Right
      Rlum
      Rnd
      Rreg
      Rspcolor
      Rsppos
      Rsprite
      Run
      Rwindow
      Save
      Scale
      Scnclr
      Scratch
      Sgn
      Sin
      Sleep
      Slow
      Sound
      Spc
      Sprcolor
      Sprdef
      Sprite
      Sprsav
      Sqr
      Sshape
      St
      Stash
      Step
      Stop
      Str
      Swap
      Sys
      Tab
      Tan
      Tempo
      Then
      Ti
      Ti string
      To
      Trap
      Troff
      Tron
      Until
      Using
      Usr
      Val
      Verify
      Vol
      Wait
      While
      Width
      Window
      Xor
    Syntax
    Tokens
  C128
  D64plus
  Disk
  Escape Codes
  Hardware
  PCxface
  PETSCII
  Pet2asc
Futurama
IBM PC-AT
Contact
Games
Glossary
Hall of fame
Hall of shame
Miscellaneous
Privacy policy
Programming
Twisty puzzles
KeywordAbbreviationToken (hex)Version(s)Classification
DS$none44 53 243.5+Reserved variable
Note the 'token' is really the character codes of the keyword.

 Syntax 
DS$
 
ReturnsTypeValue(s)Note(s)
diskStatus_stringString
0 to 40 characters
Device specific 
 
 Purpose 
Get the most recent error/status code from a "disk" device.
 
 Remarks 
This reserved variable returns the diskStatus_string which has been (or will now be) read from the error/status channel (15) corresponding to device "DosFA" (a secret variable).
 
Unfortunately BASIC provides no direct way to set "DosFA", and attempting to supply any parameter to DS$ (such as a device number) will generate SYNTAX ERROR.  Otherwise, if a diskStatus_string already exists, then DS$ can not generate an error.
 
If the diskStatus_string has been erased (see below), then DS$ will now read a new diskStatus_string from channel 15 of the device specified by the secret "DosFA".  This might cause an I/O error, like DEVICE NOT PRESENT (for example, if the device number was changed, or the device has been powered-off or disconnected).  If you have previously OPEN'ed a file with fileNumber of zero to any device (I believe only the keyboard is allowed) then you may get either FILE OPEN ERROR or in some cases (not sure of how each are triggered) the cursor will appear on screen and wait for you to enter some text (which will be stored as the diskStatus_string, and your fileNumber 0 will be CLOSE'd).  See examples.
 
Assuming you don't have an OPEN file 0, DS$ works fine in conjunction with disk-based commands like DIRECTORY, DLOAD, and such.  But because the secret "DosFA" is not updated by other commands that are often used with a disk, like CLOSE, CMD, GET#, INPUT#, LOAD, OPEN, PRINT#, SAVE, and VERIFY, using DS$ may report on the wrong device.  This is especially true in a program that uses multiple "disk" devices at once (any device number 8 to 11).  To work around this bug, you can POKE the DosFA or use the "BASIC 2 Method" of reading the diskStatus_string (that is, INPUT #15,E,M$,T,S where '15' is an already OPEN'ed file to channel 15 of the desired device and M$ would be the diskStatus).  If that sounds a bit archaiac / difficult to understand, that's because it is!  Hence the reason for including DS and DS$ in BASIC... too bad it is buggy.
 
Here is the location of the "DosFA" secret variable for some machines: 
MachinePEEK Address
C128284
C16631
C64not applicable
CBM-II?
PET
not applicable
Plus/4
631
VIC-20not applicable
 
*Update*
I just thought (and performed some testing) of a less machine-specific way to work around the bug!  Use DCLOSE with a file# not in use, and specify the desired device as a parameter.  For example, to be sure the next read of DS$ will refer to device 9, use this just before: DCLOSE #77, U9 (where 77 is a file# that was never opened).  The only "problem" is it only works with the same devices that all disk commands accept (only device 8 to 11).  Using the POKE method works with any IEEE/IEC device (4 to 30).
 
Reading DS$ does not clear the exisitng diskStatus_string, so you may read it multiple times (if diskStatus_string did not exist, then ST will be updated when the string is read from the device).  The diskStatus_string will remain until you use any I/O command that references a device number between 8 and 11 (traditionally disk drives).  This includes both "disk commands" from BASIC 3.5+ and generic I/O commands of v2.0; all of them clear DS$ (i.e., the diskStatus_string), and a few of the disk commands will read a new diskStatus_string.  See examples.
 
Like all BASIC variables, only the first two characters of the name are significant.  So you may also use DSTAT$ if you prefer (note the "TAT" characters are superfluous).  Like most BASIC reserved variables, attempting to assign a value to it will generate SYNTAX ERROR.
 
Warning!  On the C128, using the built-in MONITOR will destroy the descriptor for the diskStatus_string, even if you don't use any MONITOR disk-commands.  Thus when you return to BASIC and try to access DS or DS$ you will get unreliable results until you use a disk command or perform CLR (directly or indirectly).
  
Examples (normal):
SCRATCH "JUNK FILE" : REM refers to device 8
ARE YOU SURE? Y
01, FILES SCRATCHED,01,00

READY.
PRINT DS
 1

READY.
PRINT DS$
01, FILES SCRATCHED,01,00

PRINT DS$
01, FILES SCRATCHED,01,00

READY.
PRINT DS
 1

READY.
OPEN 1,9 : REM access device 9 -- clears DS/DS$

READY.
PRINT DS$ : REM this gets message from device 8!
00, OK,00,00

READY.
 
Examples (with OPEN fileNumber of zero):
PRINT DS$ : REM assumes disk device is present
00, OK,00,00

READY.
OPEN 0,0 : OPEN 1,9: CLOSE 1 : REM open 1,9 will erase DS$ (don't care if device 9 present)

READY.
PRINT DS$ : REM also "works" with PRINT DS
L9, BAD MFT ENTRY IN NTFS,12,34   user input!
** text display is mangled **

READY.
PRINT DS
-127

READY.
PRINT DS$
L9, BAD MFT ENTRY IN NTFS,12,34

READY.
  
 Compare With 
  
 Contrast With 
 
 See Also 

© H2Obsession, 2014