Add SD card software interface

Adds a function to send a command to the sd card.
This commit is contained in:
Byron Lathi
2022-04-10 17:55:51 -05:00
parent cd11670fb1
commit 7092cc8f77
4 changed files with 42 additions and 0 deletions

View File

@@ -11,4 +11,7 @@ SW = LED
MM_CTRL = $7ff7
MM_DATA = $7fe0
SD_ARG = $7ff8
SD_CMD = $7ffc
IRQ_STATUS = $7fff

View File

@@ -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();

8
sw/sd_card.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef _SD_CARD_H
#define _SD_CARD_H
#include <stdint.h>
void sd_card_command(uint32_t arg, uint8_t cmd);
#endif

27
sw/sd_card.s Normal file
View File

@@ -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