Close

SD Card Drive in CP/M

A project log for The PCW Project

Doing things with an Amstrad PCW

James OtsJames Ots 10/27/2017 at 21:380 Comments

So I got my computer to boot off the SD card, but that was just blindly reading the first 40Kb off the SD card into memory and executing it. Once booted, CP/M knew absolutely nothing about the SD card. So I had to do some more coding. But before I get onto that, here's a colourful picture of the circuitry at the moment:

And a picture of my home-bodged SD card adaptor. I'm saving money for a trip to Canada for a family wedding next year, so I'm making any savings I can at the moment. Fortunately the connections on an SD card line up nicely with a 0.1" pin header:

Now, on to the programming.

I only had version 1.14 of CP/M Plus on my PCW, which doesn't support FID files (loadable device drivers), so I had to get hold of version 1.15 before I could start using the SD card in CP/M. Oddly, when I put J15CPM3.EMT onto the SD card, it started to boot, but then got stuck just before the A> prompt appeared. I spent quite a lot of time trying to work out what was going on, including disassembling J15CPM3.EMT. I'd already done some work on this before, but I got further this time, as I wrote a utility to put all the bits of the file into the right places in memory before disassembling. And then realised I could use the Joyce emulator and do a memory dump. But it all came to naught, as I couldn't work out what was going on.

Eventually I discovered the problem. J14CPM3.EMS fits into 40Kb, but J15CPM3.EMT is slightly bigger. To make things easy (hah!) I changed my ROM boot programme to just read the first 48Kb from the SD card into the first 3 pages of memory. Unfortunately, as I had these pages loaded into banks 1, 2 and 3 instead of 0, 1 and 2 (because my bootstrap programme is in bank 0), and because I had the stack at the top of bank 3, the stack was getting clobbered. I moved the stack into bank 0, and it suddenly started booting with v1.15.

The next thing was to get a FID file working. To make things easy, I first tried developing a simple FID file using Joyce — it gave me the ability to experiment with different compilers and tools without running out of disk space, or waiting for ages for things to compile and then not work. Once I had a simple driver working which just showed a message on boot, I started working on the PCW.

Writing the FID file was actually fairly simple. I've already created routines for reading from and writing to the SD card, so it was just a case of putting all the pieces together. The hardest part was creating a suitable DPB, with all the right numbers in the right places. I had a bit of trouble getting confused between logical records (128 bytes), physical sectors (512 bytes) and logical blocks (2048 bytes), but eventually I got it right, and was able to use the SD card as a 32Mb fixed disc in CP/M. I also managed to get a disk definition set up for cpmtools in Linux, so I can also read from and write to the SD card in Linux.

I have a few things which still need to be done:

And the biggest one (and probably the most difficult):

Discussions