📄 xfile.c
字号:
} } else { // use fixed name filter if(!strncmp((char*)file->Name,(char*)SpecialFileNameList,file->NameLength)) return S_SPECIAL_FILE_FOUND; } } return S_FALSE; } if ((filt == NULL) || (*filt == 0)) return S_FALSE; // file has some extension while (1) { if (!strncmp((char *) ext2, (char *) ext, exlen)) { return S_TRUE; } while ((*ext2 != '.') && (*ext2 != 0)) { ext2++; } if (*ext2 == 0) // end of extension filter reached { return S_FALSE; // end of filter } ext2++; // skip '.' in filter } // return S_FALSE; // statement unreachable}uint8 XAR_FileType(char *extptr)// function returns recognized file category{char cb[4],b;int i;for(i=0;i<3;i++){ b = *(extptr+i); if((b>64)&&(b<91)) b+=0x20; // conversion to lower case cb[i] = b;} if (!strncmp("mp3", cb, 3)) return CAFILE_MP3;#if(LAYER1) if (!strncmp("mp1", cb, 3)) return CAFILE_MP3; // mp1 same as mp3 (same decoder)#endif#if(LAYER2) if (!strncmp("mp2", cb, 3)) return CAFILE_MP3; // mp2 same as mp3 (same decoder)#endif#if(HAVE_WMA) if (!strncmp("wma", cb, 3)) return CAFILE_WMA;#endif#if(HAVE_PLAYLIST) if (!strncmp("m3u", cb, 3)) return PLAYLIST_M3U; if (!strncmp("pls", cb, 3)) return PLAYLIST_PLS;#if(HAVE_WMDRM) if (!strncmp("pla", cb, 3)) return PLAYLIST_PLA;#endif#endif#if(HAVE_AAC) if (!strncmp("aac", cb, 3) || !strncmp("m4a", cb, 3)) return CAFILE_AAC;#endif return DATA_FILE;}int16 XAR_VolumeNodeForItem(int16 index){uint16 vol = 0; if (XAR_NodeType(index) == XTYPE_VOLUME) return index; while( XAR_NodeType(vol) == XTYPE_VOLUME) { if( (vol + X_array[vol].data.xvolume.nodes_num) >= index) return vol; vol += ( X_array[vol].data.xvolume.nodes_num + 1); } return 0; // it should never come here, ERROR !! /* while (index && (XAR_NodeType(index) != XTYPE_VOLUME)) { index--; } return index; */ }// function returns ordinal number of volume added (1st volume = 1,2nd=2,...)GRESULT XAR_AddVolume(FDID fid){ uint8 *pt; FS_DESCRIPTOR *fs; int vname = 0xffff; uint16 i = 0, vol = 0;#if HAVE_EXTERNAL_XARRAY int vlen;#endif if(X_NEXTFREE_ITEM > X_MAX_INDEX) return E_FAIL; // not addresable items would be added while ((i < X_NEXTFREE_ITEM) && (XAR_NodeType(i) == XTYPE_VOLUME)) { i += (X_array[i].data.xvolume.nodes_num + 1); vol++; } if (i != X_NEXTFREE_ITEM) { return E_FS_INTEGRITY_ERROR; } if (NULL == (fs = SYS_FSDescriptor(fid))) return E_INVALID_DEVICE_ACTION;#if HAVE_EXTERNAL_XARRAY pt = ((uint8 *)&X_array[XFILE_NODES_NUM]) - X_POOL_TOP - 2; if ((pt - fs->VolumeNameLength - 1) < (uint8 *)&X_array[X_NEXTFREE_ITEM + 1]) // consider 32 bytes for volume identifier return E_INSUFFICIENT_MEMORY; // new node cannot be added#else pt = ((uint8 *)&X_array[XFILE_NODES_NUM]) - X_POOL_TOP - 1; if ((pt - fs->VolumeNameLength) < (uint8 *)&X_array[X_NEXTFREE_ITEM + 1]) // consider 32 bytes for volume identifier return E_INSUFFICIENT_MEMORY; // new node cannot be added#endif X_array[X_NEXTFREE_ITEM].nodetype.i = XTYPE_VOLUME; X_array[X_NEXTFREE_ITEM].data.xvolume.fs_type = fs->FSType; X_array[X_NEXTFREE_ITEM].data.xvolume.nodes_num = 0; // if(fs->FSType == FS_ISO9660_TYPE ) // {#if HAVE_EXTERNAL_XARRAY vname = X_POOL_TOP + 1; *(uint16 *) pt = fs->VolumeNameLength; vlen = fs->VolumeNameLength; vlen += (1 & fs->VolumeNameLength); memcpy16(pt - (fs->VolumeNameLength), fs->VolumeName, vlen); //X_POOL_TOP += (vlen + 2); writeSDRAM32((int16*)&X_POOL_TOP,X_POOL_TOP+vlen+2);#else vname = X_POOL_TOP; *pt = fs->VolumeNameLength; memcpy(pt - (fs->VolumeNameLength), fs->VolumeName, fs->VolumeNameLength); X_POOL_TOP += fs->VolumeNameLength + 1;#endif // } //X_array[X_NEXTFREE_ITEM].data.xvolume.name = vname;#if HAVE_EXTERNAL_XARRAY X_array[X_NEXTFREE_ITEM].data.xvolume.name = vname&0xffff; X_array[X_NEXTFREE_ITEM].nodetype.i = X_array[X_NEXTFREE_ITEM].nodetype.b[0] + \ ((vname&0xff0000)>>8);#else X_array[X_NEXTFREE_ITEM].data.xvolume.name = vname;#endif#if HAVE_EXTERNAL_XARRAY// writeSDRAM32((int16 *)&X_array[X_NEXTFREE_ITEM].data.xvolume.partitionLBA, fs->PartitionLBA);#else// X_array[X_NEXTFREE_ITEM].data.xvolume.partitionLBA = fs->PartitionLBA;#endif //X_array[X_NEXTFREE_ITEM].data.xvolume.devtype = SYS_DeviceType(fs->did); X_array[X_NEXTFREE_ITEM].nodetype.i |= XAR_VolNodeDevPattern(SYS_DeviceType(fs->did)); X_NEXTFREE_ITEM++; return vol + 1;}GRESULT XAR_AddTOCVolume(void){ t_XNode node;// node.data.xvolume.partitionLBA = 0; node.data.xvolume.name = 0xffff; node.data.xvolume.nodes_num = 0; node.data.xvolume.fs_type = FS_TOC; // TOC info node.data.xvolume.nextfree_item = 1; node.data.xvolume.pool_top = 0; node.nodetype.i = XTYPE_VOLUME | FLAG_VOLUME_VALID | XAR_VolNodeDevPattern(DEV_CD_ID);#if HAVE_EXTERNAL_XARRAY node.nodetype.b[1] = 0xff;#endif XAR_WriteNode(0, &node); return S_OK;}GRESULT XAR_SetVolumeTop(uint16 volume, uint16 top){ GRESULT voli; voli = XAR_VolumeNode(volume); /*if(voli<0) return E_FAIL; */ ASSERT(VALID_VOLUME_NODE(voli), "XAR_SetVolumeTop volume not found"); X_array[voli].data.xvolume.nodes_num = top - voli; X_array[voli].nodetype.i |= FLAG_VOLUME_VALID; return S_OK;}#if XARREM// used for faster song indexingGRESULT XAR_CreateSongIndexes(uint16 volume){GRESULT i;int index = 1,plindex=1; i = 0; X_dir_stop = 0; X_last_dir = 0; do { i = XAR_NextSong2(volume,i,1); if(i>0) { switch(XAR_XNodeType(i)) { case CAFILE_MP3:#if(HAVE_WMA==1) case CAFILE_WMA:#endif #if(HAVE_AAC==1) case CAFILE_AAC:#endif X_array[i].data.xfile.address = index++; break; case PLAYLIST_M3U: case PLAYLIST_PLS: // case PLAYLIST_ASX: // case PLAYLIST_WPL: X_array[i].data.xfile.address = plindex++; break; default: X_array[i].data.xfile.address = 0; } } }while(i>0); return S_OK;}#endif // XARREMvoid XAR_SetLastNode(uint16 top){ X_NEXTFREE_ITEM = top;}#if XARREMGRESULT XAR_IsPlayableFile(t_XItem node){ switch(XAR_XNodeType(node)) { case CAFILE_MP3: case CAFILE_WMA: case CAFILE_AAC: return S_TRUE; //last file in last dir default: break; } return S_FALSE;}/******************************************************************************//* Function: XAR_PreviousSong *//* *//*! \brief Sequencial switch to previous file (in case of current = 0, goto last song in volume * \param index of volume, current file * \return index (X_array) of previous song * \remark *//******************************************************************************/GRESULT XAR_PreviousSong(uint16 volume, uint16 current){ GRESULT tmp; int32 root = 0; int32 next; int32 curr_dir; // int32 vol_index; //[RB] unused // vol_index = XAR_VolumeNode(volume); // [RB] unused if (!current) curr_dir = 0; else curr_dir = XAR_DirFromFile(current); if (!curr_dir) { //goto last dir in volume root = XAR_RootDir(volume); if (root == S_NOT_FOUND) return S_NOT_FOUND; tmp = root; while (1) { next = XAR_NextDir(tmp); if (next > 0) tmp = next; else { next = XAR_DirChild(tmp); if (next <= 0) break; //tmp carries the last directory in volume tmp = next; } } if (tmp == 0) return S_NOT_FOUND; //if no direcotries found (this has not to occur) while (1) { next = XAR_FindFile(tmp, 0xffff); if (next != S_NOT_FOUND) { if(XAR_IsPlayableFile(next)) return next; while(next>0) { next = XAR_PrevFile(next); if(next>0) if(XAR_IsPlayableFile(next)) return next; } } //if last dir doesn't contain files (this has not to occur) tmp = XAR_BackwDir(tmp, root); if (tmp == S_NOT_FOUND) return S_NOT_FOUND; } } tmp = current; do { tmp = XAR_PrevFile(tmp); if (tmp != S_NOT_FOUND) if(XAR_IsPlayableFile(tmp)) return tmp; }while(tmp!=S_NOT_FOUND); while (1) { tmp = XAR_BackwDir(curr_dir, 0); if (tmp == S_NOT_FOUND) return S_NOT_FOUND; //prev dir, find last file inside this dir next = XAR_FindFile(tmp, 0xffff); while(next != S_NOT_FOUND) { if(XAR_IsPlayableFile(next)) return next; //last playable file in dir next = XAR_PrevFile(next); } curr_dir = tmp; } //return tmp; // statement unreachable}#endif // #if XARREM/******************************************************************************//* Function: XAR_IsValidVolume *//* *//*! \brief checks validity of specified volume * \param volume nr. 1,2,.. * \return S_TRUE/S_FALSE * \remark *//******************************************************************************/#ifdef APM_PICKUPGRESULT XAR_IsValidVolume(int16 volume){ if ((volume < 1) || (X_NEXTFREE_ITEM == 0)) return S_FALSE; { volume = XAR_VolumeNode(volume); //recalculate to index in X_array // if(volume<1) if (!VALID_VOLUME_NODE(volume)) return S_FALSE; if (!(X_array[volume].type & FLAG_VOLUME_VALID)) return S_FALSE; } return S_TRUE;}#endif#if XARREM/******************************************************************************//* Function: XAR_VolumeForItem *//* *//*! \brief Finds volume for current dir / file * \param index of file/dir in X_array * \return volume nr. (1,2,..) / E_FS_INTEGRITY_ERROR * \remark *//******************************************************************************/GRESULT XAR_VolumeForItem(int16 index){ int16 tmp = 0; int16 index_vol = 0; while ((XTYPE_VOLUME == XAR_NodeType(tmp)) && (tmp < X_NEXTFREE_ITEM)) { index_vol++; if ((index >= tmp) && (index <= (tmp + X_array[tmp].data.xvolume.nodes_num))) return index_vol; tmp = tmp + X_array[tmp].data.xvolume.nodes_num + 1; } ASSERT(0, "XAR_VolumeForItem invalid index"); return E_FAIL;}#endif // #if XARREMvoid XAR_UpdateNodeFlags(uint16 node, uint8 flags){#if(HAVE_EXTERNAL_XARRAY == 1) X_array[node].nodetype.i = (X_array[node].nodetype.b[1]<<8)|(0xe0 & X_array[node].nodetype.i) | (0x1F & flags);#else X_array[node].nodetype.i = (0xe0 & X_array[node].nodetype.i) | (0x1F & flags);#endif}GRESULT XAR_DirFromFile(uint16 item){ uint16 i, j; i = item - 1; while (XAR_NodeType(i) != XTYPE_VOLUME) { if (XAR_NodeType(i) == XTYPE_DIRECTORY) { j = X_array[i].data.xdir.first_file; if ((j <= item) && (j)) return i; } i--; } ASSERT(0, "XAR_DirFromFile invalid index"); return E_FAIL;}#if XARREMGRESULT XAR_DirStopFromFile(uint16 item){ uint16 i, j; GRESULT st = E_FAIL; i = item - 1; while (XAR_NodeType(i) != XTYPE_VOLUME) { if (XAR_NodeType(i) == XTYPE_DIRECTORY) { j = X_array[i].data.xdir.first_file; if ((!j) || (j > item)) { if (j > item) st = j; } else { if (st > 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -