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 > Chishm's libfat (superior to GBA_NDS_FAT)

#91774 - chishm - Sun Jul 09, 2006 1:39 pm

After many hours, days, weeks and months of work, I have gotten the new libfat to a stage ready for testing.

To try it, get libfat-20060709.tar.bz2 from my site.

To install, extract the archive to your libnds directory, so you should have /path/to/devkitpro/libnds/include/fat.h and /path/to/devkitpro/libnds/lib/libfat.a .

To use, you'll need to #include <fat.h> in the file where the library will be initialised, and #include <stdio.h> in any source file that needs file access. In your makefile, add libfat to the list of libraries, before libnds. You'll also need to link in libnds. Eg:
Code:
LIBS   :=  -lfat -lnds9


In your program initialisation code, add a call to fatInitialise. The first parameter specifies the size of the sector cache in pages and the second parameter determines if this is to be the default file driver. For 4 cache pages and setting this as the default I/O device, use:
Code:
if (fatInitialise(4, true)) {
    // Success
} else {
    // Failure
}


It needs a minimum of 2 cache pages to operate efficiently. Memory is malloc'd for this, so you'll need malloc for it to work. Each page takes about 550 bytes of memory. Use more pages for extra speed when randomly accessing files.

Once the driver is initialised, files are accessed like in normal C implementations. Use FILE* file = fopen (path, mode); to open a file, for example. If this has been set as the default I/O device, the path is simply of the form "/path/to/file". If this isn't set as the default device, you'll need to specify the device in the path, eg "fat:/path/to/file". "fat:" tells open to open files using the FAT device. There is support for using a device in both slots at once. "fat0:" is equivalent to "fat:", and uses whichever slot it finds a valid device in first (starting with slot 1). "fat1:" specifies slot 1 (the DS Card). "fat2:" specifies slot 2 (the GBA slot). "fat3:" specifies a custom device (this isn't externally visible in the library yet).

Directory listing isn't available, since DevKitPro r19a doesn't have this functionality yet.

Keep in mind that this is still in alpha stage. Functionality will be added and possibly changed in future releases. Also, it requires at least DevKitPro r19 to function.

EDIT:
Latest version comes with DevkitARM r20. Full instructions are on my libfat page.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com


Last edited by chishm on Thu Feb 15, 2007 1:17 am; edited 2 times in total

#91782 - Sausage Boy - Sun Jul 09, 2006 3:16 pm

Great work! Which devices are supported now?
_________________
"no offense, but this is the gayest game ever"

#91784 - tepples - Sun Jul 09, 2006 3:56 pm

chishm wrote:
After many hours, days, weeks and months of work, I have gotten the new libfat to a stage ready for testing.

To try it, get libfat-20060709.tar.bz2 from my site.

For those confused by "tar.bz2", that's the extension for a popular compression format on FreeBSD and Linux. Developers on Windows can use 7-Zip to extract it.

Quote:
To install, extract the archive to your libnds directory

Is the DS-only restriction just for this test version, or have you end-of-lifed the GBA version entirely?

Quote:
It needs a minimum of 2 cache pages to operate efficiently. Memory is malloc'd for this, so you'll need malloc for it to work.

If you have not EOL'd the GBA version does anyone know how to trick malloc into starting its heap from an arbitrary EWRAM address instead of from the end of the multiboot program?

Quote:
There is support for using a device in both slots at once. "fat0:" is equivalent to "fat:", and uses whichever slot it finds a valid device in first (starting with slot 1). "fat1:" specifies slot 1 (the DS Card). "fat2:" specifies slot 2 (the GBA slot).

Is fat1: compatible with Nitro FAT on a DS Game Card or compatible flash card, or only with MS-DOS FAT in the MK2/MK3 adapter? The distinction becomes important 1. for homebrew modding of games stored on DS Game Cards, and 2. once UltraFlashPass and similar cards become popular.

Quote:
"fat3:" specifies a custom device (this isn't externally visible in the library yet).

Would this be flexible enough to accommodate CIFS or HTTP?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#91792 - parrot_ - Sun Jul 09, 2006 5:18 pm

Would the fat3 "drive" be capable of handling flat-file FAT, like a FAT GBFS?
_________________
Squak! etc.
My Blog

#91800 - HyperHacker - Sun Jul 09, 2006 8:03 pm

Can it be run without caching?

[edit] Also will we be able to determine how much disk space is available, and will you add some form of directory listing function?
_________________
I'm a PSP hacker now, but I still <3 DS.

#91804 - Dwedit - Sun Jul 09, 2006 8:34 pm

So this is just for standard library file IO functions? Any differences between this and the gba_nds_fat library?
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#91811 - tepples - Sun Jul 09, 2006 9:50 pm

As far as I can tell, this replaces at least the nds part of gba_nds_fat in the same way that SnezziDS replaces snesDS.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#91869 - chishm - Mon Jul 10, 2006 9:21 am

Ok, I'll answer the questions in order of posting.

Supported devices: Neoflash MK2/3, GBAMP CF, M3 CF, M3 SD, SC CF, Flash Carts (search the forums for FCSR).
Unconfirmed but included: Max Media Player/Dock, EFA2
Included but not working: SC SD
Unsupported: Anything else.

The DS only restriction is only for this build, since I haven't finished getting the GBA build to work. I'll probably make it used a fixed cache size and static allocated memory.

All "fat[0-3]:" devices only support MS-DOS FAT. For other filesystems, it is better to write a new filesystem driver from scratch and implement it the same way as libfat -- using the devoptab in DevKitPro (see <sys/iosupport.h>).

"fat3" is intended for using hardware devices that haven't been incorporated into the library yet. For example, if a new cart comes out that hasn't been incorporated into the library yet then it can still be used by developers by mounting the custom device.

It can't be run without caching, since the unified disc cache replaces several caches that were in the old version. In gba_nds_fat, the FAT had it's own cache, as did each openned file. That's why at least 2 pages are needed.

This is a more efficient implementation of file I/O functions. In gba_nds_fat, I had to implement fopen, fputs, etc. Now I only have open, close, read, write and a few other functions implemented, and newlib handles the rest. This means other filesystems will use the same fputs, etc functions too. In case you didn't check, fat.h only has one function, used to initialise libfat. The rest is done through callbacks provided to newlib through the devoptab. We should be very thankful that WinterMute provided the devoptab.

File listing won't be available until it is included in the devoptab.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#91878 - Normmatt - Mon Jul 10, 2006 10:40 am

Wow I like the new way of doing things, Its much easier to setup than the older lib.

Also it works fine on my m3sd, nice work on the driver chishm :)

#91897 - D-loader - Mon Jul 10, 2006 2:20 pm

are you planning to make SC:SD support in the future?

#91899 - dawn2k - Mon Jul 10, 2006 2:28 pm

What about the MiniSD/MicroSD Devices?

#91906 - Normmatt - Mon Jul 10, 2006 3:14 pm

dawn2k wrote:
What about the MiniSD/MicroSD Devices?

MiniSD to my knowledge uses the same interface as the normal sized SD cards so should work using the SD drivers

#91992 - bugmenot! - Tue Jul 11, 2006 12:00 am

thank god, maybe now more homebrew will support SD devices like the M3. Flash cart file manager anyone?

#91993 - ThetaDot - Tue Jul 11, 2006 12:09 am

Please pardon my n00b question, but what immediate effect does this have? This library handles the reading and writing through the flashcart to the media storage, right?
*runs and hides*

#92019 - HyperHacker - Tue Jul 11, 2006 4:38 am

Hm, sounds great, but I guess we'll have to use soft-shutdown functions now due to the caching (unmount, then power off, instead of using the power button)? Either way its usefulness is rather limited without a directory listing function.
_________________
I'm a PSP hacker now, but I still <3 DS.

#92022 - chishm - Tue Jul 11, 2006 4:45 am

D-loader:
I would if I had a SC:SD. I've tried a few times to get it working, but without hardware to test it on, it's practically impossible.

HyperHacker:
The cache is flushed when files are closed or deleted, so as long as you close files when you are finished with them (which you should be doing anyway) it will be fine.

ThetaDot:
I guess you could say that.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#92051 - dem1980 - Tue Jul 11, 2006 9:48 am

thank you for your work !
does this first release support G6 linker for example !
_________________
I'm not inglish, sorry for my bad inglish :-/

#92060 - chishm - Tue Jul 11, 2006 11:06 am

At least read my answers in this thread before posting questions.
Chishm wrote:
Supported devices: Neoflash MK2/3, GBAMP CF, M3 CF, M3 SD, SC CF, Flash Carts (search the forums for FCSR).
Unconfirmed but included: Max Media Player/Dock, EFA2
Included but not working: SC SD
Unsupported: Anything else.

_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#92068 - quadomatic - Tue Jul 11, 2006 11:51 am

if Max Media Dock is supported by this fat library, does that mean that the Max Media Dock can/will be as homebrew capable as the gbamp?

#92074 - tepples - Tue Jul 11, 2006 1:18 pm

First you'll have to implement exec() on top of this library, as MAX Media Player doesn't seem to support .nds files larger than 1 MB.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#92263 - chishm - Wed Jul 12, 2006 12:11 pm

I have added everything I wanted to, so here it is, the latest version:
Source
DS library
GBA library
As before, you need DevKitPro r19 to use this. The GBA version still uses malloc (it's unavoidable), but there is a bug in DKP r19(a) that causes malloc to fail for gba_mb specs. Therefore, the GBA version will need DKP r20 when it's out.
To compile the source, run make where you extracted the library. To install the NDS library in windows, download it to a folder and at a command line in that directory run:
Code:
bzip2 -cd libfat-nds-20060712.tar.bz2 | tar -xv -C %DEVKITPRO%/libnds

bzip2 and tar are included with DKP, so this should work.
Likewise for the GBA library run:
Code:
bzip2 -cd libfat-gba-20060712.tar.bz2 | tar -xv -C %DEVKITPRO%/libgba


Usage of the library is the same as before. This is still in alpha, as function names may change again. Make sure to backup any media that you run this on.

EDIT:
Forgot to mention that errno is now supported. Simply #include <errno.h> and use it like normal.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#92632 - chishm - Fri Jul 14, 2006 7:44 am

There is now source code to libfat in the devkitPro CVS repository. All future source code updates will be committed to the repository.

Also, libfat is still in alpha stage, as there aren't any directory listing functions yet.

PS, I thought this news was bump worthy.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#93233 - tepples - Mon Jul 17, 2006 11:31 pm

Exactly what would it take on your part and on wintermute's to get <dirent.h> and <sys/stat.h> working?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#93248 - chishm - Tue Jul 18, 2006 1:41 am

tepples wrote:
Exactly what would it take on your part and on wintermute's to get <dirent.h> and <sys/stat.h> working?

stat and fstat work already. Directory listing needs some more functions added to devoptab_t (the structure of function pointers used for each stdio device) by WinterMute. Once that is done, I need to implement the functions within libfat. The changes to devoptab_t will need a new DKP release, and a new libfat release should follow soon after.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#93282 - melw - Tue Jul 18, 2006 8:42 am

Great work Chishm! I've been waiting unified / clean fat lib for a while and all the sudden it's here.

My two cents to the continuous "can you support this and this device" requests: Have you tried contacting flash card manufacturers asking for receiving free test adapters? To me it sounds like for example Supercard would benefit if they sent a free copy to you for testing, if that'd mean probable support for SC SD adapters. In the end lot of the flash card users are after homebrew - it'd be mutual benefit for both the card manufacturers and the homebrew community. Same goes for M3, G6... perhaps even GBAMP SD? :)

#93316 - josath - Tue Jul 18, 2006 4:25 pm

Or even making a page where people can donate money to get you to support their favorite adaptor...i know i'd throw in a few bucks

#93340 - nukomod - Tue Jul 18, 2006 6:52 pm

I'd be very tempted to throw in some change toward an SC SD adapter for you.. paypal or something?

#93353 - Sintax - Tue Jul 18, 2006 7:33 pm

Yeah just get a donations page up already, I'm sure plenty of people would throw in a few bucks to finally get full SCSD support.

#93467 - chishm - Wed Jul 19, 2006 10:26 am

Well I got a Supercard SD adapter donated yesterday, thanks to NorQue. I'll work on it as soon as I get time (busy with life, etc.).
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#94008 - chishm - Sat Jul 22, 2006 1:34 pm

New lib out. The source is in DevkitPro CVS, or you can just use the precompiled GBA version or the precompiled NDS version.

A few bugs in the FAT handling code have been fixed thanks to loopy. There is now a fatInitDefault() function to make it even easier to use. There may be a few other bugs fixed that I've forgotten about. Also, there is now full Supercard SD support.

Some of you may notice that I use ASM code in the SCSD driver. This is allowed within libfat, and is part of the reason I made it a proper library. That being said, I only used it because it was necessary for hardware timing accuracy, and I'd still prefer the drivers to be written in C.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#94014 - PeterM - Sat Jul 22, 2006 2:53 pm

Thank you very very much for the SuperCard SD support. I really appreciate it.
_________________
http://aaiiee.wordpress.com/

#94332 - melw - Mon Jul 24, 2006 1:14 pm

Chishm, I had couple of quirks I have when using the latest CVS version out of the box with my own project space. Nothing major though, but I decided to paste these here just because of the 'long long long' line. :)

Code:
c:/devkitpro/libnds/include/nds/jtypes.h:109: error: 'long long long' is too long for GCC
c:/devkitpro/libnds/include/nds/jtypes.h:109: error: declaration does not declare anything
c:/devkitpro/libnds/include/nds/jtypes.h:127: error: multiple types in one declaration
c:/devkitpro/libnds/include/nds/jtypes.h:127: error: declaration does not declare anything
c:/devkitpro/libnds/include/nds/jtypes.h:158: error: redefinition of 'struct touchPosition'
c:\devkitpro\libnds/include/nds/jtypes.h:158: error: previous definition of 'struct touchPosition'
c:/devkitpro/libnds/include/nds/jtypes.h:165: error: invalid type in declaration before ';' token
c:/devkitpro/libnds/include/nds/jtypes.h:165: error: conflicting declaration 'typedef int touchPosition'
c:\devkitpro\libnds/include/nds/jtypes.h:165: error: 'touchPosition' has a previous declaration as 'typedef struct touch Position touchPosition'


This when compiling, removing #include <nds/jtypes.h> from fat.h line 51 fixed the errors for me.

Code:
c:\devkitpro\libnds/lib\libfat.a(io_nmmc.o): In function `_Neo_SelectMMC':
c:/projects/nds/libfat/nds/../source/disc_io/io_nmmc.c:106: undefined reference to `cardWriteCommand'


This when linking. Just removed the NMMC support from disc.c as I don't need it myself right now, bypassing this problem.

#94355 - wintermute - Mon Jul 24, 2006 3:26 pm

There's something very very wrong with your devkitARM installation. This looks like you've somehow managed to break the header guards in jtypes.h or have something else included before which is breaking things.

What do you mean with your own project space? The CVS version is a library meant to be built on it's own and linked against, not copied into your project like the older one.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#94394 - melw - Mon Jul 24, 2006 6:46 pm

My bad. The first one was mangled code, and the linking error was a result of passing -lfat after -lnds9 to the linker, not the other way around. Nothing wrong with the libfat.

#94395 - josath - Mon Jul 24, 2006 6:55 pm

melw wrote:
My bad. The first one was mangled code, and the linking error was a result of passing -lfat after -lnds9 to the linker, not the other way around. Nothing wrong with the libfat.


I had the same exact problem...but I didn't see your post in time to warn you :P

Personally I can never remember the order in which to link libraries, so if I get 'undefined reference to ...', and I'm pretty sure it is defined, I just twiddle with the order of the -l commands to the linker.

---

Also, in a preliminary testing of libfat, by replacing fatlib usage in my code, appears to output 0-byte files. (on SC CF). I will also test on gbamp, and also run chkdsk, perhaps my CF card is corrupted (by some other buggy homebrew).

EDIT: It appeared to be just a onetime glitch...chkdsk'd my card, then ran it again, and it seems to work fine. Loading is currently disabled, since I can't list files yet.

If anyone wants to test this on their device and report back, please go ahead. I tested with success on GBAMP and SC CF.

NDS version | .DS.GBA version | My site

#94711 - arog - Tue Jul 25, 2006 9:58 pm

Doing some testing with libfat myself, and though I can read files (on my GBAMP with DSlite) just fine, I am having trouble outputting to a subdirectory.

Here's the latest incarnation of my code (please forgive its ugliness):

Quote:
// Write to a file
FILE *ostream, *fopen();
if ( (ostream = fopen ("/data/write.txt", "w"))) { // Open file
char x[10] = "0123456789";
fwrite(x, sizeof(x[0]), sizeof(x)/sizeof(x[0]), ostream);
fclose(ostream); // close file
iprintf("\n\n\tWrote to file\n");
}


If I take out /data, it writes the file just fine. Am I doing something wrong?

EDIT: Oh, I remember seeing that libfat couldn't list directories, is this basically the issue?

- Aaron Rogers
http://www.aaronrogers.com/nintendods/

#94843 - chishm - Wed Jul 26, 2006 12:16 pm

I tried that code, and I did manage to get it to fail. To do this I had to create a new directory and write the file into that. I have fixed that particular bug, so when writing to the end of a directory, the file should work. Updated code is in CVS.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#94852 - melw - Wed Jul 26, 2006 1:00 pm

Have done now some tests with M3, both CF and SD versions. With M3CF both the saving and reading the files work just as it should, but with M3SD fatInitDefault() returns false - same when trying something like fatInit(4, true). Not sure if the M3 firmware version has anything to do with the issue, I'm still using E18 due to problems reported with newer drivers.

Josath, with Draw3 test the M3CF outputs right away a blank/white .png but keeps jamming after that. With M3SD I can draw and it says it's saving when I press 'x' but no files are written on the memory card. If you could add an extra check to show on screen whether fatInit() fails that would be helpful with testing...

#94923 - arog - Wed Jul 26, 2006 10:05 pm

Quote:
Updated code is in CVS.


Works great, thanks!

Next question, what if I want to create a directory? Is that possible/easy to do?

- Aaron Rogers
http://www.aaronrogers.com/nintendods/

#94927 - Dwedit - Wed Jul 26, 2006 10:21 pm

chishm wrote:

Some of you may notice that I use ASM code in the SCSD driver. This is allowed within libfat, and is part of the reason I made it a proper library. That being said, I only used it because it was necessary for hardware timing accuracy, and I'd still prefer the drivers to be written in C.


If it requires exact timing, how does it work on both a GBA and NDS?
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#94932 - tepples - Wed Jul 26, 2006 10:38 pm

Either separate binaries with the exact timing adjusted, or the timing depends on the speed of the GBA cart bus interface, which can be made the same in both modes.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#95007 - chishm - Thu Jul 27, 2006 9:17 am

Dwedit wrote:
If it requires exact timing, how does it work on both a GBA and NDS?

tepples wrote:
Either separate binaries with the exact timing adjusted, or the timing depends on the speed of the GBA cart bus interface, which can be made the same in both modes.

The second one. It uses stmia to transmit 4 halfwords to the GBA cart (16 bits per transfer). The first halfword contains the data to be written, and the next 3 (along with the first) provide clock signals for the Supercard's internal circuitry to break that data into 4 nibbles and transmit them to the SD card. I tried to do it in C, but I can't guarantee that the compiler will compile to stmia, and 4 lots of strh doesn't work.

arog:
Not as yet. Directories aren't fully supported within devkitPro yet, which is why libfat is still in alpha.

melw:
It may be due to your SD card. SD cards have a wider range of quality and abilities compared to CF cards, and I only have 1 type of SD card to test with.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#95029 - Lazy1 - Thu Jul 27, 2006 12:49 pm

I'm still having problems with libfat and Mini vMac, it reads the ROM okay but when a system disk is inserted it acts like the PC version does when it's given an invalid/corrupt disk.

The problem does not exist when using the older fat library or romdiskfs.
I'm really interested in helping track this problem down.

#95033 - melw - Thu Jul 27, 2006 1:22 pm

chishm wrote:
melw:
It may be due to your SD card. SD cards have a wider range of quality and abilities compared to CF cards, and I only have 1 type of SD card to test with.


Hmm. Using Kingston 1Gb SD card over here... should be one of the better quality ones, I believe. Also, both REIN v15 and Josath's old version of Draw3 (using the same SaTa modified FAT lib?) works well with the card what comes reading and writing files.

Edit: fatInit() seems to go all the way to _M3SD_initCard() until it reaches the MAX_STARTUP_TRIES check. If I bypass that one, a moment later there's the RESPONSE_TIMEOUT failure. Couldn't find corresponding spot in SaTa's version to compare what's done differently. If you have any debugging tips on what to check next, I could do some more testing...

#95079 - Lazy1 - Thu Jul 27, 2006 7:18 pm

I though I'd post the functions being called to read from the filesystem...

Code:

#ifndef NotAfileRef
   #define NotAfileRef -1
#endif

int Drives[NumDrives]; /* open disk image files */

LOCALPROC InitDrives(void)
{
   si4b i;

   for (i = 0; i < NumDrives; ++i) {
      Drives[i] = NotAfileRef;
   }
}

GLOBALFUNC si4b vSonyRead(void *Buffer, ui4b Drive_No, ui5b Sony_Start, ui5b *Sony_Count)
{
#ifdef DiskInSRAM
   if ( Drives[ Drive_No ] == ( int ) SRAM ) {
      MyMoveBytes( ( anyp ) ( SRAM + Sony_Start ), ( anyp ) Buffer, *Sony_Count );
      return 0;
   }
#endif

   FS.seek( Drives[ Drive_No ], Sony_Start, SEEK_SET );
   FS.read( Drives[ Drive_No ], Buffer, *Sony_Count );

   return 0; /*& figure out what really to return &*/
}

GLOBALFUNC si4b vSonyWrite(void *Buffer, ui4b Drive_No, ui5b Sony_Start, ui5b *Sony_Count)
{
#ifdef DiskInSRAM
   if ( Drives[ Drive_No ] == ( int ) SRAM ) {
      MyMoveBytes( ( anyp ) Buffer, ( anyp ) ( SRAM + Sony_Start ), *Sony_Count );
      return 0;
   }
#endif

   FS.seek( Drives[ Drive_No ], Sony_Start, SEEK_SET );
   FS.write( Drives[ Drive_No ], Buffer, *Sony_Count );
   
   return 0; /*& figure out what really to return &*/
}

GLOBALFUNC si4b vSonyGetSize(ui4b Drive_No, ui5b *Sony_Count)
{
#ifdef DiskInSRAM
   if ( Drives[ Drive_No ] == ( int ) SRAM ) {
      *Sony_Count = SRAMSize;
      return 0;
   }
#endif

   FS.seek( Drives[ Drive_No ], 0, SEEK_END );
   *Sony_Count = FS.tell( Drives[ Drive_No ] );
   
   return 0; /*& figure out what really to return &*/
}

GLOBALFUNC si4b vSonyEject(ui4b Drive_No)
{
#ifdef DiskInSRAM
   if ( Drives[ Drive_No ] == ( int ) SRAM ) {
      Drives[ Drive_No ] = NotAfileRef;
      return 0x0000;
   }
#endif

   FS.close( Drives[ Drive_No ] );

   Drives[Drive_No] = -1;
   return 0x0000;
}


FS is just a wrapper for using multiple filesystems in the project, right now it supports libfat, the old fat library and romdiskfs.
The only one having problems is libfat.

#95377 - chishm - Sat Jul 29, 2006 2:44 am

TheLazy1:
I'm thinking that the problem may lie in my implementation of seek. To make it easier to track down the bug, I'll need a bit more information. Is Sony_Start always going to be a multiple of 512 (ie, it reads sectors at a time)? Does vSonyWrite get called at all before it tries to read the disc and fails? When I get back to my dev machine, I'll write an un-optimised version of seek for you to try.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#95388 - Lazy1 - Sat Jul 29, 2006 3:48 am

Quote:

vSonyRead( Buffer=B003B1C, Drive_No=0, Sony_Start=1024, *Sony_Count=128 ); IPC->heartbeat = 509
vSonyRead( Buffer=2193730, Drive_No=0, Sony_Start=0, *Sony_Count=1024 ); IPC->heartbeat = 596
vSonyRead( Buffer=2056E02, Drive_No=0, Sony_Start=1024, *Sony_Count=512 ); IPC->heartbeat = 652
vSonyRead( Buffer=205724E, Drive_No=0, Sony_Start=7168, *Sony_Count=512 ); IPC->heartbeat = 653
vSonyRead( Buffer=B003B1C, Drive_No=1, Sony_Start=1024, *Sony_Count=128 ); IPC->heartbeat = 679


vSonyWrite is only called with the old fatlib and that's after the OS has started.
I also have no idea if calls to vSonyRead follow any rules, but I doubt it does.

#95403 - chishm - Sat Jul 29, 2006 6:50 am

From the looks of those reads, Sony_Start is aligned to 1024 byte boundaries, but I'll assume 512 since that is what ATA discs use.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#95570 - chishm - Sun Jul 30, 2006 9:18 am

TheLazy1:
This is a test version with seek simplified as much as possible. Try it out and tell me if the problem is solved or not.

Everyone else:
Don't bother with the above debug version.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#95631 - Lazy1 - Sun Jul 30, 2006 5:02 pm

Problem was solved, the system boots as expected :)

#95888 - chishm - Mon Jul 31, 2006 12:35 pm

Lazy1 wrote:
Problem was solved, the system boots as expected :)

Okay, that means I have work to do on seek(), since the version you tried is severely limited.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#96361 - jandujar - Wed Aug 02, 2006 9:42 pm

Chishm:

First of all: Congratulations for your work.

The only thing that needs this library now is the directory listing.

I hope you solve this problem soon.

WTF, who is Spelling Fairy?
_________________
http://jandujar.homelinux.com
http://www.dsrobot.com


Last edited by jandujar on Thu Aug 03, 2006 9:22 am; edited 1 time in total

#96424 - chishm - Thu Aug 03, 2006 9:14 am

Heh, thanks. File listing will be done eventually, but I have a few higher priority tasks I need to take care of.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#98056 - TheRain - Sat Aug 12, 2006 11:02 pm

Hi, this is REALLY cool... I had my first chance to inspect it today and it has allowed me to add open and save features to dSTAR sequencer (my MIDI program).

One thing I found, though, is that it won't work with my Sandisk 1GB SD card within my M3 Perfect. It works just fine on my 512MB Sandisk card though.

I am using the version that was included in the latest libnds update.

Thanks so much for this work.

#98076 - chishm - Sun Aug 13, 2006 2:23 am

The last DevkitPro release of libfat (2006-07-22 IIRC) had the SD timeout values set too low (I must have fast SD cards or something). This means that the startup is timing out before some cards have a chance to respond. I've fixed this about a week ago in the source in CVS. It shouldn't be too hard to checkout a copy and compile it from source.

EDIT: w00t, 713th post!
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#98491 - Extreme Coder - Tue Aug 15, 2006 4:21 pm

I hoped EZ4 would be added in this new libfat, looks like I'll have to wait a little longer... Damn it EZ team, why don't you give us the code?

#98494 - josath - Tue Aug 15, 2006 4:54 pm

Extreme Coder wrote:
I hoped EZ4 would be added in this new libfat, looks like I'll have to wait a little longer... Damn it EZ team, why don't you give us the code?

Have you asked them? Maybe if enough people request it, and include why they want it (better homebrew support, more people use the device, etc), then they might reconsider. Apparently a G6/m3minisd library was released, but without source code. I just sent them an email requesting source, they probably won't do it, but at least they know someone out there wants it.

#98601 - chishm - Wed Aug 16, 2006 9:52 am

Extreme Coder wrote:
I hoped EZ4 would be added in this new libfat, looks like I'll have to wait a little longer... Damn it EZ team, why don't you give us the code?

There is code, but read only. It isn't a simple case of changing the command to write to the SD card (as is the case for CF), so it will be harder to add write support.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#99078 - chishm - Sat Aug 19, 2006 1:44 pm

I thought I might post a progress update. It turns out that the M3SD driver I wrote works so well even the new micro is supported (well, that's what I've been told). I have also updated the SCSD driver to support the SC Lite. Directory listing is added to the library code, but it requires an update of DevkitPro that isn't released yet. The functions chdir, mkdir and rename are also all there now too.

Once directory listing is supported by DevkitPro, libfat will reach beta stage. You may not be able to compile it from CVS at the moment, since the devoptab_t stucture needs to be updated first.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#99082 - Lick - Sat Aug 19, 2006 2:09 pm

That's great news Chishm, great news! Your hard work is appreciated.
_________________
http://licklick.wordpress.com

#99237 - tepples - Sun Aug 20, 2006 5:50 am

In this post, chishm wrote:
Actually, I'd recommend libfat, when DKP r20 comes out.

Is that a hint-hint about the status of opendir()?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#99250 - chishm - Sun Aug 20, 2006 8:38 am

tepples wrote:
In this post, chishm wrote:
Actually, I'd recommend libfat, when DKP r20 comes out.

Is that a hint-hint about the status of opendir()?


In this post, chishm wrote:
Directory listing is added to the library code, but it requires an update of DevkitPro that isn't released yet.

Although I haven't finished opendir() yet, I have written directory listing functions that behave similarly, but better. Implementing opendir() will be a simple case of writing a wrapper around them.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#99294 - Frz - Sun Aug 20, 2006 3:08 pm

is there any chance for ez4 support?

#100062 - Twibber - Fri Aug 25, 2006 9:49 pm

Much appreciated on the M3SD support indeed! Finally I can look forward to some Stella and Coleco support... pending a re-compile of course.

Aces Chishm... ACES!

#100661 - melw - Tue Aug 29, 2006 11:51 am

chishm wrote:
You may not be able to compile it from CVS at the moment, since the devoptab_t stucture needs to be updated first.

For the anxious ones like me (willing to test that M3SD again), what exactly needs to be updated in the devoptab_t structure?

#100667 - chishm - Tue Aug 29, 2006 1:12 pm

melw wrote:
chishm wrote:
You may not be able to compile it from CVS at the moment, since the devoptab_t stucture needs to be updated first.

For the anxious ones like me (willing to test that M3SD again), what exactly needs to be updated in the devoptab_t structure?

Extra entries for creating and listing contents of directories.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#101941 - Bronto - Sat Sep 09, 2006 2:29 am

fread always returns 0, although the data is read into the specified buffer. I'm using the libfat that came with the latest devkit (file date 08/13/06).
Is there a fix for this?

#101957 - chishm - Sat Sep 09, 2006 6:05 am

I haven't come across this problem before, but there are some things you can try. First, make sure you are using the latest DevkitARM. The latest is r19b. If that doesn't work, try using open / read / close instead of fopen / fread / fclose. This will bring it as close to the bare libfat routines as possible (to make sure newlib isn't doing anything to mess it up).
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#101988 - Bronto - Sat Sep 09, 2006 3:54 pm

I'm using dk r19b. open/read/close don't seem to be available (not declared in this scope). I'm using fcntl.h and stdio.h

#102057 - chishm - Sun Sep 10, 2006 9:17 am

You want to #include <unistd.h>
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#102071 - Bronto - Sun Sep 10, 2006 3:35 pm

thanks, reading works now.
write()ing however fails. It "correctly" returns the bytes written, but actually does not write anything, resulting in a 0-sized file. I *think* fwrite worked though

#102123 - chishm - Mon Sep 11, 2006 1:01 am

Make sure you close() the file after writing.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#102124 - Bronto - Mon Sep 11, 2006 1:09 am

I already do call close. Perhaps i need to flush it before?

#102132 - darkfader - Mon Sep 11, 2006 3:11 am

Can we flush within a timer or would that require some locks?

#102139 - knight0fdragon - Mon Sep 11, 2006 5:37 am

i seem to get it to write fine, but for some reason my time stamps are always fudged up, and I do close all my files when i finish using them
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#102141 - chishm - Mon Sep 11, 2006 5:58 am

Calling close() will clean the cache. You really shouldn't be accessing the internal cache at all from outside the library, as it is all handled internally.

I'll have to look into the time stamps when I get some spare time to work on this (no joke intended). They're probably fudged by the conversion from the DS representation of time to the directory entry structure. It's one of the small things that I copied directly over from gba_nds_fat without testing.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#104410 - ChronoDK - Thu Sep 28, 2006 8:03 pm

I just tried getting file access working, but I got stuck pretty fast. Hope you can help.

Code:

FILE* fp;
if ((fp = fopen("/test.xml", "r")) == NULL) {
   iprintf("\nCannot open file.\n");
}


I had hoped not to see "Cannot open file.", but unfortunatly I do see it. What am I doing wrong? I'm using CF GBAMP, r19, the precompiled fatlib 20060722 and fatInit(4, true) returns true. Both the .nds and the file I'm trying to open is at the top level directory of the flashcard.

#104457 - Sektor - Fri Sep 29, 2006 8:33 am

That code worked as expected, no problem. I'm using devkitarm r19b and libfat 20060722. I'm using fatInitDefault(); to init but that shouldn't matter.
_________________
GTAMP.com/DS


Last edited by Sektor on Fri Sep 29, 2006 1:36 pm; edited 1 time in total

#104462 - ChronoDK - Fri Sep 29, 2006 11:04 am

FatInitDefault gives me the same error. I'm using r19b too btw.

I also tried to checkout the latest version of libfat from CVS but it didn't compile. Is there a newer precompiled version than the one I'm using?

#104521 - josath - Sat Sep 30, 2006 1:37 am

ChronoDK wrote:
FatInitDefault gives me the same error. I'm using r19b too btw.

I also tried to checkout the latest version of libfat from CVS but it didn't compile. Is there a newer precompiled version than the one I'm using?


Perhaps you could post your full source code, as well as compiled .nds file? either:
A) your device has some problems such that libfat cannot use it or
B) your bug lies in some other part of your code.

Also: Make sure you don't do fatinit & open at the very beginning of your code. Wait a couple of vblanks before you call fatinit etc

#104522 - tepples - Sat Sep 30, 2006 1:59 am

josath wrote:
Also: Make sure you don't do fatinit & open at the very beginning of your code. Wait a couple of vblanks before you call fatinit etc

Reminds me of NES programming, where you're not supposed to read or write VRAM until after two vblanks.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#104527 - chishm - Sat Sep 30, 2006 4:12 am

tepples wrote:
josath wrote:
Also: Make sure you don't do fatinit & open at the very beginning of your code. Wait a couple of vblanks before you call fatinit etc

Reminds me of NES programming, where you're not supposed to read or write VRAM until after two vblanks.

You can call fatInit immediately, but try not to call fopen() before the first VBlank has passed. This is so the time value in the IPC struct has had a chance to be updated with the correct value. Before anyone asks, forcing a check inside the library would just slow it down on every open() / close() for something that is not likely to happen and can easily be prevented in user code. Hand-holding has to stop somewhere.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#104534 - PeterM - Sat Sep 30, 2006 8:49 am

What kind of slow-down would it be?

Sounds like just a "if (static boolean) wait for 2 vblanks" which wouldn't be at all noticable after the initial wait.

I think the extra effort inside the library is worth it to stop many people inserting 2 NDS vblank waits in otherwise generic code.

Then again, I like holding hands...
_________________
http://aaiiee.wordpress.com/

#104537 - Link_of_Hyrule - Sat Sep 30, 2006 9:11 am

just wondering hows the g6 compatibility for this or do we know?

#104538 - ChronoDK - Sat Sep 30, 2006 9:39 am

Thanks, I got it working. Will try not to call fopen immediately from now on.

The primary error was something else though - but it is way too embarrassing to tell about :-)

#104546 - Lick - Sat Sep 30, 2006 11:25 am

Code:
#define fatInitDefaultHoldingHands();  swiWaitForVBlank(); \
                                                      swiWaitForVBlank(); \
                                                      fatInitDefault();

LOL.

By the way, is the main focus of libfat to provide stable code for as many cards possible, or to provide perfect code (+ code design) for the popular cards? That's really a question to think about.

- Lick
_________________
http://licklick.wordpress.com

#104554 - ChronoDK - Sat Sep 30, 2006 11:54 am

Heh, I used the exact code in that define :-)

Anyway, I'm trying to do something useful with the file system stuff now. Working with strings is nice, but I would like to load my sprites from file too.

This is what I got, and it aint working:

Code:

FILE* fp;
if ((fp = fopen("/ninja_1.raw", "rb")) == NULL) {
   iprintf("\nCannot open raw file.\n");
}
else {
   dmaCopy((u8*)fp, (void*)SPRITE_MEM(0), 512);
}
   
if ((fp = fopen("/ninja_1.pal", "rb")) == NULL) {
   iprintf("\nCannot open pal file.\n");
}
else {
   dmaCopy((u8*)fp, SPRITE_PAL(0), 32);
}

I'm trying to copy a 32x32 16 color sprite converted with gfx2gba (as doing the conversion in code seems way to advanced for me). Nothing shows up on the screen.

#104556 - Lick - Sat Sep 30, 2006 12:01 pm

C I/O doesn't work that way. fp is NOT a charpointer to the bytebuffer of that file. It's a handle, that the I/O system works with.

1) use fread();
2) don't use dmaCopy(), use memcpy();
3) "rb" isn't necessary, libfat only does binary. ("r" = "rb")

- Lick
_________________
http://licklick.wordpress.com

#104558 - chishm - Sat Sep 30, 2006 12:16 pm

I thought I would try the hand-holding approach for file times after all, but I discovered a few problems along the way. The combined ARM9 / ARM7 template provided in DKP r19 doesn't update the RTC values in the IPC struct. (No calls to rtcGetTime() are made at all.) This means the time will always be incorrect. If I attempt to wait until the time is valid, it may wait indefinitely. Therefore if the time is invalid, I'll simply set the file time to NULL rather than waiting for it to become valid.

Also, it is only close() that uses the time, so you can open() (and therefore fopen()) any time.

The main focus is to provide stable, correct code for as many cards as possible. Correctness means it cannot give false positives for the card detection function, it has to support reading, and it should (but doesn't have to) support writing. It also has to be fail safe, so if a function cannot access the card, it should give up and return an indication that an error occured.

ChronoDK:
Care to share what the problem was? Other people can learn from your mistakes too.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#104559 - Sausage Boy - Sat Sep 30, 2006 12:17 pm

Using "rb" is a good habit, even if it's not necessary in this case. Who knows what future fat versions will add? Even if a text version is very unlikely, using "r" is just stupid. Don't change it.
_________________
"no offense, but this is the gayest game ever"

#104562 - chishm - Sat Sep 30, 2006 12:36 pm

Lick wrote:
"rb" isn't necessary, libfat only does binary. ("r" = "rb")

Actually, it's newlib that deals with fopen(), libfat just provides open() (which newlib calls). Therefore, if newlib gets updated to support text mode verses binary mode then so will whatever uses it. Sausage Boy is right though, leave it in just in case. It especially helps for ports.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#104564 - Lick - Sat Sep 30, 2006 1:01 pm

Whew.. man information is changing fast. Last time I asked it was still 'r is enough'.
_________________
http://licklick.wordpress.com

#104566 - chishm - Sat Sep 30, 2006 1:14 pm

Lick wrote:
Whew.. man information is changing fast. Last time I asked it was still 'r is enough'.

"r" is indeed enough. However, "rb" is better if you plan on reusing code at a later date or on another platform.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#104571 - Hermes - Sat Sep 30, 2006 1:50 pm

Hi,

I want to report a little bug present in libfat, in the function FAT_mkdir()

To initialize the entries the functions ends so:

Code:

// Write entry to disc
   disc_WriteSector(FAT_ClustToSect(newDirCluster), entries);

// Flush any sectors in disc cache
   disc_CacheFlush();


So, it only write one sector of the cluster!!! (and the rest sectors has bad datas)

Replace by:

Code:


   // Write entry to disc
   for(i=0;i<filesysSecPerClus;i++) /*  to write all the cluster correctly*/
   {
   disc_WriteSector(FAT_ClustToSect(newDirCluster)+i, entries);
   memset(entries,  FILE_LAST, BYTE_PER_READ); /* set to 0 the rest of the sectors */
   }

   // Flush any sectors in disc cache
   disc_CacheFlush();


And problem solved ;)

#104577 - chishm - Sat Sep 30, 2006 5:00 pm

Well that is actually a function from gba_nds_fat, not libfat. However, the libfat version does operate in the same way. It shouldn't have affected anything, since the end of directory marker is moved when new entries are created.

