#79104 - sofakng - Tue Apr 11, 2006 6:54 pm
I'm making a game that I would like to be compatible with as many flash cards as possible and it seems like the FAT system is only compatible with the compact flash cards...
The other filesystem I've seen is PALib's Filesystem but it seems to have a ton of problems...
What other options do I have?
#79107 - GPFerror - Tue Apr 11, 2006 7:04 pm
romfs ,gbfs or bin2s the file and using it directly.
you can get the romfs from my page http://gpf.dcemu.co.uk/ndsromdisk.shtml it uses a variation of the stdio library api, ie KOS_fopen, KOS_fread etc. you can also #undef the ones defined by stdio and redefine the ones used in my lib.
ie
#undef fopen
#define fopen KOS_fopen
Troy(GPF)
#79191 - josath - Wed Apr 12, 2006 1:52 am
fat lib is actually compatible with flash cards as well, it even uses SRAM as an overlay, so you have limited writing abilities as well. It's Just there is no tool to build the filesystem yet. (bug chishm :P )
#79263 - sofakng - Wed Apr 12, 2006 3:40 pm
GPFerror wrote: |
romfs ,gbfs or bin2s the file and using it directly.
you can get the romfs from my page http://gpf.dcemu.co.uk/ndsromdisk.shtml it uses a variation of the stdio library api, ie KOS_fopen, KOS_fread etc. you can also #undef the ones defined by stdio and redefine the ones used in my lib.
ie
#undef fopen
#define fopen KOS_fopen
Troy(GPF) |
So far KosFS is working great!
However, there seems to be a bug in kos_fgets().
Take a look at this code:
Code: |
char buf[1024]
while ( fgets(buf, 1024, fp) ) {
// whatever
}
|
That will give me an infinite loop... it looks like fgets is never returning false (eg. 0).
By any chance can you take a look at this?
#79291 - GPFerror - Wed Apr 12, 2006 6:51 pm
well fgets calls fgetc which calls fread, so im not sure yet.
I hadnt actually tested that command before, so Ill try to look into it this week.
I think that the functions return EOF which equals -1 , so that might be the problem if the while loop is looking for a return of 0; I forget what the standard fgets function returns.
Troy
#79298 - sofakng - Wed Apr 12, 2006 7:10 pm
After doing a bunch of testing, I finally figured out the problem...
Here was the problem:
Code: |
ch = s[i] = KOS_fgetc (file); |
It was simply changed to:
Code: |
ch = KOS_fgetc (file);
s[i] = ch;
|
I'm not extremely familar with C so I'm not sure why my fix works but it does... (and I guess thats all that matters :))
#79303 - tepples - Wed Apr 12, 2006 7:23 pm
fgetc() returns an int and uses the more significant bits (MSBs) of the return value to signal whether end of file has occurred. Assigning to a char variable and then reading back from that char variable discards the MSBs.
Codes A and B are equivalent[1], and codes C and D are equivalent:
Code: |
// A
ch = s[i] = KOS_fgetc (file);
// B
s[i] = KOS_fgetc (file);
ch = s[i];
// C
s[i] = ch = KOS_fgetc (file);
// D
ch = KOS_fgetc (file);
s[i] = ch;
|
[1] Modulo volatility.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#79310 - sofakng - Wed Apr 12, 2006 8:40 pm
Thanks for the explanation!
I have one more question for GPFerror about KOS_FS...
Do you have a FileExists function? (simple function that returns if a file exists... I'm not sure if I need it to return the file_type as well [like in chism's FAT driver])
Also, do you have a remove() function? It's prototyped in your code but the actual function doesn't exist.
Thanks again for all of your help!
#79319 - GPFerror - Wed Apr 12, 2006 10:26 pm
sofakng wrote: |
Thanks for the explanation!
I have one more question for GPFerror about KOS_FS...
Do you have a FileExists function? (simple function that returns if a file exists... I'm not sure if I need it to return the file_type as well [like in chism's FAT driver])
Also, do you have a remove() function? It's prototyped in your code but the actual function doesn't exist.
Thanks again for all of your help! |
no i dont have one, you can use the opendir, readdir functions maybe for that, or just try fopen the file and if it returns a handle it exists :)
there isnt a remove function, since its a permanent romdisk, the code that i originally ported is setup so you can add filesystems to it, its what we use for the dreamcast.
included in the filesystem is a ramdisk also though, that you can read and write to, just specify /ram
copy a file from romdisk to ramdisk
fs_copy("/rd/test.bin","/ram/test.bin);
to remove the file from the ramdisk you can do fs_unlink("/ram/test.bin");
within the code i use KOS_tmpfile(), which can show you better probably.
Troy(GPF)
#79333 - sofakng - Wed Apr 12, 2006 11:27 pm
Oh... so you can't save files except to the ROM disk? It looked like you had KOS_fwrite and other functions that would allow writing...
#79341 - GPFerror - Thu Apr 13, 2006 1:00 am
sofakng wrote: |
Oh... so you can't save files except to the ROM disk? It looked like you had KOS_fwrite and other functions that would allow writing... |
only can save to the RAMDISK, which disappears after you shutdown the ds. and our limited by the ram left in the ds.
Troy(GPF)