#169027 - Tyler24 - Tue Jun 09, 2009 9:29 pm
I'm trying to convert the R4's DLDI code to assembly, and I've hit quite the roadblock. I can't find any documentation on the card, or its controller, so I've pretty much just copied Chisim's DLDI code for the R4. I can communicate with the R4, and I'm pretty sure that I can write commands to it correctly because my emulator (Mac DeSmuME) will output that it doesn't see the R4 card, but my actual hardware running the same binary reports that it does see the R4. Yet, for some reason, when I try to perform a logical read, all I get is a bunch of zero-ed out data.
In summary, when I try to read the first 64b of my MicroSD card, all I get is:
0000:0000 0x00000000
0000:0004 0x00000000
0000:0008 0x00000000
0000:000C 0x00000000
0000:0010 0x00000000
...
0000:0040 0x00000000
and yet startup(), isInserted(), etc. all return TRUE on my actual hardware with the R4, and return FALSE on my emulator.
Do I need to set the DRQ bit, and enable DMA access or something??
I'm rather confused... I thought I could just read data piece by piece...
In summary, when I try to read the first 64b of my MicroSD card, all I get is:
0000:0000 0x00000000
0000:0004 0x00000000
0000:0008 0x00000000
0000:000C 0x00000000
0000:0010 0x00000000
...
0000:0040 0x00000000
and yet startup(), isInserted(), etc. all return TRUE on my actual hardware with the R4, and return FALSE on my emulator.
Code: |
@ ------------------------------------------------------------------------------ @ Sends a command to the DS card. @ @ r0 - Command @ r1 - Address @ r2 - Flags @ ------------------------------------------------------------------------------ _card_write_command: stmfd sp!, {lr} ldr r3, =0x040001A1 mov r4, #(0x80 | 0x40) strb r4, [r3, #0x00] strb r0, [r3, #0x07] mov r4, r1, lsr #24 and r4, r4, #0xFF strb r4, [r3, #0x08] mov r4, r1, lsr #16 and r4, r4, #0xFF strb r4, [r3, #0x09] mov r4, r1, lsr #8 and r4, r4, #0xFF strb r4, [r3, #0x0A] mov r4, r1 and r4, r4, #0xFF strb r4, [r3, #0x0B] mov r4, #0x00 strb r4, [r3, #0x0C] strb r4, [r3, #0x0D] strb r4, [r3, #0x0E] ldmfd sp!, {lr} mov pc, lr @ ------------------------------------------------------------------------------ @ Sends a command to the DS card, waits for it to be ready. @ @ r0 - Command @ r1 - Address @ r2 - Flags @ ------------------------------------------------------------------------------ _card_wait_ready: stmfd sp!, {lr} mov r7, #0 _card_wait_ready_loop1: bl _card_write_command ldr r3, =0x040001A4 str r2, [r3, #0x00] _card_wait_ready_loop2: ldr r4, [r3, #0x00] ands r4, r4, #(1 << 23) beq _card_wait_ready_chk2 ldr r4, =0x04100010 ldr r4, [r4, #0x00] cmp r4, #0 moveq r7, #1 _card_wait_ready_chk2: ldr r4, [r3, #0x00] ands r4, r4, #(1 << 31) bne _card_wait_ready_loop2 _card_wait_ready_chk1: cmp r7, #0 beq _card_wait_ready_loop1 ldmfd sp!, {lr} mov pc, lr @ ------------------------------------------------------------------------------ @ Does a polled transfer with the card. @ @ r0 - Command @ r1 - Address @ r2 - Flags @ r5 - Destination @ r6 - Length @ ------------------------------------------------------------------------------ _card_polled_xfer: stmfd sp!, {lr} bl _card_write_command ldr r3, =0x040001A4 str r2, [r3, #0x00] add r7, r5, r6 _card_polled_xfer_loop: ldr r4, [r3, #0x00] ands r4, r4, #(1 << 23) beq _card_polled_xfer_check ldr r4, =0x04100010 ldr r4, [r4, #0x00] _card_polled_xfer_copy_check: subs r8, r7, r5 beq _card_polled_xfer_check str r4, [r5, #0x00] add r5, r5, #4 @ ------------------------------------------------------------------------------ @ DEBUG CODE THAT PRINTS THE HEX OUTPUT OF R4 GOES HERE @ ------------------------------------------------------------------------------ _card_polled_xfer_check: ldr r4, [r3, #0x00] ands r4, r4, #(1 << 31) bne _card_polled_xfer_loop ldmfd sp!, {lr} mov pc, lr @ ------------------------------------------------------------------------------ @ Performs a logical read on the card. @ @ r1 - Address @ r5 - Destination @ r6 - Length @ ------------------------------------------------------------------------------ _card_read_data: stmfd sp!, {lr} bl _read_card_info @ not really necessary mov r0, #0xB9 ldr r2, =0xa7586000 bl _card_wait_ready mov r0, #0xBA ldr r2, =0xa1586000 bl _card_polled_xfer ldmfd sp!, {lr} mov pc, lr |
Do I need to set the DRQ bit, and enable DMA access or something??
I'm rather confused... I thought I could just read data piece by piece...