Disk Basic Summary

In addition to the capabilities of Extended Color BASIC, Color Disk BASIC adds the following.
Disk management commands
   BACKUP n TO m            Copy all files from one disk to another
   BACKUP n                 BACKUP a disk using only a single disk drive
   COPY file1 TO file2      Make a duplicate of a file
   DIR n                    List the files that are on the disk
   DRIVE n                  Use drive n as the default
   DSKINIn                  Initialize (format) a disk
   KILL file                Delete a file from the disk
   LOAD file                Load a program
   LOAD file,R              Load a program and start it running
   LOADM file,offset        Load a machine-code program, shifting by offset
   MERGE file               Load an ASCII program without clearing the old one
   MERGE file,R             Merge a program and start it running
   RENAME file1 TO file2    Change the name of a file
   RUN file                 Load a program and start it running
   RUN file,R               Load and run program, leaving files open
   SAVE file                Save a program
   SAVE file,A              Save a program in ASCII format
   SAVEM file,a1,a2,ax      Save a machine-code program, from a1 to a2, exec at ax
   VERIFY ON                Double-check all writes to the disk
   VERIFY OFF               Don't double-check

Programming commands
   FILES max_f,size         Reserve buffers for open files
   FREE(n)                  Returns the number of free granules (2304 bytes each)
   UNLOAD n                 Close all open files on drive n
   DSKI$ n,t,s,v1$,v2$      Read track t sector s into v1$ and v2$
   DSKO$ n,t,s,v1$,v2$      Write track t sector s from v1$ and v2$
   OPEN "I",f,file          Open a file for sequential input (ie: INPUT)
   OPEN "O",f,file          Open a file for sequential output (ie: PRINT/WRITE)
   OPEN "D",f,file,len      Open a file for direct access; (ie: GET/PUT);
                              record length len is optional
   CLOSE #f                 Close a file

Sequential file commands
   EOF(f)                   Returns true if file f has been read to the end
   INPUT #f, var,...        Read variables from a file
   LINE INPUT #f,var$       Read an entire line from a file into a string variable
   WRITE #f,values          Write values to file, with commas, strings in quotes,...
   PRINT #f,values          Write values to file, just as PRINT would display them
   PRINT #f,USING f$;values Formatted printing; many options for f$

Direct-access file commands
   FIELD #f, size AS v$,... Give variable names to parts of the file buffer
   RSET v$ = value$         Fill in a named part of the file buffer, right-justified
   LSET v$ = value$         Fill in ..., left justified
   PUT #f,r                 Write the buffer to record r
   GET #f,r                 Read record r into the buffer
   CVN(var$)                Make a number out of a binary string
   MKN$(num)                Make a binary string out of a number
   LOC(f)                   Return the current record number in the buffer
   LOF(f)                   Return the highest record number in the file
In all cases, f is a file number, n and m are drive numbers, file is a filename, and dollar signs signify variables that must be string-variables. Note that filenames must be either string variables or string constants in quotes. Upper-case words are keywords, lower-case words are supplied by the user.

Special file numbers are -2=printer -1=cassette and 0=screen


Syntax for a filename, in BNF. (Things in square brackets are optional, the vertical bar separates alternatives, angle brackets surround nonterminals, and uppercase words denote single-letter constants.)

<filename> ::= <name> [(DOT|SLASH) <extension>] [COLON <drivenum>]

The name can be up to eight characters long, and cannot include a dot, slash, colon, or zero. The extension can be up to three characters long, and also cannot include those four characters. The drive number is a single digit, from zero up to the highest drive on your system.

Examples of legal filenames:

   PROGRAM.BAS  -- filename=PROGRAM,  extension=BAS, no drivenum
   PROGRAM/BAS  -- filename=PROGRAM,  extension=BAS, no drivenum
   FOO.BAR:0    -- filename=FOO,      extension=BAR, drivenum=0
   FOO:1        -- filename=FOO,      no extension,  drivenum=1
   FRED         -- filename=FRED      no extension,  no drivenum

There is one documented subroutine in the Disk BASIC ROM that you can use to access the disk. Its address is stored at $C004 and $C005, so you jump to it using indirection: JSR [$C004] .

Before calling that, you should load the X register with the address of a data structure that describes what you want to do. The examples in the manual always load this address from locations $C006 and $C007. I have not tried using this, so I don't know it will work if you put your structure anyplace else. This data structure is seven bytes long:

	1 byte    op code (0 - 3)
	1 byte    drive number (0 - 3)
	1 byte    track number (0 - 34)
	1 byte    sector number (1 - 18)
	2 bytes   address of 128-byte data buffer
	1 byte    error code
Op codes are either 0 (restore to track 0), 1 (no op), 2 (read sector), or 3 (write sector).

Bits in the error code seem to come straight from the chip in the disk controller. See that for more details.

The disk control routine modifies the contents of only the condition code register.

Back to my top-level CoCo page


16-Jun-99
yakowenk@csx.unxc.edu
(remove all "x"s to get a valid address)