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