⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hpi32.lst

📁 USB U 盘 开发的源代码
💻 LST
📖 第 1 页 / 共 4 页
字号:
 448          unsigned char WriteFile32(unsigned long writeLength,unsigned char *pBuffer)
 449          {
 450   1              unsigned int  len,sector,i,cnum,tlen;
 451   1              unsigned char bSuccess,bStop;
 452   1              
 453   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 454   1                      return FALSE;           
 455   1              if(!ThisFile.bFileOpen)
 456   1                      return FALSE;
 457   1              ThisFile.bFileOpen=0;
 458   1              bSuccess=1;
 459   1              bStop=0;
 460   1              tlen=0;
 461   1      
 462   1              while(writeLength>0)
 463   1              {
 464   2                      if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
 465   2                              len=DeviceInfo.BPB_BytesPerSec;
 466   2                      else
 467   2                              len=writeLength+ThisFile.OffsetofSector;
 468   2                         
 469   2                       //////////////////////////////////////////////////////
 470   2                       if(ThisFile.OffsetofSector>0)
 471   2                              {
 472   3                              if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
 473   3                                      {
 474   4                                      
 475   4                                      len=len-ThisFile.OffsetofSector;
 476   4                                      for(i=0;i<len;i++)                                      
 477   4                                              DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
 478   4                                      if(!RBC_Write(ThisFile.SectorPointer,1,DBUF))
 479   4                                              return FALSE;                                           
 480   4                                      ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
 481   4                                      }
 482   3                              else
 483   3                                      return FALSE;                           
 484   3                              }
 485   2                       else
 486   2                              {
 487   3                              if(!RBC_Write(ThisFile.SectorPointer,1,pBuffer+tlen))
 488   3                                      return FALSE;                           
 489   3                              ThisFile.OffsetofSector=len;
C51 COMPILER V7.06   HPI32                                                                 09/18/2004 01:30:05 PAGE 9   

 490   3                              }
 491   2                       /////////////////////////////////////////////////////
 492   2                         writeLength-=len;
 493   2                         tlen+=len;
 494   2                       /////////////更新文件指针 //////////////////////////////
 495   2                        if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
 496   2                         {    
 497   3                              ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 498   3                              ThisFile.SectorofCluster+=1;
 499   3                              if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
 500   3                              {
 501   4                                      ThisFile.SectorofCluster=0;
 502   4                                       ThisFile.ClusterPointer=CreateClusterLink32(ThisFile.ClusterPointer);
 503   4                                       if(ThisFile.ClusterPointer==0x00)
 504   4                                              return FALSE;                           
 505   4                                       ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer);        
 506   4                              }
 507   3                              else
 508   3                                      ThisFile.SectorPointer=ThisFile.SectorPointer+1;
 509   3                          }
 510   2                      
 511   2              
 512   2              }//end while
 513   1              ThisFile.pointer+=tlen;
 514   1              ///////////更新文件目录信息/////////////////////////////
 515   1              if(bSuccess==1)
 516   1              {
 517   2                      NowCluster32=DirStartCluster32;         
 518   2                              do
 519   2                              {
 520   3                                      NowSector=FirstSectorofCluster32(NowCluster32);
 521   3                                      for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
 522   3                                      {   
 523   4                                              if(!RBC_Read(NowSector+sector,1,DBUF))
 524   4                                                      return FALSE;                           
 525   4                                              for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 526   4                                              {
 527   5                                                      cnum=LSwapINT16(DBUF[i+26],DBUF[i+27]);
 528   5                                                      if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
 529   5                                                              {
 530   6                                                              if(ThisFile.pointer>ThisFile.LengthInByte)
 531   6                                                                      ThisFile.LengthInByte=ThisFile.pointer;                         
 532   6                                                              DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
 533   6                                                              DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
 534   6                                                              DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
 535   6                                                              DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
 536   6                                                              if(!RBC_Write(NowSector+sector,1,DBUF))
 537   6                                                                      return FALSE;                   
 538   6                                                               bStop=1;
 539   6                                                               break;
 540   6                                                              }                                                       
 541   5                                      }
 542   4                                              if(bStop==1)break;
 543   4                                      }
 544   3                                      if(bStop==1)break;
 545   3                                      NowCluster32=GetNextClusterNum32(NowCluster32);                 
 546   3                              }while(NowCluster32<=DeviceInfo.TotCluster);
 547   2                      
 548   2                      if(NowCluster32>DeviceInfo.TotCluster)
 549   2                      return FALSE;           
 550   2              }
 551   1              
C51 COMPILER V7.06   HPI32                                                                 09/18/2004 01:30:05 PAGE 10  

 552   1              ThisFile.bFileOpen=1;
 553   1              //////////////////////////////////////////////
 554   1              return TRUE;
 555   1      }
 556          
 557          
 558          unsigned char RemoveFile32(unsigned char *pBuffer)
 559          {
 560   1              unsigned int sector,i;
 561   1              unsigned char bStop,j;
 562   1              int k;
 563   1                      
 564   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 565   1                      return FALSE;
 566   1      ////////////// 清除目录/////////////////////////////////////            
 567   1              NowCluster32=DirStartCluster32;         
 568   1                      do
 569   1                      {
 570   2                              NowSector=FirstSectorofCluster32(NowCluster32);
 571   2                              for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
 572   2                      {   
 573   3                                      if(!RBC_Read(NowSector+sector,1,DBUF))
 574   3                                              return FALSE;                           
 575   3                                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 576   3                                      {
 577   4                                              if(DBUF[i]==0x00)
 578   4                                                      return FALSE;
 579   4                                              j=0;
 580   4                                              while(DBUF[i+j]==*(pBuffer+j))
 581   4                                              {
 582   5                                                       j=j+1;
 583   5                                                       if(j>10)
 584   5                                                              break;
 585   5                                              }
 586   4                                              if(j>10)
 587   4                                              { 
 588   5                                                      DBUF[i]=0xE5;
 589   5                                                      ThisFile.StartCluster=LSwapINT32(DBUF[i+26],DBUF[i+27],DBUF[i+20],DBUF[i+21]);
 590   5                                                      for(k=(i-32);k>=0;k=k-32)
 591   5                                                      {
 592   6                                                      if(DBUF[k+11]==0x0F)
 593   6                                                              DBUF[k]=0xE5;
 594   6                                                      else
 595   6                                                              break;
 596   6                                                      }
 597   5                                                      DelayMs(15);
 598   5                                                      if(!RBC_Write(NowSector+sector,1,DBUF))
 599   5                                                              return FALSE;                                   
 600   5                                      //////////////////// 清除FAT中的纪录////////////////////////
 601   5                                                      DelayMs(10);
 602   5                                                      if(!DeleteClusterLink32(ThisFile.StartCluster))
 603   5                                                              return FALSE;                                   
 604   5                                                      bStop=1;
 605   5                                                      break;
 606   5                                                      }
 607   4                                      }
 608   3                                      if(bStop==1)break;              
 609   3                      }
 610   2                              if(bStop==1)break;      
 611   2                              NowCluster32=GetNextClusterNum32(NowCluster32);                 
 612   2                      }while(NowCluster32<=DeviceInfo.TotCluster);    
 613   1              
C51 COMPILER V7.06   HPI32                                                                 09/18/2004 01:30:05 PAGE 11  

 614   1              if(NowCluster32>DeviceInfo.TotCluster)
 615   1                  return FALSE;
 616   1              
 617   1              return TRUE;
 618   1      }
 619          
 620          
 621          unsigned char GetCapacity32(void)
 622          {
 623   1              unsigned int sectorNum,i;       
 624   1              unsigned long FreeSize,Freesectorcnt;
 625   1      
 626   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 627   1                      return FALSE;
 628   1                      
 629   1              ////////////////////////////////////////////////////////////////////////
 630   1              sectorNum=DeviceInfo.FatStartSector;
 631   1              Freesectorcnt=0;
 632   1              while(sectorNum<DeviceInfo.BPB_FATSz32+DeviceInfo.FatStartSector)
 633   1              {
 634   2                      
 635   2                      if(RBC_Read(sectorNum,1,DBUF))
 636   2                      {
 637   3                        for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+4)
 638   3                              {                        
 639   4                               if((DBUF[i]||DBUF[i+1]||DBUF[i+2]||DBUF[i+3])==0x00)
 640   4                                      {       
 641   5                                      Freesectorcnt++;
 642   5                                      }         
 643   4                              }       
 644   3                      }
 645   2                      else                    
 646   2                              return FALSE;                   
 647   2                      sectorNum++;
 648   2              }
 649   1              
 650   1              ////////////////////////////////////////////////////////////////////////
 651   1              FreeSize=DeviceInfo.BPB_BytesPerSec*DeviceInfo.BPB_SecPerClus;
 652   1              FreeSize=Freesectorcnt*FreeSize;
 653   1              
 654   1              UARTBUF[0]=(unsigned char)((FreeSize>>24)&0xff);
 655   1              UARTBUF[1]=(unsigned char)((FreeSize>>16)&0xff);
 656   1              UARTBUF[2]=(unsigned char)((FreeSize>>8)&0xff);
 657   1              UARTBUF[3]=(unsigned char)(FreeSize&0xff);
 658   1              Response.len=4;
 659   1              return TRUE;
 660   1      }
 661          
 662          
 663          unsigned char CreateDir32(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
 664          {
 665   1              unsigned int sector,i,j,DirCount;
 666   1              unsigned int cnum;
 667   1              unsigned char xdata bstop,InByte,bwrite;
 668   1              unsigned long ClusterPointer;
 669   1              
 670   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 671   1                      return FALSE;
 672   1              if((len%32)!=0)
 673   1                      return FALSE;
 674   1              if((len+32)>DeviceInfo.BPB_BytesPerSec)
 675   1                      return FALSE;
C51 COMPILER V7.06   HPI32                                                                 09/18/2004 01:30:05 PAGE 12  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -