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 > Problems using GBFS

#14481 - animension - Wed Jan 07, 2004 7:19 am

Tepples,

I decided to give your GBFS library a try and I ran into some problems using it. In my make file I have the following entry:
Code:

GBFS_OUTFILE = archive.gbfs
GBFS_INFILES = \
   module.it

all : $(PROGNAME).$(EXT) clean
   gbfs.exe $(GBFS_OUTFILE) $(GBFS_INFILES)
   cmd /c "copy /b /y $(PROGNAME).$(EXT)+$(GBFS_OUTFILE) TEMP.$(EXT)"
   cmd /c "move TEMP.$(EXT) $(PROGNAME).$(EXT)"



which compiles the ROM image, creates the GBFS archive file, and concatenates it to the end of the ROM image. I've opened the actual concatenated ROM image in a text editor to see that the "PinEight" string is there as well as the contents of the file. The CPP code I'm using to try and access the content of the file is:

Code:

// C++ CODE WHICH USES EXPLICIT CASTS
unsigned int file_length = 0;
const GBFS_FILE *myfile = find_first_gbfs_file((const void *)find_first_gbfs_file);
const char *module = (const char *)gbfs_get_obj(myfile, "module.it", &file_length);

ham_DrawText(0,0,"LENGTH:%d",file_length);
ham_DrawText(0,1,"FILE ADDRESS:%x",myfile);
ham_DrawText(0,2,"MODULE ADDRESS:%x",module);


While this code does use HAM, it's only to display address information to see whether or not a valid address returns from either find_first_gbfs_file() or gbfs_get_obj(). What happens is that both addresses show up as 0, or are NULL pointers. I can't see what's going wrong, seeing I studied your demo that uses it, and I'm doing or at least I *think* I'm doing the exact same thing.

Did I miss something?
_________________
"Beer is proof that God loves us and wants us to be happy."
-- Benjamin Franklin

#14485 - Torlus - Wed Jan 07, 2004 9:31 am

Well I could maybe help, as I did some stuff with GBFS few days ago :)

You have to use the "padbin" program in GBFS distribution to ensure that your ROM file's length is a multiple of 256 (by ROM file, I mean your $(PROGNAME) file), as find_first_gbfs_file searches for the "magic word" every 256 bytes (as far as I can remember).

Hope this helps
_________________
GBA,GC,NGPC,GP32,FPGA,DS stuff at http://torlus.com/

#14499 - tepples - Wed Jan 07, 2004 5:41 pm

Torlus is right. I chose the 256-byte linear search stride (GBFS_ALIGNMENT in gbfs.c) as a compromise between searching through a big ROM (should proceed quickly) and searching through a smaller multiboot program (shouldn't increase binary footprint by much).

Another linear search tip: If you know about how big your program is (before any GBFS files are appended) and thus an address close to its end, you can use that address as an argument to find_first_gbfs_file(), but just as in "The Price Is Right", don't go over.

When DKA R5 becomes final, I will release a new version of GBFS to take advantage of its more explicit support for appended data, replacing the linear search step with a much quicker call to a function in crt0.s.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#14509 - RaBBi - Wed Jan 07, 2004 7:35 pm

animension, I see you're using Ham Dev Kit.

You can go to the ngine.de forums, and you'll find a topic about using LUA scripts with Ham (Author is "Les").

The demo inside demonstrates how to use GBFS too.
I tested it and it works fine.

I think it could help you ^^
_________________
Sorry for my poor english, but it would be worst for you to understand me if I speak in my native language, French ^^

#14541 - animension - Thu Jan 08, 2004 4:32 am

Thanks guys for all the help! That was exactly what I needed to do to get the ROM to find the file.

One other question tho: I'm using GDB+Insight to debug the ROM, but even padding the ELF file to 256 and then appending won't let the debug build find the file. Is there an additional step I'm not seeing that needs to be done so when I debug it'll find the file?
_________________
"Beer is proof that God loves us and wants us to be happy."
-- Benjamin Franklin

#14547 - tepples - Thu Jan 08, 2004 6:58 am

GDB is not compatible with find_first_gbfs_file(). GDB works only on .elf; appended data works only on raw binary. If you depend on debugging .elf, you'll have to use a bin2s tool to compile your GBFS files to linkable objects and supply all artists with linkers.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.