📄 fat.lst
字号:
C51 COMPILER V6.20c FAT 08/21/2003 22:51:05 PAGE 1
C51 COMPILER V6.20c, COMPILATION OF MODULE FAT
OBJECT MODULE PLACED IN Fat.OBJ
COMPILER INVOKED BY: E:\WIN98\HARDWARE\KEILC\C51\BIN\C51.EXE Fat.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include "common.h"
2 #include "Fat.h"
3 #include "SL811.H"
4 #include "TPBULK.H"
5 #include "HAL.H"
6 //#include "RBCCMD.H"
7 ////////////////////////////////////////
8 extern XXGFLAGS bdata bXXGFlags;
9 extern SYS_INFO_BLOCK xdata DeviceInfo;
10 extern FILE_INFO xdata ThisFile;
11 extern unsigned char xdata DBUF[BUFFER_LENGTH];
12 unsigned char xdata FATBUF[512];
13 unsigned char xdata CurFatSector[512];
14 //unsigned char xdata OldFatSector[512];
15 FREE_FAT_INFO xdata FreeFat;
16 ////////////////////////////////////////
17 unsigned long FirstSectorofCluster(unsigned int clusterNum)
18 {
19 1 unsigned long temp;
20 1 temp=clusterNum-2;
21 1 temp=temp*DeviceInfo.BPB_SecPerClus;
22 1 temp=temp+DeviceInfo.FirstDataSector;
23 1 return temp;
24 1 }
25
26 unsigned int ThisFatSecNum(unsigned int clusterNum)
27 {
28 1 unsigned int temp;
29 1 temp=clusterNum*2;
30 1 temp=temp/DeviceInfo.BPB_BytesPerSec;
31 1 temp=temp+DeviceInfo.FatStartSector;
32 1 return temp;
33 1 }
34
35 unsigned int ThisFatEntOffset(unsigned int clusterNum)
36 {
37 1 unsigned int temp1,temp2;
38 1 temp1=2*clusterNum;
39 1 temp2=temp1/DeviceInfo.BPB_BytesPerSec;
40 1 temp1=temp1-temp2*DeviceInfo.BPB_BytesPerSec;
41 1 return temp1;
42 1 }
43
44 unsigned int GetNextClusterNum(unsigned int clusterNum)
45 {
46 1 unsigned int xxgFatSecNum,xxgFatEntOffset;
47 1
48 1 xxgFatSecNum=ThisFatSecNum(clusterNum);
49 1 xxgFatEntOffset=ThisFatEntOffset(clusterNum);
50 1 //ThisFile.FatSectorPointer=xxgFatSecNum;
51 1 if(ThisFile.FatSectorPointer!=xxgFatSecNum)
52 1 {
53 2
54 2 if(!RBC_Read(xxgFatSecNum,1,FATBUF))
55 2 return 0xFFFF;
C51 COMPILER V6.20c FAT 08/21/2003 22:51:05 PAGE 2
56 2 ThisFile.FatSectorPointer=xxgFatSecNum;
57 2 }
58 1
59 1 ///////////////////////////////////////////////////
60 1 clusterNum=FATBUF[xxgFatEntOffset+1];
61 1 clusterNum=clusterNum<<8;
62 1 clusterNum+=FATBUF[xxgFatEntOffset];
63 1 return clusterNum;
64 1 }
65
66 unsigned char DeleteClusterLink(unsigned int clusterNum)
67 {
68 1 //unsigned int nextClusterNum;
69 1 unsigned int xxgFatSecNum,xxgFatEntOffset;
70 1 //nextClusterNum=GetNextClusterNum(clusterNum);
71 1 ////////////////////////////////////////////
72 1 //nextClusterNum=clusterNum;
73 1 while((clusterNum>1)&&(clusterNum<0xfff0))
74 1 {
75 2 xxgFatSecNum=ThisFatSecNum(clusterNum);
76 2 xxgFatEntOffset=ThisFatEntOffset(clusterNum);
77 2 if(RBC_Read(xxgFatSecNum,1,DBUF))
78 2 {
79 3 clusterNum=DBUF[xxgFatEntOffset+1];
80 3 clusterNum=clusterNum<<8;
81 3 clusterNum+=DBUF[xxgFatEntOffset];
82 3 //return clusterNum;
83 3 }
84 2 else
85 2 return FALSE;
86 2 DBUF[xxgFatEntOffset]=0x00;
87 2 DBUF[xxgFatEntOffset+1]=0x00;
88 2 //DelayMs(5);
89 2 if(!RBC_Write(xxgFatSecNum,1,DBUF))
90 2 return FALSE;
91 2 //DelayMs(5);
92 2 if(!RBC_Write(xxgFatSecNum+DeviceInfo.BPB_FATSz16,1,DBUF))
93 2 return FALSE;
94 2 ////////////////////////////////////////////
95 2 }
96 1 return TRUE;
97 1 }
98
99 unsigned int GetClusterNumFromSectorNum(unsigned long sectorNum)
100 {
101 1 unsigned long temp;
102 1 temp=sectorNum-DeviceInfo.FirstDataSector;
103 1 temp=temp/DeviceInfo.BPB_SecPerClus;
104 1 temp=temp+2;
105 1 return (unsigned int)temp;
106 1 }
107 /*
108 unsigned long GetSecNumFromPointer(void)
109 {
110 unsigned int clusterNum,clusterSize;
111 unsigned long temp,pointer;
112 pointer=ThisFile.FilePointer;
113 clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
114 clusterNum=ThisFile.StartCluster;
115 while(pointer>clusterSize)
116 {
117 pointer-=clusterSize;
C51 COMPILER V6.20c FAT 08/21/2003 22:51:05 PAGE 3
118 clusterNum=GetNextClusterNum(clusterNum);
119 }
120 temp=FirstSectorofCluster(clusterNum)+pointer/DeviceInfo.BPB_BytesPerSec;
121 return temp;
122 }
123 */
124 unsigned char GoToPointer(unsigned long pointer)
125 {
126 1 //unsigned char temp;
127 1 unsigned int clusterSize;
128 1 //unsigned long temp;
129 1 //pointer=ThisFile.FilePointer;
130 1 clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
131 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
132 1 while(pointer>clusterSize)
133 1 {
134 2 pointer-=clusterSize;
135 2 ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
136 2 if(ThisFile.ClusterPointer==0xffff)
137 2 {
138 3 return FALSE;
139 3 }
140 2 }
141 1 ThisFile.SectorofCluster=pointer/DeviceInfo.BPB_BytesPerSec;
142 1 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer)+ThisFile.SectorofCluster;
143 1 ThisFile.OffsetofSector=pointer-ThisFile.SectorofCluster*DeviceInfo.BPB_BytesPerSec;
144 1 ThisFile.FatSectorPointer=0;
145 1 return TRUE;
146 1
147 1 }
148
149 unsigned int GetFreeCusterNum(void)
150 {
151 1 unsigned int clusterNum,i;
152 1 unsigned long sectorNum;
153 1 clusterNum=0;
154 1 sectorNum=DeviceInfo.FatStartSector;
155 1 while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
156 1 {
157 2
158 2 if(!RBC_Read(sectorNum,1,DBUF))
159 2 return 0x0;
160 2 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
161 2 {
162 3 //clusterNum++;
163 3
164 3 if((DBUF[i]==0)&&(DBUF[i+1]==0))
165 3 {
166 4 DBUF[i]=0xff;
167 4 DBUF[i+1]=0xff;
168 4 //DelayMs(10);
169 4 if(!RBC_Write(sectorNum,1,DBUF))
170 4 return 0x00;
171 4 //DelayMs(10);
172 4 if(!RBC_Write(sectorNum+DeviceInfo.BPB_FATSz16,1,DBUF))
173 4 return 0x00;
174 4
175 4 return clusterNum;
176 4 }
177 3 clusterNum++;
178 3 }
179 2
C51 COMPILER V6.20c FAT 08/21/2003 22:51:05 PAGE 4
180 2 sectorNum=2*clusterNum/DeviceInfo.BPB_BytesPerSec+DeviceInfo.FatStartSector;
181 2 //clusterNum+=DeviceInfo.BPB_BytesPerSec;
182 2 //DelayMs(10);
183 2 }
184 1
185 1 return 0x0;
186 1 }
187
188 unsigned int CreateClusterLink(unsigned int currentCluster)
189 {
190 1 unsigned char bFound;
191 1 unsigned int clusterNum;
192 1 unsigned int xxgFatSecNum,xxgFatEntOffset;
193 1 unsigned long temp;
194 1 bFound=0;
195 1 //////////////////////////////////////////////
196 1 //第一次读FAT
197 1 if((FreeFat.SectorNum==DeviceInfo.FatStartSector)&&(FreeFat.OffsetofSector<3))
198 1 {
199 2 if(!RBC_Read(FreeFat.SectorNum,1,CurFatSector))
200 2 return 0x0;
201 2 }
202 1 //////////////////////////////
203 1 temp=FreeFat.SectorNum-DeviceInfo.FatStartSector;
204 1 temp=temp*DeviceInfo.BPB_BytesPerSec;
205 1 temp=temp/2;
206 1 clusterNum=temp+FreeFat.OffsetofSector/2;
207 1
208 1 while(FreeFat.SectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
209 1 {
210 2
211 2 while(FreeFat.OffsetofSector<DeviceInfo.BPB_BytesPerSec)
212 2 {
213 3
214 3 ///////////////////////////////////////////////
215 3 if((CurFatSector[FreeFat.OffsetofSector]==0)&&(CurFatSector[FreeFat.OffsetofSector+1]==0))
216 3 {
217 4 CurFatSector[FreeFat.OffsetofSector]=0xff;
218 4 CurFatSector[FreeFat.OffsetofSector+1]=0xff;
219 4
220 4 FreeFat.OffsetofSector=FreeFat.OffsetofSector+2;
221 4 //return clusterNum;
222 4 bXXGFlags.bits.bFatChanged=1;
223 4 bFound=1;
224 4 break;
225 4 }
226 3 FreeFat.OffsetofSector=FreeFat.OffsetofSector+2;
227 3 clusterNum++;
228 3 }
229 2 if(bFound==1)
230 2 break;
231 2 //FreeFat.SectorNum=2*clusterNum/DeviceInfo.BPB_BytesPerSec+DeviceInfo.FatStartSector;
232 2 //FreeFat.OldSectorNum=FreeFat.SectorNum;
233 2 //FreeFat.SectorNum++;
234 2 //FreeFat.OffsetofSector=0;
235 2 UpdateFat(FreeFat.SectorNum);
236 2
237 2 FreeFat.SectorNum++;
238 2 FreeFat.OffsetofSector=0;
239 2
240 2 if(!RBC_Read(FreeFat.SectorNum,1,CurFatSector))
241 2 return 0x0;
C51 COMPILER V6.20c FAT 08/21/2003 22:51:05 PAGE 5
242 2
243 2
244 2 //clusterNum+=DeviceInfo.BPB_BytesPerSec;
245 2 //DelayMs(10);
246 2 }
247 1 //////////////////////////////////////////////
248 1 if(bFound==0)
249 1 return 0x00;
250 1
251 1 /////////////////////////////////////////////////////////////////////
252 1 xxgFatSecNum=ThisFatSecNum(currentCluster);
253 1 xxgFatEntOffset=ThisFatEntOffset(currentCluster);
254 1
255 1 if(xxgFatSecNum!=FreeFat.SectorNum)
256 1 {
257 2 RBC_Read(xxgFatSecNum,1,DBUF);
258 2
259 2 //FreeFat.OffsetofSector=FreeFat.OffsetofSector+2;
260 2
261 2 DBUF[xxgFatEntOffset]=clusterNum;
262 2 DBUF[xxgFatEntOffset+1]=clusterNum>>8;
263 2 //DelayMs(5);
264 2 if(!RBC_Write(xxgFatSecNum,1,DBUF))
265 2 return 0x00;
266 2 //DelayMs(10);
267 2 if(!RBC_Write(xxgFatSecNum+DeviceInfo.BPB_FATSz16,1,DBUF))
268 2 return 0x00;
269 2 }
270 1 else
271 1 {
272 2 CurFatSector[xxgFatEntOffset]=clusterNum;
273 2 CurFatSector[xxgFatEntOffset+1]=clusterNum>>8;
274 2
275 2 bXXGFlags.bits.bFatChanged=1;
276 2 }
277 1 return clusterNum;
278 1 }
279
280 void UpdateFat(unsigned long sectorNum)
281 {
282 1
283 1 if(bXXGFlags.bits.bFatChanged==1)
284 1 {
285 2 if(!RBC_Write(sectorNum,1,CurFatSector))
286 2 return ;
287 2 //DelayMs(10);
288 2 if(!RBC_Write(sectorNum+DeviceInfo.BPB_FATSz16,1,CurFatSector))
289 2 return ;
290 2 bXXGFlags.bits.bFatChanged=0;
291 2 }
292 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2026 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 1034 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 55
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILER V6.20c FAT 08/21/2003 22:51:05 PAGE 6
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -