{"id":1416,"date":"2020-08-21T09:55:25","date_gmt":"2020-08-21T07:55:25","guid":{"rendered":"https:\/\/www.pagetable.com\/?p=1416"},"modified":"2020-08-21T09:55:25","modified_gmt":"2020-08-21T07:55:25","slug":"fat32-filesystem-for-the-65c02","status":"publish","type":"post","link":"https:\/\/www.pagetable.com\/?p=1416","title":{"rendered":"FAT32 Filesystem for the 65c02"},"content":{"rendered":"<p>We are presenting the (to our knowledge) first full-featured open source library for 65c02 CPUs for accessing FAT32 formatted disks.<\/p>\n<ul>\n<li>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.<\/li>\n<li>It decodes a Master Boot Record (MBR) partitioning table and can have multiple partitions mounted at the same time.<\/li>\n<li>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 <a href=\"https:\/\/bitbucket.org\/steckschwein\/steckschwein-code\/src\/master\/steckos\/libsrc\/spi\/\">65c22 serial port code by the Steckschwein project<\/a>.<\/li>\n<li>Converting character encodings and matching names is done using callbacks \u2013 you can use the <a href=\"https:\/\/github.com\/commanderx16\/x16-rom\/blob\/master\/cbdos\/match.s\">X16 implementation<\/a> for a template.<\/li>\n<\/ul>\n<p>The API looks like this:<\/p>\n<pre><code>    ; allocate context for filesystem #0\n    ; (first MBR partition, mount if necessary)\n    lda #0\n    jsr fat32_alloc_context\n    sta context\n\n    ; open file\n    lda #&lt;filename\n    sta fat32_ptr\n    lda #&gt;filename\n    sta fat32_ptr + 1\n    jsr fat32_open\n\nloop:\n    ; read and print byte\n    jsr fat32_read_byte\n    bcc end\n    jsr print_character\n    jmp loop\n\nend:\n    jsr fat32_close\n\n    lda context\n    jmp fat32_free_context\n\n    filename:\n        .byte '\/path\/to\/file.txt', 0\n<\/code><\/pre>\n<p>The implementation uses the 65c02 extensions. With the help of <a href=\"https:\/\/github.com\/commanderx16\/x16-rom\/blob\/68cec17c700bd9666dc49f801e0853af4e417ebf\/cbdos\/65c02.inc\">65c02.inc<\/a> and some simple search-and-replace, it can be adapted for the 6502 though.<\/p>\n<p>The library was written by Frank van den Hoef, with features (LFN, mkfs, &hellip;) added by Michael Steil.<\/p>\n<p>It is the core of the DOS in the Commodore-like <a href=\"https:\/\/www.commanderx16.com\">Commander X16<\/a> retro computer. The source is currently maintained as part of the X16 ROM:<\/p>\n<p><a href=\"https:\/\/github.com\/commanderx16\/x16-rom\/tree\/master\/dos\/fat32\">https:\/\/github.com\/commanderx16\/x16-rom\/tree\/master\/dos\/fat32<\/a><\/p>\n<p>Contributions welcome!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8230; <a title=\"FAT32 Filesystem for the 65c02\" class=\"read-more\" href=\"https:\/\/www.pagetable.com\/?p=1416\" aria-label=\"Read more about FAT32 Filesystem for the 65c02\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,8,11,13,16,22,37],"tags":[],"class_list":["post-1416","post","type-post","status-publish","format-standard","hentry","category-2","category-commodore","category-dos","category-floppy-disks","category-github","category-operating-systems","category-x16"],"_links":{"self":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts\/1416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1416"}],"version-history":[{"count":0,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts\/1416\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}