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