FAT32 Filesystem for the 65c02

We are presenting the (to our knowledge) first full-featured open source library for 65c02 CPUs for accessing FAT32 formatted disks.

  • The library supports filesystems from 32 MB to 2 TB, can read and write long filenames, subdirectories and time stamps, and can even create new filesystems.
  • It decodes a Master Boot Record (MBR) partitioning table and can have multiple partitions mounted at the same time.
  • It comes with a driver for the SD card protocol, so you can hook it to your own SD card solution; all you have to do is implement your own byte transmission code. If you want to use a VIA 65c22, you can hook up the 65c22 serial port code by the Steckschwein project.
  • Converting character encodings and matching names is done using callbacks – you can use the X16 implementation for a template.

The API looks like this:

    ; allocate context for filesystem #0  
    ; (first MBR partition, mount if necessary)  
    lda #0  
    jsr fat32_alloc_context  
    sta context

    ; open file  
    lda #<filename  
    sta fat32_ptr  
    lda #>filename  
    sta fat32_ptr + 1  
    jsr fat32_open

loop:  
    ; read and print byte  
    jsr fat32_read_byte  
    bcc end  
    jsr print_character  
    jmp loop

end:  
    jsr fat32_close

    lda context  
    jmp fat32_free_context

    filename:  
        .byte '/path/to/file.txt', 0

The implementation uses the 65c02 extensions. With the help of 65c02.inc and some simple search-and-replace, it can be adapted for the 6502 though.

The library was written by Frank van den Hoef, with features (LFN, mkfs, …) added by Michael Steil.

It is the core of the DOS in the Commodore-like Commander X16 retro computer. The source is currently maintained as part of the X16 ROM:

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

Contributions welcome!

6 thoughts on “FAT32 Filesystem for the 65c02”

  1. Sadly, I can’t even compile the emulator anymore:

    vera_spi.c: In function ‘vera_spi_step’:
    vera_spi.c:31:8: error: ‘sdcard_attached’ undeclared (first use in this function); did you mean ‘sdcard_attach’?
    31 | if (sdcard_attached) {
    | ^~~~~~~~~~~~~~~
    | sdcard_attach
    vera_spi.c:31:8: note: each undeclared identifier is reported only once for each function it appears in
    make: *** [Makefile:57: vera_spi.o] Error 1

    • It’s not that easy. GEOS relies heavily on the BAM family of filesystems. geoWrite for example asks the system for 1541/1581/CMD-style directory entries, extracts the track/sector pointer and reads the sector to get to a VLIR file’s index table. The FAT32 driver would have to emulate the looks of a BAM-style disk. That’s a lot of work.

Leave a Reply to Michael Steil Cancel reply

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