After testing, it appears that not clearing the cluster will cause problems for other OSes when they try to add entries to the directory. This has now been fixed in libfat (despite mkdir not actually being usable at the moment).
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#104599 - ChronoDK - Sat Sep 30, 2006 7:37 pm

Yay - happy! I got sprite loading from file working now. If you want to see, here it is:

Code:

void cSprite::copyFile(cGameWorld* gameworld_, const char* strname_, bool newsprite_) {
   FILE* fp;
   
   //copy sprite data from file
   char filename[32];
   strcpy(filename, "/data/sprites/");
   strcat(filename, strname_);
   strcat(filename, ".raw");

   if ((fp = fopen(filename, "rb")) != NULL) {
      fseek(fp, 0, SEEK_END);
      u16 size = ftell(fp);
      iprintf("Bytes: %i\n", size);
      rewind(fp);
      u8* buffer;
         if ((buffer = (u8*)malloc(size)) != NULL) {
         fread(buffer, 1, size/sizeof(u8), fp);
         memcpy((void*)SPRITE_MEM(gfx), buffer, size/sizeof(u8));
         //dmaCopy(buffer, (void*)SPRITE_MEM(gfx), size);
         if (newsprite_)
            gameworld_->sprite_control->next_gfx = gameworld_->sprite_control->next_gfx + size/32;
         }
      fclose(fp);
      free(buffer);
      }
      else
      iprintf("\nCannot open raw file.\n");

   //copy sprite palette from file
   strcpy(filename, "/data/sprites/");
   strcat(filename, strname_);
   strcat(filename, ".pal");

   if ((fp = fopen(filename, "rb")) != NULL) {
      fseek(fp, 0, SEEK_END);
      u16 size = ftell(fp);
      iprintf("Bytes: %i\n", size);
      rewind(fp);
      u8* buffer;
         if ((buffer = (u8*)malloc(size)) != NULL) {
         fread(buffer, 1, size/sizeof(u8), fp);
         memcpy(SPRITE_PAL(pal), buffer, size/sizeof(u8));
         //dmaCopy(buffer, SPRITE_PAL(pal), size);
         }
      fclose(fp);
      free(buffer);
      }
      else
      iprintf("\nCannot open pal file.\n");
}


Sorry for posting all that. But perhaps someone can use it sometime. Could I have done it in a better way? An why is memcpy better than dmaCopy? They both work, but I did as you told me and used memcpy.

chism: I dont think anyone can learn from the embarrassing part of the last error - I called the file "text" but tried to open "test" :-)

#104615 - HyperHacker - Sat Sep 30, 2006 9:58 pm

You'd be surprised how common that mistake is. At least to me. >_>
_________________
I'm a PSP hacker now, but I still <3 DS.

#104652 - chishm - Sun Oct 01, 2006 6:01 am

ChronoDK wrote:
chism: I dont think anyone can learn from the embarrassing part of the last error - I called the file "text" but tried to open "test" :-)

Don't worry, I've done that too.

Also, memcpy is better than dmaCopy since dmaCopy can't access the DTCM region of the ARM9, which is where the stack is placed.

EDIT: Spelling
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#104883 - josath - Tue Oct 03, 2006 8:43 pm

Hello,

Since devkitpro r19b does not have directory listing support yet, the latest CVS of libfat will not compile under it. In order to get it to work, simply apply this patch

This is just a stopgap, to let you use the latest libfat, without having to wait for a devkitpro update (basically it comments out all the directory related functions)

#104927 - chishm - Wed Oct 04, 2006 10:36 am

Alternatively, you could just ask for the latest compiled version. This is compiled without the patch, but due to the way the device table in DevkitPro works, the extra functions will simply be ignored.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#105025 - melw - Thu Oct 05, 2006 8:42 am

Good news. Checked out the latest CVS version, and compared to the previously released pre-compiled package also all the SD adapters worked flawlessly.

A test batch with writing and reading succeeding on each adapter included:

- GBAMP CF (256Mb Kingston)
- M3 CF (256Mb Kingston)
- M3 SD (1Gb Kingston)
- M3 Lite SD (512Mb Sandisk)

I can also check how the Chinese M3 Mini SD works in the near future.. Looking forward for the official beta release of libfat!

#105551 - El Hobito - Mon Oct 09, 2006 2:40 pm

Keep up the good work chishm! Can we expect the new dewvkitpro anytime soon or is it still some ways off yet?

#105557 - josath - Mon Oct 09, 2006 4:01 pm

El Hobito wrote:
Keep up the good work chishm! Can we expect the new dewvkitpro anytime soon or is it still some ways off yet?

devkitpro = wintermute, not chishm. donate at devkitpro.org to get it out sooner!

#105578 - El Hobito - Mon Oct 09, 2006 7:47 pm

josath wrote:
El Hobito wrote:
Keep up the good work chishm! Can we expect the new dewvkitpro anytime soon or is it still some ways off yet?

devkitpro = wintermute, not chishm. donate at devkitpro.org to get it out sooner!

yeah i know that! that was just a generic cop compliment!

If anyones interested i have little tester program with a list for know working cards starting. If anyone can run it and test it that would be great.

http://teamnnc.free.fr/phpBB2/viewtopic.php?p=10581#10581

#106242 - Marcel24 - Tue Oct 17, 2006 3:52 am

hi, the new fatlib is great :)


now write / read works on my SC SD card .

but i have a small problem now .
i must RENAME a file name , but it doesnt work :(

isnt it implemented until now ?

must i make a work around ?


tnx .
cya

#106260 - chishm - Tue Oct 17, 2006 10:28 am

rename() won't appear until the rest of the directory level functions appear, with the next version of DevkitPro.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#106659 - felix123 - Sun Oct 22, 2006 9:03 am

Have you guys seen this? It is supposed to be the source code for accessing the SCCF, SCSD and SCSD mini. It also includes the rumble code.

http://scdev.org/forum/viewtopic.php?t=6896

#106694 - josath - Sun Oct 22, 2006 7:39 pm

felix123 wrote:
Have you guys seen this? It is supposed to be the source code for accessing the SCCF, SCSD and SCSD mini. It also includes the rumble code.

http://scdev.org/forum/viewtopic.php?t=6896


It seems to include code for writing to SC Rumble, but not any code for actually making it vibrate. (Though I may have missed it). Otherwise, it appears to be all ARM ASM, with most functions having comments describing what it does in C

#106705 - Lick - Sun Oct 22, 2006 9:09 pm

Using the WIP-build of libfat, is it possible to check which device is inserted? Like Supercard, M3..
_________________
http://licklick.wordpress.com

#106712 - josath - Sun Oct 22, 2006 9:24 pm

it doesn't seem there is any easy way. I think you could do:

Code:
// make sure the libfat source directory is searched for includes,
// but not for source
#include "partition.h"

extern PARTITION *_partitions;

for(int i=0; i<MAXIMUM_PARTITIONS; i++) {
  if(_partitions[i] != NULL) {
     iprintf("Partition %d type = %X\n", i, _partitions[i].disc->ioType);
  }
}


Then you can compare the 'partition type' with the magic numbers in the various io_*.h files in the disc_io dir:
Code:
io_efa2.h:#define DEVICE_TYPE_EFA2 0x32414645
io_fcsr.h:#define DEVICE_TYPE_FCSR 0x52534346
io_m3cf.h:#define DEVICE_TYPE_M3CF 0x4643334D
io_m3sd.h:#define DEVICE_TYPE_M3SD 0x4453334D
io_mmcf.h:#define DEVICE_TYPE_MMCF 0x46434D4D
io_mpcf.h:#define DEVICE_TYPE_MPCF 0x4643504D
io_njsd.h:#define DEVICE_TYPE_NJSD 0x44534A4E
io_nmmc.h:#define DEVICE_TYPE_NMMC 0x434D4D4E
io_sccf.h:#define DEVICE_TYPE_SCCF 0x46434353
io_scsd.h:#define DEVICE_TYPE_SCSD 0x44534353


I think they actually are 4 character strungs (not \0 terminated), so you could print them out as well.

#106715 - Lick - Sun Oct 22, 2006 10:12 pm

I tried it, but I couldn't get it to compile. Guess I'm releasing two binaries. =/
_________________
http://licklick.wordpress.com

#106716 - josath - Sun Oct 22, 2006 10:37 pm

Well, my code wasn't right, it wasn't tested like I said. They were just simple problems though (like a missing [], using a . instead of a ->, etc)

source + compiled .nds --> http://davr.org/ds2/fattest.tgz

#106717 - Lick - Sun Oct 22, 2006 11:11 pm

Would have been nice, but I already released LoveLite, without SC-detection. Thanks for your effort though, josath! Love you!

- Lick
_________________
http://licklick.wordpress.com

#106755 - chishm - Mon Oct 23, 2006 5:47 am

josath wrote:
I think they actually are 4 character strungs (not \0 terminated), so you could print them out as well.

Yes, they are the 4 characters of the name of the device. For instance, the supercard SD will be SCSD. The characters are ASCII encoded and the highest byte corresponds to the last letter in the name (little-endian architecture).
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#107131 - Lick - Thu Oct 26, 2006 11:57 pm

josath wrote:
Well, my code wasn't right, it wasn't tested like I said. They were just simple problems though (like a missing [], using a . instead of a ->, etc)

source + compiled .nds --> http://davr.org/ds2/fattest.tgz


Thanks! I'm using this and it's workig like a charm! ;)
_________________
http://licklick.wordpress.com

#107249 - Lick - Sat Oct 28, 2006 12:18 am

I'm trying to do a "FAT_GetFileCluster()" in the DevKitPro libfat. I copied the necessary structs from the libfat source and then access access the FILE* I get from fopen() like this:

Code:
typedef struct {
   u32 cluster;
   u32 sector;
   s32 byte;
} FILE_POSITION;
typedef struct {
   u32 cluster;
   u32 sector;
   s32 offset;
} DIR_ENTRY_POSITION;
typedef struct {
   u32 filesize;
   u32 startCluster;
   u32 currentPosition;
   FILE_POSITION rwPosition;
   FILE_POSITION appendPosition;
   bool read;
   bool write;
   bool append;
   bool inUse;
   PARTITION* partition;
   DIR_ENTRY_POSITION dirEntryStart;      // Points to the start of the LFN entries of a file, or the alias for no LFN
   DIR_ENTRY_POSITION dirEntryEnd;         // Always points to the file's alias entry
} FILE_STRUCT;


..
        FILE *_boot_mp = fopen("_BOOT_MP.NDS", "r");
        u32 cluster = *((FILE_STRUCT*)(_boot_mp->_file)).startCluster;
        fclose(_boot_mp);
        return cluster;
..


Will this work?

- Lick
_________________
http://licklick.wordpress.com

#107293 - chishm - Sat Oct 28, 2006 8:52 am

Use fstat. It will return a struct describing the file. The inode number (st_ino) is the file's start cluster. Also, don't use any variables or functions starting with an underscore (eg _partitions). They are meant to be hidden from the host application and may change between versions.

The latest CVS version of libfat will return the hostType (ioType) in the device field of the stat struct (st_dev). So to get the type of disc inserted, try this (untested, should work):
Code:
#include <sys/stat.h>

/* To get the inserted device type */
struct stat st;
stat ("/.", &st);       /* Get the file stat for the root directory */
u32 partitionType = st.st_dev;     /* Get the disc that the root directory is on */

/* To get the start cluster of a file */
int _boot_mp = open("_BOOT_MP.NDS", "r");
fstat (_boot_mp, st);
close(_boot_mp);
u32 cluster = st.st_ino;

_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#107297 - Lick - Sat Oct 28, 2006 9:48 am

Thanks for clearing it up! Perhaps a list of implemented standard functions should be put up, as it's hard to track what is implemented and what not. (Don't know what libnds' coding standards are, but I dislike the idea in general to use standard functions, unless you implement them ALL.)

chishm wrote:
The latest CVS version of libfat will return the hostType (ioType) in the device field of the stat struct (st_dev). So to get the type of disc inserted, try this (untested, should work) ..

chishm wrote:
Alternatively, you could just ask for the latest compiled version. This is compiled without the patch, but due to the way the device table in DevkitPro works, the extra functions will simply be ignored.


I will try that code, but it works with the quoted libfat version right?
You're the man!

- Lick
_________________
http://licklick.wordpress.com

#107300 - chishm - Sat Oct 28, 2006 10:07 am

No, I only added the code to CVS 5 minutes before making that last post.

EDIT: I did, however, compile the the latest version for you
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#107338 - Lick - Sat Oct 28, 2006 6:41 pm

Yay! .. .. Yay! Yay!

Edit: I tested the paritionType detection and.. Sigh.. It works! ;D

Will there be ezsd support? AFAIK, that code is already released, or at least known.
_________________
http://licklick.wordpress.com

#107351 - Lick - Sat Oct 28, 2006 10:29 pm

It doesn't work. I only get 0x4353 ("SC"), a 16-bit value. How do I get the whole 32-bit value? ("SCSD")

Edit: Upon investigation I found that this define causes the compiler to make dev_t a short value.
/DevKitARM/arm-eabi/include/sys/types.h
Code:
#if defined(__rtems__)
/* device numbers are 32-bit major and and 32-bit minor */
typedef unsigned long long dev_t;     // This is skipped
#else
#ifndef __CYGWIN__
typedef   short   dev_t;         // This is parsed
#endif
#endif


I simply brutely modified sys/types.h, but it still doesn't work. I think it's still 16-bit in libfat.a (or in my devkitpro version).

- Lick
_________________
http://licklick.wordpress.com

#107382 - chishm - Sun Oct 29, 2006 6:19 am

Getting the partition type and boot file cluster can be greatly simplified from the above example:
Code:
#include <sys/stat.h>

