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 > fifo example

#167261 - hacker013 - Sat Mar 07, 2009 11:10 am

hey everybody,

Has somebody some fifo examples for me because they aren't include with devkitARM.

gr,

hacker013.
_________________
Website / Blog

Let the nds be with you.

#167282 - Miked0801 - Sat Mar 07, 2009 6:49 pm

FIFO
Code:

int stack[64];
int stackPtr=0;

void push(int a)
{
    stack[stackPtr++] = a;
}

int pop()
{
    return  stack[--stackPtr];
}

#167283 - Dwedit - Sat Mar 07, 2009 7:08 pm

I think this is referring to the NDS's FIFO hardware for the ARM7 talking to the ARM9, not just a general implementation of a queue.

Anyway, for sending 32 bit values around, you use this:

fifoSetValue32Handler( CHANNEL, FUNCTION, USER_DATA );
fifoSendValue32( CHANNEL, VALUE32)

For CHANNEL, you want to use FIFO_USER_01 through FIFO_USER_08 as the channel. These are enumerations, values 8 through 15. You should probably redefine the name, because user1 is a stupid name.

FUNCTION is a function pointer for:
void myfunction(u32 value, void *user_data);

USER_DATA is a void pointer which gets passed into myfunction.


There are also FIFO handlers and senders for "Addresses", 32 bit integers, and arbitrary sized packets. Read fifocommon.h for more information.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#167285 - Echo49 - Sat Mar 07, 2009 8:09 pm

When would you use USER_DATA? Every use of the FIFO I've seen passes NULL.

btw Mike's example is a stack (LIFO) and not a queue (FIFO) :P

#167303 - Miked0801 - Sun Mar 08, 2009 4:14 pm

Bleh. I knew it was too easy as a stack.

int queue[32]
int queueFront = 0;;
int queueBack = 0;

void push(int a)
{
queue[queueFront++] = a;
queueFront &= 0x1F;
}

int pop()
{
int retVal = queue[queueBack++];
queueBack &= 0x1F;

return retVal;
}