Originally Posted by
Salem
- the buffer is being passed to the OS for use in some DMA transfer
It’s being sent to an API for file IO for the intended platform which was Sony PSP, and have similar file IO functions for other platforms.
I can’t pretend to follow it like execution, but understand that it looks for a particular directory (Music) and iteratively populates a structure with number and file,
and can also test an entry is a file or another directory, to allow stepping into the new directory and caching that one.
If I understand you correct you could save memory by having it squash the array?
Although this calls Sony functions (Sony Computer Entertainment prefix), it’s part of a free home-brew SDK, so assume it’s ok to post.
Code:
void recacheGameDir() {
struct SceIoDirent dir;
memset( &dir, 0, sizeof(SceIoDirent));
static int dfd;
if (musicfolderexists == 0) {
dfd = sceIoDopen(current_dir);
} else {
dfd = sceIoDopen(current_dirx);
}
if(dfd > 0) {
int f = 0;
for( f = 0; f < MAX_ENTRIES; f++) {
if( gameEntry[f].name) {
free( gameEntry[f].name);
}
gameEntry[f].name = NULL;
}
countentry = 0;
while( sceIoDread( dfd, &dir) > 0) {
static char * name;
name = (char*)memalign( 16, 300);
sprintf( name,"%s" , dir.d_name);
static int s = 0;
s = strlen(name);
gameEntry[countentry].name = name;
countentry++;
if(countentry > MAX_ENTRIES - 1) {
countentry = MAX_ENTRIES - 1;
}
gameEntriesTotal = countentry;
if(gameEntriesTotal < 0) {
gameEntriesTotal = 0;
}
}
}
sceIoDclose(dfd);
}
int is_file (const char *filename) {
SceIoStat stats;
sceIoGetstat( filename, &stats);
if ( stats.st_mode & FIO_S_IFDIR)
return 0;
else
return 1;
}