struct stat st;
stat ("_BOOT_MP.NDS", &st);       /* Get the file stat for the root directory */
u32 partitionType = st.st_dev;     /* Get the disc that the root directory is on u32 cluster = st.st_ino;


It's rather unfortunate about the st_dev type being 16 bit. I can't do much about that without modifying the DevkitPro installation. Maybe WinterMute won't mind, but if he does, I'll need to find another (standardised) way.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#107385 - josath - Sun Oct 29, 2006 6:35 am

chishm wrote:

It's rather unfortunate about the st_dev type being 16 bit. I can't do much about that without modifying the DevkitPro installation. Maybe WinterMute won't mind, but if he does, I'll need to find another (standardised) way.


Another option is to use non-ascii representations of device types. like SCSD = 100, SCCF = 101, SCLite = 102, M3CF = 200, M3SD=201, gbamp=50, and so on. It's not like we will ever have more than 2^16 device types. You can then just provide an id->string lookup table in the fat.h headers for example.

#107393 - Lick - Sun Oct 29, 2006 10:11 am

chishm wrote:
Maybe WinterMute won't mind, but if he does, ..

Why would he mind? It's actually a FIX rather than a plain modification. ARM is 32-bit, y'know.

chishm wrote:
..but if he does, I'll need to find another (standardised) way.

What about using the first 8bit for brand identification, and the second 8bit for the type identification? Josath is completely right that a 16-bit value is more than enough. (Oh, and 32-bit is actually waaaay too much. Although you can use it as a non-zeroed string..)


I still think a simple fix in stat.h will do and should be allowed. (Chishm, could you be kind, for the millionth time, and build a version with a 32-bit st_dev? I really appreciate the immediate help you've given!)

- Lick
_________________
http://licklick.wordpress.com

#107403 - masscat - Sun Oct 29, 2006 11:26 am

I would go with a change along the lines described by josath. Although the change of dev_t to a 32bit value is simple it is a change to the base source of newlib - maintenance hassle for the devkitARM team when/if a new version of newlib is used.

#107426 - diggla - Sun Oct 29, 2006 4:33 pm

< continued from http://forum.gbadev.org/viewtopic.php?t=7195&start=155 >

When using fread '\n' is also interpreted as the end of a string and libfat stops reading.

So what i have to do as a workaround is to read my data char after char and stop reading when it finds '\n'. Then the program must fseek to the next position after the '\n' and continue reading. This is the only way to avoid garbage in memory when reading binary files. This does not happen when i use gcc for win32. binary data is read without any problems using fget or fread.

code snippet for non working read method. This will stop reading after '\n':

Code:
     fread(book_buffer, 20, cluster, book_file);


here is my example code for the workaround:

Code:

      char tmp[20];

     // Binary Read Hack for NDS, 0x0a=\n causes corrupt reads
    
    for (j = 0; j < cluster; j++) {

      for (i = 0; i < 20; i++) {
         tmp[i] = fgetc(book_file);
         key++;
         if (tmp[i] == 0x0a) {
            myprintf("Found 0x0a at pos %d\n",key);
//             use seek to read correct bytes after \n
            fseek(book_file, key, SEEK_SET);
         }
      }

      for (i = 0; i < 20; i++) {
            myprintf("%02X",(unsigned char) tmp[i]);
      }

      memcpy(&book_buffer[j],tmp,20);
   }


Last edited by diggla on Sun Oct 29, 2006 5:57 pm; edited 1 time in total

#107434 - josath - Sun Oct 29, 2006 5:37 pm

diggla wrote:
< continued from http://forum.gbadev.org/viewtopic.php?t=7195&start=155 >

When using fread '\n' is also interpreted as the end of a string and libfat stops reading.


You must be doing something else wrong, I've used fread and never needed to use fseek to skip \n, even when reading in a text file with many \n's in it

#107464 - diggla - Sun Oct 29, 2006 10:23 pm

josath wrote:
You must be doing something else wrong, I've used fread and never needed to use fseek to skip \n, even when reading in a text file with many \n's in it


ok i found the flaw. i must stuff the disk data to a temp buffer first and then memcopy the data to my custom structures. loading directly to my structures didnt work.

#107471 - Lick - Sun Oct 29, 2006 10:51 pm

chishm: does _BOOT_MP.NDS' startCluster always equal 0?

Also, besides st_dev there is another 16-bit variable that should be 32-bit: st_ino. =/
_________________
http://licklick.wordpress.com

#107480 - chishm - Mon Oct 30, 2006 12:34 am

Lick wrote:
chishm: does _BOOT_MP.NDS' startCluster always equal 0?

Also, besides st_dev there is another 16-bit variable that should be 32-bit: st_ino. =/

The start cluster should never be 0, unless it is the root directory. I can work around the 16 bit st_dev field, but inodes really should be at least 32 bit. Imagine a modern operating system only being able to store a maximum of 65536 files.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#107482 - Lick - Mon Oct 30, 2006 12:39 am

But if I simply enter 0 (for *(vu16*)0x027FFFFC, that is), will GBAMP's hacked firmware do the job of locating _BOOT_MP.NDS for me?

Edit: yes.
_________________
http://licklick.wordpress.com

#108664 - Mota - Sat Nov 11, 2006 2:48 am

Apologies for the noob question, can libfat write to DS-Link? It's a slot-1 device. I didn't see the name mentioned in the thread but I may have missed it.

#108777 - tepples - Sun Nov 12, 2006 12:52 am

It's time for me to stop complaining and start contributing. If I wanted to download a suitable version of libfat source code and customize it by making, say, fopen("/", "r") return a newline-delimited list of files within the root directory, how would I go about this?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#108783 - Lick - Sun Nov 12, 2006 1:23 am

Purrrhaps you shouuuld look at the other fatlibs that DO have directory functions and see what they do? Afterwards, just find a way to implement it into the standard C functions (but I think standard C doesn't include directory functions, so you should check out the Posix functions.)
_________________
http://licklick.wordpress.com

#108798 - felix123 - Sun Nov 12, 2006 3:38 am

DS-link doesn't work yet. The company claims it will in the future.

#108829 - chishm - Sun Nov 12, 2006 6:50 am

tepples wrote:
It's time for me to stop complaining and start contributing. If I wanted to download a suitable version of libfat source code and customize it by making, say, fopen("/", "r") return a newline-delimited list of files within the root directory, how would I go about this?

You can checkout the code from DevkitPro CVS. If you just want to look at a couple of files, you can browse the repository.

To commit back to the source tree you'll need to get access rights from Wintermute, the project administrator. If you are going to make such a major change as this, it is best to discuss it with me or Wintermute before commiting.

For your example, I'd suggest creating a fork instead of adding this to the main code base. This is because the proposed changes will be extraneous when DevkitPro r20 is finally released.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#109280 - Jospfh - Thu Nov 16, 2006 8:36 pm

Hi,

I made a simple piece of code to test libfat on my Supercard. I found out that the code did not work (fatInit() failed) on my 512 MB DaneElec SD card.
Then I tried a 16MB SD card (SDC-16M Canon) and the code worked like a charm!

I have no problem running Beup and DSlinux which both do not use libfat.

Anyway, if there is an update I would be happy to test it!

I'm about to buy a 2 GB SD card. Can anyone let me know which brand and type SD works with libfat & supercard?

Here is some info:

NDS lite
SuperKey
Supercard (firmware 1.7, also tried firmware 1.63)
libfat-nds-20061028.tar.bz2
devkitpro 19b

The code:
Code:
   iprintf("fatInit()..");
   if (fatInit(4, true)) {
    iprintf("\tSuccess\n");
   } else {
    iprintf("\tFailure\n");
   }

   // Write to a file
   FILE *ostream, *fopen();
   if ((ostream = fopen("/test.txt", "w")) == NULL) {
    iprintf("Cannot open file\n");
   }else{
     iprintf("File opened.\n");
     char x[10] = "0123456789";
     fwrite(x, sizeof(x[0]), sizeof(x)/sizeof(x[0]), ostream);
     fclose(ostream); // close file
     iprintf("Wrote to file\n");
   }

   // Read the same file
   FILE *handle;
   if ((handle = fopen("/test.txt", "r")) == NULL) {
    iprintf("Cannot open file\n");
   }else{
     iprintf("File opened\n");
    fseek(handle, 0, SEEK_END);  // Go to end of file
    u32 size = ftell(handle);  // Get current position in file, because it is the end it will be the size
    char* text = (char*) malloc (size);  // Allocate memory for file
    fseek(handle, 0, SEEK_SET);  // Go to begining of file
    fread((void*)text, size, 1, handle); // Read all of file into memory
    fclose(handle); // Close file
  }

   while(1) {

      touchXY=touchReadXY();
      iprintf("\x1b[10;0HTouch x = %04X, %04X\n", touchXY.x, touchXY.px);
      iprintf("Touch y = %04X, %04X\n", touchXY.y, touchXY.py);

   }


fattest.zip
_________________
CircuitDB - Free electronics circuits & schematics!

#109418 - gimblefoot - Sat Nov 18, 2006 4:17 am

I read through this topic in its entirety and figured I'd try using libfat in a NDS app I've written to allow me to remotely control XBMC using the NDS (e.g. edit/create play list, see album art, switch songs, ff/rw, etc). The app works great except that it currently uses the GBA SRAM to save its settings (i.e. wifi settings, XBOX hostname/ip addresses, etc). This is annoying with flash carts because saving is a two step process:

1. Save in app/game.
2. Restart NDS and save SRAM to flash cart.

I figured using libfat in the app would be nice because then the app can just write its settings directly. Also, I'm currently using gbfs for some data files used by the app. This works fine with the SuperCard Lite but doesn't seem to work with the SuperCard Lite Rumble (probably because it doesn't support GBA). I figured libfat should be able to help with this as well.

I decided to test out if libfat works in my app... so I wrote some code just to stat some files on the flash cart. I started out by using fatInitDefault() and it seemed to be successful. However, as soon as stat() was called, the program appeared to hang. I tried using open() to read a file and to write a file but same problem. So then based on the posts in this topic, I figured maybe my flash carts aren't supported properly or maybe I need to wait for a newer version of DevKitPro.

Instead of giving up, I decided to grab fattest source/binary linked on this topic to see if it would work. The binary seemed to work fine printing out mounted partitions but I wasn't sure if stat or open would work since fattest didn't do any of these operations. I managed to get the code to compile (after fiddling with the source a little) and I added in stat, open, read, write calls. Everything worked fine.

Hmm... I checked my build env to make sure I'm using same options in Makefile, including same header files, linking to same library, etc. Everything seemed to check out. While I was checking this stuff out, I left the NDS running after it froze on a stat() call. I noticed that the call eventually returned with an error. I assume the call eventually timed out but failed... I moved my libfat test code around and tried commenting some code out to see if it would have any effect. It turns out that my config loading code that accesses SRAM was causing problems for libfat. I'm guessing the reason was that after loading config details, I was doing a WAIT_CR that gave ownership of the cart/rom back to the ARM7 CPU. After fixing this, libfat worked fine...

Anyway, I just thought I'd share this with the forum in case someone else hits this problem and doesn't feel like banging their head against a wall.

devkitPro 19b
libfat-nds-20061116 (with directory functions commented out)
NDS lite (flashmev7lite)
SuperCard SD (firmware 1.63)
SuperCard Lite (firmware 1.7)
SuperCard Lite Rumble (firmware 1.7)

#109895 - Drifter - Wed Nov 22, 2006 11:35 am

I've just tried libfat with dualis and it doesn't appear to work (it actually crashes dualis).

Maybe I'm doing something wrong. gba_nds_fat worked.

Any ideas?

#110213 - simonjhall - Sun Nov 26, 2006 10:00 pm

I'm having trouble seeking then reading data from within a big file. I'm 99% sure that the file on the PC is the same as the file being used by the DS, but when I read data I don't get the same results. The data that gets read is from several hundred bytes later on in the file.

Here's a quick snippet of code which I can put near the beginning of my program which will replicate the problem. I call fatInitialise(4, true) before this.

Code:
char buf[9];

FILE *fp = fopen("fat0:/baseq2/pak0.pak", "rb");

fseek(fp, 183786082, SEEK_SET);
fread(&buf, 1, 9, fp);

fclose(fp);

printf("buf is %s\n", buf);


The DS returns data from slightly further into the file and I get the string "textures/". The PC (under Linux) gives "env/unit".

I'd like to check which version is correct with a hex editor or something - could anyone suggest anything easy to use? Although as the PC runs fine and the DS gives whack results I'd like to think the PC's doing it right!

And does anyone have any suggestions as to what the problem could be? I'm using a gbamp with a 512 meg CF card.

Ta guys.

#110219 - tepples - Sun Nov 26, 2006 11:03 pm

At what offset do you see env/unit when reading the file on a PC?

You could find a hex editor (on Windows, I use Notepad++). Scroll to offset 0AF45A60, which corresponds to decimal 183786080.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#110226 - simonjhall - Sun Nov 26, 2006 11:34 pm

On the PC reading 183786082 gives env/unit<and the rest of the filename>
On the DS reading 183786082 gives textures/e1u1/hint.wal

If I examine the pak file (on the CF card) myself with a hex editor the textures string actually lives at 183794274. So the DS is really reading 8192 bytes further into the file than where it really should do...

I would try the old fat driver just to see what's going on, but I really don't want to replace all the FILE * pointers in Q2 with plain integers...

EDIT: I just formatted the CF card and copied back on just the files I needed (as that pak file was fragmented), so now there are no fragmented files. I'm still getting the same problem though :-(

#110233 - chishm - Mon Nov 27, 2006 3:35 am

I'm going to guess that the cluster size of that disc is 8192 bytes. It's probably a seek() bug. If you can tell me the true cluster size, as well as try this test only 8200 bytes into the file, that'd be helpful for tracking it down.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#110317 - simonjhall - Mon Nov 27, 2006 9:15 pm

I was gonna try that this evening but I left my card reader on my desk at work!
Is it likely that the error will be shown at 8200 bytes in? I could just imagine myself searching through a 175 meg file, 8k at a time (by hand) until I detect a difference...
I'll do it tomorrow night :-p

#110339 - chishm - Mon Nov 27, 2006 11:16 pm

It might be an off-by-one error in the cluster determination formula, in which case it should show up 8200 bytes into the file.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#110519 - simonjhall - Wed Nov 29, 2006 12:34 am

Right, I've just spent a while checking what's going on and no, I don't get an error at 8192 or 8200 bytes in. I've only managed to get an error at the address that I gave (175.271k in). I don't get an error at 175k and I don't get an error at 176k, only at that specific address. I could keep homing in until I figure out the exact address it fails on if you like. What would you like me to do?

If you've got pak0.pak from Quake 2 and a gbamp you could always test this yourself...

#110542 - chishm - Wed Nov 29, 2006 2:47 am

Can you tell me what the cluster size of the disc is. Also, make sure that there really is no error at 175k or 176k by checking to see you aren't simply seeing data that really is 8192 bytes ahead but is the exact same as you were expecting. What is the size of the file (in bytes)? Unfortunately I don't have Q2 to try this on. Perhaps try reading from 183777890 and see if you get the data you expected at 183786082.

Just to get the simple stuff out of the way, you are opening the file in "rb" mode on both the PC and DS right?

You can also cast the FILE* handle to a FILE_STRUCT* (see fatfile.h) then extract the position information directly. This way you can tell what cluster, sector and byte it thinks it the data is at (after seeking) and compare it to the actual data position. It helps if the file is not fragmented when doing this.

Finally, try opening the file using
Code:
int fp = open (file_name, O_RDONLY);
to bypass newlib, then use seek and read instead of fseek and fread. This is only a test and I don't expect it to be a permanent solution.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#110609 - simonjhall - Wed Nov 29, 2006 10:11 pm

Ok, I've been testing more...
The file size is 183,997,730 bytes. Diskeeper tells me that the file is not fragmented.

This broken region seems to start somewhere between 0xaf44f46 and 0xaf450c2 and seems to finish at 0xaf46022 to 0xaf45fe6 ish. So it's about 4000 bytes in size... Reads in this area appear to take data from 8k further into the file.
Sorry I can't be more specific, but there's a lot of empty and repeated data.

This is what *fp is just after opening:
Code:
(gdb) print *fp
$9 = {_p = 0x0, _r = 0, _w = 0, _flags = 4, _file = 36930704, _bf = {_base = 0x0, _size = 0}, _lbfsize = 0, _cookie = 0x233830c,
  _read = 0x20a8018 <__sread>, _write = 0x20a7fac <__swrite>, _seek = 0x20a7f60 <__sseek>, _close = 0x20a7f38 <__sclose>, _ub = {_base = 0x0,
    _size = 0}, _up = 0x0, _ur = 0, _ubuf = "\000\000", _nbuf = "", _lb = {_base = 0x0, _size = 0}, _blksize = 0, _offset = 0, _data = 0x0,
  _lock = 0}


after the a seek (to an address which I know works fine, 0xaf44f6c)
Code:
$11 = {_p = 0x2338854 ']' <repeats 32 times>, '\177' <repeats 86 times>, "\215\215\215\215\215UUUU\177\177\177\177PP\\\\\\]]]]]][[[[[[", _r = 148,
  _w = 0, _flags = 5252, _file = 36930704, _bf = {
    _base = 0x23384e8 ']' <repeats 20 times>, '\177' <repeats 82 times>, "Y\216\215\215\215\215\215YYUUUUU]]]]\\\\]]]]]]]]", '[' <repeats 35 times>, "
U", '\177' <repeats 34 times>..., _size = 1024}, _lbfsize = 0, _cookie = 0x233830c, _read = 0x20a8018 <__sread>, _write = 0x20a7fac <__swrite>,
  _seek = 0x20a7f60 <__sseek>, _close = 0x20a7f38 <__sclose>, _ub = {_base = 0x0, _size = 0}, _up = 0x0, _ur = 0, _ubuf = "\000\000", _nbuf = "",
  _lb = {_base = 0x0, _size = 0}, _blksize = 1024, _offset = 183783424, _data = 0x0, _lock = 0}


after the read:
Code:
(gdb) print *fp
$13 = {_p = 0x2338868 ']' <repeats 12 times>, '\177' <repeats 86 times>, "\215\215\215\215\215UUUU\177\177\177\177PP\\\\\\]]]]]][[[[[[", _r = 128,
  _w = 0, _flags = 5252, _file = 36930704, _bf = {
    _base = 0x23384e8 ']' <repeats 20 times>, '\177' <repeats 82 times>, "Y\216\215\215\215\215\215YYUUUUU]]]]\\\\]]]]]]]]", '[' <repeats 35 times>, "
U", '\177' <repeats 34 times>..., _size = 1024}, _lbfsize = 0, _cookie = 0x233830c, _read = 0x20a8018 <__sread>, _write = 0x20a7fac <__swrite>,
  _seek = 0x20a7f60 <__sseek>, _close = 0x20a7f38 <__sclose>, _ub = {_base = 0x0, _size = 0}, _up = 0x0, _ur = 0, _ubuf = "\000\000", _nbuf = "",
  _lb = {_base = 0x0, _size = 0}, _blksize = 1024, _offset = 183783424, _data = 0x0, _lock = 0}


Dunno if that's any use!

I don't know what the cluster size of the disk is - I just chose default. Is there an easy way of finding out?

Thanks for the help btw :-)

EDIT: I forgot to say, yes I'm using 'rb' and I tried to use open/seek/read, but I didn't know what the prototypes were. I'll try your other fat driver later to see if I get the same read problems.

#110710 - simonjhall - Thu Nov 30, 2006 10:05 pm

Yo, I just tested this with your gba_nds_fat library and it reads the data just as it should... Looks like I'm just gonna have to use that then instead!

#110774 - chishm - Fri Dec 01, 2006 1:33 pm

Unfortunately those structs aren't any help. I really needed the data pointed to by _file within that struct, but I suppose it isn't too important. I mistakenly asked for the wrong data. That doesn't really matter now, if you don't want to spend any more time debugging it.

However, if you do want to debug further, the prototypes are in <sys/unistd.h>. It would also really help if you could find out the cluster size.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#110812 - simonjhall - Fri Dec 01, 2006 9:13 pm

Right! This is with libfat again. I've got 8192-byte clusters.

Here's me opening, seeking and reading from that funny bit of disk. I've basically printed *(FAT_FILE *)fp->_file here. Is that right? Sorry for the whack characters...
after opening:
Code:
$15 = {firstCluster = 3, length = 36953500, curPos = 183997730, curClus = 54, curSect = 0, curByte = 54,
  readBuffer = "\000\000\000\000\000\000\000\000‗W\000\000\n\000\000\000\"\001\000\000\001\000\000\001h?3\002\002\000\000\000\001\000\000\000\b\000\00
0\000\002\000\000\000\001\000\000\000\b", '\0' <repeats 11 times>, "▒\000\000\000\003\000\000\000\234?3\002\"\225?\n6\000\000\000\000\000\000\0006", '
\0' <repeats 11 times>, "‗W\000\000\n\000\000\000\"\001\000\000\001\000\000\001h?3\002\002\000\000\000\001\000\000\000\b\000\000\000\002\000\000\000\0
01\000\000\000\b\000\000\000\000\000\000\000\034\000\000\000\001\000\000\000@?3\002?", '\0' <repeats 79 times>, "i!", '\0' <repeats 190 times>, "█\000
\000\000&YA1? ", '\0' <repeats 14 times>, "z▀3"..., appClus = 1, appSect = 8273, appByte = 2, read = true, write = false, append = false,
  inUse = false, dirEntSector = 8, dirEntOffset = 0}


after seeking:
Code:
$19 = {firstCluster = 3, length = 36953500, curPos = 183997730, curClus = 54, curSect = 183786496, curByte = 22489,
  readBuffer = "\016\000\000\000\000\000\000\000‗W\000\000\n\000\000\000\"\001\000\000\001\000\000\001h?3\002\002\000\000\000\001\000\000\000\b\000\00
0\000\002\000\000\000\001\000\000\000\b", '\0' <repeats 11 times>, "\t\004", '\0' <repeats 28 times>, "\n?┬\000\212\003\001\000env/space1dn.tga", '\0'
 <repeats 40 times>, "\224?├\000\022\000\003\000maps/base1.bsp", '\0' <repeats 42 times>, "???\000pc\036\000textures/e1u1/metal2_1.wal", '\0' <repeats
 30 times>, "\026K?\000?*\000\000textures/e1"..., appClus = 0, appSect = 0, appByte = 0, read = false, write = false, append = false,
  inUse = false, dirEntSector = 0, dirEntOffset = 0}


after reading:
Code:
$21 = {firstCluster = 3, length = 36953500, curPos = 183997730, curClus = 54, curSect = 183786496, curByte = 22489,
  readBuffer = "\016\000\000\000\000\000\000\000‗W\000\000\n\000\000\000\"\001\000\000\001\000\000\001h?3\002\002\000\000\000\001\000\000\000\b\000\00
0\000\002\000\000\000\001\000\000\000\b", '\0' <repeats 11 times>, "\t\004", '\0' <repeats 28 times>, "\n?┬\000\212\003\001\000env/space1dn.tga", '\0'
 <repeats 40 times>, "\224?├\000\022\000\003\000maps/base1.bsp", '\0' <repeats 42 times>, "???\000pc\036\000textures/e1u1/metal2_1.wal", '\0' <repeats
 30 times>, "\026K?\000?*\000\000textures/e1"..., appClus = 0, appSect = 0, appByte = 0, read = false, write = false, append = false,
  inUse = false, dirEntSector = 0, dirEntOffset = 0}


...and the data in my buffer is the data from 8192 bytes further into the file.
Hope this can be some use.

I've not yet tried using open()/seek() etc btw.

#110865 - chishm - Sat Dec 02, 2006 9:44 am

After tracing through all the pointers, you should be using
Code:
*(FAT_FILE *)(*(__handle *)fp->_file)->fileStruct
You'll need to #include <sys/iosupport.h> for __handle. This is all assuming DKP r19b.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#110986 - simonjhall - Sun Dec 03, 2006 12:08 pm

Do I need to be using r19b? I'm still using r19a. Is this likely to be the problem? I've been putting off upgrading as I'm sure everything will just suddenly break! Y'know, don't fix what ain't broken etc ;-)

#110990 - chishm - Sun Dec 03, 2006 12:48 pm

Um, yeah, you need r19b for libfat to work correctly. r19a had a small bug that caused the fileStruct data to become corrupted. This may be the root of your problem.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#111036 - OOPMan - Sun Dec 03, 2006 7:54 pm

Doh :-( That's kinda funny, in a not so funny way...

Maybe devkitPro should try and version check and then cry bloody murder if it's not up to date :-)
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#111043 - simonjhall - Sun Dec 03, 2006 8:30 pm

Right...I didn't know that you required a certain version in order for it to work. I thought they were, like, two separate things...

I'll get back to you when I get round to updating!
_________________
Big thanks to everyone who donated for Quake2

#111460 - mysteryegg - Wed Dec 06, 2006 7:44 pm

If anybody has encountered problems with chism's fat lib using DS-X, I've discovered this may be related to the auto-boot option in DS-X. If your DS-X settings allow for your program to be loaded without loading the DS-X operating system first, the fat lib will not function properly, and both read & write operations may fail.

#111469 - OOPMan - Wed Dec 06, 2006 8:37 pm

That's no surprise, since the DS-X is not officially supported by fatlib and won't be until to DS-X developers actually release some info about how their fat system works...
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#111967 - JessTicular - Tue Dec 12, 2006 2:48 am

About the EFA2 support - I don't think it works.

I've tried using both init and initDefault, but both of which return false unfortunatly.

Is there anything different or special I could try to get it to work for the EFAII?

[EDIT]
ie, do I have to enable something in the source, and re-compile?
[/EDIT]

Cheers,
Jess.
_________________
Nintendo DS & Dominos :: DS Dominos
http://jt0.org

#111972 - chishm - Tue Dec 12, 2006 3:32 am

That's unfortunate. EFA2 is placed as the very last device in the list, as an experimental card. Either another driver is returning true incorrectly or the EFA2 driver is faulty. I don't have an EFA2 to test with, so I can't really fix it, but feel free to play with the source.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#112077 - JessTicular - Wed Dec 13, 2006 12:19 am

Ok, I rearranged the order and made the efa2 first, and it still failed. So it's definatly the driver.

Next, I have put in a number of debug strings throughout the efa2 io code, and narrowed the issue down to the fact that the returned NAND ID is wrong (getting 0x41000000 instead of 0xEC79A5C0).

I have absolutlely no idea where to go from here, so I've emailed CyteX, but in the mean-time, do you know much about the EFA2 hardware and its registers?

Cheers,
Jess.
_________________
Nintendo DS & Dominos :: DS Dominos
http://jt0.org

#112083 - chishm - Wed Dec 13, 2006 2:45 am

I know next to nothing about the EFA2, so your best bet is CyteX.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#112179 - JessTicular - Thu Dec 14, 2006 1:48 am

No worries.

Thanks for the great library, though, without it, I'd still be stuck not knowing what to do :P

If I ever do get the EFA2 code working, I'll most definatly give you the updated source to include into the repository so others can benefit from it.

Cheers,
Jess.
_________________
Nintendo DS & Dominos :: DS Dominos
http://jt0.org

#112261 - sirpoonga - Thu Dec 14, 2006 10:49 pm

Is there an emulator that supports libfat for testing?

#112337 - OOPMan - Fri Dec 15, 2006 10:49 am

I think Dualis does. I know it gets past basic init...

*checks quickly*

Hmmmm, Dualis can pretend that a GBAMP v2 is plugged in, but it doesn't actually allow you to specify and image for use with it, so I guess the real answer is: Not really...
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#112362 - josath - Fri Dec 15, 2006 5:43 pm

OOPMan wrote:
I think Dualis does. I know it gets past basic init...

*checks quickly*

Hmmmm, Dualis can pretend that a GBAMP v2 is plugged in, but it doesn't actually allow you to specify and image for use with it, so I guess the real answer is: Not really...


Reading documentation might have been helpful. Dualis emulates a GBAMP, and the root of the CF card should be taken as the same directory that the NDS is in. However, I've had problems with it with newer versions of libfat, don't know if this has been fixed.

DeSmMuUEme (or whatever it's called), supposedly has GBAMP emulation as well in newest version. I haven't tried this, so can't comment on it.

#112364 - OOPMan - Fri Dec 15, 2006 6:12 pm

Good point :-(

No noddy badge for me :-(
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#112368 - tepples - Fri Dec 15, 2006 7:20 pm

Noddy badge? What's that?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#112437 - felix123 - Sat Dec 16, 2006 11:12 am

Supercard released the driver for SC DS ONE. It's good to see manufacturer release drivers on launch day.
_________________
Nintendo DS homebrew on Wikipedia

#112438 - OOPMan - Sat Dec 16, 2006 11:18 am

That is good news. I may consider getting a SC-DS at some point. I've disinterested in the DS-X mainly because the creators have yet to release any of their actual homebrew support...

EDIT: Crap, no USB port or anything on it :-(
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#112439 - Sunray - Sat Dec 16, 2006 11:25 am

Well, I rather have only auto FAT integration (which works perfectly for me) than only a FAT lib (sucks to recompile every app out there). gba_nds_fat and fatlib works fine in my apps, without a driver. Hopefully DS-Xtreme will have both soon.

#112441 - OOPMan - Sat Dec 16, 2006 11:39 am

I'd rather not have closed-source auto-integration, thanks.

At least with an open-source fatlib and open source drivers for devices
you have some way of dealing with problems.

At present people using a DS-X can only rely on the DS-X team to
fix homebrew compataibility problems. Not optimal, as the homebrew
community has demonstrated itself quite capable of fixing stuff itself.
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#112634 - sirpoonga - Mon Dec 18, 2006 11:33 pm

FYI, the new R4 slot 1 device released it's I/O interface.
http://www.r4ds.com/soft/3-other-en.htm

#113307 - chishm - Tue Dec 26, 2006 10:27 am

There is a new version of libfat that should hopefully solve device interface problems forever. See this post in this thread for details.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#114841 - Vich - Thu Jan 11, 2007 1:06 am

I wonder if there are plans for integrating EZ-Flash 5?
(I'm on the virge of buying a cartridge and the EZ5 is cheaper than the M3-SD one, while the EZ5 doesn't need a flashed DS)
_________________
[project website] [personal website]

#114842 - josath - Thu Jan 11, 2007 1:33 am

Vich wrote:
I wonder if there are plans for integrating EZ-Flash 5?
(I'm on the virge of buying a cartridge and the EZ5 is cheaper than the M3-SD one, while the EZ5 doesn't need a flashed DS)


The shop I looked at (not supposed to mention its name, but it starts with "kick") had both of them for $45, and neither one requires flashed DS. I'd say go with the M3 Simply.

#114892 - Vich - Thu Jan 11, 2007 10:13 am

josath wrote:
Vich wrote:
I wonder if there are plans for integrating EZ-Flash 5?
(I'm on the virge of buying a cartridge and the EZ5 is cheaper than the M3-SD one, while the EZ5 doesn't need a flashed DS)


The shop I looked at (not supposed to mention its name, but it starts with "kick") had both of them for $45, and neither one requires flashed DS. I'd say go with the M3 Simply.


Add shipping costs(to the Netherlands) and taxes and it'll be very close to what the shops are asking here (65? at the lowst ... to 100?+ :X)
But almost all of them get delivered with a passme device, so I presume it doesn't work without one?
Although I have a flashed DS, I might buy a DS light later, so it would be nice if I don't have to flash it(for warranty).

(sorry for taking this thread offtopic)
_________________
[project website] [personal website]

#115667 - HyperHacker - Thu Jan 18, 2007 7:51 am

So... I don't see a download link anywhere on the site for libfat.
_________________
I'm a PSP hacker now, but I still <3 DS.

#115682 - Lick - Thu Jan 18, 2007 11:31 am

HyperHacker wrote:
So... I don't see a download link anywhere on the site for libfat.

Third page of that topic. I agree that the libfat build should be linked on the DLDI page, even just temporarily.
_________________
http://licklick.wordpress.com

#115720 - Puyo - Thu Jan 18, 2007 6:05 pm

How about looking 6 posts earlier in this topic? But indeed should be added to DLDI page.

#115762 - HyperHacker - Fri Jan 19, 2007 12:03 am

Ah, I didn't see the link there. They're almost the same colour as the text; when I'm up that late they start to blend right in. Thanks. (Though still, why no link on the page? I checked the source, so I doubt I missed it.)
_________________
I'm a PSP hacker now, but I still <3 DS.

#116043 - HyperHacker - Sun Jan 21, 2007 11:18 am

If anyone else is getting "undefined reference to irqDisable" in libfat.a, the solution is so trivial it's almost funny.
_________________
I'm a PSP hacker now, but I still <3 DS.

#116220 - Vich - Tue Jan 23, 2007 8:36 am

Can we update the startpost with the latest version of libfat and the drivers? It's a real pain to browse to 15-page topics for stuff that could be the right link...
Why don't the developpers always keep a zip file named like "MyDriver-Latest.zip"? This way, we don't have to change the topic start continuously!
_________________
[project website] [personal website]

#116251 - tepples - Tue Jan 23, 2007 6:03 pm

Vich wrote:
Why don't the developpers always keep a zip file named like "MyDriver-Latest.zip"?

There are only two ways to do it: filenames with the version number and filenames without the version number. If the version number is included, you complain. If the version number is omitted, people who keep an archive of multiple previous versions of software would complain about having to go in and rename each version after downloading it, as I have seen when figuring out the distribution for LOCKJAW.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#116273 - HyperHacker - Tue Jan 23, 2007 11:48 pm

So I suppose the simple solution is to update the first post to link to the latest version with each new release.
_________________
I'm a PSP hacker now, but I still <3 DS.

#116316 - Vich - Wed Jan 24, 2007 10:08 am

tepples wrote:
Vich wrote:
Why don't the developpers always keep a zip file named like "MyDriver-Latest.zip"?

There are only two ways to do it: filenames with the version number and filenames without the version number. If the version number is included, you complain. If the version number is omitted, people who keep an archive of multiple previous versions of software would complain about having to go in and rename each version after downloading it, as I have seen when figuring out the distribution for LOCKJAW.

And what about uploading the file that has the version number in it ?nd uploading it as MyDriver-Latest.zip
If they put a changelog or version.txt or an empty [version x].txt in it, it would be easily identifyable. Of course that's more work for the developpers, but it's not as much work as constantly updating the startpost.
_________________
[project website] [personal website]

#118291 - simonjhall - Sun Feb 11, 2007 10:35 pm

Feeling kinda dumb here...
Which DLDI driver do I need to use for a Supercard which takes miniSD? The regular 'scsd' one doesn't wanna know when using the dldi tester.
The card worked fine when using the SCSD stuff from gba_nds_fat...

PS: I realise there's a search function, but searching for Supercard, DLDI or FAT is gonna turn up like a million hits...
_________________
Big thanks to everyone who donated for Quake2

#118292 - dantheman - Sun Feb 11, 2007 10:38 pm

simon, using the regular SC SD patch file for my miniSD works fine, though I sometimes have to apply it to the .ds.gba instead of the .nds. I haven't used the DLDI tester myself though.

#118296 - simonjhall - Sun Feb 11, 2007 11:12 pm

Seems that I can't get the dldi tester to work on my SC no matter what (there's gotta be something obv that I'm missing), but Quake runs 'fine' with DLDI. It also works when I patch it with the R4 driver too, which I find a bit suspicious!
On the other hand, the M3 Simply works first time with DLDI, but after one frame of gameplay it locks up. O...k!
_________________
Big thanks to everyone who donated for Quake2

#121419 - theli - Mon Mar 12, 2007 8:27 am

chishm, can you update G6 driver on your DLDI page?
http://forum.gbadev.org/viewtopic.php?p=120549#120549

#121420 - Diddl - Mon Mar 12, 2007 9:04 am

and could you update the DLDI driver for DS Link card?

http://forum.gbadev.org/viewtopic.php?p=120281#120281

#121511 - silent_code - Mon Mar 12, 2007 9:14 pm

hi!

this may be a rather dumb question, but: i have a neoflash mk4 mini and a neoflash slot 2 card - can someone point me to a solution how to get my files and directories onto it? do i need to make some sort of disk image? i don't have the possibility (read: software) to create directories on the flash card. just... how? couldn't find a forum for this (may be that i'm blind or something or it just doesn't exist) and i don't have the time to read through *all* post. (sorry.)

thanks for any help!

#121515 - josath - Mon Mar 12, 2007 9:52 pm

silent_code wrote:
hi!

this may be a rather dumb question, but: i have a neoflash mk4 mini and a neoflash slot 2 card - can someone point me to a solution how to get my files and directories onto it? do i need to make some sort of disk image? i don't have the possibility (read: software) to create directories on the flash card. just... how? couldn't find a forum for this (may be that i'm blind or something or it just doesn't exist) and i don't have the time to read through *all* post. (sorry.)

thanks for any help!


What you want is called 'FCSR', GPF has a tool for fcsr images under windows, you can find it on his website. Also search for it on the forums, it should come up.

#121523 - silent_code - Mon Mar 12, 2007 10:17 pm

thanks, i'll have a look at it.

#121543 - Paco_777 - Tue Mar 13, 2007 1:18 am

Hi,
I may be wrong but it seems that there is a memory leak in the fopen/fclose code
(on Supercard SD, at least)

To reproduce the problem I performed the following code:

Code:
int allocsize=1000;
void* before = malloc(allocsize);
free(before);

FILE *handle = fopen("/my.file", "r");
fclose(handle);

void* after = malloc(allocsize);
free(after);

As a result, I get different values for 'before' and 'after'.

Has anyone else having this problem ?

(I cannot really confirm that, but I think that the libfat I used before the directory listing was available, did not have this problem)
_________________
http://Gnese.free.fr/NDS/

#121587 - Diddl - Tue Mar 13, 2007 9:21 am

I think this is no memory leak. it is cause of the buffer allocation of libfat.

#121604 - chishm - Tue Mar 13, 2007 12:50 pm

Updated DLDIs for DS Link and G6 flash cart.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#121635 - Paco_777 - Tue Mar 13, 2007 5:29 pm

Diddl wrote:
I think this is no memory leak. it is cause of the buffer allocation of libfat.


You might be right.
I checked on XP and the result is the same (the addresses are different).
I was not aware of that behaviour.

So i guess that there is one memory allocation performed with the first fopen method call (which is kept during all the program execution).
Is it possible that some new memory allocation (not deleted by a fclose()) are done in the next fopen calls (or is the first one, the only one) ?


For information, i need to know what is happening in order to avoid memory fragmentation.
_________________
http://Gnese.free.fr/NDS/

#124003 - felix123 - Mon Apr 02, 2007 12:25 pm

Here's a DLDI for N-Card. I think it is written by the manufacturer.
http://www.superdslink.com/download/file/NC_DLDI.rar
originally from
http://www.superdslink.com/download/download.html
_________________
Nintendo DS homebrew on Wikipedia

#124016 - Diddl - Mon Apr 02, 2007 2:20 pm

felix123 wrote:
Here's a DLDI for N-Card. I think it is written by the manufacturer.


we have this since many weeks from other companies (Neo MK5, DS Linker ...) it is same and has READ SUPPORT ONLY. (write functions are only for SRAM).

#124397 - ps2aich - Thu Apr 05, 2007 7:26 pm

Hi to all,

when Moonshell 1.5.1 came out and my GBAMP SD worked with it,
I lived with that for the last 3 month now.

Today, I tried the first time to use DLDI with the GBAMP SD.
(especially to test the new NDS_loader of chishm).
And, it unfortunately does not work. Has anyone got it to work?

I then tried the DLDI Testing tool, injected the mpsd.dldi and it stops by the line
Code:
Initing FAT...



Since on the DLDI site GBAMP SD is still remarked untested, am I the first one to test it?????


Last edited by ps2aich on Mon Apr 09, 2007 10:12 am; edited 1 time in total

#124509 - knight0fdragon - Fri Apr 06, 2007 1:29 pm

qwerty, author of blubb, seems to be having problems with fseek and the lastest CVS. I have tracked it down to where any file exactly mod 16k ends up crashing the program when fseek (fp, 0, SEEK_END);
the temporary fix I gave him right now is to add one byte do the file, since it will work that way
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#124515 - chishm - Fri Apr 06, 2007 2:16 pm

Can you please post the relevant code snippets and indicate the exact location where it crashes. Also, make sure it is definitely the latest code from CVS. I had placed a fix in there about a month ago that dealt with a similar case to yours (or Blubb's).
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#124534 - qw3rty - Fri Apr 06, 2007 5:34 pm

Code:

...
FILE* fp;
fp = fopen (tiledatafilename, "rb");
   if (!fp)
    {
      fprintf (stderr, "error: couldn't open \"%s\"!\n", tiledatafilename);
     free(palette8);
      return -1;
    }
   printf("seeking file raw %d\n",fp);
   fseek (fp, 0, SEEK_END); //<----this call crashes at files with n*16K bytes
   printf("telling size\n");
   i = ftell (fp);//size



I am using the newest CVS - downloaded two times today, verified that fatfile.c is indeed the one with the "fix" for fseeking.

I never had any problems with fseeking, before I updated to the libfat-cvs today.(I used the current stable version before I tried the CVS)

#124594 - chishm - Sat Apr 07, 2007 3:05 am

Okay, can you try this (replaced with direct calls to open/seek) and tell me what happens:
Code:
int fd;
fd = open (tiledatafilename, O_RDONLY, 0);
   if (fd < 0)
    {
      fprintf (stderr, "error: couldn't open \"%s\"!\n", tiledatafilename);
     free(palette8);
      return -1;
    }
   printf("seeking file raw %d\n",fd);
   lseek (fd, 0, SEEK_END); // Does it still crash here?
   printf("telling size\n");
 // No tell operation for i = ftell (fp);//size


This will help me figure out where the bug is.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com


Last edited by chishm on Sat Apr 07, 2007 12:53 pm; edited 1 time in total

#124625 - qw3rty - Sat Apr 07, 2007 10:19 am

I tried hard, but I just can't find this 'seek' function you are talking about :(
(undefined refernece to 'seek')

I searched devkitpro up&down, I just can't find what lib /h to include

#124631 - chishm - Sat Apr 07, 2007 12:53 pm

Sorry, I meant lseek. I've fixed the above code fragment now. The header for it is <sys/unistd.h>.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#124633 - qw3rty - Sat Apr 07, 2007 1:19 pm

lseek crashed too.

but I replaced O_RDONLY with 0....no idea if that is correct.

fd is "35702408", maybe that helps.

#124641 - chishm - Sat Apr 07, 2007 3:34 pm

It really shouldn't be 0. Hmm, the fd should've been returned as -1 in that case, but that's a different matter. When it crashes, does it simply freeze, or does it do something else entirely. If you don't mind sticking in debug iprintfs, and since you are already compiling libfat yourself, you might want to add some debug messages to _FAT_seek_r in fatfile.c .
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#124703 - qw3rty - Sat Apr 07, 2007 9:46 pm

<sys/fcntl.h> :
#define O_RDONLY 0

so I thought putting ZERO would be ok.
I included fcntl.h now, exactly the same result.

Code:
   int fd;
fd = open (tiledatafilename, O_RDONLY, 0);
   if (fd < 0)
    {
      fprintf (stderr, "error: couldn't open \"%s\"!\n", tiledatafilename);
     free(palette8);
      return -1;
    }
   printf("seeking file raw %d\n",fd);
   lseek (fd, 0, SEEK_END); // Does it still crash here?
   printf("lseek didn't crash\n");
   while(1);


about the crash - lseek never returns.
Maybe I'll look further into the problem tomorrow - I just returned from work.

#124862 - qw3rty - Mon Apr 09, 2007 7:53 am

Hi :)

I included a printf() in _FAT_seek :

Code:

...
                        while ((clusCount > 0) && (nextCluster != CLUSTER_FREE) && (nextCluster != CLUSTER_EOF)) {
         clusCount--;
         cluster = nextCluster;
         nextCluster = _FAT_fat_nextCluster (partition, cluster);
         printf("while cluscount %i, %i\n",cluster,nextCluster);
      }
....



It does NOT crash with the printf, but it does if I uncomment it again :O
This does sound very strange !
Either I included a stupid bug in my program somewhere ?!
Or the little "pause" from the printf() fixes the crash - no idea ?!

#124864 - qw3rty - Mon Apr 09, 2007 8:21 am

Code:

      while ((clusCount > 0) && (nextCluster != CLUSTER_FREE) && (nextCluster != CLUSTER_EOF)) {
         vcount_old = REG_VCOUNT;
         clusCount--;
         cluster = nextCluster;
         nextCluster = _FAT_fat_nextCluster (partition, cluster);
         //printf("while cluscount %i, %i\n",cluster,nextCluster);
         while (vcount_old == REG_VCOUNT);
      }


fixes the bug too !

EDIT : !
It doesn't really fix it, it just doesn't crash anymore, but now it returns the wrong size (for n*16k files) !

EDIT2 : printf() didn't really fix it neither - also wrong file size !
The filesize I get from ftell is -22 !
I tried to make a huge pause, 190 scanlines - same result.

P.S. : All my tests were made on GBA-MP, default dldi-driver (binary NOT patched)

#124897 - HyperHacker - Mon Apr 09, 2007 8:31 pm

It's memory corruption. Have fun! <_<
_________________
I'm a PSP hacker now, but I still <3 DS.

#125081 - chishm - Wed Apr 11, 2007 5:34 am

Try sticking the printf after the while loop and see if it ever makes it out of the while loop, and to see if it still crashes. I'm with HyperHacker on this one, it sounds like memory corruption. Now we just need to figure out where.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#125203 - chishm - Thu Apr 12, 2007 2:13 am

It seems that you were bitten by a bug that I cam across a few months ago. The newlib stubs that call _FAT_seek_r were passing a NULL pointer when they shouldn't, and _FAT_seek_r was writing to it, causing the freezing. There was also a related bug when seeking to the end of a read-mode file that was an integer multiple of a cluster size, which I just fixed. Try the latest CVS code now.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#125229 - qw3rty - Thu Apr 12, 2007 7:26 am

OK, I will test it - thanks for the fix chism :D

P.S. : Seems to work flawless now (at least seaking to the end of n*16k files)

#126317 - cory1492 - Sun Apr 22, 2007 4:30 am

ttbal pointed this out to me yesterday, is this problem localized to my build of what is in cvs? Is it something I missed?
fattest_1492.zip
(a sample showing symptoms of the problem)

I am able to create multiple entries with identical file names (a side effect being that the name displayed by the dir iteration is also not correct) using current cvs revision of libfat???

Example:
Within a directory "test2" I open a non-existant file called "zelda DX.sav" in "wb" mode, write data to it and close it, open a file called "zelda DX.sav" in "wb" mode, write data to it and close it, then use the directory iteration function to get the name of the file... they both are "zelda.sav" - the problem occurs whether /test is my cwd or when I call fopen with "/test/" prepended.

It doesn occur when the file was already existing via creation by windows (even if it is just a 0k file).

edit:/ meant cvs not svn

#126325 - chishm - Sun Apr 22, 2007 8:35 am

I've just fixed the code in CVS. It was because I had forgotten to add space to the list of illegal alias (short filename) characters. That sample really helped to track down the bug, thanks.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#126330 - cory1492 - Sun Apr 22, 2007 11:18 am

Awesome, I'm not crazy... maybe.

Thanks chishm for the fast fix, works great now. Jumping from R17 to R20 was mildly painful, but for libfat it is definitely worth it.

On another note:
Is there a simple way to tell free/used space (preferably before opening a file and writing to it)? I'm guessing no, but I figured I'd ask at any rate. Writing a file without enough free space, and then closing it (pretty much ignoring any ferror/errno) seems to be corrupting the card.

#130431 - wandafritsch - Sun Jun 03, 2007 11:29 am

cory1492 wrote:
I am able to create multiple entries with identical file names (a side effect being that the name displayed by the dir iteration is also not correct) using current cvs revision of libfat???

chishm wrote:
I've just fixed the code in CVS. It was because I had forgotten to add space to the list of illegal alias (short filename) characters. That sample really helped to track down the bug, thanks.


Same thing happens if I worked with DSFTP.
The ftp client showed two directories with the same name within one folder.
DSOrganize told me the same, two times an identical name...

[APPL]
---- [DSMI]
---- [DSMI]
---- ...

Putting this 'corrupted' card into my PC shows up:

[APPL]
---- [DSAIM]
---- [DSMI]
---- ...

So I am wondering why the PC could see the right things
while the DS shows wrong ones!?

:-)


Last edited by wandafritsch on Sun Jun 03, 2007 3:31 pm; edited 1 time in total

#130439 - jackman - Sun Jun 03, 2007 1:00 pm

wandafritsch wrote:
The ftp client showed two directories with the same name within one folder.
DSOrganize told me the same, two times an identical name...

the same as on my SD Cards, but two things are different:

1. DSO freeze when I open the folder with the "corrupted" filenames
2. MoonShell 1.7x displays wrong filenames, but opens the correct ones (will happen with both scsd.dldi and scsd_moon.dldi)
_________________
Equipment:
Nintendo DS, GBAMP v2, SuperCard SD, SuperKey, Acekard 2i

#132897 - HyperHacker - Sun Jul 01, 2007 8:50 am

Is there a way to tell which slot fat0:/ is accessing?
_________________
I'm a PSP hacker now, but I still <3 DS.

#133141 - tepples - Tue Jul 03, 2007 8:08 pm

If fat1: is present, then fat0: uses it. Otherwise, fat0: uses fat2:.

cory1492 wrote:
Is there a simple way to tell free/used space (preferably before opening a file and writing to it)? I'm guessing no, but I figured I'd ask at any rate. Writing a file without enough free space, and then closing it (pretty much ignoring any ferror/errno) seems to be corrupting the card.

I'd like to know as well so that my programs don't corrupt the card when writing out the state of a simulated village.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#133784 - abszero - Sun Jul 08, 2007 6:44 pm

chishm wrote:
It seems that you were bitten by a bug that I cam across a few months ago. The newlib stubs that call _FAT_seek_r were passing a NULL pointer when they shouldn't, and _FAT_seek_r was writing to it, causing the freezing.


I think a similar bug may still exist. I seem to be getting sporadic data aborts from _FAT_seek_r that are arising from r being NULL when setting r->_errno. They seem to all be arising from the 'if (position < 0)' block, though I haven't tested this extensively.

Testing for NULL before accessing _errno seems to avoid the crashes, though it's somewhat hard to confirm whether my program is losing any data because of whatever's going on. I haven't tracked down what the circumstances leading to the NULL call are, but they seem to only happen in _FAT_seek_r, even though the other _FAT_xxx functions are equally prone.

#133838 - chishm - Mon Jul 09, 2007 4:03 am

_FAT_seek_r being called with r = NULL was a fault of the seek stub that was calling it. This fault should have been fixed in DKA r20, unless my memory of the release date is a little off. If not, then it will definitely be fixed in DKA r21.

The other _FAT_xxx functions should not have this problem, since the calling stubs don't have the same fault.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#133851 - abszero - Mon Jul 09, 2007 8:28 am

Ah, good to know. For the record, I was getting the problem with R20 and a freshly checked out version of libfat (07/07/07 I guess) so perhaps a real fix will have to wait till R21.

Thanks for all the work on libfat, btw :)

#135054 - josath - Thu Jul 19, 2007 8:13 pm

I am attempting to make the DS appear as a Mass Storage Device via the USB port on the DSerial. In order to do this, I need to be able to read/write 512 byte sectors directly on the disk.

What is the best way to directly call a readSector(s)/writeSector(s) function, that still takes advantage of DLDI & libfat's ability to autodetect the device type? (This way the MSD driver will automatically work for any libfat-supported slot-2 device)

I mean, I can see i want something like partition->disc->fn_readSectors & fn_writeSectors, but if at all possible, I don't want to hack into the internals of libfat, which might make my code break if libfat gets changed internally.

#135102 - chishm - Fri Jul 20, 2007 5:31 am

Using the disc pointer is probably the best way to do it. Alternatively, you can just use the code in the disc_io folder of libfat's source to access the disc. This requires that you not use libfat at all, otherwise you'll end up with 2 DLDI sections and only the first will be patched.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#135149 - Dwedit - Fri Jul 20, 2007 12:42 pm

I was wondering if the busy waiting code for the Disc IO devices requires cycle-accurate accuracy, or if the CPU be spent doing something else useful while waiting for the device to become ready. For example, let's say the disc IO code was modified to set a high resolution timer to generate interrupts, then check if the device is ready within the interrupt handler.
I wouldn't expect all busy waiting to be interruptible, for example SCSD required assembly code to communicate.
Additionally, I'm wondering if it's okay to have interrupts enabled during Disc IO calls. I see nothing to disable interrupts anywhere in libfat, except for the apparently interrupt-driven NinjaDS driver.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#135157 - chishm - Fri Jul 20, 2007 1:52 pm

Most devices don't need cycle-level accuracy.

Many SLOT-2 cards use the read/write signals on the GBA bus to generate the clock signal for the inserted SD/CF card. Media cards tend to have a high tollerance for the clock timings, and as long as you don't read/write other parts of the GBA cart when trying to access the media card, you should be okay. The SuperCard SD is an exception to this, as it uses an internal register when writing to the SD card.

SLOT-1 cards either abstract away the communication with the media card to work using the SLOT-1 ROM bus, or they use the SPI bus, which is also tolerant of varying clock signals.

For the same reason, interrupts should be acceptable when communicating with the media card, unless the adapter device's hardware requires higher cycle accuracy.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#135251 - Dwedit - Sat Jul 21, 2007 12:56 pm

Why not disable interrupts while talking to the SCSD then?

Also, is it possible to have a different IO driver that leaves the M3/supercard in RAM mode all the time, except when it's time to access the disk, then switches it to disk mode and back again on each IO call?
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#135253 - Snaeng - Sat Jul 21, 2007 2:28 pm

Maybe this was already asked, but theese are 16 pages :|

Does this also work with the C++ implementions of file accessing? -> ifstream

#135259 - tepples - Sat Jul 21, 2007 3:27 pm

Libfat is a file system implementation that installs itself into the "devoptab" of devkitARM libc. Such file systems work with anything that calls _open_r() (a function that is like open() but reentrant). The newlib implementation of fopen() of standard C I/O (<stdio.h>) calls _open_r(). ofstream::open() of libstdc++, the GNU implementation of C++ standard library, calls fopen().

Caution: Like Knuth, I have only proved this call graph correct; I have not tested it.

But in practice, I would recommend against the use of C++'s I/O facilities unless you can spare 0.25 MiB of the 4 MiB EWRAM for dead code dealing with data types that your program does not use. (If you want verification of this, ask me for the results from nm on hello world.) Particularly on the GBA, which has only 0.25 MiB of EWRAM, you cannot.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#135268 - Snaeng - Sat Jul 21, 2007 5:08 pm

Well, I decided to code in C++, so I'll code in C++.
I don't like a C++ / C mix, that's just awful.

But thanks for the answer. :>

#135277 - tepples - Sat Jul 21, 2007 6:40 pm

It's possible to code in C++ and use <cstdio> (std::printf(), etc) for binary sizes roughly comparable to those of C.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#135281 - Snaeng - Sat Jul 21, 2007 7:43 pm

That would still be a mix of C++ / C. std::printf are just there, because they were in C.

#135305 - chishm - Sun Jul 22, 2007 2:50 am

Dwedit wrote:
Why not disable interrupts while talking to the SCSD then?

The SCSD only needs cycle accurate tming for each halfword of data written to the disc. It works by the host filling the SCSD's register with a 16 bit value on the first cycle, which the SCSD then outputs 4 bits at a time to the SD card. Each of those 4 bits is output on each strobe of the WR line (not absolutely sure on this one, but it describes the behaviour). Strobing the CS line inbetween causes problems. This is all achieved by using a stmia instruction to write 2 CPU register's contents to the GBA bus, with the low 16 bits of the low register containing the value to be written to the SD card and the rest containing garbage.

The SC Lite is slightly different, and doesn't use seem to use an intermediate register, so the data written in each halfword has to contain the correct nybble to be written to the SD card.

In either case, I'm pretty sure that the stmia instruction should be atomic, except on data aborts.

Dwedit wrote:
Also, is it possible to have a different IO driver that leaves the M3/supercard in RAM mode all the time, except when it's time to access the disk, then switches it to disk mode and back again on each IO call?

Sure, DLDI allows you to write your own driver and use it without recompiling libfat.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#135648 - abszero - Wed Jul 25, 2007 7:37 am

It's not normal behavior for fseeks over a file to stop working after a bad seek is it? I don't see any evidence of such in what documentation google readily turns up.

Specifically, I found a place in my code where I was calling fseek (SEEK_SET) with a negative file offset. I got a correct error response at that point and handled it okay in my code, but at the next fseek on that file (to a correct offset that works fine if you haven't made the bad call first), I get a crash occuring in iocontrol.h's AddDevice during the fseek.

Am I supposed to be clearerr'ing or something? Or is this a bug somewhere?

#135652 - calcprogrammer1 - Wed Jul 25, 2007 8:10 am

I'm making a file browser/manager for the DS, with the intention of using both SLOT1 and SLOT2. I have the folder system implemented with but a few modifications to get it working.

I'd like to know, where is there a full documentation (all commands) reference of libfat? If there is none, where might I find information about using the commands it has?

Also, is there a way to read the name/description of the DLDI? I know in MoonShell it will say "adapter:gmtf" and "Datel Games n' Music (microSD)" somewhere in it's bootup sequence. I'd like to put that information on my program too, as well (if possible) the name of the SLOT2 device (non-DLDI) like a GBAMP or Supercard CF or whatever didn't need DLDI.

Last thing...how would you go about copying a file? Do you need to reserve a chunk of RAM to read stuff to, or can you directly read from SLOT2 and write to SLOT1 at the same time? (hoping to add copy support between cards, also same card, if possible).

I've asked lots of questions, but once I get the documentation and enough time at my computer I usually can figure them out on my own...but I need documentation on this, as I've done very little file access, and that was only in C++, my app's using just C.
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135654 - Dwedit - Wed Jul 25, 2007 8:44 am

abszero wrote:
It's not normal behavior for fseeks over a file to stop working after a bad seek is it? I don't see any evidence of such in what documentation google readily turns up.

Specifically, I found a place in my code where I was calling fseek (SEEK_SET) with a negative file offset. I got a correct error response at that point and handled it okay in my code, but at the next fseek on that file (to a correct offset that works fine if you haven't made the bad call first), I get a crash occuring in iocontrol.h's AddDevice during the fseek.

Am I supposed to be clearerr'ing or something? Or is this a bug somewhere?

According to this: http://www.cplusplus.com/reference/clibrary/cstdio/clearerr.html
You're supposed to use clearerr, otherwise the error condition stays set on the stream.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#135655 - Dwedit - Wed Jul 25, 2007 8:45 am

calcprogrammer1 wrote:
I'm making a file browser/manager for the DS, with the intention of using both SLOT1 and SLOT2. I have the folder system implemented with but a few modifications to get it working.

I'd like to know, where is there a full documentation (all commands) reference of libfat? If there is none, where might I find information about using the commands it has?

Also, is there a way to read the name/description of the DLDI? I know in MoonShell it will say "adapter:gmtf" and "Datel Games n' Music (microSD)" somewhere in it's bootup sequence. I'd like to put that information on my program too, as well (if possible) the name of the SLOT2 device (non-DLDI) like a GBAMP or Supercard CF or whatever didn't need DLDI.

Last thing...how would you go about copying a file? Do you need to reserve a chunk of RAM to read stuff to, or can you directly read from SLOT2 and write to SLOT1 at the same time? (hoping to add copy support between cards, also same card, if possible).

I've asked lots of questions, but once I get the documentation and enough time at my computer I usually can figure them out on my own...but I need documentation on this, as I've done very little file access, and that was only in C++, my app's using just C.


Usually you just use a small buffer, maybe 4k or 32k large. Internally, the Disk IO routines read and write full 512 byte sectors, or multiple sectors as a whole cluster.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#135666 - chishm - Wed Jul 25, 2007 12:48 pm

calcprogrammer1:
http://chishm.drunkencoders.com/libfat/index.html has all the non-standard information about libfat. Everything else can be done C stdio.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#135686 - calcprogrammer1 - Wed Jul 25, 2007 4:50 pm

Ok, I'm reading some C copying examples. The browsing part seems to be done, and checking filenames shouldn't be hard.

Is there any way to read the name of the current devices?
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135724 - abszero - Wed Jul 25, 2007 8:14 pm

Dwedit wrote:
abszero wrote:

Am I supposed to be clearerr'ing or something? Or is this a bug somewhere?

According to this: http://www.cplusplus.com/reference/clibrary/cstdio/clearerr.html
You're supposed to use clearerr, otherwise the error condition stays set on the stream.


Yeah, that's one of the places I looked, but it says nothing about clearing the error being a requirement to continue using the stream (is this common knowledge I'm lacking?), and does say the next call to fseek should clear the error anyway.

#135760 - calcprogrammer1 - Thu Jul 26, 2007 5:09 am

How can you tell if a device is inserted or not? My program crashes when I don't have a GBA card in, I want it to check to see if there's a slot-1, check to see if there's a slot-2, and if there is a slot 2 show its contents, otherwise show the slot-1's contents.
_________________
DS Firmware 1, Datel Games n' Music card / Chism's FW hacked GBA MP v2 CF

There's no place like 127.0.0.1.

#135782 - Dwedit - Thu Jul 26, 2007 8:17 am

abszero wrote:
Dwedit wrote:
abszero wrote:

Am I supposed to be clearerr'ing or something? Or is this a bug somewhere?

According to this: http://www.cplusplus.com/reference/clibrary/cstdio/clearerr.html
You're supposed to use clearerr, otherwise the error condition stays set on the stream.


Yeah, that's one of the places I looked, but it says nothing about clearing the error being a requirement to continue using the stream (is this common knowledge I'm lacking?), and does say the next call to fseek should clear the error anyway.


Well, basically if you've ever coded for C++, and accidently typed a non-number character when trying to do 'cin >> int', you'll notice that the program goes crazy. What happens is that the Fail bit for the stream gets set, and until it gets cleared, all IO operations are basically aborted (because they test the Fail bit before starting) until you call cin.clear(); I'd assume it was similar for C. Functions would immediately abort if the stream has an error condition.

Edit: I just realized my post was completely stupid and incorrect, disregard it. Failbit does not propegate to other input, it just passes the input it did not take to the next call. But Bad bit and EOF bit do behave like I mentioned.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#135846 - abszero - Thu Jul 26, 2007 7:57 pm

Well, I appreciate all the input, but I dug a little further and it turns out the answer is that I'm stupid.

I had some old cleanup code hidden away that was closing the stream on an error. That code was supposed to have been deleted but wasn't, and so the stream was being closed before the second seek. Removing the fclose causes the whole thing to work fine (without correcting the initial fseek to a negative offset or clearerr'ing afterwards).

It still seems to me like incorrect behavior for a stream access to a closed stream to result in a pointer exception instead of returning EBADF or something. But my problem is prevented several times over now, so I'm not too worried if people disagree.

Thanks again for the responses.

#137091 - tepples - Tue Aug 07, 2007 9:13 pm

A couple weeks ago, chishm wrote:
Using the disc pointer is probably the best way to do it.

But how do I do that? Would I need to recompile libfat from source to do it? And would I have to wait for CVS to stabilize after devkitARM R21 comes out? I ask because I am in the process of writing code that determines the number of free clusters and number of free kibibytes on the disc, and it appears to need some private interfaces into libfat.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#138544 - EyeballKid - Sat Aug 25, 2007 9:04 am

When creating new files, does libfat always force short filenames to upper case?

Looking at the source, the _FAT_directory_addEntry() function does seem to force short filenames to upper case.
I don't know much about the FAT filesystem (and all its variants :- ), but would a fix be to leave entry->filename as it is, and force just the generated alias to uppercase instead?

I'd be happy to sumbit a patch to do this, if it were the right approach!


(I discovered this when using libfat to write NDS files to my supercard sd. I was wondering why the written file wasn't appearing in the supercard boot menu. It turns out the supercard sd bootmenu only displays nds files with a lowercase extension).

#138566 - tepples - Sat Aug 25, 2007 7:44 pm

EyeballKid wrote:
When creating new files, does libfat always force short filenames to upper case?

FAT long file names as implemented by the NT kernel (Windows 2000, Windows XP, Windows Server 2003, Windows Vista) do not use aliases for short filenames where the name is entirely one case and the extension is entirely one case, such as "example.TXT" or "EXAMPLE.txt" or "example.txt". Instead, they are stored uppercase, without a long file name entry, with two bits in byte 0x0C used to transform the case. Linux since 2.6.something implements this, but I'm not sure that libfat does this correctly.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#143153 - spinal_cord - Wed Oct 17, 2007 1:36 pm

Can someone tell me how to check if a file is hidden?
I don't think st_attr works (or I'm not using it correctly).
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#143179 - Dwedit - Wed Oct 17, 2007 7:34 pm

Feature request:
When scanning a directory containing many many files, I would like a function to call that returns a handle to a directory entry. That way, I can call open on a file without rescanning the directory.

I've thought about this a bit, and obviously this will fail if there is more than one thread messing with the file system unless done carefully.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#143416 - spinal_cord - Sun Oct 21, 2007 1:30 am

spinal_cord wrote:
Can someone tell me how to check if a file is hidden?
I don't think st_attr works (or I'm not using it correctly).


anyone? oh well...
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#143422 - chishm - Sun Oct 21, 2007 3:45 am

spinal_cord:
There's no field in the stat struct to indicate a hidden file. Maybe the execute bit in st_mode can be used for this, since it is used to indicate listable directories.

Dwedit:
You can cast the dirStruct* in your DIR_ITER handle to a DIR_STATE_STRUCT, as defined in fatdir.h. This has the DIR_ENTRY of the current file, which you can use from there.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#143839 - load*,8,1 - Fri Oct 26, 2007 6:00 pm

I'm having a bit of trouble with the dirnext() function. What entries is it supposed to give you? Only all the files/folders for the diropen()ed directory or subfolders as well? Because I'm getting all the files of the directory as well as all those of the first subfolder. I even get that result with the code snippet from here: http://chishm.drunkencoders.com/libfat/index.html
Am I doing something wrong or is it a bug in libfat?

Edit: I did some more testing and something seems to be screwed up big time. :( I have two subdirectories, /data and /lang. When I open /data, I get the contents of /. Without any garbage from other subdirectories. And when I open /lang I get all the files from /data. Seems like the directory structure is shifted somehow.

#143897 - chishm - Sat Oct 27, 2007 5:04 am

Scandisk your card. If it still happens then remove all unnecessary files, defrag it, make a binary dump to a file, zip the file, then send the file to me so I can try to recreate the problem.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#144095 - load*,8,1 - Mon Oct 29, 2007 1:15 am

Thanks, that worked. Must've been just a screwed up file system.

#144496 - Lazy1 - Sat Nov 03, 2007 12:21 am

I don't know if it has been mentioned in this thread but how about a parameter in the fat initialize code to disable certain interrupts during I/O operations?

#144503 - HyperHacker - Sat Nov 03, 2007 2:34 am

I noticed with GBAMP if I give ARM7 access to the GBA slot, fopen() will just hang. I know it can't actually work, and I shouldn't have been doing that (stupid bug), but shouldn't it check if it has access and fail if not?

Also, if I want to write an app specifically for one device that already has a built-in driver, can I remove DLDI support since it wouldn't be necessary?
_________________
I'm a PSP hacker now, but I still <3 DS.

#144529 - chishm - Sat Nov 03, 2007 9:11 am

Lazy1:
Interrupt usage is up to the user. Wrap file accesses with interrupt disabling code if you want to be sure they won't fire.

HyperHacker:
libfat sets access when it initializes. I take the view that the application code should have as much control as it wants. Checking that the user code hasn't changed slot permissions is an unnecessary overhead.

You can remove DLDI support if you are sure you won't need it. at least for now. You will have to remove references to it in disc_io.c and recompile libfat.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#144568 - Lazy1 - Sat Nov 03, 2007 11:18 pm

I have already disabled interrupts before the main loop does any file access, I just thought it would be neater/easier code wise if this was done at the driver level.

#144584 - HyperHacker - Sun Nov 04, 2007 5:51 am

So is fflush() broken? Writing to a file, calling fflush(), and turning off the system without closing the file results in an empty file. There's no way to close it when I'm done because I'm using it to keep track of what happens before the program crashes.

[edit] I managed to install my own exception handler and found that within it, fcloseall() hangs but fclose() works fine. O_o
_________________
I'm a PSP hacker now, but I still <3 DS.

#145155 - HyperHacker - Mon Nov 12, 2007 1:00 am

I had some interesting ideas of things you could do with DLDI, especially if multiple patches were implemented.

-RAM disks. The driver creates a filesystem in slot-2 RAM and reads/writes to it. Maybe even in a malloc()'d buffer, of course then some apps would run out of memory, but others would be fine.

-Multiple patches would allow you to support multiple partitions on a card, or perhaps mount a filesystem image on the card. (fat0:/ is the card itself, fat1:/ is an image file.)

-A driver allowing read-only access to a filesystem appended to the .nds file itself. This would let you test in any emulator, or by WMB without a working flash card if your DS is flashed. With multiple patches, perhaps it could be made writeable too by finding the file on the card and writing to it.

I might just try that last one, since it's the only way I can use homebrew that uses the filesystem until I get a new flash card. >_> Aside from the obvious advantage to developers, I can see a few uses of this for users too: using DSOrganize without a flash card (a few KB should hold the required INI files and a playlist for a streaming radio station or some NSFs), or packing all of an app's required files into the app itself without having to change its code (no more clutter in the root directory!).
_________________
I'm a PSP hacker now, but I still <3 DS.

#145167 - tepples - Mon Nov 12, 2007 2:35 am

HyperHacker wrote:
I had some interesting ideas of things you could do with DLDI, especially if multiple patches were implemented.

-RAM disks. The driver creates a filesystem in slot-2 RAM

Extending FCSR to act as a RAM disk has already been discussed. Consensus was that a separate file system for the RAM disk would be a better idea.

Quote:
-A driver allowing read-only access to a filesystem appended to the .nds file itself. This would let you test in any emulator, or by WMB without a working flash card if your DS is flashed.

As far as I can tell, DS Download Play does not use appended data. You'd have to append the files to the ARM9 segment and then run ndstool again.

If a program is designed for use with FlashMe+wmb, it should probably pull configuration data such as a playlist over the network. Official games do this with Ni-Fi; homebrew could do it with CIFS or HTTP.

Quote:
With multiple patches, perhaps it could be made writeable too by finding the file on the card and writing to it.

Are you looking for EFS?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#145169 - Lazy1 - Mon Nov 12, 2007 2:50 am

That just reminded me, for some reason FCSR is allowing files to be opened in write mode.
I had this weird bug where under no$gba the screen would mess up and lock everything after high scores were displayed.

What was happening was it was trying to save the high scores to a file and sort-of succeeding.
Normally I would expect fopen to fail for a read-only filesystem but for some reason it was allowed and messed up no$gba good.

I spent hours looking for this bug before trying hardware and finding out that an exception was raised during the highscore save.

Moral of the story: FCSR allows writes when it shouldn't, exceptions don't work under no$gba.

#145170 - tepples - Mon Nov 12, 2007 2:54 am

Lazy1 wrote:
That just reminded me, for some reason FCSR is allowing files to be opened in write mode.

Are the modified sectors going to GBA SRAM?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#145171 - Lazy1 - Mon Nov 12, 2007 3:00 am

I'm not sure, I thought that the image needed to be set up a certain way to support SRAM overlays.
I just wanted a read-only filesystem so I left that alone.

#145174 - HyperHacker - Mon Nov 12, 2007 4:55 am

tepples wrote:
Extending FCSR to act as a RAM disk has already been discussed. Consensus was that a separate file system for the RAM disk would be a better idea.
Right, this wouldn't be related to FCSR, this would be FAT16/32 in RAM.

Quote:
As far as I can tell, DS Download Play does not use appended data. You'd have to append the files to the ARM9 segment and then run ndstool again.
Good to know. Thanks. Just tacking stuff on to the end of the ARM9 binary like that won't break anything will it?

Quote:
If a program is designed for use with FlashMe+wmb, it should probably pull configuration data such as a playlist over the network. Official games do this with Ni-Fi; homebrew could do it with CIFS or HTTP.
Certainly a good idea, but I'm thinking more along the lines of programs that aren't designed for it. (That is, I'd rather use DSO than write an entire streaming music player of my own without access to hardware. :-p)

Quote:
Are you looking for EFS?
Hm, I didn't know you could use actual FAT with that. Interesting. Still, if it can be done in a DLDI driver, you wouldn't need to modify the program at all.
_________________
I'm a PSP hacker now, but I still <3 DS.

#145560 - chishm - Sun Nov 18, 2007 3:30 am

As you might (not) have noticed, I've been busy tinkering away with libfat to add a few requested features.

First up is Unicode support. libfat now supports UTF-8 encoded file names for both directory listing and opening files. Only the basic multilingual plane is supported. This is a limitation of VFAT, since it uses UCS-2 encoding of long file names. You will need multibyte string support in devkitARM for it to work, so you'll have to wait until r22 for this feature. For r21 it will behave the same as previous versions of libfat.

Next is a minor bug fix. Files opened for writing will only have a cluster allocated when data is written, rather than when the file is opened. This should keep Windows happy.

Finally there is a complete overhaul of the disc I/O. There are no longer any built-in drivers. Instead, there is a single space for a DLDI patch. Other drivers are loaded from disc at run-time, making them truly dynamic. The regular fatInit(u32 cacheSize, bool setAsDefaultDevice) and fatInitDefault() functions are there. The majority of applications and games will use these as they always have.

For applications that use more than one disc at a time, there is the fatLoadExtraInterfaces (u32 cacheSize, u32 lastPartition) function. Start libfat like usual, then call fatLoadExtraInterfaces. This will load all DLDI files from fat0:/DS/config/DLDI/disc?.dldi where ? is a number from 0 to lastPartition. The files will be patched, then the discs initialised. The number of successfully initialised discs is returned. disc0.dldi will replace the built in driver, so you can load apps from one device and have them load their remaining files from another.

fat0: is the only disc guaranteed to be available. fat1: and above are only loaded at run-time, and don't correspond to any particular slot. It is possible, through fatGetInterface (u32 partitionNumber), to get the DLDI used by a disc, then retrieve the desired information, including the DLDI's friendly name.

The disc I/O changes have not been committed to the devkitPro repository yet. I want to let people try the modified libfat out first and give feedback before I force this change on everyone.

The latest compiled version is libfat-nds-20071118.zip. Download it then extract libfat.a to your libnds/lib directory and extract fat.h to your libnds/include directory. Backup the original files before you overwrite them.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#145570 - tepples - Sun Nov 18, 2007 5:29 am

chishm wrote:
First up is Unicode support. libfat now supports UTF-8 encoded file names for both directory listing and opening files.

Good job :-)

Quote:
For applications that use more than one disc at a time, there is the fatLoadExtraInterfaces (u32 cacheSize, u32 lastPartition) function. Start libfat like usual, then call fatLoadExtraInterfaces. This will load all DLDI files from fat0:/DS/config/DLDI/disc?.dldi

In Windows terms, that would be something like J:\DS\config\DLDI\disc0.dldi through ...\disc9.dldi right? But why use /DS/config/ and not the /data/ folder that some other DS homebrew seems to use?

Quote:
It is possible, through fatGetInterface (u32 partitionNumber), to get the DLDI used by a disc, then retrieve the desired information, including the DLDI's friendly name.

Including FEATURE_SLOT_NDS vs. FEATURE_SLOT_GBA.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#145571 - Dwedit - Sun Nov 18, 2007 5:47 am

Where are you hearing that VFAT is UCS-2 only? As far as I know, Windows XP treats VFAT filenames as full UTF-16.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#145572 - chishm - Sun Nov 18, 2007 6:14 am

tepples wrote:
In Windows terms, that would be something like J:\DS\config\DLDI\disc0.dldi through ...\disc9.dldi right? But why use /DS/config/ and not the /data/ folder that some other DS homebrew seems to use?

Honestly, I had to come up with a directory that could be shared by all DS apps, and I like the idea of having DS stuff separate from, say, photos taken by a digital camera (/DCIM/). /DS/ seems the logical choice, just as /PSP/ is used by Sony for their handheld.

This is one thing I wasn't sure everyone would like, so the path may be changed if there is a consensus on a different one.

tepples wrote:
Including FEATURE_SLOT_NDS vs. FEATURE_SLOT_GBA.

Yes, those are all defined in the fat.h header, but they use FAT_* or DLDI_* to distinguish them from client code defines.

Dwedit wrote:
Where are you hearing that VFAT is UCS-2 only? As far as I know, Windows XP treats VFAT filenames as full UTF-16.

Windows 2000 and above use UTF-16 internally, versions before (Windows 95, 98, ME, previous versions of NT) use UCS-2. Microsoft only ever specify UNICODE in the official FAT white paper (fatgen103.doc), and the actual type depends on the OS. So yes, VFAT can be UTF-16, but not everything supports it, and it's not a requirement.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#145577 - Quirky - Sun Nov 18, 2007 12:25 pm

Nice work! I had noticed that there were changes going on...

A small request: Any chance of tagging the devkitpro CVS repository so we know what is in this release, and can see when new stuff is added afterwards?

e.g. fatfile.c log has CVS Tags: libfat-20070127 at version 1.4. So it'd be nice to see a tag libfat-20071118 for the current release. Tags are one area where CVS is better than SVN, so may as well use 'em.

#145608 - HyperHacker - Mon Nov 19, 2007 12:21 am

My vote is with /data just because it's common already. Also, this sounds great. Unicode support is quite a bonus.
_________________
I'm a PSP hacker now, but I still <3 DS.

#145619 - chishm - Mon Nov 19, 2007 4:35 am

Quirky wrote:
Nice work! I had noticed that there were changes going on...

A small request: Any chance of tagging the devkitpro CVS repository so we know what is in this release, and can see when new stuff is added afterwards?

e.g. fatfile.c log has CVS Tags: libfat-20070127 at version 1.4. So it'd be nice to see a tag libfat-20071118 for the current release. Tags are one area where CVS is better than SVN, so may as well use 'em.

This is an unofficial test release. None of the disc code has been committed to CVS yet, hence it's not possible to tag it.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#145641 - Quirky - Mon Nov 19, 2007 8:30 pm

chishm wrote:
The disc I/O changes have not been committed to the devkitPro repository yet.


chishm wrote:
This is an unofficial test release. None of the disc code has been committed to CVS yet, hence it's not possible to tag it.


Fair enough, I didn't read all of your post - I got all excited after the first few paragraphs and skipped to the "post" button :-)

#145986 - tepples - Tue Nov 27, 2007 4:41 am

Today I ran devkitPro Updater to make sure I had the latest release (not pre-release) of devkitARM, libnds, and libfat. Then I made the following program to test whether libfat creates 8.3 character file names with the correct case. See "Instructions" at the bottom for more info.

Code:
/*
upper/lowercase tester for Chishm's libfat
Copyright (c) 2007 Damian Yerrick

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

based on devkitARM R21 libnds examples: arm9 template
by dovoto and wintermute

*/

#include <nds.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fat.h>
#include <sys/stat.h>
#include <sys/syslimits.h>
#include <sys/dir.h>
#include <errno.h>

// init DS video hardware: taken directly from template
void dsInit(void) {
   irqInit();
   irqEnable(IRQ_VBLANK);

   videoSetMode(0);   //not using the main screen
   videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);   //sub bg 0 will be used to print text
   vramSetBankC(VRAM_C_SUB_BG);

   SUB_BG0_CR = BG_MAP_BASE(31);

   BG_PALETTE_SUB[255] = RGB15(31,31,31);   //by default font will be rendered with color 255

   //consoleInit() is a lot more flexible but this gets you up and running quick
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
}

void press_A(void) {
  fflush(stdout);
  while (REG_KEYINPUT & KEY_A) {
    swiWaitForVBlank();
  }
  while (!(REG_KEYINPUT & KEY_A)) {
    swiWaitForVBlank();
  }
}

/**
 * Ensures that a folders from root up to a file exist.
 * Path separator is /.
 * If the folders do not exist, they are created.
 * @param filename the name of the file
 * @param mode as for mkdir(path, mode)
 * @return 0 for success or <0 for failure
 */
int makedirs(const char *filename, mode_t mode) {
  const char *curSlash = filename + 1;

  for (curSlash = strchr(curSlash, '/');
       curSlash != 0;
       curSlash = strchr(curSlash, '/')) {
    char seg[PATH_MAX];

    // compute the length of this path segment
    int segLen = curSlash - filename;
   
    // check length of buffer
    if (segLen > sizeof(seg) - 1) {
      errno = ENAMETOOLONG;
      return -1;
    }

    memcpy(seg, filename, segLen);
    seg[segLen] = 0;
    if (mkdir(seg, mode) < 0) {
      switch (errno) {
      case ENOTDIR:
        return -1;
      case EEXIST:
        // this is normal
        break;
      default:
        return -1;
      }
    } else {
    }
   
    // skip slash
    curSlash += 1;
  }
  return 0;
}

void makeHelloFile(const char *filename) {
  FILE *fp = fopen(filename, "wt");

  if (fp) {
    fputs("hello world\n", fp);
    fclose(fp);
  } else {
    fputs("could not write to ", stderr);
    perror(filename);
  }
}

void ls(const char *path) {
  struct stat st;
  char filename[PATH_MAX];
  DIR_ITER *dir = diropen(path);

  if (dir == NULL) {
    fputs("Unable to open the directory.\n", stderr);
    return;
  }
  while (dirnext(dir, filename, &st) == 0) {
    fputs(filename, stdout);
    // if it's a folder, write a trailing slash
    if (st.st_mode & S_IFDIR) {
      fputc('/', stdout);
    }
    fputc('\n', stdout);
  }
}

void ls_break(void) {
  fputs("press A to list disk", stdout);
  press_A();
  fputs("\033[2J", stdout);
  ls("/data/hello/");
  press_A();
  fputs("\033[2J", stdout);
}

__attribute__((noreturn))
void die(const char *str) {
  fputs(str, stderr);
  fputs("\nSystem halted.\n", stderr);
  while (1) { swiWaitForVBlank(); }
}

int main(void) {
  touchPosition touchXY;

  dsInit();
  fputs("libfat test suite\n"
        "Copr. 2007 Damian Yerrick\n", stdout);
  if (!fatInitDefault()) {
    die("libfat init failed.\n"
        "Did you use the right DLDI?\n"
        "http://dldi.drunkencoders.com/");
  }
  if (makedirs("/data/hello/",
               S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
    die("Could not make /data/hello/");
  }
  ls_break();
  fputs("Making four files with 8.3\n"
        "character names, only one of\n"
        "which should be all caps\n", stdout);
  makeHelloFile("/data/hello/lowupper.TXT");
  makeHelloFile("/data/hello/lowlower.txt");
  makeHelloFile("/data/hello/UPPUPPER.TXT");
  makeHelloFile("/data/hello/UPPLOWER.txt");
  ls_break();
  fputs("C:\\>", stdout);
 
  // we're done; close the program
  while(1) {
    press_A();
    fputc('A', stdout);
    fflush(stdout);
  }

  return 0;
}

/* Instructions:

 1. Make a copy of the folder
     .../devkitPro/examples/nds/templates/arm9
 2. Replace the 'main.c' file in the copy with this file.
 3. Build the project with latest devkitARM, libnds, and libfat.
 4. Patch the .nds with DLDI if needed.
 5. Run the program on your DS.
 6. Look at the /data/hello/ folder on the card in Windows Explorer.

Expected result:
The second time "list disk" happens, the names are mixed case:
lowupper.TXT, lowlower.txt, UPPUPPER.TXT, and UPPLOWER.txt
In Windows Explorer, "hello" is lowercase, and the names of the files
inside it are mixed case as well.

Actual result:
The second time "list disk" happens, the names are uppercase:
LOWUPPER.TXT, LOWLOWER.TXT, UPPUPPER.TXT, and UPPLOWER.TXT
In Windows Explorer, "HELLO" is uppercase, and the names of the files
inside it are uppercase as well.

*/


EDIT: Chishm told me on IRC that this is fixed in CVS.

EDIT 2: I installed the pre-release from last page (as fat-pre.h and libfat-pre.a), and it worked as expected.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#146305 - Peter - Sun Dec 02, 2007 1:38 pm

I wonder if the time to access/read files from flash-cards differ much.

I ask because I would like to sync music/soundeffects/visualeffecs in my current project, but need to load data from flash-card from time to time. When I trial&error until it's correct with my card (DL Linker 16G), I guess other cards might need longer or less time to read x bytes and so it would be out of sync again.

Maybe there exists a listing that gives information how much time xyz flash-cards need to load x bytes or something like this? :)
_________________
Kind Regards,
Peter

#146331 - tepples - Sun Dec 02, 2007 10:08 pm

Peter wrote:
I wonder if the time to access/read files from flash-cards differ much.

They do. My benchmark program shows that the R4 is generally eight times as fast as the Games n' Music. But it also depends on what brand of CF, SD, miniSD, or microSD card you have.

Quote:
Maybe there exists a listing that gives information how much time xyz flash-cards need to load x bytes or something like this? :)

Given the number of brands of adapters times the number of different memory cards, I'm not sure that such a list maintained by amateurs could ever be comprehensive.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#148600 - Dwedit - Mon Jan 07, 2008 8:23 pm

One of the things I miss from GBA_NDS_FAT is the ability to change directory, and use relative paths.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#148616 - wintermute - Mon Jan 07, 2008 10:32 pm

chdir works fine, haven't tried relative paths recently but I don't see why they wouldn't work.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#148625 - tepples - Tue Jan 08, 2008 12:40 am

wintermute wrote:
chdir works fine, haven't tried relative paths recently but I don't see why they wouldn't work.

They do work. RAC uses libfat. Its file chooser uses chdir() and at least the relative path "..".
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#150671 - nipil - Sun Feb 10, 2008 12:28 pm

The purpose of this post is to bring a small point to the attention : when using the dirnext function, you have no clue on which length the filename buffer should be. When searching, you find a hint in CVS / fatdir.c / line 560, where it should be MAX_FILENAME_LENGTH. You learn in CVS / directory.h / line 046 that it equals 768 (due to UTF-8 encoding possibilities). I know it has already been discussed here, but at that time, it was limited to 256 chars. Now it's still "256 chars", but expands to 768 bytes because of possible UTF-8 encoding , so it's quite misleading to llib's users (imho).

My thought is, there should be a define somewhere in the library (user side, not only in its source), so we can malloc and use the right buffer size. Maybe there are other functions in the lib which are using a buffer as output, so the same "problem" might apply.

Just my 2 cents.
_________________
NDS Lite Gold/Silver, MK5/R4DS, MSI PC54G2, D-Link DI-624

#151678 - HyperHacker - Mon Mar 03, 2008 4:46 am

I can't get either of the Games'n'Music DLDIs to initialize in my apps, while other programs work fine. I made a barebones test case and sure enough it's not working either, with any boot method. (It just turns one screen red and calls fatInitDefault() in a loop. If it succeeds the screen turns green. ARM7 does absolutely nothing.) In my app it worked precisely once and I was able to navigate the filesystem, then I powered off and on again and it went back to not working. Most other homebrew I've tried works every time, from the latest DSOrganize to the DLDI build of TxtWriter and many other apps released ages ago.
_________________
I'm a PSP hacker now, but I still <3 DS.

#151872 - HyperHacker - Thu Mar 06, 2008 7:03 am

Tested this some more today. The app itself works if launched from DSOrganize but not if launched as bootme.nds or through WMB.The test program still doesn't work in any scenario. (With WMB, you have to boot up without the card inserted, stick it in once the app is loaded, and have it wait for a button to be pressed before trying to init, because it has that damn auto-boot flag, and putting it in at the firmware menu locks up the system. I suspected maybe the card has to be initialized with the encryption and so on before it can be used, but this app is actually capable of doing that itself - booting DS cards is one of its functions - and that doesn't help.)

The only thing I can think of that makes this app different from others is that it loads the ARM9 binary to 0x02260000. However, the test program doesn't do this, and it has the same problem, so I doubt that's related.

I remember hearing older versions of DSOrganize worked only if they were launched as bootme.nds. Any idea what was changed to fix that?
_________________
I'm a PSP hacker now, but I still <3 DS.

#152073 - HyperHacker - Sun Mar 09, 2008 7:50 am

OK, it's working for the most part now (but the test program still isn't), but calling stat() breaks everything. The call itself only succeeds if the file is in the root directory, else it returns -1. Afterward, any directory listing returns the contents followed by the 8.3 filename of the last file repeated endlessly.
_________________
I'm a PSP hacker now, but I still <3 DS.

#152220 - HyperHacker - Wed Mar 12, 2008 3:04 am

Tried another MicroSD, same result. Test program doesn't work at all. My app usually - not always - initializes (as in fatInitDefault()) fine, though it sometimes takes several seconds, and reads files from various directories without a problem. Reading anything from /Apps is unreliable. Any given file will sometimes read fine, other times not read (haven't checked just what fails, but it just locks up reading the file), and most of the time stat() will just return -1 (occasionally taking several seconds to do so). Other apps seem to work fine, but also sometimes fail to init or take several seconds. errno.h doesn't even define a return value of -1, so I don't know what that's supposed to mean.

Both cards have been formatted repeatedly with FAT32. One is the 128MB that came with the G&M and the other is a 2GB Kingston.

This is the directory listing for the 128MB card:
Code:
J:\AUDIO
J:\GAMES
J:\VIDEO
J:\_bootme.nds
J:\SNEmulDS.nds
J:\TI85.tisv
J:\TIDS.CFG
J:\data
J:\gmtest.nds
J:\Apps
J:\bootme.nds
J:\bootmenu2.nds
J:\DualSlotBrowser.nds
J:\lameboy.nds
J:\Moonshell.nds
J:\nesDS.nds
J:\snemul.cfg
J:\ti85.rom
J:\GAMES\AquelaBall.nds
J:\GAMES\bahlz.nds
J:\GAMES\battleship.nds
J:\GAMES\breakout.nds
J:\GAMES\Bubbles.nds
J:\GAMES\CarreRouge.nds
J:\GAMES\ChainReaction.nds
J:\GAMES\collection.nds
J:\GAMES\diggerds.nds
J:\GAMES\DoubleSkill.nds
J:\GAMES\DSChess.nds
J:\GAMES\HexaVirus.nds
J:\GAMES\invasion.nds
J:\GAMES\JoggleDS.nds
J:\GAMES\London-Underground.nds
J:\GAMES\Number_Minds.nds
J:\GAMES\PaddleBattleDS.nds
J:\GAMES\PopTheBalls.nds
J:\GAMES\solitaire_ds.nds
J:\GAMES\squashds.nds
J:\GAMES\SuperSnakeDS.nds
J:\GAMES\TalesOfDagur.nds
J:\GAMES\TetrisAndTouch.nds
J:\GAMES\tictactoe.nds
J:\GAMES\warrior_training.nds
J:\GAMES\Zi.nds
J:\VIDEO\shrek_3.d3v
J:\data\bootmenu
J:\data\DSOrganize
J:\data\bootmenu\config.ini
J:\data\bootmenu\vortex.bmp
J:\data\bootmenu\coolpurple.bmp
J:\data\bootmenu\snowboard.bmp
J:\data\bootmenu\vortexhighlight.bmp
J:\data\bootmenu\rena.bmp
J:\data\bootmenu\kite.bmp
J:\data\bootmenu\kitedark.bmp
J:\data\DSOrganize\autoperform.txt
J:\data\DSOrganize\colors.ini.sample
J:\data\DSOrganize\CONFIG.INI
J:\data\DSOrganize\favorites.txt
J:\data\DSOrganize\IRC.INI
J:\data\DSOrganize\notify.wav
J:\data\DSOrganize\searchprefs.txt
J:\data\DSOrganize\specialkeys.txt
J:\data\DSOrganize\startup.wav
J:\data\DSOrganize\wifi.dat
J:\data\DSOrganize\genre.dat
J:\data\DSOrganize\sound.dat
J:\data\DSOrganize\Cache
J:\data\DSOrganize\VCARD
J:\data\DSOrganize\TODO
J:\data\DSOrganize\SCRIBBLE
J:\data\DSOrganize\RESOURCES
J:\data\DSOrganize\REMINDER
J:\data\DSOrganize\PLUGINS
J:\data\DSOrganize\LANG
J:\data\DSOrganize\ICONS
J:\data\DSOrganize\HOME
J:\data\DSOrganize\HELP
J:\data\DSOrganize\DAY
J:\data\DSOrganize\COOKIES
J:\data\DSOrganize\RESOURCES\resource0.bin
J:\data\DSOrganize\RESOURCES\exec_stub.bin
J:\data\DSOrganize\RESOURCES\load.bin
J:\data\DSOrganize\LANG\Sample.lng
J:\data\DSOrganize\ICONS\readme.txt
J:\data\DSOrganize\HOME\readme.txt
J:\data\DSOrganize\HOME\lmp.dss
J:\data\DSOrganize\HOME\bunjalloo.dss
J:\data\DSOrganize\HOME\firmware.dss
J:\data\DSOrganize\HOME\jds.dss
J:\data\DSOrganize\HELP\english
J:\data\DSOrganize\HELP\english\address.html
J:\data\DSOrganize\HELP\english\browser.html
J:\data\DSOrganize\HELP\english\calculator.html
J:\data\DSOrganize\HELP\english\calendar.html
J:\data\DSOrganize\HELP\english\color.html
J:\data\DSOrganize\HELP\english\configuration.html
J:\data\DSOrganize\HELP\english\dayplanner.html
J:\data\DSOrganize\HELP\english\db.html
J:\data\DSOrganize\HELP\english\edit.html
J:\data\DSOrganize\HELP\english\editaddress.html
J:\data\DSOrganize\HELP\english\editscribble.html
J:\data\DSOrganize\HELP\english\edittodo.html
J:\data\DSOrganize\HELP\english\home.html
J:\data\DSOrganize\HELP\english\irc.html
J:\data\DSOrganize\HELP\english\pictureviewer.html
J:\data\DSOrganize\HELP\english\recorder.html
J:\data\DSOrganize\HELP\english\renaming.html
J:\data\DSOrganize\HELP\english\scribble.html
J:\data\DSOrganize\HELP\english\sound.html
J:\data\DSOrganize\HELP\english\texteditor.html
J:\data\DSOrganize\HELP\english\todo.html
J:\data\DSOrganize\HELP\english\viewer.html
J:\data\DSOrganize\HELP\english\webbrowser.html
J:\data\DSOrganize\HELP\english\config
J:\data\DSOrganize\HELP\english\config\altboot.txt
J:\data\DSOrganize\HELP\english\config\autoconnect.txt
J:\data\DSOrganize\HELP\english\config\autohide.txt
J:\data\DSOrganize\HELP\english\config\bullets.txt
J:\data\DSOrganize\HELP\english\config\date.txt
J:\data\DSOrganize\HELP\english\config\dhcp.txt
J:\data\DSOrganize\HELP\english\config\dns.txt
J:\data\DSOrganize\HELP\english\config\fixededitor.txt
J:\data\DSOrganize\HELP\english\config\fixedip.txt
J:\data\DSOrganize\HELP\english\config\gateway.txt
J:\data\DSOrganize\HELP\english\config\homescreen.txt
J:\data\DSOrganize\HELP\english\config\htmlmode.txt
J:\data\DSOrganize\HELP\english\config\iconset.txt
J:\data\DSOrganize\HELP\english\config\imageorientation.txt
J:\data\DSOrganize\HELP\english\config\ircfixed.txt
J:\data\DSOrganize\HELP\english\config\keysound.txt
J:\data\DSOrganize\HELP\english\config\language.txt
J:\data\DSOrganize\HELP\english\config\lefthanded.txt
J:\data\DSOrganize\HELP\english\config\name.txt
J:\data\DSOrganize\HELP\english\config\normalboot.txt
J:\data\DSOrganize\HELP\english\config\primarydns.txt
J:\data\DSOrganize\HELP\english\config\save.txt
J:\data\DSOrganize\HELP\english\config\secondarydns.txt
J:\data\DSOrganize\HELP\english\config\secondclick.txt
J:\data\DSOrganize\HELP\english\config\showhidden.txt
J:\data\DSOrganize\HELP\english\config\ssid.txt
J:\data\DSOrganize\HELP\english\config\ssidsearch.txt
J:\data\DSOrganize\HELP\english\config\start.txt
J:\data\DSOrganize\HELP\english\config\subnet.txt
J:\data\DSOrganize\HELP\english\config\swapab.txt
J:\data\DSOrganize\HELP\english\config\time.txt
J:\data\DSOrganize\HELP\english\config\wep.txt
J:\data\DSOrganize\HELP\english\config\wifi.txt
J:\Apps\AireplayNDS_EB.nds
J:\Apps\consoledemo.nds
J:\Apps\DS2Key.nds
J:\Apps\DSAIM.nds
J:\Apps\dsbasic.nds
J:\Apps\dslinux.nds
J:\Apps\flashme.nds
J:\Apps\memviewer.nds
J:\Apps\motiontest.nds
J:\Apps\TxtWriter.nds
J:\Apps\wifi_VoiceChatClient14.nds
J:\Apps\firmware.nds
J:\Apps\DSLiveWeather.nds
J:\Apps\lmp-ng-1.02.nds
J:\Apps\NitroHax.nds
J:\Apps\okiwi.nds
J:\Apps\firmware2.nds
J:\Apps\ds85_r3.nds
J:\Apps\lmp-ng-2-alpha.nds
J:\Apps\WabbitDS.nds
J:\Apps\JDS.nds
J:\Apps\bunjalloo.nds
The 2GB one is almost the same; /Apps is a direct copy.

This app worked just fine with the GBAMP when I had one, and I've sanity-checked all the paths being passed to stat(). /Apps seems to be the only directory causing trouble. It has yet to fail reading several files from /data/bootmenu on startup nor any .nds file in another directory.

To be more specific:
-The test program has never worked. fatInitDefault() always fails. This is what really makes me think something is wrong with the patch (or possibly libNDS), given how ridiculously simple the program is.
-The demo that came with Chishm's loader, which loads .nds files, initializes successfully almost every time, but sometimes takes several seconds. It has no trouble reading any file, including those in /Apps.
-DSOrganize, LMP-NG 1.02, and the G&M's built-in menu have no problems.
-My app initializes successfully almost every time (sometimes taking several seconds), then proceeds to read several files from /data/bootmenu without any problems, but fails almost every time trying to load a file from /Apps.
_________________
I'm a PSP hacker now, but I still <3 DS.

#152733 - Dwedit - Thu Mar 20, 2008 7:27 am

It looks like Loopy backported some bugfixes and other changes into GBA_NDS_FAT when he made NesDS.
Loopy's modified version of gba_nds_fat can be found in the DLDI folder of the NesDS source code, http://www.cs.utah.edu/~tew/nesDS/

These functions appear to have bugfixes in Loopy's version:
u32 FAT_FirstFreeCluster(void)
u32 FAT_LinkFreeCluster(u32 cluster)
bool FAT_ClearLinks (u32 cluster)
bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry)

I suggest you fire up WinMerge, and see if some of Loopy's changes should be placed into the official distribution of GBA_NDS_FAT, or at least tell me which of those fixes is important.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#153071 - SnakerDLK - Mon Mar 24, 2008 7:18 pm

hi,
when I use ' dirnext' , the function that uses it freezes up when 'exiting'
with return or even when the function 'returns' void...
( I used it as explained in the example in chisms site about libfat...)
( Im using the PAlib beta community release 080203 )

more specific topic...
http://forum.gbadev.org/viewtopic.php?t=15251

#153109 - thegamefreak0134 - Tue Mar 25, 2008 1:37 am

I just noticed a bug in this topic. In the main post, there is example code that is supposed to call "fatInitialise". This function has been changed to "fatInit" and the example code no longer compiles. (I made that one change and that fixed it.) Thought I'd let you know. ^_^

-gamefreak
_________________
What if the hokey-pokey really is what it's all about?

[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]

#160232 - ferrand.d - Sat Jul 12, 2008 1:10 pm

Hi everybody !
I'm french so please excuse me for my bad english. I'm trying to compile a project which uses libfat, but this is a very old project, so I think many things have changed in two years.

The error I get is
Quote:
error: 'DIR_ITER' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: 'd' undeclared (first use in this function)


And my (simplified) source code is
Code:
#include <nds.h>

#include <fat.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/dir.h>

// ...

DIR_ITER* d;


Actually, I don't know where does the DIR_ITER come from and even trying to compile the example code given by chishm on his website, I got that error !
I think the error comes from the header sys/dir.h, but I didn't really understand the POSIX/non-POSIX point.

I'm totally lost so please help me !

#162034 - hacker013 - Sat Aug 23, 2008 7:31 pm

hey,

My project with the old libfat was 80 kb and with the new one from here (the one wihout the include drivers) is 97 kb, i thought this version was smaller than the previous one or am i wrong??
_________________
Website / Blog

Let the nds be with you.

#165737 - hacker013 - Mon Jan 05, 2009 6:28 pm

anybody?
_________________
Website / Blog

Let the nds be with you.

#165743 - Dwedit - Mon Jan 05, 2009 7:15 pm

Look at the map file to see where the size is coming from.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#165746 - elhobbs - Mon Jan 05, 2009 7:28 pm

I think the difference can be attributed to the new libnds in general. keep in mind that the default arm7 is a lot bigger as it has wifi and mod support builtin. I am not sure that this effects free main memory though - can anyone confirm?

#165747 - hacker013 - Mon Jan 05, 2009 7:29 pm

hacker013 wrote:
hey,

My project with the old libfat was 80 kb and with the new one from here (the one wihout the include drivers) is 97 kb, i thought this version was smaller than the previous one or am i wrong??


this was with the old devkitARM 23 and with the new libfat.
_________________
Website / Blog

Let the nds be with you.

#165764 - chishm - Tue Jan 06, 2009 4:18 am

hacker013 wrote:
hacker013 wrote:
hey,

My project with the old libfat was 80 kb and with the new one from here (the one wihout the include drivers) is 97 kb, i thought this version was smaller than the previous one or am i wrong??


this was with the old devkitARM 23 and with the new libfat.

The newest libfat shouldn't be able to link against devkitARM r23. In any case, the extra size is likely due to the allowances for Unicode (UTF-8 to/from UCS-16 conversion is not free) and other additional features.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#166139 - Tommmie - Sat Jan 31, 2009 10:58 am

chishm, when i try to integrate your dldi loader in my app it doesn't work.
is this because of the new libfat or the newest libnds? and if you know why it's not working, could you tell me how to solve it?
the error that i'm getting is this:

Code:

d:/devkitPro/loader/arm9/source/nds_loader_arm9.c: In function 'runNds':
d:/devkitPro/loader/arm9/source/nds_loader_arm9.c:77: warning: likely type-punni
ng may break strict-aliasing rules: object '*src16' of main type 'short unsigned
 int' is referenced at or around d:/devkitPro/loader/arm9/source/nds_loader_arm9
.c:77 and may be aliased to object '_io_dldi' of main type 'unsigned int' which
is referenced at or around d:/devkitPro/loader/arm9/source/nds_loader_arm9.c:77.

linking loader.arm9.elf
nds_loader_arm9.o: In function `runNds':
d:/devkitPro/loader/arm9/source/nds_loader_arm9.c:248: undefined reference to `_
io_dldi'
d:/devkitPro/loader/arm9/source/nds_loader_arm9.c:248: undefined reference to `_
io_dldi'
d:/devkitPro/loader/arm9/source/nds_loader_arm9.c:248: undefined reference to `_
io_dldi'
d:/devkitPro/loader/arm9/source/nds_loader_arm9.c:248: undefined reference to `_
io_dldi'
collect2: ld returned 1 exit status

#166140 - Echo49 - Sat Jan 31, 2009 11:15 am

Did you include the libfat library in your makefile?

#166149 - Tommmie - Sat Jan 31, 2009 5:59 pm

yes i did, but i think it has to be something with the new devkitarm or libnds because it also doesn't compile when i replace libfat with the older one

#166151 - hacker013 - Sat Jan 31, 2009 6:13 pm

the var _io_dldi doesn't exists anymore with the newest libfat.
_________________
Website / Blog

Let the nds be with you.

#166159 - Tommmie - Sat Jan 31, 2009 7:49 pm

so do i have to make this variable or do i have to use another one?

#166168 - chishm - Sun Feb 01, 2009 5:45 am

Check <nds/arm9/dldi.h> for io_dldi_data. There are probably a few other changes that need to be made, but I can't remember. I suppose I should put a new loader release together, but it's just such nice weather outside.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#166169 - Tommmie - Sun Feb 01, 2009 7:12 am

I know, its summer there, but here in the Netherlands its freezing. but ok i will give your advice a try and it would be great if you update the loader.

edit

yeah chishm you were right, no errors after changing _io_dldi but when i tested it i got two white screen and nothing happened

#167677 - renatobs - Sat Mar 21, 2009 11:56 pm

Hi. I?m a brazilian developer ( newby ) and my english is not good but I think that you?ll understand me. I?m developing a remake of the game and I already have a lot of thing of the game finished, but now I need to use LIBFAT to imrpoved my "cart space".
I have read a lot about Chishm FAT but I?m very confused with a lot of things. I have studied the exemples and I could got some ideias. Does not the EFS working in NO$GBA ?! In my real NDS with EZFlashV the most of them are working... Need I to do some special thing to these files working on No$gba ?
My main problem now is that I?m putting "mp3" files in my game. I?m using the AS_Lib ( that is so fantastic ) and I can play "mp3" and "sound efeccts" together without problems. These is excelent !!! But now I can?t do more things cuz the cart became almost 4Mb. I need to put the "Mp3" files out of RAM, using the "Mp3 Strem Player". Unfortunaly NODA is out ( I guess ) cuz I can?t a answer from him. Then I?d like a help from someone here, cuz "you are a kind of GOD?s of development in NDS".
Well, these are my problems:

- I need that someone detect what?s happen with "AS_Lib" that it can?t play "MP3 stream" by "FAT", "ESF_FAT" or try change to "Chishm FAT";

- In the case that I can?t solve this problem, is there some way to play the MP3 change these in the RAM ? The Direct Play of AS_Lib play a MP3 from RAM, but when I compile the code, the compiler create 2 files from MP3 ( *.o and *.h ), one have the codes of MP3 and other the headers with name and size. How could I change these in the RAM ? Creating a volatile array and put there a mp3 to play ?!?

- If I have a "image" file converted by "pcx2gba" with a "data" and "pal" arrays, how can I put these in a Chishm FAT dir, read and put in VRAM, for exemple ?! Usually I use the "swicopy" or "dmacopy" with a pointer to tranfer the arrays to VRAM, but the files are in RAM, included in the code, and them get space of.

I don?t know if I wrote understandably... If not, sorry !! Please, I need some help and i?ll be so grateful !!!

Thanks !!

PS.: here is my game:
- http://br.youtube.com/watch?v=oHwqK46bE50
- http://forums.shiningforcecentral.com/index.php?showtopic=12564

#167745 - nanou - Wed Mar 25, 2009 11:12 am

renatobs, I sent you a PM about this.
_________________
- nanou