From 7092cc8f77947159976133e17a85e60fdefc9a02 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sun, 10 Apr 2022 17:55:51 -0500 Subject: [PATCH] Add SD card software interface Adds a function to send a command to the sd card. --- sw/io.inc65 | 3 +++ sw/main.c | 4 ++++ sw/sd_card.h | 8 ++++++++ sw/sd_card.s | 27 +++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 sw/sd_card.h create mode 100644 sw/sd_card.s diff --git a/sw/io.inc65 b/sw/io.inc65 index 5e87bc2..3586e7c 100644 --- a/sw/io.inc65 +++ b/sw/io.inc65 @@ -11,4 +11,7 @@ SW = LED MM_CTRL = $7ff7 MM_DATA = $7fe0 +SD_ARG = $7ff8 +SD_CMD = $7ffc + IRQ_STATUS = $7fff diff --git a/sw/main.c b/sw/main.c index 4f894d8..aea99c8 100644 --- a/sw/main.c +++ b/sw/main.c @@ -4,6 +4,7 @@ #include "board_io.h" #include "uart.h" #include "mapper.h" +#include "sd_card.h" int main() { int i; @@ -46,6 +47,9 @@ int main() { cprintf("Reading from 0x4000: %x\n", *(unsigned int*)(0x4000)); cprintf("Reading from 0x5000: %x\n", *(unsigned int*)(0x5000)); + sd_card_command(0, 0); + sd_card_command(0x000001aa, 8); + while (1) { sw = sw_read(); diff --git a/sw/sd_card.h b/sw/sd_card.h new file mode 100644 index 0000000..1cd59af --- /dev/null +++ b/sw/sd_card.h @@ -0,0 +1,8 @@ +#ifndef _SD_CARD_H +#define _SD_CARD_H + +#include + +void sd_card_command(uint32_t arg, uint8_t cmd); + +#endif \ No newline at end of file diff --git a/sw/sd_card.s b/sw/sd_card.s new file mode 100644 index 0000000..f6c6ed6 --- /dev/null +++ b/sw/sd_card.s @@ -0,0 +1,27 @@ +.include "io.inc65" + +.importzp sp, sreg + +.export _sd_card_command + +.autoimport on + +.code + +; Send sd card command. +; command is in A register, the args are on the stack +; I think the order is high byte first? +_sd_card_command: + pha + + jsr popeax + sta SD_ARG + stx SD_ARG+1 + lda sreg + sta SD_ARG+2 + lda sreg+1 + sta SD_ARG+3 + + pla + sta SD_CMD + rts