Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

COLLECT

Keyword Abbreviation Token (hex) Version(s) Classification
COLLECT CO{Shift+L} D1 4.x Command and Statement
DEC none D1 3.5, 7.0 Function
COLLECT COL{Shift+L} F3 3.5 Command and Statement
COLLECT COLL{Shift+E} F3 7.0 Command and Statement

  Syntax   
COLLECT [ driveNumber ] [ { , | ON } U unitNumber ] ... [ , ItwoChar ] [ , R ] ... 
 
Parameters Type Legal Value(s) Default Value Note(s)
driveNumber Integer 0 or 1 0 Non-literal must be enclosed in parentheses ()
unitNumber Integer  8 ~ 11  Non-literal must be enclosed in parentheses () 
twoChar Char[2]  any    Must be two literal characters. 
 
 
  Purpose  
Simple disk repair.  Checks and repairs the file system.

 
  Remarks  
COLLECT closes all files that are open on the device (unitNumber), regardless of which driveNumber they use, and then sends the device a "validate" command.
 
The "validate" command is device-specific.  The following is a an description of COLLECT in terms of a CBM-DOS file system (similar things would happen on FAT or NTFS file system).  First it rebuilds the BAM by freeing all blocks, then tracing all properly closed files in the disk directory and allocating each block of those files in the BAM.  Along the way, improperly closed files (so-called "splat" files) are removed from the directory.  Some software (in particular GEOS) stores data in blocks that can't be "found" the by most devices.  This results in some used blocks being marked "free" in the BAM.  Later writes to the "disk" can then use those blocks, but since they are really in use, the disk data has just become corrupt.  COLLECT should never be used on any commerical software disk (and some demo / hacker disks), unless the publisher specifically tells you it is safe to do so.  The makers of GEOS specifically tell you to never use COLLECT.
 
If an expression (enclosed in parentheses) is not valid, or an expression is used without parentheses, SYNTAX ERROR occurs.  If any parameter is not the correct type a TYPE MISMATCH ERROR will be generated.  Otherwise if a parameter is not a legal value (see table above), an ILLEGAL QUANTITY ERROR is generated.
 
Like all disk commands and statements, the Syntax is more flexible than shown above.  In particular, the parameters may be given in any order.  The general restrictions are: a comma (,) must not precede the first parameter (ON may do so), any non-literal value (a variable name or expression) must be enclosed in parentheses (), and do not supply the same parameter more than once.  Exceptions include the U and R parameters, which may used an unlimited number of times (R is ignored and the last unitNumber is used), and the twoChar parameter which must always be two literal characters (it may not be repeated although it is otherwise ignored). 
 
Assuming the syntax is good, BASIC will close all files on the device.  This may (rarely) generate an error by the KERNAL (for example DEVICE NOT PRESENT). Next it sends the "validate" command which again may be generate a KERNAL error; otherwise BASIC will not complain.  However you should check the error/status channel with DS or DS$ to ensure the command completed successfully.
 
Like all disk-based commands, COLLECT restricts the driveNumber to either 0 or 1 which often makes it unusable on a "disk" with multiple partitions.
 
Like all disk-based commands, COLLECT will reset DS$ and set the secret variable "DosFA" to the unitNumber (defaults to 8 if not given).  It also indirectly updates ST.
 
Examples:
COLLECT      : REM validate disk in drive 0 of unit 8
COLLECT U9   : REM validate disk in drive 0 of unit 9
COLLECT U(U) : REM validate disk in drive 0 of the unit given by variable U
 
 
  Compare With  
 
  Contrast With  
  See Also  
DS, DS$ONPRINT#ST
© H2Obsession, 2014
Comments