Commodore 1541 DOS Commands

- by
Commodore Logo

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

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

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

Duplicating Files

You can duplicate THISFILE into THATFILE on the same floppy and generate your own safety copies.

OPEN 15,8,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.

Renaming Files

OPEN 15,8,15

Can be abbreviated with R.

Deleting Files

The SCRATCH command will do this. Can be abbreviated with S:

OPEN 15,8,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

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 

// 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.

If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

5 thoughts on “Commodore 1541 DOS Commands”

  1. The format command may have been slow, but not 10 minutes slow, It took just under 2 minutes to format a disk in a 1541.
    Until I got an Action Replay cart and started formating disks with it in under 10 seconds, that is…

  2. Perhaps it just seemed so long to me… ? Wow, 10 seconds is amazing! I remember being thrilled by how fast the 1571 could format disks. I’ve never tried the AR, maybe one day 😉

  3. Thanks for the well written list! One correction, I think: The “initialize” (“I”) command does not erase anything. It just loads the BAM into drive memory. You sometimes need to do this after changing disks and to clear errors. The command does not take arguments. (I did a quick check and the arguments did nothing.) It’s definitely confusing because the term “initialize” has been used to mean “format” or “erase” in other contexts.

  4. Oh Dan, you’re absolutely right – I’ve just tried this myself too, and to my complete surprise I or INITIALIZE doesn’t format the disk at all. Thank you so much for pointing that out! Now I wonder, how did we soft-format floppy disks back then? I remember there was an option, and if I didn’t do it… how did it work?
    I’ll amend the article forthwith.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.