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.

Coding > GBA and file systems

#177327 - atomen - Sat Apr 14, 2012 5:49 pm

Hi!

I've been doing some GBA coding lately and now I've started working with files which requires far more
memory than what is possible with normal binary files (.h and .c). Therefore I've started looking on some
file systems for the GBA. From my understanding there are two different viable choices; GBFS and libfat (both
are supplied with the devkitPro toolchain). Since GBFS has far more examples than libfat (excluding NDS),
GBFS seems like a better choice, but I have two problems.

With GBFS I've had no success using either gbfs, ungbfs and lsgbfs (these are all tools supplied with
GBFS). The gbfs tool creates invalid .gba files (which does not work). Both ungbfs and lsgbfs has no
output (even if I am using them on a valid .gba file; in this case, the one which is supplied with GBFS
(NOTE: the gba file supplied with GBFS works flawlessly on the emulators I've tried)).

After looking on the source code for the tools, the function which check the information of the appended
data (in the .gba file) return 0 (file count and file offset, in lsgbfs.c and ungbfs.c. NOTE: the function to
observe is fgeti16). This is the output when I use the tools on the supplied .gba file. If used on a .gba
file compiled on my own, only garbage is printed using lsgbfs and ungbfs says the file can not be found.

I've tested the executables/tools using the supplied ones, and by compiling them myself. I've even tried on Ubuntu
and Windows 7 (both 64-bit, could this be an issue?). Does anyone have a clue why I can not get these to function
properly?

The other filesystem is libfat, which seems a lot more up to date. The problem with libfat is the lack of documentation
on the GBA. It seems pretty easy to use but there is one thing I do not get; how do you supply the files to the
.gba file? Is it like GBFS and you're supposed to append them to the .gba file?. And if that is the case, which application
are you supposed to use so the files are appended in the FAT format?

I'm sorry for the long post, but to conclude:
GBFS; what am I doing wrong/can you get it to work(?), and if so, how?
LibFAT; how do you use libfat with .gba files, or rather, how do you include your own files for use?

#177328 - Dwedit - Sat Apr 14, 2012 9:02 pm

You don't necessarily need to use a filesystem to store a lot of data. You can use things like "bin2o" to convert binary files into .o files that can be linked in to your project. Then you refer to the binary thing by it's name in code.
The devkitpro makefiles will do this automatically, you just tell it where the directory of binary files is, and it throws them into the project, generating tiny .h files as needed.

One common newbie mistake is to declare large amounts of data in a source file and not make it const. That forces the compiler to throw it into RAM at startup time. GBA only has 256k of RAM, so you'll hit a limitation there. But if you declare it as const, you won't hit any limitations until you reach the maximum GBA ROM size of 32MB.
But using .h and .c files for data is considered to be bad form.

LibFAT on the GBA is intended for use on the GBA flash devices which use SD or CF cards, to provide access to the filesystem on those devices.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#177329 - atomen - Sun Apr 15, 2012 12:13 pm

How stupid of me to forget get about linking the data directly into the executable!

Excuse me if I sound dumb or just thinking about it in the wrong way, but how is the data used if
you link it instead of appending it to the final binary? From what I understand, non-const arrays are
placed in IWRAM which has a very limited space (therefore the constant reminder of defining data as
'const' whenever possible), whilst const arrays are placed in EWRAM. If this is true, how do you harness
32MB (the maximum ROM size), since EWRAM is limited to only 256KB?

Yeah, I was afraid libFAT was only usable with a flash card...