📄 fat.s
字号:
sts _FileIndex+2+1,R21
sts _FileIndex+2,R20
sts _FileIndex+2+2+1,R23
sts _FileIndex+2+2,R22
xjmp L60
L57:
.dbline 133
lds R16,_FileIndex+6
lds R17,_FileIndex+6+1
xcall _FAT_ReadFAT
sts _FileIndex+6+1,R17
sts _FileIndex+6,R16
L58:
.dbline 132
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
lds R4,_FileIndex+2+2
lds R5,_FileIndex+2+2+1
lds R2,_FileIndex+2
lds R3,_FileIndex+2+1
add R2,R20
adc R3,R21
adc R4,R22
adc R5,R23
sts _FileIndex+2+1,R3
sts _FileIndex+2,R2
sts _FileIndex+2+2+1,R5
sts _FileIndex+2+2,R4
L60:
.dbline 132
movw R2,R12
clr R4
clr R5
lds R8,_FileIndex+2+2
lds R9,_FileIndex+2+2+1
lds R6,_FileIndex+2
lds R7,_FileIndex+2+1
cp R6,R2
cpc R7,R3
cpc R8,R4
cpc R9,R5
brlo L57
.dbline 136
; FileIndex.ClusID = FAT_ReadFAT(FileIndex.ClusID);
;
;
; FileIndex.i = (Start % BytePerClus) / 512; //开始位置所在扇区簇内偏移
movw R2,R10
clr R4
clr R5
movw R30,R28
ldd R6,z+40
ldd R7,z+41
ldd R8,z+42
ldd R9,z+43
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R6
movw R18,R8
xcall mod32u
ldi R24,9
ldi R25,0
st -y,R24
xcall lsr32
sts _FileIndex+2+1,R17
sts _FileIndex+2,R16
sts _FileIndex+2+2+1,R19
sts _FileIndex+2+2,R18
.dbline 137
; FileIndex.m = (Start % BytePerClus) % 512; //开始位置扇区内偏移
movw R2,R10
clr R4
clr R5
movw R30,R28
ldd R6,z+40
ldd R7,z+41
ldd R8,z+42
ldd R9,z+43
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R6
movw R18,R8
xcall mod32u
ldi R20,255
ldi R21,1
ldi R22,0
ldi R23,0
movw R2,R16
movw R4,R18
and R2,R20
and R3,R21
and R4,R22
and R5,R23
sts _FileIndex+1,R3
sts _FileIndex,R2
.dbline 139
;
; FileIndex.LBA = ClusConvLBA(FileIndex.ClusID) + FileIndex.i; //开始位置所在的扇区号
lds R16,_FileIndex+6
lds R17,_FileIndex+6+1
xcall _ClusConvLBA
lds R4,_FileIndex+2+2
lds R5,_FileIndex+2+2+1
lds R2,_FileIndex+2
lds R3,_FileIndex+2+1
movw R6,R16
movw R8,R18
add R6,R2
adc R7,R3
adc R8,R4
adc R9,R5
sts _FileIndex+8+1,R7
sts _FileIndex+8,R6
sts _FileIndex+8+2+1,R9
sts _FileIndex+8+2,R8
.dbline 140
; FAT_ReadBlock(FileIndex.LBA); //预读取一个扇区的内容
movw R16,R6
movw R18,R8
xcall _FAT_ReadBlock
.dbline 141
; return (FileDir.Size);
movw R30,R28
ldd R16,z+28
ldd R17,z+29
ldd R18,z+30
ldd R19,z+31
.dbline -2
L52:
adiw R28,32
xcall pop_gset4
adiw R28,2
.dbline 0 ; func end
ret
.dbsym l FileDir 0 S[.4]
.dbsym r BytePerClus 10 i
.dbsym r ClusNum 12 i
.dbsym l Start 40 l
.dbsym r Name 12 pc
.dbend
.dbfunc e FAT_FileRead _FAT_FileRead fi
; data -> R10,R11
; Data -> y+14
; Length -> y+10
.even
_FAT_FileRead::
xcall push_arg4
xcall push_gset3
sbiw R28,4
.dbline -1
.dbline 147
; }
; //********************************************************************************************
; //读取文件的数据
; //********************************************************************************************
; uint16 FAT_FileRead(uint32 Length, void* Data)
; {
.dbline 148
; uint8 *data = Data;
ldd R10,y+14
ldd R11,y+15
.dbline 149
; goto FAT_FileRead_Start;
xjmp L91
L74:
.dbline 152
;
; while(1)
; {
.dbline 153
; FileIndex.ClusID = FAT_ReadFAT(FileIndex.ClusID); //下一簇簇号
lds R16,_FileIndex+6
lds R17,_FileIndex+6+1
xcall _FAT_ReadFAT
sts _FileIndex+6+1,R17
sts _FileIndex+6,R16
.dbline 154
; if (FileIndex.ClusID==0xFFFF)
cpi R16,255
ldi R30,255
cpc R17,R30
brne L79
.dbline 155
; {
.dbline 156
; return FALSE; //文件结束
clr R16
clr R17
xjmp L72
L79:
.dbline 158
; }
; FileIndex.LBA = ClusConvLBA(FileIndex.ClusID); //簇的开始扇区号
lds R16,_FileIndex+6
lds R17,_FileIndex+6+1
xcall _ClusConvLBA
sts _FileIndex+8+1,R17
sts _FileIndex+8,R16
sts _FileIndex+8+2+1,R19
sts _FileIndex+8+2,R18
.dbline 159
; FileIndex.i = 0; //簇内扇区偏移
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
sts _FileIndex+2+1,R21
sts _FileIndex+2,R20
sts _FileIndex+2+2+1,R23
sts _FileIndex+2+2,R22
xjmp L86
L85:
.dbline 161
; while(FileIndex.i < Info.BPB_SecPerClus)
; {
.dbline 162
; FAT_ReadBlock(FileIndex.LBA); //读当前簇
lds R18,_FileIndex+8+2
lds R19,_FileIndex+8+2+1
lds R16,_FileIndex+8
lds R17,_FileIndex+8+1
xcall _FAT_ReadBlock
.dbline 163
; FileIndex.m = 0; //当前扇区内的数据偏移
clr R2
clr R3
sts _FileIndex+1,R3
sts _FileIndex,R2
xjmp L91
L90:
.dbline 166
; FAT_FileRead_Start:
; while(FileIndex.m < 512)
; {
.dbline 167
; *data++ = BUFFER[FileIndex.m];
ldi R24,<_BUFFER
ldi R25,>_BUFFER
lds R30,_FileIndex
lds R31,_FileIndex+1
add R30,R24
adc R31,R25
ldd R2,z+0
movw R30,R10
st Z+,R2
movw R10,R30
.dbline 168
; FileIndex.m++;
lds R24,_FileIndex
lds R25,_FileIndex+1
adiw R24,1
sts _FileIndex+1,R25
sts _FileIndex,R24
.dbline 170
; //如果读取完成就退出
; if(--Length == 0)
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
movw R30,R28
ldd R2,z+10
ldd R3,z+11
ldd R4,z+12
ldd R5,z+13
sub R2,R20
sbc R3,R21
sbc R4,R22
sbc R5,R23
movw R30,R28
std z+0,R2
std z+1,R3
std z+2,R4
std z+3,R5
movw R30,R28
ldd R2,z+0
ldd R3,z+1
ldd R4,z+2
ldd R5,z+3
movw R30,R28
std z+10,R2
std z+11,R3
std z+12,R4
std z+13,R5
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
movw R30,R28
ldd R2,z+0
ldd R3,z+1
ldd R4,z+2
ldd R5,z+3
cp R2,R20
cpc R3,R21
cpc R4,R22
cpc R5,R23
brne L93
.dbline 171
; {
.dbline 172
; return (FileIndex.m);
lds R16,_FileIndex
lds R17,_FileIndex+1
xjmp L72
L93:
.dbline 174
L91:
.dbline 165
lds R24,_FileIndex
lds R25,_FileIndex+1
cpi R24,0
ldi R30,2
cpc R25,R30
brsh X2
xjmp L90
X2:
.dbline 175
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
lds R4,_FileIndex+8+2
lds R5,_FileIndex+8+2+1
lds R2,_FileIndex+8
lds R3,_FileIndex+8+1
add R2,R20
adc R3,R21
adc R4,R22
adc R5,R23
sts _FileIndex+8+1,R3
sts _FileIndex+8,R2
sts _FileIndex+8+2+1,R5
sts _FileIndex+8+2,R4
.dbline 176
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
lds R4,_FileIndex+2+2
lds R5,_FileIndex+2+2+1
lds R2,_FileIndex+2
lds R3,_FileIndex+2+1
add R2,R20
adc R3,R21
adc R4,R22
adc R5,R23
sts _FileIndex+2+1,R3
sts _FileIndex+2,R2
sts _FileIndex+2+2+1,R5
sts _FileIndex+2+2,R4
.dbline 177
L86:
.dbline 160
lds R2,_Info
clr R3
clr R4
clr R5
lds R8,_FileIndex+2+2
lds R9,_FileIndex+2+2+1
lds R6,_FileIndex+2
lds R7,_FileIndex+2+1
cp R6,R2
cpc R7,R3
cpc R8,R4
cpc R9,R5
brsh X3
xjmp L85
X3:
.dbline 178
L75:
.dbline 151
xjmp L74
X1:
.dbline 179
; }
; }
; FileIndex.LBA++; //下一扇区号
; FileIndex.i++;
; }
; }
; return FALSE;
clr R16
clr R17
.dbline -2
L72:
adiw R28,4
xcall pop_gset3
adiw R28,4
.dbline 0 ; func end
ret
.dbsym r data 10 pc
.dbsym l Data 14 pV
.dbsym l Length 10 l
.dbend
.dbfunc e FAT_FileWrite _FAT_FileWrite fV
; data -> R10,R11
; Data -> y+14
; Length -> y+10
.even
_FAT_FileWrite::
xcall push_arg4
xcall push_gset3
sbiw R28,4
.dbline -1
.dbline 184
; }
; //********************************************************************************************
; //写文件的数据
; //********************************************************************************************
; void FAT_FileWrite(uint32 Length, void* Data) {
.dbline 185
; uint8 *data = Data;
ldd R10,y+14
ldd R11,y+15
.dbline 187
;
; goto FAT_FileWrite_Start;
xjmp L113
L99:
.dbline 189
;
; while(1) {
.dbline 190
; FileIndex.ClusID = FAT_ReadFAT(FileIndex.ClusID); //下一簇簇号
lds R16,_FileIndex+6
lds R17,_FileIndex+6+1
xcall _FAT_ReadFAT
sts _FileIndex+6+1,R17
sts _FileIndex+6,R16
.dbline 191
; FileIndex.LBA = ClusConvLBA(FileIndex.ClusID);
xcall _ClusConvLBA
sts _FileIndex+8+1,R17
sts _FileIndex+8,R16
sts _FileIndex+8+2+1,R19
sts _FileIndex+8+2,R18
.dbline 192
; FileIndex.i = 0;
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
sts _FileIndex+2+1,R21
sts _FileIndex+2,R20
sts _FileIndex+2+2+1,R23
sts _FileIndex+2+2,R22
xjmp L108
L107:
.dbline 193
; while(FileIndex.i < Info.BPB_SecPerClus) {
.dbline 194
; FAT_ReadBlock(FileIndex.LBA);
lds R18,_FileIndex+8+2
lds R19,_FileIndex+8+2+1
lds R16,_FileIndex+8
lds R17,_FileIndex+8+1
xcall _FAT_ReadBlock
.dbline 195
; FileIndex.m = 0;
clr R2
clr R3
sts _FileIndex+1,R3
sts _FileIndex,R2
xjmp L113
L112:
.dbline 197
; FAT_FileWrite_Start:
; while(FileIndex.m < 512) {
.dbline 198
; BUFFER[FileIndex.m] = *data++;
ldi R24,<_BUFFER
ldi R25,>_BUFFER
lds R30,_FileIndex
lds R31,_FileIndex+1
add R30,R24
adc R31,R25
movw R26,R10
ld R2,X+
movw R10,R26
std z+0,R2
.dbline 199
; FileIndex.m++;
lds R24,_FileIndex
lds R25,_FileIndex+1
adiw R24,1
sts _FileIndex+1,R25
sts _FileIndex,R24
.dbline 201
; //如果读取完成就退出
; if(--Length == 0) {
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
movw R30,R28
ldd R2,z+10
ldd R3,z+11
ldd R4,z+12
ldd R5,z+13
sub R2,R20
sbc R3,R21
sbc R4,R22
sbc R5,R23
movw R30,R28
std z+0,R2
std z+1,R3
std z+2,R4
std z+3,R5
movw R30,R28
ldd R2,z+0
ldd R3,z+1
ldd R4,z+2
ldd R5,z+3
movw R30,R28
std z+10,R2
std z+11,R3
std z+12,R4
std z+13,R5
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
movw R30,R28
ldd R2,z+0
ldd R3,z+1
ldd R4,z+2
ldd R5,z+3
cp R2,R20
cpc R3,R21
cpc R4,R22
cpc R5,R23
brne L115
.dbline 201
.dbline 202
; FAT_WriteBlock(FileIndex.LBA); //回写扇区
lds R18,_FileIndex+8+2
lds R19,_FileIndex+8+2+1
lds R16,_FileIndex+8
lds R17,_FileIndex+8+1
xcall _FAT_WriteBlock
.dbline 203
; return;
xjmp L97
L115:
.dbline 205
L113:
.dbline 197
lds R24,_FileIndex
lds R25,_FileIndex+1
cpi R24,0
ldi R30,2
cpc R25,R30
brsh X5
xjmp L112
X5:
.dbline 206
lds R4,_FileIndex+8+2
lds R5,_FileIndex+8+2+1
lds R2,_FileIndex+8
lds R3,_FileIndex+8+1
movw R30,R28
std z+0,R2
std z+1,R3
std z+2,R4
std z+3,R5
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
movw R30,R28
ldd R2,z+0
ldd R3,z+1
ldd R4,z+2
ldd R5,z+3
add R2,R20
adc R3,R21
adc R4,R22
adc R5,R23
sts _FileIndex+8+1,R3
sts _FileIndex+8,R2
sts _FileIndex+8+2+1,R5
sts _FileIndex+8+2,R4
movw R30,R28
ldd R16,z+0
ldd R17,z+1
ldd R18,z+2
ldd R19,z+3
xcall _FAT_WriteBlock
.dbline 207
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
lds R4,_FileIndex+2+2
lds R5,_FileIndex+2+2+1
lds R2,_FileIndex+2
lds R3,_FileIndex+2+1
add R2,R20
adc R3,R21
adc R4,R22
adc R5,R23
sts _FileIndex+2+1,R3
sts _FileIndex+2,R2
sts _FileIndex+2+2+1,R5
sts _FileIndex+2+2,R4
.dbline 208
L108:
.dbline 193
lds R2,_Info
clr R3
clr R4
clr R5
lds R8,_FileIndex+2+2
lds R9,_FileIndex+2+2+1
lds R6,_FileIndex+2
lds R7,_FileIndex+2+1
cp R6,R2
cpc R7,R3
cpc R8,R4
cpc R9,R5
brsh X6
xjmp L107
X6:
.dbline 209
L100:
.dbline 189
xjmp L99
X4:
.dbline -2
L97:
adiw R28,4
xcall pop_gset3
adiw R28,4
.dbline 0 ; func end
ret
.dbsym r data 10 pc
.dbsym l Data 14 pV
.dbsym l Length 10 l
.dbend
.area bss(ram, con, rel)
.dbfile D:\桌面\mp3\FAT\fat.c
_FileIndex:
.blkb 12
.dbstruct 0 12 .6
.dbfield 0 m i
.dbfield 2 i l
.dbfield 6 ClusID i
.dbfield 8 LBA l
.dbend
.dbsym s FileIndex _FileIndex S[.6]
_Info:
.blkb 24
.dbstruct 0 24 .5
.dbfield 0 BPB_SecPerClus c
.dbfield 1 BPB_RsvdSecCnt i
.dbfield 3 BPB_NumFATs c
.dbfield 4 BPB_RootEntCnt i
.dbfield 6 BPB_TotSec16 i
.dbfield 8 BPB_FATSz16 i
.dbfield 10 BPB_HiddSec l
.dbfield 14 DirStartSec l
.dbfield 18 DataStartSec l
.dbfield 22 DirSecCount i
.dbend
.dbsym s Info _Info S[.5]
_BUFFER:
.blkb 512
.dbsym s BUFFER _BUFFER A[512:512]c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -