Drive commands are commands sent to a Commodore floppy drive. Using commands, disks can be formatted, files deleted, drive number changed (until powerdown typically), programs can get uploaded and executed in the drive (typically done by fastloaders), and many other things. In case an error occurs when executing the command, the red drive LED starts to flash, and a more verbose error message can be fetched from the drive.
List of standard drive commands[edit | edit source]
- NEW/N - Format a floppy disk
- Syntax: "N:label,id"
- label may be up to 16 characters long. id must be two characters. If id is omitted, the directory of the disk will be erased (disk must be formatted already).
- RENAME/R - Rename a file
- Syntax: "R:newname=oldname"
- SCRATCH/S - Delete files
- Syntax: "S:file"
- Wildcards "*" and "?" are supported.
- VALIDATE/V - Validate disk
A consistency check of the disk's BAM and directory is carried out, e.g., the block availability in the BAM will match with blocks that are actually used by files, as will the free blocks count. Runtime of validate is dependent on the amount of used space on disk.
Sending drive commands[edit | edit source]
Drive commands can be sent in a number of ways. Most disk copy programs or other disk utility programs include an extra menu point for sending drive commands, too.
C64 BASIC V2.0 / C128 BASIC V7.0[edit | edit source]
OPEN 1,8,15,"command":CLOSE 1 :REM send command to drive 8
Where "1" is the "handle", "8" is the device number (default drive is 8), and "15" denotes "command channel".
Some examples using drive 8 (NOTE: After any command that alters the directory, you will need to reload it from disk(LOAD"$",8) to show the update):
OPEN 1,8,15,"N:NEWDISK,01":CLOSE 1 :REM format disk in drive 8 with label NEWDISK and disk id 01 OPEN 1,8,15,"S:TEMPFILE":CLOSE 1 :REM scratch (delete) the file "TEMPFILE" OPEN 1,8,15,"R:NEWNAME=TEMPFILE":CLOSE 1 :REM renames the file "TEMPFILE" to "NEWNAME" - note that the new name comes first
Reading the error message from the drive is even a bit more complicated as one has to read the error message using INPUT# which BASIC does not allow in direct mode, so an own small BASIC program has to be written:
10 OPEN 1, 8, 15 :REM Open Error/Command Channel 20 INPUT#1, EN, ER$, TR, SC :REM Read Message 30 CLOSE 1 :REM Close Channel 40 PRINT "ErrNr: "; EN :REM Display Results 50 PRINT "Error: "; ER$ 60 PRINT "Track: "; TR 70 PRINT "Sector:"; SC RUN
In case the error number, track and sector value is used for further processing (output formatting or whatever) it is recommended to read the error channel with
20 INPUT#1, EN$, ER$, TR$, SC$
A combined output like
or a string similar to BASIC 3.5/7.0 system variable DS$ is easier to construct (prevents to fiddle around with the leading blank):
If the a numeric value is needed it can still be derived by using VAL(EN$) (for the error number in this case).
Final Cartridge 3[edit | edit source]
Using the Final Cartridge 3, commands can be sent using the new
DOS"command BASIC command. Error messages get displayed by
DOS without parameters.
The FC3 implements some non-standard floppy commands that are handled directly by the DOS command.
DOS"N:NEWDISK,01 :REM format disk in drive 8 with label NEWDISK and disk id 01 DOS"F:NEWDISK,01 :REM FC3 specific - fast format a disk DOS"D:NEWNAME,01 :REM FC3 specific - rename disk
JiffyDOS[edit | edit source]
Using JiffyDOS, commands can be sent using
@"command for S-JiffyDOS). Error messages get displayed by
@ without parameters.
@N:NEWDISK,01 :REM JiffyDOS: format disk in drive 8 with label NEWDISK and disk id 01 @"N:NEWDISK,01 :REM S-JiffyDOS: format disk in drive 8 with label NEWDISK and disk id 01
Action Replay[edit | edit source]
Similar to Jiffy, the Action Replay cartridge provides an
@command command for sending drive commands.
Similar to the FC3, the Action Replay implements some additional commands (N: fast format and C: TODO: unknown). If you want to prevent these command strings to be parsed by the AR instead of the drive, use
@"command to send the command.
@N:NEWDISK,01 :REM fast format disk in drive 8 with label NEWDISK and disk id 01 @"N:NEWDISK,01 :REM standard format disk in drive 8 with label NEWDISK and disk id 01