?? save.c
字號(hào):
printf_P(PSTR("\r\nSearchInit"));
#endif
if(FAT32_Enable)
WriteFolderCluster(addr,FirstDirClust);
else
WriteFolderCluster(RECORD_ADDR_START,0);
addr += 4;
WriteFolderCluster(addr, 0xffffffff);
#if FAT_DEBUG
printf_P(PSTR("\r\n"));
#endif
temp_addr = addr;
addr = RECORD_ADDR_START;
while(1)
{
cluster = GetFolderCluster(addr);
if(cluster == 0xffffffff)break;
else
{
#if FAT_DEBUG
printf_P(PSTR("\r\nSearch one folder start, cluster = %ld"),cluster);
#endif
if(SearchFolder(cluster,&temp_addr))
{
#if FAT_DEBUG
printf_P(PSTR("\r\nERROR: search folder error"));
#endif
}
if(GetFolderCluster(temp_addr) != 0xffffffff)
WriteFolderCluster(temp_addr,0XFFFFFFFF);
if(temp_addr == RECORD_ADDR_END)
{
#if FAT_DEBUG
printf_P(PSTR("\r\nWARNING: EEPROM is full, no more space!"));
#endif
WriteFolderCluster(temp_addr - 4,0XFFFFFFFF);
break;
}
#if FAT_DEBUG
printf_P(PSTR("\r\nSearch one folder complete!\r\n"));
#endif
}
addr+=4;
}
#if FAT_DEBUG
printf_P(PSTR("\r\nSearch Completed!\r\n"));
#endif
}
//BYTE *dir
//search the file , when *count = 0 it will bring the number whole songs, when *cout != 0 the *MusicInfo will bring the infomation of the file
BYTE Search(WORD *music_record_addr,struct direntry *MusicInfo,WORD *Count,BYTE *type) //當(dāng)COUNT為零時(shí),有它帶回這個(gè)目錄下總共有多少首音樂
{ //不為零時(shí)有MusicInfo帶回第Count首歌的詳細(xì)文件信息
BYTE *buffer;
DWORD sector;
DWORD cluster;
DWORD tempclust;
unsigned char cnt;
unsigned int offset;
unsigned int i=0;
unsigned char j;//long name buffer offset;
unsigned char *p;//long name buffer pointer
struct direntry *item = 0;
struct winentry *we =0;
//cluster = FAT_OpenDir(dir);
//if(cluster == 1)return 1;
WORD addr = RECORD_ADDR_START;
while(1)
{
#if FAT_DEBUG
printf_P(PSTR("\r\n"));
#endif
cluster = GetFolderCluster(addr);
#if FAT_DEBUG
printf_P(PSTR("\r\nSearch the folder: cluster: %ld"),cluster);
#endif
addr += 4;
if(cluster == 0xffffffff)break;
else
{
if(music_record_addr != 0) *music_record_addr = addr - 4; // record in which record found the right file
if(cluster==0 && FAT32_Enable==0)// root directory
{
buffer=malloc(512);//apply memory
if(buffer==0)return 1;//if failed
for(cnt=0;cnt<RootDirSectors;cnt++)
{
if(SD_ReadSingleBlock(FirstDirSector+cnt,buffer)){free(buffer);return 1;}
for(offset=0;offset<512;offset+=32)
{
item=(struct direntry *)(&buffer[offset]);//pointer convert
//find a valid item and display it
if((item->deName[0] != '.') && (item->deName[0] != 0x00) && (item->deName[0] != 0xe5))
{
if(item->deAttributes == 0x0f)
{
we = (struct winentry *)(&buffer[offset]);
j = 26 *( (we->weCnt-1) & WIN_CNT);
if(j<MAX_LONG_NAME_SIZE-25)
{
p = &LongNameBuffer[j];
for (j=0;j<10;j++) *p++ = we->wePart1[j];
for (j=0;j<12;j++) *p++ = we->wePart2[j];
for (j=0;j<4;j++) *p++ = we->wePart3[j];
if (we->weCnt & 0x40) (*(unsigned int *)p) = 0;
if ((we->weCnt & WIN_CNT) == 1) LongNameFlag = 1;
}
LongNameBuffer[MAX_LONG_NAME_SIZE-1] = 0;
LongNameBuffer[MAX_LONG_NAME_SIZE-2] = 0;
/*p = &LongNameBuffer[j];
for (j=0;j<10;j++) *p++ = we->wePart1[j];
for (j=0;j<12;j++) *p++ = we->wePart2[j];
for (j=0;j<4;j++) *p++ = we->wePart3[j];
if (we->weCnt & 0x40) (*(unsigned int *)p) = 0;
if ((we->weCnt & WIN_CNT) == 1) LongNameFlag = 1;*//*
}
else if((item->deExtension[0] == 'M')&&(item->deExtension[1] == 'P')&&(item->deExtension[2] == '3'))
{
#if FAT_DEBUG
printf_P(PSTR("\r\nFound mp3 file! index = %d name: "),i+1);
for(j=0;j<8;j++)putchar(item->deName[j]);
putchar('.');
for(j=0;j<3;j++)putchar(item->deExtension[j]);
#endif
CopyDirentruyItem(MusicInfo,item);
*type=1;
i++;
if(i==*Count){free(buffer);return 0;}
else LongNameFlag = 0;
}
else if((item->deExtension[0] == 'W')&&(item->deExtension[1] == 'M')&&(item->deExtension[2] == 'A'))
{
#if FAT_DEBUG
printf_P(PSTR("\r\nFound wma file! index = %d name: "),i+1);
for(j=0;j<8;j++)putchar(item->deName[j]);
putchar('.');
for(j=0;j<3;j++)putchar(item->deExtension[j]);
#endif
CopyDirentruyItem(MusicInfo,item);
*type=2;
i++;
if(i==*Count){free(buffer);return 0;}
else LongNameFlag = 0;
}
else if((item->deExtension[0] == 'M')&&(item->deExtension[1] == 'I')&&(item->deExtension[2] == 'D'))
{
#if FAT_DEBUG
printf_P(PSTR("\r\nFound mp3 file! index = %d name: "),i+1);
for(j=0;j<8;j++)putchar(item->deName[j]);
putchar('.');
for(j=0;j<3;j++)putchar(item->deExtension[j]);
#endif
CopyDirentruyItem(MusicInfo,item);
*type=3;
i++;
if(i==*Count){free(buffer);return 0;}
else LongNameFlag = 0;
}
else if((item->deExtension[0] == 'W')&&(item->deExtension[1] == 'A')&&(item->deExtension[2] == 'V'))
{
#if FAT_DEBUG
printf_P(PSTR("\r\nFound wav file! index = %d name: "),i+1);
for(j=0;j<8;j++)putchar(item->deName[j]);
putchar('.');
for(j=0;j<3;j++)putchar(item->deExtension[j]);
#endif
CopyDirentruyItem(MusicInfo,item);
*type=4;
i++;
if(i==*Count){free(buffer);return 0;}
else LongNameFlag = 0;
}
else LongNameFlag = 0;
}
}
}
free(buffer);//release
}
else//other folders
{
tempclust=cluster;
while(1)
{
sector=FirstDataSector+(DWORD)(tempclust-2)*(DWORD)SectorsPerClust;//calculate the actual sector number
buffer=malloc(512);//apply memory
if(buffer==0)return 1;//if failed
for(cnt=0;cnt<SectorsPerClust;cnt++)
{
if(SD_ReadSingleBlock(sector+cnt,buffer)){free(buffer);return 1;}
for(offset=0;offset<512;offset+=32)
{
item=(struct direntry *)(&buffer[offset]);
if((item->deName[0] != '.') && (item->deName[0] != 0x00) && (item->deName[0] != 0xe5))
{
if(item->deAttributes == 0x0f)
{
we = (struct winentry *)(&buffer[offset]);
j = 26 *( (we->weCnt-1) & WIN_CNT);
if(j<MAX_LONG_NAME_SIZE-25)
{
p = &LongNameBuffer[j];
for (j=0;j<10;j++) *p++ = we->wePart1[j];
for (j=0;j<12;j++) *p++ = we->wePart2[j];
for (j=0;j<4;j++) *p++ = we->wePart3[j];
if (we->weCnt & 0x40) (*(unsigned int *)p) = 0;
if ((we->weCnt & WIN_CNT) == 1) LongNameFlag = 1;
}
LongNameBuffer[MAX_LONG_NAME_SIZE-1] = 0;
LongNameBuffer[MAX_LONG_NAME_SIZE-2] = 0;
/*p = &LongNameBuffer[j];
for (j=0;j<10;j++) *p++ = we->wePart1[j];
for (j=0;j<12;j++) *p++ = we->wePart2[j];
for (j=0;j<4;j++) *p++ = we->wePart3[j];
if (we->weCnt & 0x40) (*(unsigned int *)p) = 0;
if ((we->weCnt & WIN_CNT) == 1) LongNameFlag = 1; *//*
}
else if((item->deExtension[0] == 'M')&&(item->deExtension[1] == 'P')&&(item->deExtension[2] == '3'))
{
#if FAT_DEBUG
printf_P(PSTR("\r\nFound mp3 file! index = %d name: "),i+1);
for(j=0;j<8;j++)putchar(item->deName[j]);
putchar('.');
for(j=0;j<3;j++)putchar(item->deExtension[j]);
#endif
CopyDirentruyItem(MusicInfo,item);
*type = 1;
i++;
if(i==*Count){free(buffer);return 0;}
else LongNameFlag = 0;
}
else if((item->deExtension[0] == 'W')&&(item->deExtension[1] == 'M')&&(item->deExtension[2] == 'A'))
{
#if FAT_DEBUG
printf_P(PSTR("\r\nFound wma file! index = %d name: "),i+1);
for(j=0;j<8;j++)putchar(item->deName[j]);
putchar('.');
for(j=0;j<3;j++)putchar(item->deExtension[j]);
#endif
CopyDirentruyItem(MusicInfo,item);
*type = 2;
i++;
if(i==*Count){free(buffer);return 0;}
else LongNameFlag = 0;
}
else if((item->deExtension[0] == 'M')&&(item->deExtension[1] == 'I')&&(item->deExtension[2] == 'D'))
{
#if FAT_DEBUG
printf_P(PSTR("\r\nFound mid file! index = %d name: "),i+1);
for(j=0;j<8;j++)putchar(item->deName[j]);
putchar('.');
for(j=0;j<3;j++)putchar(item->deExtension[j]);
#endif
CopyDirentruyItem(MusicInfo,item);
*type = 3;
i++;
if(i==*Count){free(buffer);return 0;}
else LongNameFlag = 0;
}
else if((item->deExtension[0] == 'W')&&(item->deExtension[1] == 'A')&&(item->deExtension[2] == 'V'))
{
#if FAT_DEBUG
printf_P(PSTR("\r\nFound wav file! index = %d name: "),i+1);
for(j=0;j<8;j++)putchar(item->deName[j]);
putchar('.');
for(j=0;j<3;j++)putchar(item->deExtension[j]);
#endif
CopyDirentruyItem(MusicInfo,item);
*type=4;
i++;
if(i==*Count){free(buffer);return 0;}
else LongNameFlag = 0;
}
else LongNameFlag = 0;
}
}
}
free(buffer);//release
tempclust=FAT_NextCluster(tempclust);//next cluster
if(tempclust == 0x0fffffff || tempclust == 0x0ffffff8 || (FAT32_Enable == 0 && tempclust == 0xffff))break;
}
}
}
}
if(*Count==0)*Count=i;
return 0;
}
//search the file
BYTE SearchLrc(BYTE *dir,BYTE * longnamebuffer,struct direntry *LrcInfo,WORD music_record_addr)
{
BYTE *buffer;
BYTE longbuffertemp[130];
BYTE * p1, * p2;
BYTE match = 0;
DWORD sector;
DWORD cluster;
DWORD tempclust;
BYTE i;
unsigned char cnt;
unsigned int offset;
//unsigned int i=0;
unsigned char j;//long name buffer offset;
unsigned char *p;//long name buffer pointer
struct direntry *item = 0;
struct winentry *we =0;
//cluster = FAT_OpenDir(dir);
//if(cluster == 1)return 1;
#if FAT_DEBUG
printf_P(PSTR("\r\nmusic_record_addr = %d"),music_record_addr);
#endif
for(i=0;i<2;i++)
{
if(i==0)cluster = GetFolderCluster(music_record_addr); // the same folder where the music file placed
else cluster = FAT_OpenDir(dir); // search the default lyric folder
if(cluster == 1)return 1;
if(cluster==0 && FAT32_Enable==0)// root directory
{
buffer=malloc(512);//apply memory
if(buffer==0)return 1;//if failed
for(cnt=0;cnt<RootDirSectors;cnt++)
{
if(SD_ReadSingleBlock(FirstDirSector+cnt,buffer)){free(buffer);return 1;}
for(offset=0;offset<512;offset+=32)
{
item=(struct direntry *)(&buffer[offset]);//pointer convert
//find a valid item and display it
if((item->deName[0] != '.') && (item->deName[0] != 0x00) && (item->deName[0] != 0xe5))
{
if(item->deAttributes == 0x0f)
{
we = (struct winentry *)(&buffer[offset]);
j = 26 *( (we->weCnt-1) & WIN_CNT);
if(j<MAX_LONG_NAME_SIZE-25)
{
p = &longbuffertemp[j];
for (j=0;j<10;j++) *p++ = we->wePart1[j];
for (j=0;j<12;j++) *p++ = we->wePart2[j];
for (j=0;j<4;j++) *p++ = we->wePart3[j];
if (we->weCnt & 0x40) (*(unsigned int *)p) = 0;
if ((we->weCnt & WIN_CNT) == 1) LongNameFlag = 1;
}
longbuffertemp[MAX_LONG_NAME_SIZE-1] = 0;
longbuffertemp[MAX_LONG_NAME_SIZE-2] = 0;
}
else if((item->deExtension[0] == 'L')&&(item->deExtension[1] == 'R')&&(item->deExtension[2] == 'C'))
{
CopyDirentruyItem(LrcInfo,item);
p1 = longnamebuffer;
p2 = longbuffertemp;
match = 1;
if(LongNameFlag)
{
while(*((unsigned int*)p1))
{
if(*(unsigned int*)p1 != *(unsigned int*)p2)
{
match = 0;
break;
}
p1 += 2;
p2 += 2;
}
}
else
{
p2 = item->deName;
while(*p1)
{
if(*p1++ != *p2++)
{
match = 0;
break;
}
}
}
if(match){free(buffer);return 0;}
else LongNameFlag = 0;
}
else LongNameFlag = 0;
}
}
}
free(buffer);//release
}
else//other folders
{
tempclust=cluster;
while(1)
{
sector=FirstDataSector+(DWORD)(tempclust-2)*(DWORD)SectorsPerClust;//calculate the actual sector number
buffer=malloc(512);//apply memory
if(buffer==0)return 1;//if failed
for(cnt=0;cnt<SectorsPerClust;cnt++)
{
if(SD_ReadSingleBlock(sector+cnt,buffer)){free(buffer);return 1;}
for(offset=0;offset<512;offset+=32)
{
item=(struct direntry *)(&buffer[offset]);
if((item->deName[0] != '.') && (item->deName[0] != 0x00) && (item->deName[0] != 0xe5))
{
if(item->deAttributes == 0x0f)
{
we = (struct winentry *)(&buffer[offset]);
j = 26 *( (we->weCnt-1) & WIN_CNT);
if(j<MAX_LONG_NAME_SIZE-25)
{
p = &longbuffertemp[j];
for (j=0;j<10;j++) *p++ = we->wePart1[j];
for (j=0;j<12;j++) *p++ = we->wePart2[j];
for (j=0;j<4;j++) *p++ = we->wePart3[j];
if (we->weCnt & 0x40) (*(unsigned int *)p) = 0;
if ((we->weCnt & WIN_CNT) == 1) LongNameFlag = 1;
}
longbuffertemp[MAX_LONG_NAME_SIZE-1] = 0;
longbuffertemp[MAX_LONG_NAME_SIZE-2] = 0;
}
else if((item->deExtension[0] == 'L')&&(item->deExtension[1] == 'R')&&(item->deExtension[2] == 'C'))
{
CopyDirentruyItem(LrcInfo,item);
p1 = longnamebuffer;
p2 = longbuffertemp;
match = 1;
if(LongNameFlag)
{
while(*((unsigned int*)p1))
{
if(*(unsigned int*)p1 != *(unsigned int*)p2)
{
match = 0;
break;
}
p1 += 2;
p2 += 2;
}
}
else
{
p2 = item->deName;
while(*p1)
{
if(*p1++ != *p2++)
{
match = 0;
break;
}
}
}
if(match){free(buffer);return 0;}
else LongNameFlag = 0;
}
else LongNameFlag = 0;
}
}
}
free(buffer);//release
tempclust=FAT_NextCluster(tempclust);//next cluster
if(tempclust == 0x0fffffff || tempclust == 0x0ffffff8 || (FAT32_Enable == 0 && tempclust == 0xffff))break;
}
}
}
return 1; //can't find lrc file
} */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -