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 > Need help with FAT porting

#64126 - FloFri - Mon Dec 19, 2005 6:46 pm

Hi!
I want to port the file-class of the new movie player by Moonlight to the GMAMP with chisms FAT driver. This is the class:

Code:
CStream::CStream(char *filename)
{
  fhandle = FAT_fopen(filename, "r");
  size = FAT_GetFileSize();
}

CStream::~CStream(void)
{
  FAT_fclose(fhandle);
}

int CStream::GetOffset(void) const
{
  return FAT_ftell(fhandle);
}

void CStream::SetOffset(int _ofs)
{
  if(size<FAT_ftell(fhandle))
    FAT_fseek(fhandle, size, 0);
  else
    FAT_fseek(fhandle, _ofs, 0);
}

int CStream::GetSize(void) const
{
  return(size);
}

void CStream::OverrideSize(int _size)
{
  return;
}

bool CStream::eof(void) const
{
  return FAT_feof(fhandle);
}

u8 CStream::Readu8(void)
{
  if(eof()==true) return(0);
  char temp = FAT_fgetc(fhandle);
  FAT_fseek(fhandle, 1, FAT_ftell(fhandle));
  return(temp);
}

u16 CStream::Readu16(void)
{
  u16 data;
 
  data=(u16)Readu8();
  data=data | ((u16)Readu8() << 8);
 
  return(data);
}

u32 CStream::Readu32(void)
{
  u32 data;
 
  data=(u32)Readu8();
  data=data | ((u32)Readu8() << 8);
  data=data | ((u32)Readu8() << 16);
  data=data | ((u32)Readu8() << 24);
 
  return(data);
}

int CStream::ReadBuffer(void *_dstbuf,const int _readsize)
{
  if(eof()==true) return(0);
 
  int readsize = FAT_fread(_dstbuf, _readsize, sizeof(char), fhandle);
 
  return(readsize);
}


Can someone tell me if he can find any mistakes in this code, because the function Readu32 seems to return 0 all the time.

Thanks in advance.
FloFri

#64147 - duencil - Mon Dec 19, 2005 8:58 pm

Careful with your arguments to fseek. The third param should be 0, 1 or 2. Actually you can remove the fseek in Readu8 altogether, fgetc advances a character anyway. Not sure why you move to the eof in the first result of the conditional in SetOffset, maybe you meant your condition to be
Code:
 if(size< _ofs)


Otherwise, I don't know much about chisms FAT driver, so can't help you more. Good luck!

#64165 - FloFri - Mon Dec 19, 2005 10:58 pm

Thanks for your help! I finally got the mistake! I forgot to call FAT_InitFiles();

Thanks for your help!

(P.s.: I GOT IT! I got a movie with GBAMP directly from CF! There a some graphic glitches but i have to look what, if i use a lower framerate! So stay tuned!)