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 > viewing a text file?

#105672 - spinal_cord - Tue Oct 10, 2006 8:58 pm

For some reason the following code doesnt work on my gbamp, can someone take a look and tell me what im doing wrong.
Its supposed to put the text from test.txt on the screen, but it doesn't.

Code:

// Includes
#include <PA9.h>       // Include for PA_Lib

#define BUFFER_SIZE 32

//void shutdown(void);

// Function: main()
int main(int argc, char ** argv)
{
   PA_Init();    // Initializes PA_Lib
   PA_InitVBL(); // Initializes a standard VBL
   PA_InitText(1,0); //init text bottom screen

FAT_InitFiles();  // Init FAT driver
 
FAT_FILE* handle = FAT_fopen("test.txt", "r");  // Open test.txt for reading

u32 size = 256;  // Read in 256 bytes at a time

char* text = (char*) malloc (size+1);  // Allocate memory for string, including end of string character

text[size] = '\0'; // Add string terminate character

FAT_fseek(handle, 0, SEEK_SET);  // Go to begining of file

int i=0;
while (!FAT_feof(handle))
{
    FAT_fread((void*)text, size, 1, handle); // Read next bit of file into memory
//    consolePrintf(text);  // Print file to screen
PA_OutputSimpleText(1, 0, i++, text);  // this sinstead for palib
}

FAT_fclose(handle); // Close file

   
   return 0;
} // End of main()



yes i know its palib but that shouldnt be a problem, the function is almost exactly the same (just comment the PA_OutputSimpleText and put back in the consolePrintf)

I would like to use custom levels for my game, but if I cant load from the CF, then thats a great big chunck of my game missing.
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#105675 - Lick - Tue Oct 10, 2006 9:27 pm

Code:
FAT_InitFiles();
FAT_FILE* handle = FAT_fopen("test.txt", "r");

u32 size = 256;
char* text = (char*) malloc (size+1);
text[size] = 0;
FAT_fread((void*)text, size, 1, handle);

consolePrintf(text);
PA_OutputSimpleText(1, 0, 0, text);

FAT_fclose(handle);

_________________
http://licklick.wordpress.com

#105679 - spinal_cord - Tue Oct 10, 2006 9:46 pm

hmm :? its the same, was that supposed to fix anything?
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage