#72154 - genfish - Thu Feb 16, 2006 7:18 pm
Is it possible to use fopen and fread on the DS with GBFS?
I have written a TGA reading function and want to try to get 16bit tga sprites displayed in framebuffer mode.
As fopen usually takes a const char*, would i be able to pass a uint8* for example to open and read the file?
thanks for your help
edit: If not, how do any of u guys do file reading?
_________________
there is no rl only afk
#72161 - Webez - Thu Feb 16, 2006 7:51 pm
I load files using gbfs and then read bytes with memcpy.
#72162 - waruwaru - Thu Feb 16, 2006 7:52 pm
Can't you replace/abstract all the fopen/fread/fclose calls in the TGA reading function with your own calls to functions in this example?[/url]
#72166 - GPFerror - Thu Feb 16, 2006 8:34 pm
you could use my romdiskfs port, it uses stdio like functions that are all prefaced with KOS_ (ie KOS_fopen KOS_fread) etc
http://gpf.dcemu.co.uk/ndsromdisk.shtml
and also the FAT lib uses FAT_fopen etc . But then again it wouldn't be that difficult to write a abstract api that sits on top of gbfs as well.
Troy(GPF)
#72175 - Webez - Thu Feb 16, 2006 10:02 pm
I have made this right now for gbfs
Code: |
struct GBFSFILE{
u8 *data;
int index;
u32 length;
};
GBFSFILE * fopen (const char * filename){
GBFSFILE *file=new GBFSFILE();
file->data=(u8*)gbfs_get_obj(gbfs_file,filename,&file->length);
file->index=0;
return file;
}
int fread(void * buffer, size_t size, size_t count, GBFSFILE *file){
memcpy(buffer,&file->data[file->index],size*count);
file->index+=size*count;
}
int fseek (GBFSFILE * file , long offset , int origin ){
switch (origin)
{
case 0 : file->index=0+offset;
break;
case 1 : file->index+=offset;
break;
case 2 : file->index=file->length+offset;
break;
}
}
int DS_Loader::fclose (GBFSFILE * file){
file->data=NULL;
delete file;
}
////////////////////
GBFSFILE *file;
file=fopen("name.extension");
fseek(file,10,SEEK_CUR);
int variable[3];
fread(variable,4,3,file);
fclose(file);
|
I don't know how useful they are.
#72178 - Lazy1 - Thu Feb 16, 2006 10:31 pm
I'm currently working on a filesystem wrapper which should do basically the same thing.
The idea is to call Initialize() on each supported filesystem, if Initialize() returns nonzero the correct filesystem has been detected and you can use stdio like functions without worrying about FS specific details.
Code: |
void blah( void ) {
DS_FILE fileHandle = 0;
fileHandle = FS->fopen( "/test.bin", F_READONLY );
...
...
}
|
Currently I have chishm's FAT driver working and the GBFS wrappers are completed but untested.
#72183 - genfish - Thu Feb 16, 2006 10:49 pm
ooo some helpful stuff, thanks guys. I'll give a couple of them a shot.
_________________
there is no rl only afk
#72208 - tepples - Fri Feb 17, 2006 1:32 am
Lazy1 wrote: |
I'm currently working on a filesystem wrapper which should do basically the same thing.
The idea is to call Initialize() on each supported filesystem |
Good idea. What license? And are you planning to make it DS-specific or C++-only or both?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#72211 - Lazy1 - Fri Feb 17, 2006 1:48 am
License: I haven't decided on a license or if I'll use one.
DS Specific: At the moment yes, though it would be easy to port it.
C++ only: It is written in C.
I have no idea when I'll finish it, gotta figure out how to test GBFS without a flashcart.
#72220 - tepples - Fri Feb 17, 2006 2:10 am
Lazy1 wrote: |
License: I haven't decided on a license or if I'll use one. |
You need to use a license, even if it's just a permissive license a la zlib, because the copyright law assumes "all rights reserved" unless the author states otherwise.
Quote: |
DS Specific: At the moment yes, though it would be easy to port it.
[...]
I have no idea when I'll finish it, gotta figure out how to test GBFS without a flashcart. |
At least on Game Boy Advance, GBFS works in multiboot mode. For instance, Tetanus On Drugs accesses a GBFS file in EWRAM. This gives you yet another reason not to make it DS-specific. I asked because I wanted to use it for GSM Player and Luminesweeper, both GBA programs, so that I could consolidate the GBFS version and the (future) GBAMP version.
Quote: |
C++ only: It is written in C. |
I was confused by the FS-> part.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#72256 - Lazy1 - Fri Feb 17, 2006 6:30 am
FS is just a pointer to filesystem functions like fopen, fclose, fread, ect...
I was thinking though, if I build the filesystem code as generic arm - could I put the FS pointer somewhere in memory where both CPUs can access it?
That way I wouldn't need to have the library compiled into the arm7 aswell as the arm9 along with the FS drivers which take up quite a bit of space.
#73323 - genfish - Fri Feb 24, 2006 7:46 pm
Webez wrote: |
fseek(file,10,SEEK_CUR);
|
what does this function do exactly, what is 'offset' and 'origin'.
thanks :)
_________________
there is no rl only afk
#73328 - josath - Fri Feb 24, 2006 8:30 pm
genfish wrote: |
Webez wrote: |
fseek(file,10,SEEK_CUR);
|
what does this function do exactly, what is 'offset' and 'origin'.
thanks :) |
http://www.google.com/search?q=fseek
#73339 - genfish - Fri Feb 24, 2006 10:40 pm
still not having any luck, gettin late now so im gonna give GPFerror's romdisk a shot tomorrow. I dunno if im using gbfs right or not, but do i basically do this... ?
- make the .gbfs file e.g. gbfs test.gbfs test.txt
- compile my code
- padbin the .nds file
- use cat to append the gbfs e.g. cat test.nds test.gbfs >test_tmp.nds
- move back to original filename from the tmp using mv
- then dsbuild, and trasnfer to the flash cart.
is that right?
_________________
there is no rl only afk
#73342 - Webez - Fri Feb 24, 2006 11:00 pm
This is what I do
gbfs.exe temp.gbfs files/*.*
padbin 256 nds.nds
cat nds.nds temp.gbfs >temp.nds
del temp.gbfs
del nds.nds
cat ndsmall.bin temp.nds >nds.ds.gba
Try it with an example that already works, but using gbfs instead of a header and .bin
#73464 - genfish - Sat Feb 25, 2006 9:16 pm
call me stupid, but once i have gone through these steps, the only thing i send to the neoflash cart is the test.ds.gba file yes?
also webez, why have u appended a .bin file in the example above if it uses gbfs?
thanks again :/
edit: thought i better include some code...
i've simplified it so much now, i just have:
arm9main:
Code: |
char str[] = { 's', 't', 'r', 'i', 'n', 'g', '\0' };
WAIT_CR &= ~0x80;
GBFS_FILE const *gbfs_file = find_first_gbfs_file((void*)0x08000000);
u8 *data = (u8*)gbfs_get_obj(gbfs_file, "test.txt", NULL);
memcpy(str, data, 5);
iprintf("\n\n\tHello World!\n");
iprintf("Filereading Test: %s\n", str);
|
then i've been doing this...
Quote: |
gbfs tga.gbfs test.txt
padbin 256 DStga.nds
cat DStga.nds tga.gbfs >DStga_tmp.nds
mv DStga_tmp.nds DStga.nds
dsbuild DStga.nds -o DStga.nds.gba
|
(test.txt contains just the word hello)
i then transfer DStga.nds.gba to my neoflash using the NEO Power Kit, and the output is:
Hello World!
Filereading test: _____g
edit2: (hehe) after reading a few forums threads, could it be that im using the libnds template makefiles to compile my code? just another random thought in the desparation of solving my problem :/
_________________
there is no rl only afk
#73477 - Webez - Sun Feb 26, 2006 12:09 am
It is a loader for flashcarts. I don't know if it still necessary but I use it.
http://darkfader.net/ds/files/ndsmall.bin
I use libnds templates and they work perfectly. Try the commands I have put before. You could also try the .nds file in desmume
#73555 - genfish - Sun Feb 26, 2006 5:27 pm
i knew i wasnt crazy!!!! lol
i tried an old nds file from this program in desmume, and it worked!
the text displays is "hellog" which is right as i only told it to copy 5 chars.
Only thing is tho, it didnt have the framebuffer mode active on the main screen. Does desmume not supprt framebuffer mode?
_________________
there is no rl only afk
#73562 - Webez - Sun Feb 26, 2006 6:16 pm
There are 2 versions of desmume. Try both of them. You could also try the new version of dualis that it finally supports gbfs
#73565 - genfish - Sun Feb 26, 2006 6:22 pm
dualis works, which is good. i just tried it now.
At least i can get on with developing and worry about transferring to the neoflash later.
thanks for all your help, its much appreciated.
_________________
there is no rl only afk
#74216 - genfish - Fri Mar 03, 2006 4:15 pm
update on this... i got it to work :D
i simplified it to have a text file containing 'hello' and just read that.
the problem was, i was appending the gbfs file to the .nds BEFORE i ran dsbuild. this is bad!!
So for those of you with a neoflash kit, how it should be done....
1. compile your code (with a makefile)
2. create the .gbfs file
3. run dsbuild on your .nds file
4. padbin the .ds.gba file
5. append the gbfs file to the .ds.gba file.
6. trasnfer using neopowerkit
7. et voila
_________________
there is no rl only afk
#89547 - JessTicular - Sun Jun 25, 2006 12:37 pm
Hey there,
I know it's a 3 1/2 month old thread, and I hate to bump it like this, but...
You can now automate this whole process for every build;
I just the other day made a modification to the template combined Makefile provided by wintermute via the CVS examples.
(The Makefile that you use as a control to call the Makefiles for the arm7 & arm9's individually)
It's a basic fix that forces a dependancy to be added at the highest level - The .ds.gba file must first be built, then the gbfs archive can be created, then it can be appended.
Simply make sure you have the gbfs.exe & padbin.exe in your devkitARM/bin directory, create a folder called 'data' at your top-most level of source to hold all the files to be gbfs'd, and use this Makefile to put it all together.
Download the Makefile
The final output file with the gbfs appended will now be <ProjectName>.gbfs.ds.gba
Along with keeping your un-gbfs'd <ProjectName>.ds.gba & <ProjectName>.nds binaries in tact.
Also, if you don't have any files in the /data directory, gbfs will throw an error. But, don't worry, it just means that it couldn't find anything to append, so it didn't append anything :P
That explanation in plain english;
Your directory should have been:
- ./arm7/
- ./arm9/
- ./Makefile
and now, it should be:
- ./arm7/
- ./arm9/
- ./data/
- ./Makefile (The new Makefile)
... Enjoy :)