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 > Passing an address pointer from ARM9 to ARM7..?

#170156 - Ruben - Fri Sep 04, 2009 9:48 am

Hi~

So I started porting XMid to the DS but I need to have an address from a variable on the ARM9 exec and, since the ARM7 and ARM9 execs must be compiled separately, I can't seem to be able to do this without using FIFO, but I was wondering.. Since I'll only need this once during setting up of sound (that is, setting up the hardware channels), is there any other way to do this?

#170158 - headspin - Fri Sep 04, 2009 5:59 pm

Are you using the latest libnds? If so then just use FIFO. You can take a look at the example used in libxm7 here which uses a custom FIFO command to send over a pointer to a struct used on the ARM7.

The older method is using shared memory (IPC) which is at 0x027FF000. You can take a look at older libnds source and see how they use a struct in IPC to share memory with the ARM7. It's not the recommended method to communicate with the ARM7 anymore though.

You will need to use the "combined" template example from devkitARM to do custom stuff on the ARM7.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#170223 - Ruben - Wed Sep 09, 2009 12:17 pm

Hm, well I've been trying to use FIFO, but I think I've broken the code somewhere along the line.. anyone care to point me in the right direction?

Code:
@ File: XMid_Comm7.s

/******************************/
/* XMid v1.08f                */
/******************************/
#include "XMidLib.h"
#include "XMid_Internal.inc"
/******************************/

.global   XMid_FIFO_Receive7
.global   XMid_FIFO_Req7
.global __XMid_FIFO7_Tbl

/******************************/
.text
.align
.arm
/******************************/

XMid_FIFO_Receive7:
   adr     r1, __XMid_FIFO7_Tbl @ fetch FIFO buffer adr
   mov     r2, #0x20            @ queue length
1: ldr     r3, [r1], #0x04      @ *buffer
   cmp     r3, #0x00            @ if(*buffer != 0) {
   subnes  r2, r2, #0x01        @   if(--max) loop
   bne     1b                   @ }
   cmp     r3, #0x00            @ if(!hit end)
   streq   r0, [r1, #-0x04]     @   store
   bx      lr

__XMid_FIFO7_Tbl:
   .space   32*4

.align
.size XMid_FIFO_Receive7, .-XMid_FIFO_Receive7

/******************************/

XMid_FIFO_Req7:
   adr     r1, __XMid_FIFO7_Tbl @ adr buffer
   mov     r2, #0x20            @ size of queue
1: ldr     r3, [r1], #0x04      @ *buffer
   cmp     r0, r3, lsr #0x1C    @ if(buffer->type != type) {
   subnes  r2, r2, #0x01        @   if(--max) loop
   bne     1b                   @ }
   cmp     r0, r3, lsr #0x1C    @ double check type
   mov     r0, #0x00            @ clear return value
   streq   r0, [r1, #-0x04]     @ if(ty == bf->ty) clear from tbl
   biceq   r0, r3, #0xF0000000  @ return (buffer & ~type_mask)
   bx      lr

.align
.size XMid_FIFO_Req7, .-XMid_FIFO_Req7

/******************************/
/* EOF                        */

Code:
@ File: XMid_Comm9.s

/******************************/
/* XMid v1.08f                */
/******************************/
#include "XMidLib.h"
#include "XMid_Internal.inc"
/******************************/

.global XMid_FIFO_Receive9

/******************************/
.text
.align
.arm
/******************************/

XMid_FIFO_Receive9:
   cmp     r0, #FIFO_UPDATE
   beq     1f                      @ on update, skip return value
   adr     r1, 2f                  @ fetch table pointer
   ldr     r1, [r1, r0, lsl #0x02] @ load value from idx
   orr     r1, r1, r0, lsl #0x1C   @ ORR with type
   mov     r0, #FIFO_CHAN          @ FIFO chan (8)
   stmfd   sp!, {lr}               @ save lr
   blx     fifoSendValue32         @ return value (8, ptr + type<<28)
   ldmfd   sp!, {lr}
   bx      lr
1: stmfd   sp!, {lr}
   blx     XMid_Song               @ update players
   ldmfd   sp!, {lr}
   bx      lr
2: .word   __XMid_Var @ FIFO_VARADR
   .word   __XMid_Chn @ FIFO_CHNADR
   .word   __XMid_Bfr @ FIFO_BFRADR

.size XMid_FIFO_Receive9, .-XMid_FIFO_Receive9

/******************************/
/* EOF                        */


All I plan for them to do is:
The ARM7 sends a request for an address (out of VAR/CHN/BFR), the ARM9 returns the address into the ARM7 FIFO, and then I look through the list for the address I wanted.

For example, I use this in the ARM7 initialization code:
Code:
@ setup FIFO handler
   mov      r0, #FIFO_CHAN
   ldr      r1, =XMid_FIFO_Receive7
   ldr      r2, =fifoSetValue32Handler
   bl      .Lexit_r2
   
@ request buffer address
   mov      r0, #FIFO_CHAN
   mov      r1, #FIFO_BFRADR
   ldr      r2, =fifoSendValue32
   bl      .Lexit_r2

@ wait until it shows up
1: mov      r0, #FIFO_BFRADR
   ldr      r2, =XMid_FIFO_Req7
   bl      .Lexit_r2
   mov      r2, r0
   beq      1b @ <----- Never goes past that


All the ARM9 does with FIFO in init is this
Code:
mov      r0, #FIFO_CHAN
ldr      r1, =XMid_FIFO_Receive9
ldr      r2, =fifoSetValue32Handler
blx      r2


Btw, sorry for the code spam, but I just can't figure out any other way to explain without linking a bunch of files >>'