📄 hpi.lst
字号:
853 1 else
854 1 {
855 2 NowCluster=DirStartCluster;
856 2 do
857 2 {
858 3 NowSector=FirstSectorofCluster(NowCluster);
859 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
860 3 {
C51 COMPILER V7.07 HPI 04/02/2009 22:39:37 PAGE 15
861 4 if(!RBC_Read(NowSector+sector,1,DBUF))
862 4 return FALSE;
863 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
864 4 {
865 5 if(DBUF[i]==0x00)
866 5 return FALSE;
867 5 j=0;
868 5 while(DBUF[i+j]==*(pBuffer+j))
869 5 {
870 6 j=j+1;
871 6 if(j>10)
872 6 break;
873 6 }
874 5 if(j>10)
875 5 {
876 6 DBUF[i]=0xE5;
877 6 ThisFile.StartCluster=LSwapINT16(DBUF[i+26],DBUF[i+27]);
878 6 for(k=(i-32);k>=0;k=k-32)
879 6 {
880 7 if(DBUF[k+11]==0x0F)
881 7 DBUF[k]=0xE5;
882 7 else
883 7 break;
884 7 }
885 6 DelayMs(15);
886 6 if(!RBC_Write(NowSector+sector,1,DBUF))
887 6 return FALSE;
888 6 //////////////////// 清除FAT中的纪录////////////////////////
889 6 DelayMs(10);
890 6 if(!DeleteClusterLink(ThisFile.StartCluster))
891 6 return FALSE;
892 6 bStop=1;
893 6 break;
894 6 }
895 5 }
896 4 if(bStop==1)break;
897 4 }
898 3 if(bStop==1)break;
899 3 NowCluster=GetNextClusterNum(NowCluster);
900 3 }while(NowCluster<=0xffef);
901 2
902 2 if(NowCluster>0xffef)
903 2 return FALSE;
904 2 }
905 1 return TRUE;
906 1 }
907
908 unsigned char GetCapacity(void)
909 {
910 1 unsigned int sectorNum,i;
911 1 unsigned long FreeSize,Freesectorcnt;
912 1
913 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
914 1 return FALSE;
915 1
916 1 ////////////////////////////////////////////////////////////////////////
917 1 sectorNum=DeviceInfo.FatStartSector;
918 1 Freesectorcnt=0;
919 1 while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
920 1 {
921 2
922 2 if(RBC_Read(sectorNum,1,DBUF))
C51 COMPILER V7.07 HPI 04/02/2009 22:39:37 PAGE 16
923 2 {
924 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
925 3 {
926 4 if((DBUF[i]==0x00)&&(DBUF[i+1]==0x00))
927 4 {
928 5 Freesectorcnt++;
929 5 }
930 4 }
931 3 }
932 2 else
933 2 return FALSE;
934 2 sectorNum++;
935 2 }
936 1
937 1 ////////////////////////////////////////////////////////////////////////
938 1 FreeSize=DeviceInfo.BPB_BytesPerSec*DeviceInfo.BPB_SecPerClus;
939 1 FreeSize=Freesectorcnt*FreeSize;
940 1
941 1 UARTBUF[0]=(unsigned char)((FreeSize>>24)&0xff);
942 1 UARTBUF[1]=(unsigned char)((FreeSize>>16)&0xff);
943 1 UARTBUF[2]=(unsigned char)((FreeSize>>8)&0xff);
944 1 UARTBUF[3]=(unsigned char)(FreeSize&0xff);
945 1 Response.len=4;
946 1 return TRUE;
947 1 }
948
949 unsigned char CreateDir(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
950 {
951 1 unsigned int sector,i,j,DirCount;
952 1 unsigned int cnum,ClusterPointer;
953 1 unsigned char xdata bstop,InByte,bwrite;
954 1
955 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
956 1 return FALSE;
957 1 if((len%32)!=0)
958 1 return FALSE;
959 1 if((len+32)>DeviceInfo.BPB_BytesPerSec)
960 1 return FALSE;
961 1
962 1 ThisFile.bFileOpen=0;
963 1 ThisFile.FatSectorPointer=0;
964 1
965 1 cnum=GetFreeCusterNum();
966 1 if(cnum<0x02)
967 1 return FALSE;
968 1
969 1 pBuffer[11]=0x10;
970 1 pBuffer[26]=(unsigned char)(cnum);
971 1 pBuffer[27]=(unsigned char)(cnum>>8);
972 1 pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
973 1 bstop=0;
974 1
975 1 if(DirStartCluster==0)
976 1 {
977 2 /////// Search a free space in the root dir space and build the item ///
978 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
979 2 {
980 3 if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
981 3 return FALSE;
982 3 DirCount=0;bwrite=0;
983 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
984 3 {
C51 COMPILER V7.07 HPI 04/02/2009 22:39:37 PAGE 17
985 4 if(len==0)
986 4 {
987 5 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
988 5 {
989 6 for(j=0;j<32;j++)
990 6 DBUF[i+j]=*(pBuffer+j);
991 6 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
992 6 return FALSE;
993 6 bstop=1;
994 6 break;
995 6 }
996 5 }
997 4 else
998 4 {
999 5 if(DirCount==0)
1000 5 InByte=i;
1001 5 if(DBUF[i]==0xE5)
1002 5 DirCount++;
1003 5 else if(DBUF[i]==0x00)
1004 5 {
1005 6 DirCount++;
1006 6 DBUF[i]=0xE5;
1007 6 bwrite=1;
1008 6 }
1009 5 else
1010 5 DirCount=0;
1011 5
1012 5 if((DirCount*32)>=(len+32))
1013 5 {
1014 6 for(j=0;j<len;j++)
1015 6 DBUF[InByte+j]=*(pName+j);
1016 6
1017 6 for(j=0;j<32;j++)
1018 6 DBUF[InByte+len+j]=*(pBuffer+j);
1019 6
1020 6 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
1021 6 return FALSE;
1022 6 bstop=1;
1023 6 break;
1024 6 }
1025 5 }
1026 4 }
1027 3 if(bstop==1)break;
1028 3
1029 3 if((len!=0)&&(bwrite==1))
1030 3 {
1031 4 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
1032 4 return FALSE;
1033 4 }
1034 3 }
1035 2
1036 2 if(sector>=DeviceInfo.BPB_RootEntCnt)
1037 2 return FALSE;
1038 2 }
1039 1 ////////////////////////////////////////////////////////////
1040 1 else
1041 1 {
1042 2 NowCluster=DirStartCluster;
1043 2 do
1044 2 {
1045 3 NowSector=FirstSectorofCluster(NowCluster);
1046 3 ClusterPointer=NowCluster;
C51 COMPILER V7.07 HPI 04/02/2009 22:39:37 PAGE 18
1047 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
1048 3 {
1049 4 if(!RBC_Read(NowSector+sector,1,DBUF))
1050 4 return FALSE;
1051 4 DirCount=0;bwrite=0;
1052 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
1053 4 {
1054 5 if(len==0)
1055 5 {
1056 6 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
1057 6 {
1058 7 for(j=0;j<32;j++)
1059 7 DBUF[i+j]=*(pBuffer+j);
1060 7 if(!RBC_Write(NowSector+sector,1,DBUF))
1061 7 return FALSE;
1062 7 bstop=1;
1063 7 brea
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -