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 > Using data files beyond 4Mb memory limit

#76309 - melw - Mon Mar 20, 2006 1:17 pm

Hi,

So far I've included all my data files (graphics, sounds, binaries all alike) in the code and got myself finally into a situation where DS is starting to run out of memory - mostly thanks to sound data sucking up space. The question is, what are the alternatives when having more than 4 megs of data?

I've been using Chishms FAT library, but having separate data files is tad ugly - how do you use your data when packing everything in a single .nds file?

#76313 - genfish - Mon Mar 20, 2006 1:35 pm

if you have a huge sound file try streaming it maybe?
_________________
there is no rl only afk

#76386 - josath - Tue Mar 21, 2006 6:35 am

There's two options:
1. When loading from a flashcart, you can append the data to the end of your .nds file, and it gets mapped into memory with 0x08000000 being the beginning of your .nds file
2. When loading from a device like GBAMP, you can append the data to the end of your .nds file, and just open the .nds file itself using the FAT_open(), FAT_read(), etc commands.

Ideally, your code would detect which situation it was, and use the appropriate method.

Either way, I'd suggest using some 'mini-filesystem,' look up GBFS, it was designed for just such an occasion.

#76396 - EyeballKid - Tue Mar 21, 2006 9:16 am

josath wrote:
There's two options:
1. When loading from a flashcart, you can append the data to the end of your .nds file, and it gets mapped into memory with 0x08000000 being the beginning of your .nds file
2. When loading from a device like GBAMP, you can append the data to the end of your .nds file, and just open the .nds file itself using the FAT_open(), FAT_read(), etc commands.


Can anyone clarify for me how nds files are handled? Presumably the main (compiled) part is copied out of ROM into the 4Mb RAM block. If there is extra data tacked onto the end of the nds file, is that copied into RAM too or just left in ROM?

#76397 - melw - Tue Mar 21, 2006 9:36 am

josath wrote:
There's two options:
1. When loading from a flashcart, you can append the data to the end of your .nds file, and it gets mapped into memory with 0x08000000 being the beginning of your .nds file
2. When loading from a device like GBAMP, you can append the data to the end of your .nds file, and just open the .nds file itself using the FAT_open(), FAT_read(), etc commands.

Ideally, your code would detect which situation it was, and use the appropriate method.

Either way, I'd suggest using some 'mini-filesystem,' look up GBFS, it was designed for just such an occasion.


Thanks! Now when thinking of it, this sounds very simple... One more follow-up question though - where do I get the correct offset for the appended data? Checking quickly the NDS Format specs there's a 4 byte ROM Size at position 0x080... well, I will try that. :)

EyeballKid wrote:
Can anyone clarify for me how nds files are handled? Presumably the main (compiled) part is copied out of ROM into the 4Mb RAM block. If there is extra data tacked onto the end of the nds file, is that copied into RAM too or just left in ROM?


Well, that was my initial reason for asking this - all data appended after the end of the .nds file is not loaded into memory unless you do so yourself - which is what I want to do in my case for all the sound files as they're growing to several megabytes in size.

#76410 - genfish - Tue Mar 21, 2006 2:25 pm

PM me your email address and i'll send you the code i use for gbfs if you like. Been developing it for a project i'm doing.
_________________
there is no rl only afk

#76424 - GPFerror - Tue Mar 21, 2006 4:40 pm

i use my romfs and FAT lib , but i just set them up like this

Code:
#ifdef EMU
#include <kos/kosstdio.h>
#else
#include "gba_nds_fat/gba_nds_fat.h"
#endif
#include <stdio.h>

#undef FILE
#undef DIR
#undef size_t
#undef fopen
#undef fread
#undef fwrite
#undef fclose
#undef ftell
#undef rewind
#undef fseek
#undef chdir
#undef ftell
#undef getc
#undef tmpfile
#undef rewind
#undef putc
#undef fputc
#undef fscanf
#undef feof
#undef stdin
#undef stdout
#undef fflush

#ifdef EMU
#define FILE KOS_FILE
#define fopen KOS_fopen
#define fwrite KOS_fwrite
#define fread KOS_fread
#define fclose KOS_fclose
#define fseek KOS_fseek
#define fputs KOS_fputs
#define fgets KOS_fgets
#define fputc KOS_fputc
#define getc KOS_getc
#define putc KOS_putc
#define fgetc KOS_fgetc
#define fprintf KOS_fprintf
#define vfprintf KOS_fprintf
#define ftell KOS_ftell
#define tmpfile KOS_tmpfile
#define rewind KOS_rewind
#define feof KOS_feof
#define stdin KOS_stdin
#define stdout KOS_stdout
#define fscanf KOS_fscanf
#define fflush KOS_fflush
#else
#define FILE FAT_FILE
#define fopen FAT_fopen
#define fwrite FAT_fwrite
#define fread FAT_fread
#define fclose FAT_fclose
#define fseek FAT_fseek
#define fputs FAT_fputs
#define fgets FAT_fgets
#define fputc FAT_fputc
#define getc FAT_getc
#define putc FAT_putc
#define fgetc FAT_fgetc
#define fprintf FAT_fprintf
#define vfprintf FAT_fprintf
#define ftell FAT_ftell
#define tmpfile FAT_tmpfile
#define rewind FAT_rewind
#define feof FAT_feof
#define stdin FAT_stdin
#define stdout FAT_stdout
#define fscanf FAT_fscanf
#define fflush FAT_fflush
#endif


and in my main() i do

Code:
#ifdef EMU
  fs_init();
  // Map Game Cartridge memory to ARM9
  sysSetCartOwner( BUS_OWNER_ARM9 );

  fs_romdisk_mount("/rd", (uint8*)find_first_romfs_file((uint8*)0x08000000), 0); 
#else
   if (!FAT_InitFiles())
   {
      iprintf("Unable to initialize media device!");
      return -1;
   }
#endif


then if Im compile for fat i undefine EMU or define it if I want to use the romfs, which uses genromfs to packed a directory into one file that can be appended to the end of the .ds.gba or .nds file. For use in emulators or hardware(except gbamp). And I can for the most part use stdio function names which allows for easier porting or future filesystems.

note. I have added some missing functions to the FAT lib so that my above defines can be used. But the romfs has them implemented already.

you can download romfs from my site
http://gpf.dcemu.co.uk/ndsromdisk.shtml

Troy(GPF)