CMDR-DOS: Commodore DOS on FAT32

All disk drives connected to the Serial Bus of a Commodore 64 speak the Commodore DOS protocol, from the popular 1541 5.25″ drive to the modern sd2iec SD card interfaces. CMDR-DOS is a new and open source implementation of the Commodore DOS protocol, using SD cards with the FAT32 filesystem and supporting advances features like partitions, subdirectories and timestamps – and running on a 65c02!

Commander X16

It is the built-in DOS of the Commander X16, and runs on the main CPU, so the KERNAL API (talk, tksa, untlk, listn, secnd, unlsn, acptr, ciout) calls directly into the DOS implementation. This allows LOAD speeds of about 140 KB/sec on an 8 MHz system.

Demo:

Transcript:

DOS"$=P":REM THERE ARE TWO PARTITIONS ON THIS SD-CARD

255 "CMDR-DOS SD CARD"  MBR  
1    "PART1"            FAT32  
2    "PART2"            FAT32

READY.  
DOS"N1:SYSTEM,1616,FAT32":REM FORMAT PARTITION 1

READY.  
DOS"N2:DATA,1617,FAT32":REM FORMAT PARTITION 2

READY.  
DOS"$=P":REM THE NEW NAMES OF THE TWO PARTITIONS

255 "CMDR-DOS SD CARD"  MBR  
1    "SYSTEM"           FAT32  
2    "DATA"             FAT32

READY.  
DOS"CP1":REM SWITCH TO PARTITION 1

READY.  
DOS"$":REM SHOW DIRECTORY

0 "SYSTEM          " FAT32  
99 MB FREE.

READY.  
OPEN1,8,2,"HELLO,P,W":PRINT#1,"HELLO WORLD!":CLOSE1:REM CREATE FILE

READY.  
DOS"$"

0 "SYSTEM          " FAT32  
1    "HELLO"            PRG  
99 MB FREE.

READY.  
DOS"C:WORLD=HELLO":REM DUPLICATE FILE

READY.  
DOS"$"

0 "SYSTEM          " FAT32  
1    "HELLO"            PRG  
1    "WORLD"            PRG  
99 MB FREE.

READY.  
DOS"C:HELLO WORLD=HELLO,WORLD":REM CONCATENATE FILES

READY.  
DOS"$"

0 "SYSTEM          " FAT32  
1    "HELLO"            PRG  
1    "WORLD"            PRG  
1    "HELLO WORLD"      PRG  
99 MB FREE.

READY.  
DOS"MD:SECRET":REM CREATE SUBDIRECTORY

READY.  
DOS"$"

0 "SYSTEM          " FAT32  
1    "HELLO"            PRG  
1    "WORLD"            PRG  
1    "HELLO WORLD"      PRG  
0    "SECRET"           DIR  
99 MB FREE.

READY.  
DOS"$//SECRET/:":REM SHOW SUBDIR CONTENTS

0 "SYSTEM          " FAT32  
0    "."                DIR  
0    ".."               DIR  
99 MB FREE.

READY.  
DOS"CD:SECRET":REM CHANGE TO SUBDIR

READY.  
DOS"$"

0 "SYSTEM          " FAT32  
0    "."                DIR  
0    ".."               DIR  
99 MB FREE.

READY.  
DOS"C:SECRET HELLO=//:HELLO":REM COPY FILE FROM ROOT TO HERE

READY.  
DOS"CD:_":REM CHANGE BACK UP

READY.  
DOS"CP2":REM CHANGE TO PARTITION 2

READY.  
DOS"$

0 "DATA            " FAT32  
98 MB FREE.

READY.  
DOS"C:DATA FILE=1//SECRET/:SECRET HELLO":REM COPY FILE FROM PARTITION 1

READY.  
DOS"$

0 "DATA            " FAT32  
1    "DATA FILE"        PRG  
98 MB FREE.

READY.  
DOS"$1:":REM SHOW DIRECTORY OF PARTITION 1

1 "SYSTEM          " FAT32  
1    "HELLO"            PRG  
1    "WORLD"            PRG  
1    "HELLO WORLD"      PRG  
0    "SECRET"           DIR  
99 MB FREE.

READY.  
DOS"S1:H*":REM DELETE ALL FILES THERE STARTING WITH H

READY.  
DOS:REM THIS WILL SAY THAT "02" FILES WERE DELETED  
01, FILES SCRATCHED,02,00

READY.  
DOS"CP1":REM CHANGE BACK TO PARTITION 1

READY.  
DOS"$

0 "SYSTEM          " FAT32  
1    "WORLD"            PRG  
0    "SECRET"           DIR  
99 MB FREE.

READY.  
DOS"S:*":REM DELETE ALL REMAINING FILES

READY.  
DOS:REM THIS WILL SAY THAT "01" FILE WAS DELETED  
01, FILES SCRATCHED,01,00

READY.  
DOS"$":REM THE DIRECTORY IS STILL THERE

0 "SYSTEM          " FAT32  
0    "SECRET"           DIR  
99 MB FREE.

READY.  
DOS"RD:SECRET":REM DELETE IT

READY.  
DOS:REM "00" FILES DELETED, BECAUSE DIR WAS NOT EMPTY  
01, FILES SCRATCHED,00,00

READY.  
DOS"S//SECRET/:*":REM DELETE ALL FILES INSIDE

READY.  
DOS:REM "01" FILE DELETED  
01, FILES SCRATCHED,01,00

READY.  
DOS"RD:SECRET":REM NOW TRY DELING THE DIR AGAIN

READY.  
DOS:REM "01" FILES DELETED, IT WORKED THIS TIME  
01, FILES SCRATCHED,01,00

READY.  
DOS"$

0 "SYSTEM          " FAT32  
99 MB FREE.

READY.  
REM THAT'S IT. :)

READY.

Source

The implementation is part of the Commander X16 ROM and available here:

https://github.com/commanderx16/x16-rom/tree/master/dos

Future

The codebase is very versatile and could be reused for other kinds of projects:

Other New Retro Machines

CMDR-DOS could be easily ported to other Commodore-like 65c02+ systems like the MEGA65 and the C256 Foenix, providing a DOS interface to FAT32 on those platforms.

sd2iec-like Device

Functionality-wise, the CMDR-DOS codebase is also very similar to what sd2iec does – minus the Commodore Serial part. It could be ported a device like the 1581replica, with an SD card attached instead of a disk drive, and one would have a 65c02-based sdi2ec-like device.

2 thoughts on “CMDR-DOS: Commodore DOS on FAT32”

  1. Hallo Michael.
    Nice job :) But something’s bothering me. Why not have a real dictionary of methods ? a-la MSDOS, unix shell or other ?

Leave a Comment