Compact Flash Emulation?

A project log for 3-Chip Z80 Design

Combining a Z80 retro design with a modern PSoC CPU. 10/20/2019 at 19:420 Comments

I'd like to get something very difficult going next. Maybe Grant's Compact Flash code? I'd like to get it working with Grant's stock 9-Chip Z80 code. I'd really like to map it to an SDHC card instead of the more ancient Compact Flash. An SDHC card only needs a SPI bus connection for the physical connection.

Physical Connections in Grant's Design

Grant has the following connections in his 9-Chip Z80 design to connect to the CF from the Z80 bus.  

Grant uses I/O addresses 0x10-0x1F and connects the Z80 lines A[2..0] directly to the CF. Makes me wish I had put the Z80 lines onto a connector - I'd only need a Chip Select now and that would be easy.  Grant generates a single Chip Select line when he is accessing the CF card that covers the 0x10-0x17 range. (The Front Panel address range (0x18-0x1F) is already out of the way so I have no conflicts with his code.)

Grant hooks up other Z80 lines:

CF Mode?

Grant's page describes the method of connection as:

Additionally, the CF is set up as "IDE" mode so it only requires 3 address lines 
and one chip select.

This is why Compact Flash Drives can be connected to IDE connectors with purely passive connections.

This page has some hints on the IDE mode. There's more information here.

Grant has the following in his monitor.asm code:

; CF registers
CF_DATA        .EQU    $10
CF_FEATURES    .EQU    $11
CF_ERROR    .EQU    $11
CF_SECCOUNT    .EQU    $12
CF_SECTOR    .EQU    $13
CF_CYL_LOW    .EQU    $14
CF_CYL_HI    .EQU    $15
CF_HEAD        .EQU    $16
CF_STATUS    .EQU    $17
CF_COMMAND    .EQU    $17
CF_LBA0        .EQU    $13
CF_LBA1        .EQU    $14
CF_LBA2        .EQU    $15
CF_LBA3        .EQU    $16

This seems pretty straightforward. Where there are two EQUs at the same address the first one is the write value and the second is the read value. I'm going to add support for this to the 9-Chip build. I will spare the reader the details - at least for the present moment - but I want to set it up to step through the code and watch what the Z80 tries to do when booting CP/M. This will be educational - for me at least.

This will be very similar in steps to the M6850 emulation I completed in the most recent logs. If this looks promising I may pick it up here in the logs for this project.

Added: A couple of quick observations.

Grant's code in monitor.asm only does reads of particular low sectors. That's because it is loading CP/M. Once CP/M loads it must have it's own software for read/writing SD card sectors. That may complicate emulation because I may need to dump the code that is running . Fortunately Grant includes the CP/M code.

The file cbios128 looks like it's the low level IO routines and it uses the same $EQU values as Grant's monitor.asm code. So it should be easy to pick out what it does from there.