📄 hpi.lst
字号:
638 1 if(!ThisFile.bFileOpen)
639 1 return FALSE;
640 1 ThisFile.bFileOpen=0;
641 1 bSuccess=1;
642 1 bStop=0;
643 1 tlen=0;
644 1
645 1 while(writeLength>0)
646 1 {
647 2 if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
648 2 len=DeviceInfo.BPB_BytesPerSec;
649 2 else
650 2 len=writeLength+ThisFile.OffsetofSector;
651 2
652 2 //////////////////////////////////////////////////////
653 2 if(ThisFile.OffsetofSector>0)
654 2 {
655 3 if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
656 3 {
657 4
658 4 len=len-ThisFile.OffsetofSector;
659 4 for(i=0;i<len;i++)
660 4
661 4 DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
662 4 if(!RBC_Write(ThisFile.SectorPointer,1,DBUF))
663 4 return FALSE;
664 4 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
665 4 }
666 3 else
667 3 return FALSE;
668 3 }
669 2 else
670 2 {
671 3 if(!RBC_Write(ThisFile.SectorPointer,1,pBuffer+tlen))
672 3 return FALSE;
673 3 ThisFile.OffsetofSector=len;
674 3 }
675 2 /////////////////////////////////////////////////////
C51 COMPILER V7.06 HPI 09/18/2004 01:30:03 PAGE 12
676 2 writeLength-=len;
677 2 tlen+=len;
678 2 /////////////更新文件指针 //////////////////////////////
679 2 if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
680 2 {
681 3 ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
682 3 ThisFile.SectorofCluster+=1;
683 3 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
684 3 {
685 4 ThisFile.SectorofCluster=0;
686 4 ThisFile.ClusterPointer=CreateClusterLink(ThisFile.ClusterPointer);
687 4 if(ThisFile.ClusterPointer==0x00)
688 4 return FALSE;
689 4 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);
690 4 }
691 3 else
692 3 ThisFile.SectorPointer=ThisFile.SectorPointer+1;
693 3 }
694 2
695 2
696 2 }//end while
697 1 ThisFile.pointer+=tlen;
698 1 ///////////更新文件目录信息/////////////////////////////
699 1 if(bSuccess==1)
700 1 {
701 2 if(DirStartCluster==0)
702 2 {
703 3 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
704 3 {
705 4 //////////////////////////////////////////////////
706 4 if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
707 4 return FALSE;
708 4 ///////////////////////////////////////////////////
709 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
710 4 {
711 5 cnum=LSwapINT16(DBUF[i+26],DBUF[i+27]);
712 5 if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
713 5 {
714 6 if(ThisFile.pointer>ThisFile.LengthInByte)
715 6 ThisFile.LengthInByte=ThisFile.pointer;
716 6 DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
717 6 DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
718 6 DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
719 6 DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
720 6 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
721 6 return FALSE;
722 6 bStop=1;
723 6 break;
724 6 }
725 5 }
726 4 if(bStop==1)
727 4 break;
728 4 }
729 3 }
730 2 //////////////////////////////////////////////////////////////////////////////
731 2 else
732 2 {
733 3 NowCluster=DirStartCluster;
734 3 do
735 3 {
736 4 NowSector=FirstSectorofCluster(NowCluster);
737 4 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
C51 COMPILER V7.06 HPI 09/18/2004 01:30:03 PAGE 13
738 4 {
739 5 if(!RBC_Read(NowSector+sector,1,DBUF))
740 5 return FALSE;
741 5 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
742 5 {
743 6 cnum=LSwapINT16(DBUF[i+26],DBUF[i+27]);
744 6 if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
745 6 {
746 7 if(ThisFile.pointer>ThisFile.LengthInByte)
747 7 ThisFile.LengthInByte=ThisFile.pointer;
748 7 DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
749 7 DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
750 7 DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
751 7 DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
752 7 if(!RBC_Write(NowSector+sector,1,DBUF))
753 7 return FALSE;
754 7 bStop=1;
755 7 break;
756 7 }
757 6 }
758 5 if(bStop==1)break;
759 5 }
760 4 if(bStop==1)break;
761 4 NowCluster=GetNextClusterNum(NowCluster);
762 4 }while(NowCluster<=0xffef);
763 3
764 3 if(NowCluster>0xffef)
765 3 return FALSE;
766 3 }
767 2 }
768 1
769 1 ThisFile.bFileOpen=1;
770 1 //////////////////////////////////////////////
771 1 return TRUE;
772 1 }
773
774 unsigned char RemoveFile(unsigned char *pBuffer)
775 {
776 1 unsigned int sector,i;
777 1 unsigned char bStop,j;
778 1 int k;
779 1
780 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
781 1 return FALSE;
782 1 if(DirStartCluster==0)
783 1 {
784 2 ////////////// 清除目录/////////////////////////////////////
785 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
786 2 {
787 3 //////////////////////////////////////////////////
788 3 if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
789 3 return FALSE;
790 3 ///////////////////////////////////////////////////
791 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
792 3 {
793 4 if(DBUF[i]==0x00)
794 4 return FALSE;
795 4 ///////////////////////////////////////////
796 4 j=0;
797 4 while(DBUF[i+j]==*(pBuffer+j))
798 4 {
799 5 j=j+1;
C51 COMPILER V7.06 HPI 09/18/2004 01:30:03 PAGE 14
800 5 if(j>10) break;
801 5 }
802 4
803 4 if(j>10)
804 4 {
805 5 DBUF[i]=0xE5;
806 5 ThisFile.StartCluster=LSwapINT16(DBUF[i+26],DBUF[i+27]);
807 5
808 5 for(k=(i-32);k>=0;k=k-32)
809 5 {
810 6 if(DBUF[k+11]==0x0F)
811 6 DBUF[k]=0xE5;
812 6 else
813 6 break;
814 6 }
815 5 DelayMs(15);
816 5 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
817 5 return FALSE;
818 5 /*
819 5 k=sector-1;
820 5 if(k>=0)
821 5 {
822 5 if(!RBC_Read(DeviceInfo.RootStartSector+k,1,DBUF))
823 5 return FALSE;
824 5 for(k=DeviceInfo.BPB_BytesPerSec;k>=0;k=k-32)
825 5 {
826 5 if(DBUF[k+11]==0x0F)
827 5 DBUF[k]=0xE5;
828 5 else
829 5 break;
830 5 }
831 5 // DelayMs(15);
832 5 if(!RBC_Write(DeviceInfo.RootStartSector+sector-1,1,DBUF))
833 5 return FALSE;
834 5 }
835 5 */
836 5 //////////////////// 清除FAT中的纪录////////////////////////
837 5 DelayMs(10);
838 5 if(!DeleteClusterLink(ThisFile.StartCluster))
839 5 return FALSE;
840 5 bStop=1;
841 5 break;
842 5 }
843 4
844 4 }//end for
845 3 if(bStop==1)
846 3 break;
847 3
848 3 }//end search
849 2 if(sector>=DeviceInfo.BPB_RootEntCnt)
850 2 return FALSE;
851 2 }
852 1 else
853 1 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -