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 > fgetc ideas

#138170 - ghuldan - Mon Aug 20, 2007 4:45 pm

Hello there,
Recently i started to use fatlib and i got stuck with my poor knowledge I/O and emulator :

Code:
FILE *pFile;
char c;
pFile = fopen("/Decor.tileset", "r");
   
if (pFile == NULL)
   PA_OutputText("Error loading file");
else {
   PA_OutputText("file opened");
   fseek(pFile , 0 , SEEK_SET);
   c = fgetc(pFile);
   if (ferror (pFile))
      PA_OutputText("Error reading from file");
   PA_OutputText("c = %d", c);
}


then ideas display :
file opened
and
Error reading from file
c = 255

Decor.tileset starts with "12096{0,0,0,0,0,0,0,0,..."

I Dldied my ds.gba with R4 driver, set ideas to use R4 driver ... i can open a file but can't read into it ...

Does anyone have any clue please ?

EDIT : after more tests it seems fseek return -1 too

#138171 - Lino - Mon Aug 20, 2007 5:52 pm

You can give me yours .ds.gba? If you use the email make me know.

#138183 - tepples - Mon Aug 20, 2007 8:59 pm

ghuldan wrote:
ds.gba with R4

ds.gba does not work on R4; it only works on SLOT-2 cards (and emulators that emulate SLOT-2 cards). Have you tried using FCSR?

And does your code call fatInitDefault?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#138215 - NorQue - Tue Aug 21, 2007 7:46 am

One rather obvious error is the space between ferror and (pfile) in this line:
Code:
   if (ferror (pFile))

#138223 - ghuldan - Tue Aug 21, 2007 11:19 am

I finally managed to get it to work.
It was te fault of my slightly modified PA_loadsimpleBG, where i do multiples DMA calls instead of one : I saw somewhere DLDI drivers don't like too much you tickle the DMA thing ... In fact when i used MY_loadsimpleBG, backgrounds would not appear ... and files would be read ... I didnot see the connection ^^ , was first time on Ideas, which i never got to display anything by the past ...

Quote:
ds.gba does not work on R4; it only works on SLOT-2 cards (and emulators that emulate SLOT-2 cards). Have you tried using FCSR?

I use Ideas now ;)

Quote:
One rather obvious error is the space between ferror and (pfile) in this line:
Code:
if (ferror (pFile))

Ah that was it ! thanks

Thanks to all, this forum is pretty much cool ...

#138228 - chishm - Tue Aug 21, 2007 12:35 pm

NorQue wrote:
One rather obvious error is the space between ferror and (pfile) in this line:
Code:
   if (ferror (pFile))

Uh, what? White space should have no effect in this case. You could even write it
Code:
 if             (
ferror
                             (
pFile)


)

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

#138250 - NorQue - Tue Aug 21, 2007 8:18 pm

Really? I thought spaces weren't allowed in function calls? Looks like it's not when the space is in the end of a call... quick skimming through Schildt and K&R showed nothing in this direction, guess you're right. You should know of all people. ;)

#138252 - tondopie - Tue Aug 21, 2007 8:37 pm

putting a space between 'if' and '(' or 'void function' and '(void);' never hurt anyone did it? ;)