Commodore DOS


Commodore DOS, also known as CBM DOS, is the disk operating system used with Commodore's 8-bit computers. Unlike most other DOSes, which are loaded from disk into the computer's own RAM and executed there, CBM DOS is executed internally in the drive: the DOS resides in ROM chips inside the drive, and is run there by one or more dedicated MOS 6502 family CPUs. Thus, data transfer between Commodore 8-bit computers and their disk drives more closely resembles a local area network connection than typical disk/host transfers.

CBM DOS versions

At least seven distinctly numbered versions of Commodore DOS are known to exist; the following list gives the version numbers and related disk drives. Unless otherwise noted, drives are 5¼-inch format. The "lp" code designates "low-profile" drives. Drives whose model number starts with 15 connect via Commodore's unique serial IEEE-488 bus serial protocols; all others use the parallel IEEE-488.
  • 1.0 - found in the 2040 and 3040 floppy drives
  • 2.0 - found in the 4040 and 3040 floppy drives
  • 2.5 - found in the 8050 floppy drives
  • 2.6 - found in the 1540, 1541 including the one built into the SX-64, 1551, 2031, and 4031 floppy drives
  • 2.7 - found in the 8050, 8250, and SFD-1001 floppy drives
  • 3.0 - found in the 1570, external 1571, and 8280 floppy drives, as well as the 9060 and 9090 hard drives
  • 3.1 - found in the built-in 1571 drive of C128DCR computers
  • 10.0 - found in the 1581 floppy drive
Version 2.6 was by far the most commonly used and widely known DOS version, due to its use in the 1541 as part of C64 systems.
Note: The revised firmware for the 1571 which fixed the relative file bug was also identified as V3.0. Thus it is not possible to differentiate the two versions using the version number alone.

Technical overview

1541 directory and file types

The 1541 Commodore floppy disk can contain up to 144 files in a flat namespace ; the directory is stored on reserved track 18, which is located halfway from the hub to the edge of a 35-track single-sided disk. A file name may be up to 16 bytes in length and is theoretically unique; by using direct access methods on the directory structure, it is possible to rename a file to that of another—although accessing such files may be difficult or impossible. Files with identical names usually serve no purpose except to inform or visually manage files. One popular trick, used, for example, by The Final Cartridge III, was to add files named "----------------" of type DEL< to the directory, and files could then be rearranged around those lines to form groups. Many game developers, warez group members, and demoscene hackers used some more clever custom directory entries as well.
File names may contain a shifted space character, and if the directory listing is being viewed from BASIC, the portion of the file name beyond the $A0 character will appear to have been separated from the first part of the file name by a quotation mark, causing BASIC to not consider it to be part of the full file name. This feature can be used to create directory entries such as, which will then appear in the directory listing as, for example,. When the user moves the cursor to the beginning of the line, types the word LOAD over the file size, and presses, BASIC interprets that as, causing the program to be loaded into memory. Anything after the colon or the secondary address will not be executed, since the computer ignores any command after a LOAD. Alternatively, the user could press to and the program automatically.
A null byte embedded in a file name will interrupt the listing after loading by BASIC. If there are three null bytes, that makes it difficult to list through BASIC. Many machine language programmers would experiment with null bytes in an attempt to make it harder for BASIC programmers to access their code and tamper with it.
In BASIC, the directory can be accessed as a non-executable pseudo-BASIC program with followed by LIST. The first line has a line number of 0 or 1, showing in reverse video the name and ID of the disk and a shorthand code for the DOS version with which it was created. Lines after this have the size of a file as their pseudo "line number", followed by the file name in quotes and the three-letter type code. The last line shows the number of unallocated blocks on the disk, followed by the words "BLOCKS FREE."
On the Commodore 64, entering will flood the screen with garbage instead of loading the directory into BASIC RAM. This is because the drive assigns the directory a load address of $0401, which is equivalent to the start of BASIC for the Commodore PET, but corresponds to the default screen memory in the C64.
Viewing the directory with a command overwrites the BASIC program in memory. The DOS Wedge and various third-party cartridges and extenders such as Epyx Fast Load, Action Replay, and The Final Cartridge III allow viewing of the disk directory using special commands that load the directory into screen memory without destroying the current BASIC program. Some versions of Commodore BASIC include a DIRECTORY or CATALOG command that performs the same function.
The following file types are supported:
;SEQ
;PRG
;REL
;USR
;DEL
The presence of an asterisk prepended to the file type in a directory listing indicates that the file was not properly closed after writing. When the drive is commanded to close a file that has been opened for writing, the associated buffer is flushed to the disk and the block availability map is updated to accurately reflect which blocks have been used. If a program crash or other problem results in an "orphan file", also referred to as a "poison" or "splat" file, buffers are not flushed and the BAM will not accurately reflect disk usage, putting the disk at risk of corruption. A poison file generally cannot be accessed, and an attempt to use the DOS scratch command to delete the file may cause filesystem corruption, such as crosslinking. The only practical method of removing one of these files is by opening the file in "modify" mode, or by validating the disk, the latter which rebuilds the BAM and removes poison file references from the directory. The infamous [|save-with-replace bug] could result in creation of splat files.
*DEL is a special type written into the on-disk directory entry of files that have been deleted. Such files are not shown in a normal directory listing, and their data blocks and directory entries will be reused by files that are subsequently created. Some utility programs allow the "un-deletion" of such files if their data blocks and directory entries haven not yet been overwritten by other files. DEL files are commonly used to insert banners or comment sections into a directory listing.
File types with < after them are "locked", and cannot be deleted—they can be opened for reading, however. There is no Commodore DOS command that can explicitly set or clear this status, but many third-party utilities were written to allow this to be done. These utilities generally read the directory using direct-access commands, perform the necessary modifications to the raw data, and then write the changes back to the disk.

