📄 write.lst
字号:
C51 COMPILER V7.50 WRITE 07/13/2005 11:15:16 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE WRITE
OBJECT MODULE PLACED IN WRITE.OBJ
COMPILER INVOKED BY: e:\Keil\C51\BIN\C51.EXE WRITE.C BROWSE DEBUG OBJECTEXTEND
line level source
1 #ifndef _FAT32_DEFINE
2 #include "FAT32.c"
3 #endif
4
5 #define LAST_CLUSTER 0xFFFFFFFF
6 //#define EOF 0xFF
7 #define DISK_FULL 0xFF
8
9 CHAR FAT32WriteFile(BYTE fp,CHAR *WriteBuffer,WORD BytesToWrite);
10 DWORD FreeClus(void);
11 DWORD ReqstNewClus(OldClus);
12 BYTE DEleteFile(CHAR *filename);
13 BYTE CreatFile(CHAR * filename);
14
15 CHAR FAT32WriteFile(BYTE fp,CHAR *WriteBuffer,WORD BytesToWrite)
16 {
17 1 WORD WritedBytes;
18 1 WORD i,j;
19 1 BYTE dir;
20 1 bit FILE_END;
21 1 while(FCB[fp].LastCluster<LAST_CLUSTER) //find the last cluster
22 1 {
23 2 FCB[fp].LastCluster=FAT32NextCluster(FCB[fp].LastCluster);
24 2 }
25 1 while (FILE_END !=1) //find the end of the file
26 1 {
27 2 FAT32ReadCluster(&FCB[fp].LastCluster);
28 2 for(j=0;j<512;j++)
29 2 {
30 3 if(DiskBuffer[j]==EOF)
31 3 {
32 4 FCB[fp].ClusSecCnt = i;
33 4 FCB[fp].ByteCnt = j;
34 4 FILE_END = 1;
35 4 break;
36 4 }
37 3 }
38 2 }
39 1 do
40 1 {
41 2 if(FCB[fp].ByteCnt<=512)
42 2 {
43 3 DiskBuffer[FCB[fp].ByteCnt] = WriteBuffer[WritedBytes]; //ready
44 3 if((WritedBytes++)>=BytesToWrite) return 0;
45 3 }
46 2 else
47 2 {
48 3 WriteDiskSector(FCB[fp].LastCluster*FAT32.SecPerClus); //write a sector
49 3 FCB[fp].ByteCnt=0;
50 3 FCB[fp].ClusSecCnt++;
51 3 if(FCB[fp].ClusSecCnt>=FAT32.SecPerClus)
52 3 {
53 4 FCB[fp].LastCluster=ReqstNewClus(FCB[fp].LastCluster);
54 4 if(FCB[fp].LastCluster!=0) continue;
55 4 }
C51 COMPILER V7.50 WRITE 07/13/2005 11:15:16 PAGE 2
56 3 }
57 2 }while(1);
58 1 dir = FAT32FindDIREntry(FCB[fp].FileName);
59 1 sDIR[dir].FileSize+= BytesToWrite;
60 1 FCB[fp].Size += BytesToWrite;
61 1
62 1 WriteDiskSector(ClusterToSector( FAT32.CurrentDirectory)+FAT32.ClusSecCnt);
63 1 }
64
65 DWORD FreeClus(void)
66 {
67 1 BYTE i;
68 1 for(FAT.Sector=0;FAT.Sector<FAT32.FATSz;FAT.Sector++)
69 1 {
70 2 ReadDiskSector(FAT32.FATSec+FAT.Sector);
71 2 for(i=0;i<128;i++)
72 2 {
73 3 if(((DWORD *)&DiskBuffer)[i]==0x0000)
74 3 {
75 4 return (i+128*FAT.Sector);
76 4 }
77 3 }
78 2 }
79 1 return DISK_FULL;
80 1 }
81
82 DWORD ReqstNewClus(OldClus)
83 {
84 1 DWORD NewClus;
85 1 NewClus = FreeClus();
86 1 if(NewClus == DISK_FULL) return DISK_FULL;
87 1 ((DWORD *)DiskBuffer)[NewClus%128] = LAST_CLUSTER;
88 1 WriteDiskSector(FAT32.FATSec+FAT.Sector); //write the first FAT
89 1 WriteDiskSector(FAT32.FATSec+FAT.Sector+FAT32.FATSz); //write the second FAT
90 1 if(OldClus)
91 1 {
92 2 FAT.Sector = OldClus/128;
93 2 ReadDiskSector(FAT32.FATSec+FAT.Sector);
94 2 ((DWORD *)DiskBuffer)[OldClus%128] = NewClus;
95 2 WriteDiskSector(FAT32.FATSec+FAT.Sector);
96 2 WriteDiskSector(FAT32.FATSec+FAT.Sector+FAT32.FATSz);
97 2 }
98 1 return NewClus;
99 1 }
100
101 BYTE DEleteFile(CHAR *filename)
102 {
103 1 BYTE fp;
104 1 BYTE dir;
105 1 DWORD chain;
106 1 fp=FAT32OpenFile(filename);
107 1 if(fp==FAT32_MAX_FCB) return (0x00);
108 1 /*delete the FAT*/
109 1 while(FCB[fp].LastCluster!=LAST_CLUSTER)
110 1 {
111 2 ReadDiskSector(FAT32.FATSec+FCB[fp].LastCluster/128);
112 2 ((DWORD *)DiskBuffer)[FCB[fp].LastCluster] = 0x0000;
113 2 WriteDiskSector(FAT32.FATSec+FCB[fp].LastCluster%128);
114 2 WriteDiskSector(FAT32.FATSec+FCB[fp].LastCluster%128+FAT32.FATSz);
115 2 FCB[fp].LastCluster = FAT32NextCluster(FCB[fp].LastCluster);
116 2 }
117 1 FAT32CloseFile(fp);
C51 COMPILER V7.50 WRITE 07/13/2005 11:15:16 PAGE 3
118 1 /*delete the directory*/
119 1 dir = FAT32FindDIREntry(filename);
120 1 sDIR[dir].Name[0]=0x00;
121 1 chain=FAT32.CurrentDirectory;
122 1 WriteDiskSector(ClusterToSector(chain)+FAT32.ClusSecCnt);
123 1 }
124
125 BYTE CreatFile(CHAR * filename)
126 {
127 1 DWORD FstClus;
128 1 DWORD chain;
129 1 BYTE i,j;
130 1 FstClus = ReqstNewClus(0);
131 1 chain=FAT32.CurrentDirectory;
132 1 while(chain!=0x0fffffff)
133 1 {
134 2 FAT32ReadCluster(&chain);
135 2 for (i=0;i<16;i++)
136 2 {
137 3 if (sDIR[i].Name[0]==0xe5||sDIR[i].Name[0]==0x00)
138 3 {
139 4 for(j=0;j<11;j++)
140 4 sDIR[i].Name[j] = filename[j];
141 4 sDIR[i].Attr =
142 4 sDIR[i].FstClusHI = ((WORD *)&FstClus)[1];
143 4 sDIR[i].FstClusLO = ((WORD *)&FstClus)[0];
144 4 sDIR[i].FileSize = 0;
145 4 return 0;
146 4 }
147 3 }
148 2 }
149 1 return DISK_FULL;
150 1 }
151
152
153
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1946 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 2 41
IDATA SIZE = ---- ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -