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 > fopen not reading whole file

#175496 - Scribe - Sat Dec 04, 2010 5:00 pm

Hi guys,

I've just written a universal image converter to uncompressed xBGR 16bit for use with the DS.

I'm using libfat to load in these image files but am finding the use of fread is returning EOF too early. In my example the filesize should be 98312 bytes but it's falling 6156 bytes short.

I've confirmed that the image file size after conversion is correct and that the size data being fed in is also correct.

This leads me to assume the issue is with either libfat or the virtual fat system script I'm using to run this code on an emulator (I don't currently have a DS available).

The build steps for the virtual filesystem are thus:
Code:

cd fcsrimage

padbin.exe 512 ../NDS_Template.nds

CALL build.bat image.img ..\Filesystem

copy /b ..\NDS_Template.nds + image.img ..\NDS_Template.ds.gba

dlditool.exe fcsr.dldi ..\NDS_Template.ds.gba

cd ..

build.bat =
Code:

@echo off
REM
REM based on davr http://blog.davr.org/ linux code and shell script
REM by Troy(GPF) http://gpf.dcemu.co.uk
REM

echo Builds a FAT disk image from a given directory.
IF "%1" == "" goto ERROR
IF "%2" == "" goto ERROR
for /f "tokens=3,4*" %%a in ( 'dir /w /s /-C %2 ^| tail -n 2 ^| head -n 1') do @set info=%%a
set /A size="%info%+64"
echo %size%

if /I %size% LSS 10000  ( set /A size="10000" )

echo Creating image
mkdosfs.exe %1 %size%
add_to_disk_image.exe %1 %2
rem 'bless' the image so it is recognized by FCSR driver, and sets up SRAM overlay

echo Blessing image
bless.exe %1
echo "FAT12 image built as %1 from %2"
goto :end

:ERROR
echo usage: build.bat name.img dirname
goto :end

:tobig
echo directory size to large , remove some files and try again
goto :end


:end


Any ideas what could be causing this issue guys?

Many thanks

#175497 - Quirky - Sat Dec 04, 2010 6:27 pm

Is the file definitely that size on the SD card? I know I've had problems where files are actually corrupt and reading them back even on a PC gives errors.

#175498 - Sektor - Sat Dec 04, 2010 11:04 pm

He's not using an SD card. It could be a problem with the emulator or FCSR. Try nitrofs or real hardware.
_________________
GTAMP.com/DS