File access

Accessing files is primarily an issue for the host computer. The kernal ROM in the computer contains the necessary primitive routines needed to access files, and the BASIC ROM contains a higher level abstraction for file access using BASIC syntax. The components that concern the DOS itself are file name parsing and the secondary address. This section will give an overview of the necessary BASIC commands for the sake of completeness.
Opening a file on a Commodore disk unit entails the processing of a number of parameters that are vaguely analogous to file opening procedures in other environments. Since the DOS is actually running in the drive's controller, the file opening sequence must pass enough information to the drive to assure unambiguous interpretation. A typical statement in BASIC to write to a sequential file would be as follows:
The parameters following the OPEN verb are as follows:
;3
;8
;4
;COMMAND STRING
Files can also be loaded and saved to with LOAD and SAVE commands. File name specifiers can also be used here, for example, saves the BASIC program to a PRG file and saves the BASIC program to a sequential file. If the secondary address isn't specified or is specified as 0, the file is saved/loaded from the BASIC memory area. If the secondary address is specified as a non-zero value, the program is loaded starting from the address specified by the file itself —this form of command is more common when loading machine code programs.
Load relocation was first introduced on the VIC-20 because this machine could start BASIC RAM in several different locations, depending on the memory expansion that was installed. The older Commodore PET series did not support relocation, so and would have the same effect: the file would be loaded into the same memory region from which it was saved. Load relocation happens in the host, being an exception to what is said above about the secondary address being used only device-internally. Since the PET cannot relocate files, BASIC programs written on later Commodore machines must be modified by using a sector editor to change the header bytes. It is also possible to use the PET's built-in machine language monitor to change the link address for the BASIC program after loading it.
The command will load the first program on the disk starting from the file-specified memory location. This is one of the most popular load commands of the platforms, the method to start majority of commercial software, for example. Of note is the fact that the wildcard expansion will only pick the first catalog name when no other file on that disk has been accessed before; the name of the last-used file is kept in memory, and subsequent commands will load that file rather than the first.
The directories of disks in two-drive units are accessed as and. "0:$" and "1:$" do not access the directory but actual files on one drive or the other that just happen to be named "$". Partial directories can be loaded by adding a colon and a template: for example, would load a partial directory that shows only the files whose name starts with the letter K and which are of type PRG; all such partial directories still contain the initial disk name line and the final "BLOCKS FREE" line.