Trying to access data from the MicroSD inside the R4 directly, without using libfat.
It appears that the card is accepting commands, and responding, but no data is being read... help?
Code:
@ ------------------------------------------------------------------------------
@ card.s - Talks to the R4.
@
@ See function for parameters and list of destroyed registers.
@ ------------------------------------------------------------------------------
@ ------------------------------------------------------------------------------
@ Global declarations
@ ------------------------------------------------------------------------------
.global _card_write_command
.global _card_read_data
@ ------------------------------------------------------------------------------
@ Sends a command to the DS card.
@
@ r0 - Command
@ r1 - Address
@ r2 - Flags
@
@ Destroys r4-r5
@ ------------------------------------------------------------------------------
_card_write_command:
mov r4, #0x04000001 @ Prepare to write to card
add r4, r4, #0x1A0
mov r5, #(0x0080 | 0x0040)
strb r5, [r4, #0x00]
strb r0, [r4, #0x07] @ Write the command and address
mov r5, r1, lsr #24 @ while accounting for the
strb r5, [r4, #0x09] @ endian-ness of the card reader
mov r5, r1, lsr #16
strb r5, [r4, #0x0B]
mov r5, r1, lsr #8
strb r5, [r4, #0x0D]
mov r5, r1, lsr #0
strb r5, [r4, #0x0F]
str r2, [r4, #0x03] @ Write card control flags
_card_write_command_wait:
ldr r5, [r4, #0x03] @ Check card control register
ands r5, r5, #(1 << 23) @ to see if we can proceed
beq _card_write_command_wait
mov pc, lr
@ ------------------------------------------------------------------------------
@ Reads from the DS (R4) card by sending commands to it.
@
@ r1 - Address
@ r6 - Destination
@ r7 - Length
@
@ Destroys r4-r6
@ ------------------------------------------------------------------------------
_card_read_data:
mov r8, lr
mov r0, #0xB9 @ Write commands and flags
ldr r2, =0xa7586000
bl _card_write_command
mov r0, #0xBA @ Write commands and flags
ldr r2, =0xa1586000 @ Undocumented values... not
bl _card_write_command @ sure what they do...
mov r4, #0x04000001 @ Prepare to write to card
add r4, r4, #0x1A0
str r2, [r4, #0x03] @ Write card control flags
_card_read_data_loop:
mov r4, #0x4000001 @ Check card control register
add r4, r4, #0x1A0 @ to see if the card is ready
ldr r5, [r4, #0x03] @ for us to read data
ands r5, r5, #(1 << 23)
beq _card_read_data_wait
mov r4, #0x04100000 @ Card is ready, copy data
ldr r5, [r4, #0x10] @ to the destination location
str r5, [r6, #4]!
subs r7, r7, #4
beq _card_read_data_done
_card_read_data_wait:
mov r4, #0x4000001 @ Check card control register
add r4, r4, #0x1A0 @ to see if the card is still
ldr r5, [r4, #0x03] @ busy... if not, we're done
ands r5, r5, #(1 << 31)
bne _card_read_data_loop
_card_read_data_done:
mov pc, r8