#167286 - Kariddi - Sun Mar 08, 2009 1:35 am
Hi.
I'm experimenting with NDS programming and , for what i'm trying to do, I need to use some "function pointers".
What I'm trying to do is loading some code in the RAM , then launching that code by running the "main" of that code using a function pointer.
This is the code in main:
I have these pointers:
Where __table is a table that should contain addresses of functions that the program I'm loading into ram should be able to use.
TABLE_ADDRESS is defined as 0x03000000 (should be Shared WRAM, right?).
The function that can be called from the loaded program is :
and tableInit() is a function that initializes the table by loading the address of "funzione()" into __table[0] :
The code of the program I'm loading into the ram simply calls "funzione()" into its main and returns.
The strange behavior is this:
When I'm running this program into an emulator everything works like should. (I've tried No$GBA and desmume)
The program is loaded into ram, the execution switch to "main_f" (that is the main of the loaded program) "funzione()" is called from the loaded program and shows "It Works!" and then exits.
When I run this program on REAL hardware (my DS) the result is that when "tableInit()" is called instead of setting __table[0] to the right value it calls "funzione()" (really strange!!) and then when the execution passes to "main_f" the screen blanks out (probably due to the fact that tableInit() didn't do what it was meant to).
Do you have any idea why on a real DS this line :
instead of setting __table[0] at the right value calls "funzione()"???
Thanks for your help
Kariddi
I'm experimenting with NDS programming and , for what i'm trying to do, I need to use some "function pointers".
What I'm trying to do is loading some code in the RAM , then launching that code by running the "main" of that code using a function pointer.
This is the code in main:
Code: |
consoleDemoInit(); fatInitDefault(); tableInit(); iprintf("Caricamento programma\n"); load_program(prog_str); main_f(0, NULL); iprintf("Fine main\n"); |
I have these pointers:
Code: |
address** __table = (address**) TABLE_ADDRESS; address prog = NULL; main_function main_f = NULL; |
Where __table is a table that should contain addresses of functions that the program I'm loading into ram should be able to use.
TABLE_ADDRESS is defined as 0x03000000 (should be Shared WRAM, right?).
The function that can be called from the loaded program is :
Code: |
void funzione() { iprintf("It works!!\n"); } |
and tableInit() is a function that initializes the table by loading the address of "funzione()" into __table[0] :
Code: |
void tableInit() { __table[0] = (address*) &funzione; } |
The code of the program I'm loading into the ram simply calls "funzione()" into its main and returns.
The strange behavior is this:
When I'm running this program into an emulator everything works like should. (I've tried No$GBA and desmume)
The program is loaded into ram, the execution switch to "main_f" (that is the main of the loaded program) "funzione()" is called from the loaded program and shows "It Works!" and then exits.
When I run this program on REAL hardware (my DS) the result is that when "tableInit()" is called instead of setting __table[0] to the right value it calls "funzione()" (really strange!!) and then when the execution passes to "main_f" the screen blanks out (probably due to the fact that tableInit() didn't do what it was meant to).
Do you have any idea why on a real DS this line :
Code: |
__table[0] = (address*) &funzione; |
instead of setting __table[0] at the right value calls "funzione()"???
Thanks for your help
Kariddi