All pastes #98172 Raw Edit

Someone

public text v1 · immutable
#98172 ·published 2006-07-24 11:51 UTC
rendered paste body
// Includes
#include <PA9.h>       // Include for PA_Lib

int GetFileList(int filenum){
	int palnr;
	char filename[255]; int fcount=2;
	FAT_FindFirstFile(filename);
	PA_SmartText(1, 0, 1, 255, 7, "File Browser", 2, 0, 0, 100);
	if(filenum==1){
		palnr=4;
	} else {
		palnr=1;
	}
	FAT_GetLongFilename(filename);
	PA_SmartText(1, 0, 7, 255, 14, filename, palnr, 0, 0, 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, 0, 100);

	}

		PA_InitText(0, 0);

		PA_OutputText(0, 1, 11, " %d, %d", fcount, filenum);


	return fcount;
}

void 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);
	}
		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);
			break;
		}
		if(type == 1){
			PA_OutputText(0, 1, 11, "Unhandled");

		}
		fcount++;	

	}

}
// 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_Init8bitBg(0, 3);
	PA_Init8bitBg(1, 3);
	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++;
				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()