📄 fat16.lst
字号:
129 4 {
130 5 SONG[l * 11 + i] = Page_Buf[j * 32 + i];
131 5 }
132 4 l++;
133 4 }
134 3 }
135 2 k++;
136 2 ReadPage(0 + k / 32, k % 32, Page_Buf);
137 2 }
138 1 return (l);
139 1 }
140 int ReadSector(unsigned char *Name, unsigned char *databuff)
141 {
142 1 int i, k, Page;
143 1 unsigned long CurrentSector;
144 1 if (DataRead == 0) //第一次读取,先查找文件,然后进行读取
145 1 {
146 2 Page = BootSector + RsdSector + 2 * SectorofFatSize;
147 2 ReadPage(0 + Page / 32, Page % 32, databuff);
148 2 while (databuff[0] != 0)
149 2 {//遍历整个目录
150 3 for (i=0; i<16; i++)
151 3 {
152 4 if (!memcmp(Name, &databuff[i * 32], 11))
153 4 {
154 5 Current_Cluster = databuff[32 * i + 27] * 256 + databuff[32 * i + 26];
155 5 printuf("Current_Cluster : %x", (Current_Cluster & 0xff00) >> 8);
156 5 printuf("%x\n", Current_Cluster);
157 5 for (k=31; k>27; k--)
158 5 {
159 6 DataRemain = (DataRemain << 8) | databuff[i * 32 + k];
160 6 }
161 5 //ReadPage((Current_Cluster+Sector_Offset)/32,(Current_Cluster+Sector_Offset)%32,databuff);
162 5
163 5 CurrentSector = (Current_Cluster - 2) * SecPerClus + FirstDataSec;
164 5 ReadPage(CurrentSector / 32, CurrentSector % 32, databuff);
165 5
166 5 DataRead += 512;
167 5 DataRemain -= 512;
168 5 if (DataRemain < 0)
169 5 {
170 6 DataRead = 0;
171 6 return (DataRemain + 512);
172 6 }
173 5 else
C51 COMPILER V7.50 FAT16 03/16/2006 09:11:14 PAGE 4
174 5 {
175 6 return (512);
176 6 }
177 5 }
178 4 }
179 3 Page++;
180 3 ReadPage(0 + Page / 32, Page % 32, databuff);
181 3 }
182 2 printu("\nfile is not found!");
183 2 return (0);
184 2 }
185 1 else
186 1 {
187 2 // if((Current_Cluster+Sector_Offset+DataRead/BytesPerSec)%32) Current_Cluster=NextCluster(Current_Clust
-er);
188 2 // ReadPage((Current_Cluster+Sector_Offset)/32,(Current_Cluster+Sector_Offset+DataRead/BytesPerSec)%32,d
-atabuff);
189 2 Current_Cluster++;
190 2 CurrentSector = (Current_Cluster - 2) * SecPerClus + FirstDataSec;
191 2 ReadPage(CurrentSector / 32, CurrentSector % 32, databuff);
192 2
193 2 DataRead += 512;
194 2 // if(!((Current_Cluster+Sector_Offset+DataRead/BytesPerSec)%32)) Current_Cluster=NextCluster(Current_Cl
-uster+32);
195 2 // if(!((Current_Cluster+Sector_Offset+DataRead/BytesPerSec)%32)) Current_Cluster+=32;//默认歌曲文件是顺
-序存放的。
196 2 DataRemain -= 512;
197 2 if (DataRemain < 0)
198 2 {
199 3 DataRead = 0;
200 3 return (DataRemain + 512);
201 3 }
202 2 else return (512);
203 2 }
204 1
205 1 }
206
207 unsigned int NextCluster(unsigned int CurrentCluster)
208 {
209 1 unsigned int i, j;
210 1 if (FAT_TYPE == FAT12)
211 1 {
212 2 ReadPage(Begin_Cluster + (BootSector + RsdSector + (CurrentCluster * 3 / 2) / BytesPerSec) / SecPerClus,
-
213 2 (BootSector + RsdSector + (CurrentCluster * 3 / 2) / BytesPerSec) % SecPerClus, Page_Buf);
214 2 if (CurrentCluster % 2 == 0)
215 2 {
216 3 j = Page_Buf[(CurrentCluster * 3 / 2) % BytesPerSec + 1];
217 3 i = Page_Buf[(CurrentCluster * 3 / 2) % BytesPerSec] | (j << 8);
218 3 i &= 0x0fff;
219 3 }
220 2 else
221 2 {
222 3 j = Page_Buf[(CurrentCluster * 3 / 2) % BytesPerSec + 1];
223 3 i = Page_Buf[(CurrentCluster * 3 / 2) % BytesPerSec] | (j << 8);
224 3 i = (i >> 4);
225 3 }
226 2 return (i);
227 2 }
228 1 else if (FAT_TYPE == FAT16)
229 1 {
230 2 ReadPage(Begin_Cluster + (BootSector+RsdSector + (CurrentCluster * 2) / BytesPerSec) / 32,
C51 COMPILER V7.50 FAT16 03/16/2006 09:11:14 PAGE 5
231 2 (BootSector + RsdSector + (CurrentCluster * 2) / BytesPerSec) % 32, Page_Buf);
232 2 i = Page_Buf[(CurrentCluster * 2) % BytesPerSec + 1] * 256 + Page_Buf[(CurrentCluster * 2) % BytesPerSec
-];
233 2 return (i);
234 2 }
235 1 else if (FAT_TYPE == FAT32)
236 1 {
237 2 ReadPage(Begin_Cluster + (BootSector+RsdSector + (CurrentCluster * 4) / BytesPerSec) / SecPerClus, (Boot
-Sector + RsdSector + (CurrentCluster * 4) / BytesPerSec) % SecPerClus, Page_Buf);
238 2 i = Page_Buf[(CurrentCluster * 4) % BytesPerSec + 3] * 256 * 256 * 256 + Page_Buf[(CurrentCluster * 4) %
- BytesPerSec + 2]
239 2 * 256 * 256 + Page_Buf[(CurrentCluster * 4) % BytesPerSec + 1] * 256 + Page_Buf[(CurrentCluster * 4) %
-BytesPerSec];
240 2 return (i);
241 2 }
242 1 }
243
244
245
246
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2853 ----
CONSTANT SIZE = 134 ----
XDATA SIZE = 37 30
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -