The 1541 Floppy Drive was equipped with its own MOS 6502 chip and was therefore capable of understanding and executing its own commands (to format the disk, copy files, erase files, etc). The idea was that it could operate autonomously without the attached C64 to get involved – revolutionary at the time. They were called CBM DOS commands – indeed as in Disk Operating System, not to be confused with the later MS-DOS or DR-DOS.
Those DOS commands were not part of BASIC and had to be sent to the drive with a dedicated channel. In principle you needed to
- open a channel (with OPEN 15,8,15)
- issue the command (for example, PRINT#15,”command”)
- and close the channel (CLOSE 15)
This worked in direct mode as well as from within programs too. Note that opening a channel followed by a BASIC disk operation involving the drive (such as LOADing or SAVEing a file) would automatically close the channel.
If you’re wondering about the significance of 15: it’s the 1541’s command channel. Channel 0 and 1 are for the operating system to transfer files, 2-14 can be used for your own operations, and 15 is good for what we’re doing now.
Here are some of the more useful commands. We’re assuming your drive number is 8 (change where appropriate):
Formatting a Floppy Disk
Nothing came pre-formatted in those days – everything was blank. The NEW command would be your best friend, taking about 10 minutes or so to give you a whopping 170KB of precious space per side. This was known as a “hard format”:
OPEN 15,8,15 PRINT#15,"NEW0:disktitle,id" CLOSE 15
You can also abbreviate NEW with N. The presence of the 0: after the command was used to indicate which drive you were using in dual-drive setups, meaning 0 for the left and 1 for the right drive. The 1541 was a single drive and hence will only respond as 0.
This took a whole minute or two for the whole disk, and being the busy people we were turning into even back then, we were glad to know that there was a sort of “soft format” command available that would only erase the BAM and thereby clear out the directory. It did not write sectors on the disk, and instead simply marked them all as “available” again. It saved a lot of time and could be achieved by omitting the disk ID from the above command, like so:
OPEN 15,8,15 PRINT#15,"N0:newtitle" CLOSE 15
Notice the way I’ve used the N instead of the NEW command here, and that there’s no comma or ID after the disk title. Since we do not specify an ID, it will remain as it was before the soft-format. We still use the same principle with modern hard drives today when we use the “quick format” option.
The Mysterious Initialize Command
Some CBM commands were a little puzzling and rarely used. The I or INITIALIZE command was one of those. It exists, and thanks to a comment by Dan, I finally understand what it actually does.
It takes no parameters and will read the current BAM/Directory into the disk drive’s memory. This is sometimes necessary as a way to check if the user has indeed changed a diskette after being prompted so by their software. Without such a check, software packages might receive data that does not exist on the disk.
OPEN 15,8,15 PRINT#15,"INITIALIZE0" CLOSE 15
You can duplicate THISFILE into THATFILE on the same floppy and generate your own safety copies.
OPEN 15,8,15 PRINT#15,"COPY0:thisfile=thatfile" CLOSE 15
Can be abbreviated with C. Note that you cannot use this command to copy from one drive to the other (like drive 8 to drive 9). You could even copy up to 4 files together, presumably concatenating them – but it never worked for me.
OPEN 15,8,15 PRINT#15,"RENAME0:newfile=oldfile" CLOSE 15
Can be abbreviated with R.
The SCRATCH command will do this. Can be abbreviated with S:
OPEN 15,8,15 PRINT#15,"SCRATCH0:thisfile" CLOSE 15
Validating your Floppy Disk
Before there was our new favourite “Device hasn’t been removed properly” message, things could still go wrong with floppies over time: write operations were started but never finished, channels were opened and prematurely closed, and so forth. If you’ve used a floppy over time for saving, renaming and deleting a lot of files, it may need a cleanup.
VALIDATE to the rescue. This command will go through existing files, defragment your sectors, update the BAM and speedup disk access to your precious 170KB of space. Can be abbreviated with V:
OPEN 15,8,15 PRINT#15,"VALIDATE" CLOSE 15
This will however ruin your data forever if you’ve been using your drive it with direct access (i.e. without LOAD or SAVE commands – we shall speak about this in another article).
Reading the Error Channel
One final thing that we did was to diagnose error messages that the 1541 was reporting – in the rarest of circumstances of course. Usually you knew what happened (i.e. no disk in drive, bad floppy, etc), but sometimes it wasn’t obvious – or you wanted to give users an explanation.
Much like we can issue a command with PRINT#, we can also read what the drive is telling us with INPUT# – much like we can read keyboard input from a user into a variable.
INPUT# does not work in direct mode, only in BASIC programs. Here’s how:
10 open 15,8,15 20 input# 15,a,b$,c,d 30 print "error number: ";a 40 print "error name: ";b$ 50 print "on track: ";c 60 print "sector: ";d 70 close 15 // run it with run // if all is well will show something like error number: 0 error name: ok on track: 0 sector: 0
This little programme will remove the blinking red light from the drive and show you what’s wrong. Only the second variable is a string, but you can read the others in as strings too if you like.
Will report the CBM DOS version when the drive has just been switched on. Should the drive not be available (i.e. turned off) the programme will hang until you hit RUN STOP/RESTORE.
What’s that 0 after these commands?
Notice how I’ve used a 0 after each command, like NEW0. That’s the belt-and-braces approach to using disk commands. This is optional in most single drive units. Most of us never had the pleasure to use the old dual disk drives, but they did exist – and from what I understand, Commodore used very similar firmware in newer drives.
In these dual-disk machines (i.e. 4040, 8050, etc) you could specify which drive in the unit you were talking to. Drive 0 is the one on the left, drive 1 is the one on the right. The whole unit is then either unit 8, 9, 10 or whatever else. In single drive units, you can leave the 0 out and simply call the command (like NEW or N) without a number behind it.