gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > asm to C

#106790 - Lick - Mon Oct 23, 2006 1:53 pm

I found this code in the Supercard IO source package. Wondering what it does, anyone who can translate this short function to C?

Code:
scms_sdcard_reset:
    ldr r0, =0x4000204
    ldrh r1, [r0]
    bic r1, r1, #0x1c
    strh r1, [r0]              @micro sd/rumble must set
    ldr r0, =sd_reset
    strh r0, [r0]
    bx r14

_________________
http://licklick.wordpress.com

#106794 - sgeos - Mon Oct 23, 2006 2:51 pm

My ASM sucks. I think it translates to:
Code:
void scms_sdcard_reset(void)
{
   int *r0_ptr   = 0x4000204;
   int  r1_value = *r0_ptr;
   r1_value &= ~0x1c;
   *r0_ptr = r1_value;
   r0_ptr = sd_reset;  // global?!
   *r0_ptr = (int)r0_ptr;  // really?!
   return;  // bx r14
}

ldrh a, [b]
I forgot what ldrh and strh mean. ldr is load register. str is store register. h is either "high" or "halfword" or someting else entirely. =P
"high" would translate to:
*b_ptr = a_value << 16;
Halfword would translate to:
*b_ptr = a_value & 0xFFFF;

It looks like it sets *(int *)0x4000204 to 0x1c and then loads the value of sd_reset to the memory address of sd_reset. I'm sort of hoping I'm wrong about sd_reset, because that operation is completely illogical to me.

-Brendan

#106797 - masscat - Mon Oct 23, 2006 3:14 pm

sgeos wrote:
I'm sort of hoping I'm wrong about sd_reset, because that operation is completely illogical to me.

The action of performing the write is probably the important thing (cause the sd reset?) and the value of the data written is not important.

ldrh and strh are load and store halfword i.e. 16bit value.

0x4000204 is the WAIT_CR register and clearing bits with mask 0x1c is setting the GBA slot ROM waitstates according to gbatek.

#106802 - Lick - Mon Oct 23, 2006 4:47 pm

The value for sd_reset:
Code:
.equ sd_reset,0x9440000

So it becomes this?
Code:
   WAIT_CR &= ~0x1c;
   *((u32*)0x9440000) = (u32)0x9440000;



Here's another one:
Code:
@----------------void scms_mode(u16 data)---------------
      .ALIGN
@      .GLOBAL    scms_mode
      .CODE 32
scms_mode:
   mvn     r2,#0x0F6000000
   sub     r2,r2,#0x01
   mov     r1,#0x0A500
   add     r1,r1,#0x5A
   strh    r1,[r2]
   strh    r1,[r2]
   strh    r0,[r2]
   strh    r0,[r2]
   bx   r14


Thanks a lot, sgeos! Your ASM is at least better than mine, hehe.
- Lick
_________________
http://licklick.wordpress.com

#106805 - Cearn - Mon Oct 23, 2006 5:33 pm

Lick wrote:

Code:

scms_sdcard_reset:
    ldr r0, =0x4000204
    ldrh r1, [r0]
    bic r1, r1, #0x1c
    strh r1, [r0]              @micro sd/rumble must set
    ldr r0, =sd_reset
    strh r0, [r0]
    bx r14

@----------------void scms_mode(u16 data)---------------
      .ALIGN
@      .GLOBAL    scms_mode
      .CODE 32
scms_mode:
   mvn     r2,#0x0F6000000
   sub     r2,r2,#0x01
   mov     r1,#0x0A500
   add     r1,r1,#0x5A
   strh    r1,[r2]
   strh    r1,[r2]
   strh    r0,[r2]
   strh    r0,[r2]
   bx   r14



Code:
// (~0xF6000000)-1 = 0x09FFFFFF-1 = (0x0A000000-2)

#define sd_reset   *(vu16*)0x09440000
#define sd_mode    *(vu16*)(0x0A000000-2)

void scms_sdcard_reset()
{
   REG_WAITCNT &= ~0x1C;  // 4,2 waitstate
   sd_reset= 0;   // strh means halfword store; (u16)0x09440000 is 0
}

void scms_mode(u16 data)
{
    sd_mode= 0xA55A;
    sd_mode= 0xA55A;
    sd_mode= data;
    sd_mode= data;
}

#106811 - Lick - Mon Oct 23, 2006 5:53 pm

Big thank you to you Cearn! Dank je wel!

- Lick
_________________
http://licklick.wordpress.com