📄 fat16.s
字号:
.module fat16.c
.area data(ram, con, rel)
_vol:
.blkb 2
.area idata
.word 2570
.area data(ram, con, rel)
.dbfile D:\ICCFIL~1\五键MP3ICC\fat16.c
.dbsym s vol _vol i
_fileindex:
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile D:\ICCFIL~1\五键MP3ICC\fat16.c
.dbsym s fileindex _fileindex i
_flag:
.blkb 1
.area idata
.byte 1
.area data(ram, con, rel)
.dbfile D:\ICCFIL~1\五键MP3ICC\fat16.c
.dbsym s flag _flag c
_keyflag:
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile D:\ICCFIL~1\五键MP3ICC\fat16.c
.dbsym s keyflag _keyflag c
_longfileflag:
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile D:\ICCFIL~1\五键MP3ICC\fat16.c
.dbsym s longfileflag _longfileflag c
_volume:
.blkb 2
.area idata
.byte 53,48
.area data(ram, con, rel)
.dbfile D:\ICCFIL~1\五键MP3ICC\fat16.c
.dbsym s volume _volume A[2:2]c
_timecount:
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile D:\ICCFIL~1\五键MP3ICC\fat16.c
.dbsym s timecount _timecount c
_zero::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile D:\ICCFIL~1\五键MP3ICC\fat16.c
.blkb 31
.area idata
.word 0,0,0,0,0
.word 0,0,0,0,0
.word 0,0,0,0,0
.byte 0
.area data(ram, con, rel)
.dbfile D:\ICCFIL~1\五键MP3ICC\fat16.c
.dbsym e zero _zero A[32:32]c
.area text(rom, con, rel)
.dbfile D:\ICCFIL~1\五键MP3ICC\fat16.c
.dbfunc e FAT_Init _FAT_Init fV
.even
_FAT_Init::
.dbline -1
.dbline 48
; #include<iom16v.h>
; #include<main.h>
; #include<fat16.h>
; #include<12232.h>
; #include<sd.h>
; #include<vs1003.h>
; extern uint8 BUFFER[512];
; extern zikustart;
; static uint16 unicodestart;
; static uint16 vol=0x0a0a;
; static uint16 fileindex=0;
; static DIR fileid;
; static uint8 flag=1;
; static uint8 keyflag=0;
; static uint8 longfileflag=0;
; static uint8 volume[2]="50";
; volatile static uint8 timecount=0;
;
; unsigned char zero[32]={0};
; typedef struct
; {
; uint16 m;
; uint16 ClusID;
; uint32 i;
; uint32 LBA;
; } FATFileIndex;
; static FATFileIndex FileIndex; //当前打开的文件
; uint8 BPB_SecPerClus;
; static uint16 BPB_RsvdSecCnt;
; static uint8 BPB_NumFATs;
; static uint16 BPB_RootEntCnt;
; static uint16 BPB_TotSec16;
; static uint16 BPB_FATSz16;
; static uint32 BPB_HiddSec;
;
; void ReadBlock (uint32 LBA);
; void WriteBlock (uint32 LBA);
; static uint8 IsEqual (void* A, void* B, uint8 Size);
; static uint8 Ismp3(void* A);
; void ReadBPB (void);
; static uint32 ClusConvLBA (uint16 ClusID);
; uint16 ReadFAT (uint16 Index);
; static uint16 GetNextmp3(void);
; static uint8 GetFileID(uint8 Name[11],DIR* ID);
; void show(uint8 filename[2],uint8 location,uint8 loca);
;
; void FAT_Init(void)
; {
.dbline 49
; ReadBPB();
rcall _ReadBPB
.dbline -2
L5:
.dbline 0 ; func end
ret
.dbend
.dbfunc e SD_SPI_HIGH _SD_SPI_HIGH fV
.even
_SD_SPI_HIGH::
.dbline -1
.dbline 53
; }
;
; void SD_SPI_HIGH(void)
; {
.dbline 54
; SPCR=(1<<SPE)|(1<<MSTR);
ldi R24,80
out 0xd,R24
.dbline 55
; SPSR|= (1<<SPI2X);
sbi 0xe,0
.dbline -2
L6:
.dbline 0 ; func end
ret
.dbend
.dbfunc e ReadBlock _ReadBlock fV
; LBA -> y+2
.even
_ReadBlock::
rcall push_arg4
sbiw R28,2
.dbline -1
.dbline 61
; }
; //********************************************************************************************
; //读一个扇区
; void ReadBlock(uint32 LBA)
; //********************************************************************************************
; {
.dbline 62
; SD_read_sector(LBA, BUFFER);
ldi R24,<_BUFFER
ldi R25,>_BUFFER
std y+1,R25
std y+0,R24
movw R30,R28
ldd R16,z+2
ldd R17,z+3
ldd R18,z+4
ldd R19,z+5
rcall _SD_read_sector
.dbline -2
L7:
adiw R28,6
.dbline 0 ; func end
ret
.dbsym l LBA 2 l
.dbend
.dbfunc e WriteBlock _WriteBlock fV
; LBA -> y+2
.even
_WriteBlock::
rcall push_arg4
sbiw R28,2
.dbline -1
.dbline 68
; }
;
; //********************************************************************************************
; void WriteBlock(uint32 LBA)
; //********************************************************************************************
; {
.dbline 69
; SD_write_sector(LBA , BUFFER);
ldi R24,<_BUFFER
ldi R25,>_BUFFER
std y+1,R25
std y+0,R24
movw R30,R28
ldd R16,z+2
ldd R17,z+3
ldd R18,z+4
ldd R19,z+5
rcall _SD_write_sector
.dbline -2
L8:
adiw R28,6
.dbline 0 ; func end
ret
.dbsym l LBA 2 l
.dbend
.dbfunc s IsEqual _IsEqual fc
; b -> R20,R21
; a -> R22,R23
; i -> R10
; Size -> R12
; B -> R18,R19
; A -> R16,R17
.even
_IsEqual:
rcall push_gset4
ldd R12,y+8
.dbline -1
.dbline 75
; }
;
; //********************************************************************************************
; static uint8 IsEqual(void* A, void* B, uint8 Size)
; //********************************************************************************************
; {
.dbline 76
; uint8 i, *a = A, *b = B;
movw R22,R16
.dbline 76
movw R20,R18
.dbline 77
; for(i = 0; i < Size; i++)
clr R10
rjmp L13
L10:
.dbline 78
; {
.dbline 79
; if((a[i] != b[i]))
mov R30,R10
clr R31
add R30,R20
adc R31,R21
ldd R2,z+0
mov R30,R10
clr R31
add R30,R22
adc R31,R23
ldd R3,z+0
cp R3,R2
breq L14
.dbline 80
; return 0;
clr R16
rjmp L9
L14:
.dbline 81
L11:
.dbline 77
inc R10
L13:
.dbline 77
cp R10,R12
brlo L10
.dbline 82
; }
; return 1;
ldi R16,1
.dbline -2
L9:
rcall pop_gset4
.dbline 0 ; func end
ret
.dbsym r b 20 pc
.dbsym r a 22 pc
.dbsym r i 10 c
.dbsym r Size 12 c
.dbsym r B 18 pV
.dbsym r A 16 pV
.dbend
.area lit(rom, con, rel)
L17:
.byte 'M,'P,51
L18:
.byte 'W,'M,'A
.area text(rom, con, rel)
.dbfile D:\ICCFIL~1\五键MP3ICC\fat16.c
.dbfunc s Ismp3 _Ismp3 fc
; c -> y+3
; b -> y+0
; a -> R20,R21
; i -> R22
; A -> R22,R23
.even
_Ismp3:
rcall push_gset2
movw R22,R16
sbiw R28,6
.dbline -1
.dbline 85
; }
; static uint8 Ismp3(void* A)
; {
.dbline 86
; uint8 i,*a=A;
movw R20,R22
.dbline 87
; uint8 b[3]="MP3";
ldi R24,<L17
ldi R25,>L17
movw R30,R28
ldi R16,3
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
rcall asgncblk
.dbline 88
; uint8 c[3]="WMA";
ldi R24,<L18
ldi R25,>L18
movw R30,R28
adiw R30,3
ldi R16,3
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
rcall asgncblk
.dbline 89
movw R30,R20
ldd R2,z+0
clr R3
mov R24,R2
cpi R24,229
breq L21
tst R24
brne L19
L21:
.dbline 89
; if((a[0]==0xe5)||(a[0]==0)) return 0;
clr R16
rjmp L16
L19:
.dbline 90
; for(i=0;i<3;i++)
clr R22
rjmp L25
L22:
.dbline 91
; {
.dbline 92
; if((a[i+8]!=b[i])&&(a[i+8]!=c[i]))
mov R30,R22
clr R31
add R30,R20
adc R31,R21
ldd R2,z+8
clr R3
movw R24,R28
mov R30,R22
clr R31
add R30,R24
adc R31,R25
ldd R4,z+0
cp R2,R4
breq L26
movw R24,R28
adiw R24,3
mov R30,R22
clr R31
add R30,R24
adc R31,R25
ldd R4,z+0
cp R2,R4
breq L26
.dbline 93
; return 0;
clr R16
rjmp L16
L26:
.dbline 94
L23:
.dbline 90
inc R22
L25:
.dbline 90
cpi R22,3
brlo L22
.dbline 95
; }
; return 1;
ldi R16,1
.dbline -2
L16:
adiw R28,6
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym l c 3 A[3:3]c
.dbsym l b 0 A[3:3]c
.dbsym r a 20 pc
.dbsym r i 22 c
.dbsym r A 22 pV
.dbend
.dbfunc e ReadBPB _ReadBPB fV
.dbstruct 0 512 .1
.dbfield 0 BS_jmpBoot A[3:3]c
.dbfield 3 BS_OEMName A[8:8]c
.dbfield 11 BPB_BytesPerSec i
.dbfield 13 BPB_SecPerClus c
.dbfield 14 BPB_RsvdSecCnt i
.dbfield 16 BPB_NumFATs c
.dbfield 17 BPB_RootEntCnt i
.dbfield 19 BPB_TotSec16 i
.dbfield 21 BPB_Media c
.dbfield 22 BPB_FATSz16 i
.dbfield 24 BPB_SecPerTrk i
.dbfield 26 BPB_NumHeads i
.dbfield 28 BPB_HiddSec l
.dbfield 32 BPB_TotSec32 l
.dbfield 36 BS_DrvNum c
.dbfield 37 BS_Reservedl c
.dbfield 38 BS_BootSig c
.dbfield 39 BS_VolID l
.dbfield 43 BS_VolLab A[11:11]c
.dbfield 54 BS_FilSysType A[8:8]c
.dbfield 62 ExecutableCode A[448:448]c
.dbfield 510 ExecutableMarker A[2:2]c
.dbend
; BPB -> R10,R11
.even
_ReadBPB::
rcall push_gset3
.dbline -1
.dbline 102
;
; }
; //********************************************************************************************
; //读取BPB数据结构
; void ReadBPB(void)
; //********************************************************************************************
; {
.dbline 103
; FAT_BPB* BPB = (FAT_BPB*)BUFFER;
ldi R24,<_BUFFER
ldi R25,>_BUFFER
movw R10,R24
.dbline 104
; ReadBlock(0);
ldi R16,0
ldi R17,0
ldi R18,0
ldi R19,0
rcall _ReadBlock
.dbline 107
;
; //缓存相关参数
; BPB_SecPerClus = BPB->BPB_SecPerClus;
movw R30,R10
ldd R2,z+13
sts _BPB_SecPerClus,R2
.dbline 108
; BPB_RsvdSecCnt = BPB->BPB_RsvdSecCnt;
movw R30,R10
ldd R2,z+14
ldd R3,z+15
sts _BPB_RsvdSecCnt+1,R3
sts _BPB_RsvdSecCnt,R2
.dbline 109
; BPB_NumFATs = BPB->BPB_NumFATs;
movw R30,R10
ldd R2,z+16
sts _BPB_NumFATs,R2
.dbline 110
; BPB_RootEntCnt = BPB->BPB_RootEntCnt;
movw R30,R10
ldd R2,z+17
ldd R3,z+18
sts _BPB_RootEntCnt+1,R3
sts _BPB_RootEntCnt,R2
.dbline 111
; BPB_TotSec16 = BPB->BPB_TotSec16;
movw R30,R10
ldd R2,z+19
ldd R3,z+20
sts _BPB_TotSec16+1,R3
sts _BPB_TotSec16,R2
.dbline 112
; BPB_FATSz16 = BPB->BPB_FATSz16;
movw R30,R10
ldd R2,z+22
ldd R3,z+23
sts _BPB_FATSz16+1,R3
sts _BPB_FATSz16,R2
.dbline 113
; BPB_HiddSec = BPB->BPB_HiddSec;
movw R30,R10
ldd R2,z+28
ldd R3,z+29
ldd R4,z+30
ldd R5,z+31
sts _BPB_HiddSec+1,R3
sts _BPB_HiddSec,R2
sts _BPB_HiddSec+2+1,R5
sts _BPB_HiddSec+2,R4
.dbline -2
L28:
rcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r BPB 10 pS[.1]
.dbend
.dbfunc s DirStartSec _DirStartSec fl
.even
_DirStartSec:
.dbline -1
.dbline 121
;
; }
;
; //********************************************************************************************
; //获取根目录开始扇区号
; static uint32 DirStartSec(void)
; //********************************************************************************************
; {
.dbline 122
; return BPB_RsvdSecCnt + BPB_NumFATs * BPB_FATSz16;
lds R18,_BPB_FATSz16
lds R19,_BPB_FATSz16+1
lds R16,_BPB_NumFATs
clr R17
rcall empy16s
lds R2,_BPB_RsvdSecCnt
lds R3,_BPB_RsvdSecCnt+1
add R2,R16
adc R3,R17
clr R4
clr R5
movw R16,R2
movw R18,R4
.dbline -2
L29:
.dbline 0 ; func end
ret
.dbend
.dbfunc s DataStartSec _DataStartSec fl
.even
_DataStartSec:
.dbline -1
.dbline 129
; }
;
; //********************************************************************************************
; //获取数据区开始扇区号
; static uint32 DataStartSec(void)
; //********************************************************************************************
; {
.dbline 130
; return DirStartSec() +( BPB_RootEntCnt >>4);
rcall _DirStartSec
lds R2,_BPB_RootEntCnt
lds R3,_BPB_RootEntCnt+1
lsr R3
ror R2
lsr R3
ror R2
lsr R3
ror R2
lsr R3
ror R2
clr R4
clr R5
add R16,R2
adc R17,R3
adc R18,R4
adc R19,R5
.dbline -2
L30:
.dbline 0 ; func end
ret
.dbend
.dbfunc s GetDirSecCount _GetDirSecCount fi
.even
_GetDirSecCount:
.dbline -1
.dbline 137
; }
;
; //********************************************************************************************
; //目录项占用的扇区数
; static uint16 GetDirSecCount(void)
; //********************************************************************************************
; {
.dbline 138
; return (BPB_RootEntCnt >>4);
lds R16,_BPB_RootEntCnt
lds R17,_BPB_RootEntCnt+1
lsr R17
ror R16
lsr R17
ror R16
lsr R17
ror R16
lsr R17
ror R16
.dbline -2
L31:
.dbline 0 ; func end
ret
.dbend
.dbfunc e ClusConvLBA _ClusConvLBA fl
; ClusID -> R10,R11
.even
_ClusConvLBA::
rcall push_gset3
movw R10,R16
.dbline -1
.dbline 145
; }
;
; //********************************************************************************************
; //获取一个簇的开始扇区
; uint32 ClusConvLBA(uint16 ClusID)
; //********************************************************************************************
; {
.dbline 146
; return DataStartSec() + ((uint32)BPB_SecPerClus) * (ClusID - 2);
rcall _DataStartSec
movw R2,R16
movw R4,R18
movw R24,R10
sbiw R24,2
movw R6,R24
clr R8
clr R9
lds R20,_BPB_SecPerClus
clr R21
clr R22
clr R23
st -y,R9
st -y,R8
st -y,R7
st -y,R6
movw R16,R20
movw R18,R22
rcall empy32u
add R2,R16
adc R3,R17
adc R4,R18
adc R5,R19
movw R16,R2
movw R18,R4
.dbline -2
L32:
rcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r ClusID 10 i
.dbend
.dbfunc e ReadFAT _ReadFAT fi
; RAM -> R20,R21
; Index -> R22,R23
.even
_ReadFAT::
rcall push_gset2
movw R22,R16
.dbline -1
.dbline 153
; }
;
; //********************************************************************************************
; //读取文件分配表的指定项
; static uint16 ReadFAT(uint16 Index)
; //********************************************************************************************
; {
.dbline 154
; uint16 *RAM = (uint16*)BUFFER;
ldi R20,<_BUFFER
ldi R21,>_BUFFER
.dbline 155
; ReadBlock(BPB_RsvdSecCnt + (Index >>8));
movw R2,R22
mov R2,R3
clr R3
lds R4,_BPB_RsvdSecCnt
lds R5,_BPB_RsvdSecCnt+1
add R4,R2
adc R5,R3
movw R2,R4
clr R4
clr R5
movw R16,R2
movw R18,R4
rcall _ReadBlock
.dbline 156
; return RAM[Index % 256];
movw R18,R22
andi R19,0
ldi R16,2
ldi R17,0
rcall empy16s
movw R30,R16
add R30,R20
adc R31,R21
ldd R16,z+0
ldd R17,z+1
.dbline -2
L33:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r RAM 20 pi
.dbsym r Index 22 i
.dbend
.dbfunc s GetNextmp3 _GetNextmp3 fi
; DirSecCut -> R20,R21
; i -> R22
; DirStart -> R10,R11
; m -> R20
.even
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -