rendered paste body// Includes
#include <PA9.h> // Include for PA_Lib
void Skin(){
FAT_FILE* element; char* data; int lSize;
element = FAT_fopen("/skin/dsPodtop.bmp","r");
if (element==NULL) PA_OutputText(0, 1, 12, "Failed opening file");
// obtain file size.
FAT_fseek (element , 0 , SEEK_END);
lSize = FAT_ftell (element);
FAT_fseek (element, 0, SEEK_SET);
// allocate memory to contain the whole file.
data = (char*) malloc (lSize);
if (data == NULL) PA_OutputText(0, 1, 13, "Something is wrong");
// copy the file into the buffer.
FAT_fread (data,1,lSize,element);
FAT_fclose(element);
PA_LoadBmpEx(1,0,0,data);
}
int GetFileList(int filenum){
int palnr;
char filename[255]; int fcount=2;
FAT_FindFirstFile(filename);
Skin();
PA_Clear16bitBg(1);
PA_SmartText(1, 0, 1, 255, 7, "dsPod", 2, 0, 1, 100);
if(filenum==1){
palnr=4;
} else {
palnr=1;
}
FAT_GetLongFilename(filename);
PA_SmartText(1, 0, 7, 255, 14, filename, palnr, 0, 1, 100);
while(FAT_FindNextFile(filename)!=0){
if(filenum==fcount){
palnr=4;
} else {
palnr=1;
}
fcount++;
FAT_GetLongFilename(filename);
PA_SmartText(1, 0, 7*(fcount-1), 255, 7*fcount, filename, palnr, 0, 1, 100);
}
PA_OutputText(0, 1, 11, " %d, %d", fcount, filenum);
return fcount;
}
int HandleFile(int filenum){
char filename[255]; int type; int fcount=2;
type = FAT_FindFirstFile(filename);
if(type == 2 && filenum == 1){
FAT_chdir(filename);
GetFileList(1);
filenum = 1;
}
if(type == 1){
PA_OutputText(0, 1, 11, "Unhandled");
}
while(type != 0){
type = FAT_FindNextFile(filename);
if(type == 2 && filenum == fcount){
FAT_chdir(filename);
GetFileList(1);
filenum = 1;
break;
}
if(type == 1){
PA_OutputText(0, 1, 11, "Unhandled");
}
fcount++;
}
return filenum;
}
// Function: main()
int main(int argc, char ** argv)
{
int filenum;
int cnt;
PA_Init(); // Initializes PA_Lib
PA_InitVBL(); // Initializes a standard VBL
PA_SetBgPalCol(0, 1, PA_RGB(31, 31, 31));
PA_SetBgPalCol(0, 2, PA_RGB(31, 0, 0));
PA_SetBgPalCol(0, 3, PA_RGB(0, 0, 31));
PA_SetBgPalCol(0, 4, PA_RGB(0, 31, 0));
PA_SetBgPalCol(1, 1, PA_RGB(31, 31, 31));
PA_SetBgPalCol(1, 2, PA_RGB(31, 0, 0));
PA_SetBgPalCol(1, 3, PA_RGB(0, 0, 31));
PA_SetBgPalCol(1, 4, PA_RGB(0, 31, 0));
PA_Init16bitBg(0, 1);
PA_Init16bitBg(1, 1);
PA_InitText(0, 0);
FAT_InitFiles();
FAT_chdir("/");
filenum=1;
cnt = GetFileList(filenum);
// Infinite loop to keep the program running
int lock=0;
while (1)
{
// PA_UpdatePad();
if(Pad.Newpress.Up && filenum>1){
if(lock == 0){
filenum--;
cnt = GetFileList(filenum);
lock = 1;
}
}
if(Pad.Newpress.Down && filenum<cnt-1){
if(lock == 0){
filenum++;
cnt = GetFileList(filenum);
lock = 1;
}
}
if(Pad.Newpress.A){
if(lock == 0){
// filenum++;
filenum = HandleFile(filenum);
lock = 1;
}
}
if(Pad.Released.Down){
lock = 0;
}
if(Pad.Released.Up){
lock = 0;
}
if(Pad.Released.A){
lock = 0;
}
PA_WaitForVBL();
}
return 0;
} // End of main()