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 > Problems with memmov

#142922 - racerxdl - Mon Oct 15, 2007 4:25 am

I have some problems with memmove, My Code:
Code:

   FILE* test = fopen ("rom.bin", "rb");
   iprintf("\nInicializado.");
   iprintf("\nDirecionando para 0x020000");
   if(memmove(*(volatile int *)0x20F0000, test, 1177005))
   {
   iprintf("\nDirecionado.");
   iprintf("\n\nArm7");
   *(volatile int *)0x2900000 = 0xFFFF3210;
   }else{
   iprintf("Erro!!!!!!");
   return 1;


But it frezzes on memmove, I didnt receive the message "Direcionado".

I made something wrong?

#142929 - wintermute - Mon Oct 15, 2007 6:16 am

Try to avoid magic numbers.

0x02900000 isn't a valid address with the default MPU configuration and 0x20f0000 is fairly likely to be somewhere in the middle of libfat data, if not in your program itself.

What is it you're trying to do?
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#142974 - racerxdl - Mon Oct 15, 2007 7:47 pm

I Trying to load the file and put the arm7 to execute it (the file its a rom made for arm7), but the libfat doesnt say the address of the opened file.

Its there another way to load a file and get arm7 to execute it?

My arm7 code:

Code:

#include <nds.h>
#include <stdlib.h>
void reboot() {
    irqDisable(IRQ_ALL);
    *(vu32*)0x27FFE34 = 0x020F0000;
    swiSoftReset();
}
int main() {
while (*(volatile int *)0x2900000 != 0xFFFF3210);
reboot();
return 0;
}

#142977 - DragonMinded - Mon Oct 15, 2007 8:03 pm

Look at chishm's launcher code. It does just what you are asking about.
_________________
Enter the mind of the dragon.

http://dragonminded.blogspot.com

Seriously guys, how hard is it to simply TRY something yourself?

#142985 - kusma - Mon Oct 15, 2007 9:32 pm

racerxdl wrote:
but the libfat doesnt say the address of the opened file.

What do you mean "address of the opened file"? fopen() doesn't load the entire file into RAM, it provides you with a handle for use with fread(), which loads data from disk to RAM.

#142994 - Rajveer - Mon Oct 15, 2007 11:05 pm

This is my file loading function:

Code:


FILE *file_Pointer; //Pointer to an opened file
long file_Length; //Variable to store length of opened file

char* load_File(char* file_Location)
{
   //Open file location inputted, check if exists
   file_Pointer = fopen(file_Location, "rb")

   //Find length of file
   fseek(file_Pointer, 0L, SEEK_END);
   file_Length = ftell(file_Pointer);
   rewind(file_Pointer);

   //Create space for file storage in RAM, read into RAM and close filestream
   char *mem = malloc(file_Length + 1);
   fread(mem, file_Length, 1, file_Pointer);
   
   fclose(file_Pointer);
   
   return mem;
}


The location of the file in RAM is mem, which is returned by the function into a character variable.