Adventures in FAT32 with 65c02
Posted: Fri Dec 05, 2025 4:08 pm
This might turn into another of my goes-on-forever screeds as I add to it, but the intent is to describe what I'm doing to get access to a FAT32 CF card on a simple 65c02 system.
For the avoidance of doubt: all code and hardware designs shown in this thread are released under the MIT licence:
The system on which I am primarily testing this design consists of a 65c02 running at 1.8342MHz and 5v. Ram is in the lower 32k, eeprom (non-writable in circuit) in the upper 16k, and a 68B50 UART giving a 115200 baud rate through an FTDI usb/serial adaptor.
So, why a CF card?
A handful of reasons, really.
With that said, it's important to note that I'm not seeking binary compatibility; there is no reason to expect a 65c02 binary to execute on a Windows or Linux machine (without an emulator) nor vice versa. However, it should be possible to create a text or data file on either machine and read it correctly on the other.
Sidenote: For new lines in text files, Windows uses CRLF, Linux uses LF, and Apple uses either CR or LF depending on the age of the OS. You're going to have to handle whichever you choose. Because of my linux system, I shall be using LF as a line break symbol and ignoring CR.
Hardware
There are two obvious choices. Either we attach directly to the card holder, or we use an existing IDE-CF adaptor module. The first choice is probably the cleanest and smallest, since the card mounts parallel to the circuit board, but the pins are on 0.635mm centres and are not the easiest thing in the world to solder. Plus, there are many card holders available, all very similar, but few with identical positioning for the (bolt) mounting holes, the locating pins, and the solder tabs. You're probably going to have to design your own footprint from the maker's datasheet (I got mine wrong!).
IDE to CF adaptor modules are all over the internet. From well-known Chinese sites, they're available for a couple of quid. The interface for the CF card was designed as a superset of the IDE interface and the adaptors are largely passive connections, though they may include things like an activity LED and possibly a driver transistor or two. The 44-pin IDE interface is a 2x22 contact part on 2mm centres (not 0.1") usually with pins, though it may be a socket. This is easy to accommodate on the PCB but with the disadvantage that unless you found one with a right angle pin set, the CF is going to stick out at right angles.
Using the IDE-CF adaptor module This derives two signals from the 65c02 control signals: R/~W NAND PHI2 gives a ~RD signal on pin 23 and ~(R/~W) NAND PHI2 gives a ~WR signal. The 74HC245 isolates the CF from the databus when not required, with the data direction selected from R/~W. You may have to investigate your socket to ensure the pins match; the numbers in this diagram match those on my adaptor, viewed from the pin side. Pin 20 is missing.
Using the CF card directly This shows a section of the single board card described above. Again, ~RD and ~WR are generated as above, and the '245 works the same way. The series resistors are _probably_ not required - they're not there on the adaptor, for example - but sources on the web strongly suggest that they be fitted to slow down the edges of the data.
Note: the CF is specified to work at either 3.3v or 5v; for 3.3v its access time is stated at 600ns and half that for 5v. I suspect that it is in fact significantly less, particularly with modern fast cards.
Threads discussing the development of both designs can be found here: viewtopic.php?f=4&t=8482 and here: viewtopic.php?f=4&t=8501
To be continued.
Neil
For the avoidance of doubt: all code and hardware designs shown in this thread are released under the MIT licence:
MIT License wrote:
Copyright 2025 Neil Barnes
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
So, why a CF card?
A handful of reasons, really.
- it's simple to implement because if its parallel interface; it doesn't need to have (for example) code running to implement SPI (or multibit SPI) in order to operate.
- it can be very simply used to interchange data between the 65c02 system and a Windows, Mac, or Linux computer; there is no requirement for a serial interface to handle data as well as text, just an inexpensive USB-CF adaptor. It's possible that your computer already has such an adaptor built in. (Though of course this also applies to the various SD card variants, too.)
- the interface is consistent between a CF and other IDE parts, such as a PATA hard drive or a floppy drive.
With that said, it's important to note that I'm not seeking binary compatibility; there is no reason to expect a 65c02 binary to execute on a Windows or Linux machine (without an emulator) nor vice versa. However, it should be possible to create a text or data file on either machine and read it correctly on the other.
Sidenote: For new lines in text files, Windows uses CRLF, Linux uses LF, and Apple uses either CR or LF depending on the age of the OS. You're going to have to handle whichever you choose. Because of my linux system, I shall be using LF as a line break symbol and ignoring CR.
Hardware
There are two obvious choices. Either we attach directly to the card holder, or we use an existing IDE-CF adaptor module. The first choice is probably the cleanest and smallest, since the card mounts parallel to the circuit board, but the pins are on 0.635mm centres and are not the easiest thing in the world to solder. Plus, there are many card holders available, all very similar, but few with identical positioning for the (bolt) mounting holes, the locating pins, and the solder tabs. You're probably going to have to design your own footprint from the maker's datasheet (I got mine wrong!).
IDE to CF adaptor modules are all over the internet. From well-known Chinese sites, they're available for a couple of quid. The interface for the CF card was designed as a superset of the IDE interface and the adaptors are largely passive connections, though they may include things like an activity LED and possibly a driver transistor or two. The 44-pin IDE interface is a 2x22 contact part on 2mm centres (not 0.1") usually with pins, though it may be a socket. This is easy to accommodate on the PCB but with the disadvantage that unless you found one with a right angle pin set, the CF is going to stick out at right angles.
Using the IDE-CF adaptor module This derives two signals from the 65c02 control signals: R/~W NAND PHI2 gives a ~RD signal on pin 23 and ~(R/~W) NAND PHI2 gives a ~WR signal. The 74HC245 isolates the CF from the databus when not required, with the data direction selected from R/~W. You may have to investigate your socket to ensure the pins match; the numbers in this diagram match those on my adaptor, viewed from the pin side. Pin 20 is missing.
Using the CF card directly This shows a section of the single board card described above. Again, ~RD and ~WR are generated as above, and the '245 works the same way. The series resistors are _probably_ not required - they're not there on the adaptor, for example - but sources on the web strongly suggest that they be fitted to slow down the edges of the data.
Note: the CF is specified to work at either 3.3v or 5v; for 3.3v its access time is stated at 600ns and half that for 5v. I suspect that it is in fact significantly less, particularly with modern fast cards.
Threads discussing the development of both designs can be found here: viewtopic.php?f=4&t=8482 and here: viewtopic.php?f=4&t=8501
To be continued.
Neil