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 > fread into vram

#142655 - ingramb - Thu Oct 11, 2007 8:20 am

Is it safe to do this? If a dldi driver did byte copies into the destination, this would fail. Is this something that I should worry about?

#142657 - chishm - Thu Oct 11, 2007 8:24 am

DLDI drivers, as well as libfat and newlib, may write bytewise to the destination memory. You have no guarantees about the behaviour in this regard. Use a temporary buffer in main RAM instead.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#142661 - Dwedit - Thu Oct 11, 2007 9:42 am

The old gba_nds_fat does 16 bit alignment if your file buffer, destination, and seek position within the file are 16-bit aligned. But I bet the new SD libraries probably use 8 bit writes since they use a serial protocol instead of reading 16-bit data off an IDE device.

I think that if you are reading in units of sectors or clusters, then it does direct reading to the target memory. Otherwise it does a memcpy to the target. That is really old data though, it might have changed.

Anyway, it's probably not reliable reading to 16 bit data. (but I still do it anyway in my customized version of gba_nds_fat)
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#142695 - ingramb - Fri Oct 12, 2007 12:30 am

OK, thanks for the info.

Quote:
I think that if you are reading in units of sectors or clusters, then it does direct reading to the target memory. Otherwise it does a memcpy to the target. That is really old data though, it might have changed.

Are there any guidelines for optimizing libfat speed? Like reading in blocks or 512 bytes or something? My program does lots of streaming from the card, so fread time is very important to me.

#142700 - tepples - Fri Oct 12, 2007 1:29 am

ingramb wrote:
Are there any guidelines for optimizing libfat speed? Like reading in blocks or 512 bytes or something? My program does lots of streaming from the card, so fread time is very important to me.

Read as large of a unit as you can without missing the vblank. In my experience with speed tester, reads that span a whole hardware block (which can be larger than a sector) or a whole file system cluster (usually 4 KiB on FAT32 file systems) are faster than reads of individual 512-byte sectors.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.