• Please review our updated Terms and Rules here

Direct SD card access (SPI) on a 6502..

orac81

Member
Joined
Mar 21, 2024
Messages
32
One interesting idea I saw on old XT PCs was a bit-wiggling interface for using an SD card as an HD drive via the printer port, using only resistors, diodes, transistors and caps, no external "helper" processor. I think the SD card can be accessed this way with a slow processor, whereas usb needs 16mhz+ processor for a bit wiggling i/f to work. There are threads on vcfed and vogons, here are some links:


(there is a thread somewhere here on vcfed too, if anyone has it..)

quote.. "the Nilquader Driver needs only ~1,5k RAM and implents SPI in Software on LPT." This design uses SD card adapters with the voltage level adapter build in, which makes the circuit very simple.

If this was possible to adapt for a 1/2/4 Mhz 6502 via a 6522 VIA it would be of general interest for many 6502 based machines. You would think if a 4.7Mhz 8088 can do it, a 4Mhz 6502 could do it too.

Has anyone tried or done this? Any thoughts welcome..
 
Last edited:
Yes a 4.7 MHz 8088 can bitbang a SPI interface... But you won't like it.
The amount of hardware to build a proper SPI interface is small and will gain a LOT of additional speed.
 
Yes a 4.7 MHz 8088 can bitbang a SPI interface... But you won't like it.
The amount of hardware to build a proper SPI interface is small and will gain a LOT of additional speed.

Well, the speed of this XT bitbang i/f is about 10k bytes per sec, which is considered very slow for PCs.
But a PET 3040 is about 2k/sec, and a C64/1541 0.3k/sec! 10k/sec is like a 35x turbo for a vic20/c64.

Its all relative..
 

Thanks, thats the FAT16 interface in 2k rom, not bad! But I didnt see a link to source code..

Also this discussion I was having is interesting from 6502.org:

http://forum.6502.org/viewtopic.php?f=4&t=8260


fachat said:
See this thread for hints to get it as fast as possible, even with bit banging: http://forum.6502.org/viewtopic.php?f=4&t=7886&hilit=spi+fast&start=0

Now reading that thread i find this interesting titbit:


NormalLuser said:
Hello.
Without extra hardware, is this the fastest possible VIA SD card read setup?
This reads a byte from a SD card in 46/38 cycles (non-ZP/ZP):
Code:
    lda VIA_PORTA
    asl
    ora VIA_PORTA
    asl
    ora VIA_PORTA
    asl
    ora VIA_PORTA
    asl
    ora VIA_PORTA
    asl
    ora VIA_PORTA
    asl
    ora VIA_PORTA
    asl
    ora VIA_PORTA

gfoot helped me out over on my Bad Apple thread in programming with this setup:

I have the SD card data MISO data out pin connected to bit 0 of VIA Port A.
There is nothing else hooked up to that port.
That port is setup to clock on read and the clock pin of the SD card is hooked up to CA2 on the VIA.
The other SD card pins are connected to Port B.
Is this the fastest SD card read possible out of a VIA alone?
I think it could be?

Given that;
I'm also interested in the smallest hardware change that would improve the SD read speed?
If the VIA lived in zero page that would reduce the cycles to 38, but what else can be done?

......

I put the SD card in READ_MULTI_BLOCK mode.
When in this mode every pulse on the clock puts a bit on MISO.
With VIA PORT A setup to pulse CA2 on reads every read of the port puts a bit in bit 0 of the port.


I didnt know that mode was available, i could have used that VIA mode in my earlier projects!

Anyway maybe this alternative code could be used:

Code:
sdread256:
    ldx #127
    ldy #0
loop:
    cpx VIA_PORTA ; input on VIA bit 7
    asl
    cpx VIA_PORTA
    asl
    cpx VIA_PORTA
    asl
    cpx VIA_PORTA
    asl
    cpx VIA_PORTA
    asl
    cpx VIA_PORTA
    asl
    cpx VIA_PORTA
    asl
    cpx VIA_PORTA
    asl
    eor #255
    sta (destptr),y
    iny
    bne loop ; approx 60 cycles/loop
    rts

(making a complete subroutine)

Its a tiny bit slower, but the other 7 VIA lines are free to be used. At 60ish cycles per loop, with a 1mhz 6502 thats reading the sd card at 16k bytes per second, which isn't too shabby.
 
Last edited:
Back
Top