⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fat.lst

📁 这是atmel公司的89C51SND1C的mp3源程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
1011   4              /* read new entry */
1012   4              ((Byte *)&new_cluster)[1]= Hard_read_byte();
1013   4              ((Byte *)&new_cluster)[0]= Hard_read_byte();
1014   4            }
1015   3          }
1016   2        }
1017   1        else                                      /* FAT12 management */
1018   1        {   /* compute offset in sector */
1019   2          fat12_parity = 0;
1020   2          i = (old_cluster + 1);
1021   2          do
1022   2          {
1023   3            if (fat12_parity == 0)
1024   3            {
1025   4              ((Byte *)&fat12_cluster)[1]= Hard_read_byte();
1026   4              ((Byte *)&fat12_cluster)[0]= Hard_read_byte();
1027   4              new_cluster = (fat12_cluster & 0x00FF);
1028   4              new_cluster += (fat12_cluster & 0x0F00);
1029   4              fat12_parity = 1;
1030   4            }
1031   3            else
1032   3            {
1033   4              ((Byte *)&fat12_cluster)[1]= Hard_read_byte();
1034   4              new_cluster = (fat12_cluster & 0xF000) >> 12;
1035   4              new_cluster += (fat12_cluster & 0x00FF) << 4;
1036   4              fat12_parity = 0;
1037   4            }
1038   3            i--;
1039   3          }
1040   2          while (i != 0);
1041   2      
1042   2          while ( (new_cluster != 0xFFF) && (new_cluster != 0xFF8))                  
1043   2          /* loop until last cluster found */
1044   2          {
1045   3            if ((new_cluster == (old_cluster + 1)) && (chain->number[index] != 255))
1046   3            { /* contiguous cluster */
C51 COMPILER V6.20c  FAT                                                                   07/10/2002 15:17:46 PAGE 18  

1047   4              chain->number[index]++;
1048   4            }
1049   3            else
1050   3            { /* compute fragmentation */
1051   4              index++;
1052   4              chain->number[index] = 1;
1053   4              chain->cluster[index] = new_cluster - 2;  /* 2 = 1st cluster */
1054   4              for (i = new_cluster - old_cluster - 1; i != 0; i--)
1055   4              {  /* dummy FAT read */
1056   5                if (fat12_parity == 0)
1057   5                {
1058   6                  ((Byte *)&fat12_cluster)[1]= Hard_read_byte();
1059   6                  ((Byte *)&fat12_cluster)[0]= Hard_read_byte();
1060   6                  fat12_parity = 1;
1061   6                }
1062   5                else
1063   5                {
1064   6                  ((Byte *)&fat12_cluster)[1]= Hard_read_byte();
1065   6                  fat12_parity = 0;
1066   6                }
1067   5              }
1068   4            }
1069   3            old_cluster = new_cluster;
1070   3            if (index == MAX_FILE_FRAGMENT_NUMBER - 2)
1071   3            {
1072   4              return KO;                          /* file too much fragmented */
1073   4            }
1074   3            else
1075   3            {
1076   4              /* read new entry */
1077   4              if (fat12_parity == 0)
1078   4              {
1079   5                ((Byte *)&fat12_cluster)[1]= Hard_read_byte();
1080   5                ((Byte *)&fat12_cluster)[0]= Hard_read_byte();
1081   5                new_cluster = (fat12_cluster & 0x00FF);
1082   5                new_cluster += (fat12_cluster & 0x0F00);
1083   5                fat12_parity = 1;
1084   5              }
1085   4              else
1086   4              {
1087   5                ((Byte *)&fat12_cluster)[1]= Hard_read_byte();
1088   5                new_cluster = (fat12_cluster & 0xF000) >> 12;
1089   5                new_cluster += (fat12_cluster & 0x00FF) << 4;
1090   5                fat12_parity = 0;
1091   5              }
1092   4            }
1093   3          }
1094   2        }
1095   1        /* mark the last chain element with number= 0 */
1096   1        chain->number[index + 1] = 0;             /* end of chain marker */
1097   1        Hard_read_close();                        /* close physical read */
1098   1        return OK;
1099   1      }
1100          
1101          
1102          /*F**************************************************************************
1103          * NAME: fat_fgetc
1104          *----------------------------------------------------------------------------
1105          * PARAMS:
1106          *
1107          * return:
1108          *   byte read
C51 COMPILER V6.20c  FAT                                                                   07/10/2002 15:17:46 PAGE 19  

1109          *----------------------------------------------------------------------------
1110          * PURPOSE:
1111          *   Read one byte from file
1112          *----------------------------------------------------------------------------
1113          * EXAMPLE:
1114          *----------------------------------------------------------------------------
1115          * NOTE:
1116          *   As this function is called very often it must be short and optimized
1117          *   in execution time
1118          *----------------------------------------------------------------------------
1119          * REQUIREMENTS:
1120          *****************************************************************************/
1121          Byte fat_fgetc (void)
1122          {
1123   1        /* check if we are at the end of a cluster */
1124   1        if ((((Byte*)&fat_file_byte_counter)[3] == 0x00) &&
1125   1            ((((Byte*)&fat_file_byte_counter)[2] & fat_cluster_mask) == 0x00))
1126   1        {
1127   2          /* extract if necessary the next cluster from the allocation list */
1128   2          if (clusters.number[fat_chain_index] == fat_chain_cluster)
1129   2          { /* new fragment */
1130   3            fat_chain_index++;
1131   3            fat_chain_cluster = 1;
1132   3            Hard_read_open(fat_ptr_data + ((Uint32)(clusters.cluster[fat_chain_index]) * fat_cluster_size));
1133   3          }
1134   2          else
1135   2          { /* no new fragment */
1136   3            fat_chain_cluster++;                /* one more cluster read */
1137   3          }
1138   2        }
1139   1        fat_file_byte_counter++;                /* one more byte read */
1140   1        return Hard_read_byte();
1141   1      }
1142          
1143          
1144          /*F**************************************************************************
1145          * NAME: fat_fputc
1146          *----------------------------------------------------------------------------
1147          * PARAMS:
1148          *   d: data byte to write
1149          * return:
1150          *----------------------------------------------------------------------------
1151          * PURPOSE:
1152          *   Write one byte to file
1153          *----------------------------------------------------------------------------
1154          * EXAMPLE:
1155          *----------------------------------------------------------------------------
1156          * NOTE:
1157          *   As this function is called very often it must be short and optimized
1158          *   in execution time
1159          *----------------------------------------------------------------------------
1160          * REQUIREMENTS:
1161          *****************************************************************************/
1162          void fat_fputc (Byte d)
1163          {
1164   1        /* check if we are at the end of a cluster */
1165   1        if ((((Byte*)&fat_file_byte_counter)[3] == 0x00) &&
1166   1            ((((Byte*)&fat_file_byte_counter)[2] & fat_cluster_mask) == 0x00))
1167   1        {
1168   2          /* extract if necessary the next cluster from the allocation list */
1169   2          if (clusters.number[fat_chain_index] == fat_chain_cluster)
1170   2          { /* new fragment */
C51 COMPILER V6.20c  FAT                                                                   07/10/2002 15:17:46 PAGE 20  

1171   3            fat_chain_index++;
1172   3            fat_chain_cluster = 1;
1173   3            Hard_write_open(fat_ptr_data + ((Uint32)(clusters.cluster[fat_chain_index]) * fat_cluster_size));
1174   3          }
1175   2          else
1176   2          { /* no new fragment */
1177   3            fat_chain_cluster++;                /* one more cluster read */
1178   3          }
1179   2        }
1180   1        fat_file_byte_counter++;                /* one more byte read */
1181   1        Hard_write_byte(d);
1182   1      }
1183          
1184          
1185          /*F**************************************************************************
1186          * NAME: fat_feof
1187          *----------------------------------------------------------------------------
1188          * PARAMS:
1189          *
1190          * return:
1191          *----------------------------------------------------------------------------
1192          * PURPOSE:
1193          *   Return the file end flag
1194          *----------------------------------------------------------------------------
1195          * EXAMPLE:
1196          *----------------------------------------------------------------------------
1197          * NOTE:
1198          *----------------------------------------------------------------------------
1199          * REQUIREMENTS:
1200          *****************************************************************************/
1201          bit fat_feof (void)
1202          {
1203   1        return (fat_file_byte_counter >= fat_cache.info.size);
1204   1      }
1205          
1206          
1207          /*F**************************************************************************
1208          * NAME: fat_dseek
1209          *----------------------------------------------------------------------------
1210          * PARAMS:
1211          *   offset: offset to current position in signed word value
1212          *
1213          * return:
1214          *----------------------------------------------------------------------------
1215          * PURPOSE:
1216          *   Seek from the current position to a new offset computing relative 
1217          *   poisition +/- scan size limited to a 16 bit offset
1218          *----------------------------------------------------------------------------
1219          * EXAMPLE:
1220          *----------------------------------------------------------------------------
1221          * NOTE:
1222          *   We consider here that the seek size is minor to the cluster size !!!
1223          *   if you want to do a more than a cluster seek, issue two successive 
1224          *   dseek commands
1225          *----------------------------------------------------------------------------
1226          * REQUIREMENTS:
1227          *****************************************************************************/ 
1228          bit fat_dseek (Int16 offset)
1229          {
1230   1      idata Byte     nb_sect;                     /* number of sectors to seek */
1231   1      idata Uint16   nb_byte;                     /* number of bytes to seek */
1232   1      idata Uint16   next_cluster;                /* the possible next cluster to load */
C51 COMPILER V6.20c  FAT                                                                   07/10/2002 15:17:46 PAGE 21  

1233   1      idata Uint16   target_cluster;              /* the cluster to reach        */
1234   1      Uint16   i;
1235   1      
1236   1        fat_directory_pos += offset;              /* Calculate the absolute byte pos */
1237   1        nb_sect = (Byte)((fat_directory_pos) / SECTOR_SIZE);
1238   1        nb_byte = (Uint16)((fat_directory_pos) % SECTOR_SIZE);
1239   1      
1240   1        fat_current_sector = fat_directory_base + nb_sect;
1241   1        fat_current_byte_counter = nb_byte;
1242   1        
1243   1        if (dir_is_root == FALSE)                 /* Sub-directory ?   */
1244   1        {                                         /* Fin the # cluster */
1245   2          target_cluster = (nb_sect / fat_cluster_size);
1246   2          fat_current_dir_cluster = 0;
1247   2          next_cluster = dir_clusters.cluster[fat_current_dir_cluster];
1248   2          fat_current_dir_fragment = 1;
1249   2          for (i = 0; i < target_cluster; i++)
1250   2          {
1251   3            if (dir_clusters.number[fat_current_dir_cluster] <= fat_current_dir_fragment)
1252   3              { /* new fragment */
1253   4                fat_current_dir_cluster++;
1254   4                fat_current_dir_fragment = 1;
1255   4                next_cluster = dir_clusters.cluster[fat_current_dir_cluster];
1256   4              }
1257   3              else
1258   3              { /* no new fragment */
1259   4                next_cluster = dir_clusters.cluster[fat_current_dir_cluster] + fat_current_dir_fragment;
1260   4                fat_current_dir_fragment++;
1261   4              }
1262   3          }
1263   2          fat_current_sector = (((Uint32)(next_cluster) * fat_cluster

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -