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 > help with the fat driver please!

#56095 - ninogenio - Thu Oct 06, 2005 2:41 am

helo everyone ive been browsing here for a little while and i must say its a great forum.now i was wondering if someone could come up with a little example of how to open a txt file and read the contents using the fat driver for gbamp ive been messing about for quite a while but i just cant get it to work correctly i have a gbamp v2 flashed with the firmware v2 and my ds is also flashed thanks very much in advanced for any help givin.

#56097 - tepples - Thu Oct 06, 2005 3:01 am

Have you got the driver to work in GBA mode yet?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#56099 - josath - Thu Oct 06, 2005 3:15 am

'rain' reads files from the CF card
http://www.pat.hi-ho.ne.jp/sata68/nds.shtml#rain

as does 'moonshell':
http://mdxonline.dyndns.org/archives/nds/

maybe these will help you.

#56123 - ninogenio - Thu Oct 06, 2005 11:54 am

@tepples ive not got it going in gba mode i used to do some coding for the gba but latley ive been consetrating on the nds as theres a lot more flexability i almost had something going last night i had my program load a txt file and display it on screen but there was some garbbled characters at the end also i was just wondering if it was quite normal for there to be a few warnings from the compiler about gbamp_cf.c file.

@josath thanks for that but im not very good at looking through other peoples code and crabbing info i like to build my programs from scratch i find i learn a lot more from them.

#56124 - chishm - Thu Oct 06, 2005 1:28 pm

What errors/warnings are you getting about gbamp_cf.c?

#56128 - ninogenio - Thu Oct 06, 2005 1:53 pm

here is exactly what i get it compiles ok and the functions do work its just im not sure exactly how to use them.

C:\ninosstuff\DSHomeBrew\demo_for_reading_data>make
arm-elf-g++ -g -Wall -O2 -mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer -ff
ast-math -mthumb-interwork -I/c/devkitPRO/libnds/include -DARM9 -c arm9.cpp -oar
m9.o
gbamp_cf.c: In function 'u32 FAT_NextCluster(u32)':
gbamp_cf.c:566: warning: comparison between signed and unsigned integer expressi
ons
gbamp_cf.c: In function 'bool FAT_WriteFatEntry(u32, int)':
gbamp_cf.c:672: warning: comparison between signed and unsigned integer expressi
ons
gbamp_cf.c: In function 'u32 FAT_fread(void*, u32, u32, int)':
gbamp_cf.c:2309: warning: comparison between signed and unsigned integer express
ions
gbamp_cf.c:2323: warning: comparison between signed and unsigned integer express
ions
gbamp_cf.c: In function 'u32 FAT_fwrite(void*, u32, u32, int)':
gbamp_cf.c:2435: warning: comparison between signed and unsigned integer express
ions
gbamp_cf.c:2457: warning: comparison between signed and unsigned integer express
ions
arm-elf-g++ -g -mthumb-interwork -mno-fpu -specs=ds_arm9.specs arm9.o -L/c/devki
tPRO/libnds/lib -lnds9 -o arm9.elf
arm-elf-objcopy -O binary arm9.elf arm9.bin
ndstool -c demo1.nds -9 arm9.bin -7 arm7.bin
Nintendo DS rom tool 1.23 - Sep 15 2005 06:28:33 by Rafael Vuijk (aka DarkFader)

dsbuild demo1.nds -o demo1.nds.gba
dsbuild 1.21 - Sep 15 2005
using default loader

C:\ninosstuff\DSHomeBrew\demo_for_reading_data>pause
Press any key to continue . . .

#56193 - chishm - Thu Oct 06, 2005 11:23 pm

Those warnings won't affect anything important. It seems I'm going to have to explicitly cast a few (u32)s to fix them.

#56326 - ninogenio - Fri Oct 07, 2005 10:21 pm

ahh right cool ive got it working now i found an old post describing what i was looking for ive got this working on my gbamp and was just wondering if this looked ok what it does is load in a jpg from the cf card.the thing im not wanting is for my program to use more reasources than neccessary. thanks very much.

Code:
#include <nds.h>
#include "fat_driver/gbamp_cf.c" 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jpeg_lib/gba-jpeg.h"
#include "jpeg_lib/gba-jpeg-decode.c"

u16 count;

void BltImage(const unsigned char* name, u16* vram)
{
  WAIT_CR &= ~0x80;
  JPEG_DecompressImage(name, vram, 256, 192);
  WAIT_CR |= 0x80;
}

int main(){
   irqInit();
   irqSet(IRQ_VBLANK,0);
        WAIT_CR=0xe800;
        powerON(POWER_ALL);

        videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE);
        vramSetBankA(VRAM_A_MAIN_BG_0x6000000);
        BG2_CR = BG_BMP16_256x256;

        BG2_XDX = 1<<8;
        BG2_XDY = 0;
        BG2_YDX = 0;
        BG2_YDY = 1<<8;
        BG2_CY = 0;
        BG2_CX = 0;

        FAT_InitFiles();
        int handle = FAT_fopen("nino.jpg", "r"); 
        int size=FAT_GetFileSize();
        char* text = (char*) malloc (size+1)  ;
       
        while (!FAT_feof(handle))
        {
               FAT_fread((void*)text, size, 1, handle);
               
        }
        FAT_fclose(handle);


        while(1)
        {
              scanKeys();
              swiWaitForVBlank();
              BltImage((const unsigned char*)(text), BG_GFX);
        }

   return 0;
}