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

📄 hpi32.lst

📁 能用51读写U盘...创建文件格式...能自由创建文件.删除.读写
💻 LST
📖 第 1 页 / 共 4 页
字号:
 237   1              unsigned long blen;
 238   1      
 239   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 240   1                      return FALSE;           
 241   1              if(!ThisFile.bFileOpen)
C51 COMPILER V7.06   HPI32                                                                 08/10/2005 23:25:29 PAGE 5   

 242   1                      return FALSE;
 243   1      
 244   1              blen=readLength;
 245   1              tlen=0;
 246   1              if(readLength>MAX_READ_LENGTH)
 247   1                      return FALSE;   
 248   1              
 249   1              if(readLength+ThisFile.pointer>ThisFile.LengthInByte)
 250   1                      return FALSE;   
 251   1                      
 252   1              ////////////////////////////////////////////            
 253   1                      while(readLength>0)
 254   1                      {
 255   2                         if(readLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
 256   2                              len=DeviceInfo.BPB_BytesPerSec;
 257   2                         else
 258   2                              len=readLength+ThisFile.OffsetofSector;
 259   2                         
 260   2                         //////////////////////////////////////////////////////
 261   2                         if(ThisFile.OffsetofSector>0)
 262   2                              {
 263   3                              if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
 264   3                                      {
 265   4                                      
 266   4                                      len=len-ThisFile.OffsetofSector;
 267   4                                      for(i=0;i<len;i++)
 268   4                                              
 269   4                                              *(pBuffer+i)=DBUF[ThisFile.OffsetofSector+i];
 270   4                                      ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
 271   4                                      }
 272   3                              else
 273   3                                      return FALSE;                           
 274   3                              }
 275   2                         else
 276   2                              {
 277   3                                      if(!RBC_Read(ThisFile.SectorPointer,1,pBuffer+tlen))
 278   3                                                      return FALSE;   
 279   3                                      ThisFile.OffsetofSector=len;
 280   3                              }
 281   2                         ////////////////////////////////////////////////////////////
 282   2                         readLength-=len;
 283   2                         tlen+=len;
 284   2                        
 285   2                         /////////////////////////////////////////////////////////
 286   2                         if((ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)&&(tlen+ThisFile.pointer<ThisFile.LengthInBy
             -te))
 287   2                         {    
 288   3                              ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 289   3                              ThisFile.SectorofCluster+=1;
 290   3                              if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
 291   3                              {
 292   4                                      ThisFile.SectorofCluster=0;
 293   4                                       ThisFile.ClusterPointer=GetNextClusterNum32(ThisFile.ClusterPointer);
 294   4                                       if(ThisFile.ClusterPointer>DeviceInfo.TotCluster)
 295   4                                                 return FALSE;                                                
 296   4                                       ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer);        
 297   4                              }
 298   3                              else
 299   3                                      ThisFile.SectorPointer=ThisFile.SectorPointer+1;
 300   3                          }
 301   2                         //////////////////////////////////////////////////////////////////
 302   2                      }//end while
C51 COMPILER V7.06   HPI32                                                                 08/10/2005 23:25:29 PAGE 6   

 303   1                      
 304   1              ThisFile.bFileOpen=1;
 305   1              ThisFile.pointer+=tlen;
 306   1              //////////////////////////////////////////////
 307   1              Response.len=blen;
 308   1      
 309   1              return TRUE;
 310   1      }
 311          
 312          unsigned char SetFilePointer32(unsigned long pointer)
 313          {
 314   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 315   1                      return FALSE;           
 316   1              if(!ThisFile.bFileOpen)
 317   1                      return FALSE;           
 318   1              ///////////////////////////////////////////////////////////
 319   1              ThisFile.pointer=pointer;
 320   1              if(ThisFile.pointer>ThisFile.LengthInByte)
 321   1                      return FALSE;   
 322   1      
 323   1              if(!GoToPointer32(ThisFile.pointer))
 324   1              {
 325   2              ThisFile.bFileOpen=0;
 326   2              return FALSE;   
 327   2              }
 328   1              //////////////////////////////////////////////
 329   1              return TRUE;
 330   1      }
 331          
 332          unsigned char CreateFile32(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
 333          {
 334   1              unsigned int sector,i,j,DirCount;
 335   1              unsigned long cnum;
 336   1              unsigned char xdata bstop,InByte,bwrite;
 337   1              unsigned long ClusterPointer;
 338   1              
 339   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 340   1                      return FALSE;
 341   1              if((len%32)!=0)
 342   1                      return FALSE;
 343   1              if((len+32)>DeviceInfo.BPB_BytesPerSec)
 344   1                      return FALSE;
 345   1      
 346   1              ThisFile.bFileOpen=0;   
 347   1      
 348   1              cnum=GetFreeCusterNum32();
 349   1              if(cnum<0x02)
 350   1                      return FALSE;   
 351   1      
 352   1              pBuffer[21]=(unsigned char)(cnum>>24);
 353   1              pBuffer[20]=(unsigned char)(cnum>>16);
 354   1              pBuffer[27]=(unsigned char)(cnum>>8);
 355   1              pBuffer[26]=(unsigned char)(cnum);
 356   1      
 357   1              pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
 358   1              bstop=0;
 359   1      
 360   1              NowCluster32=DirStartCluster32;         
 361   1                      do
 362   1                      {
 363   2                              NowSector=FirstSectorofCluster32(NowCluster32);
 364   2                              ClusterPointer=NowCluster32;
C51 COMPILER V7.06   HPI32                                                                 08/10/2005 23:25:29 PAGE 7   

 365   2                              for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
 366   2                      {   
 367   3                                      if(!RBC_Read(NowSector+sector,1,DBUF))
 368   3                                              return FALSE;
 369   3                                      DirCount=0;bwrite=0;
 370   3      
 371   3                                      for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 372   3                                      {
 373   4                                      if(len==0)
 374   4                                              {
 375   5                                              if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
 376   5                                              {
 377   6                                              for(j=0;j<32;j++)
 378   6                                                      DBUF[i+j]=*(pBuffer+j);
 379   6                                              if(!RBC_Write(NowSector+sector,1,DBUF))
 380   6                                                      return FALSE;                                   
 381   6                                              bstop=1;
 382   6                                              break;
 383   6                                              }               
 384   5                                              }
 385   4                                      else
 386   4                                      {
 387   5                                      if(DirCount==0)
 388   5                                              InByte=i;
 389   5                                      if(DBUF[i]==0xE5)                               
 390   5                                              DirCount++;                             
 391   5                                      else if(DBUF[i]==0x00)
 392   5                                              {       
 393   6                                              DirCount++;     
 394   6                                              DBUF[i]=0xE5;   
 395   6                                              bwrite=1;                               
 396   6                                              }
 397   5                                      else
 398   5                                              DirCount=0;
 399   5      
 400   5                                      if((DirCount*32)>=(len+32))
 401   5                                              {
 402   6                                              for(j=0;j<len;j++)
 403   6                                                      DBUF[InByte+j]=*(pName+j);
 404   6                                              for(j=0;j<32;j++)
 405   6                                                      DBUF[InByte+len+j]=*(pBuffer+j);
 406   6                                              if(!RBC_Write(NowSector+sector,1,DBUF))
 407   6                                                      return FALSE;                                   
 408   6                                              bstop=1;
 409   6                                              break;
 410   6                                              }
 411   5                                       }
 412   4                                      }
 413   3                                      if(bstop==1)break;
 414   3                                      
 415   3                                      if((len!=0)&&(bwrite==1))
 416   3                                      {
 417   4                                      if(!RBC_Write(NowSector+sector,1,DBUF))
 418   4                                              return FALSE;
 419   4                              }
 420   3                      }
 421   2                              if(bstop==1)break;
 422   2              
 423   2                              NowCluster32=GetNextClusterNum32(NowCluster32);
 424   2                              if(NowCluster32>DeviceInfo.TotCluster)
 425   2                      {
 426   3                              NowCluster32=CreateClusterLink32(ClusterPointer);
C51 COMPILER V7.06   HPI32                                                                 08/10/2005 23:25:29 PAGE 8   

 427   3                              if(NowCluster32==0x00)
 428   3                                       return FALSE;
 429   3                              NowSector=FirstSectorofCluster32(NowCluster32);
 430   3                              for(i=0;i<DeviceInfo.BPB_BytesPerSec;i++) DBUF[i]=0x00;
 431   3                              for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
 432   3                                      {
 433   4                                      if(!RBC_Write(NowSector+sector,1,DBUF))
 434   4                                              return FALSE;
 435   4                                      }
 436   3                              }
 437   2                      }while(NowCluster32<=DeviceInfo.TotCluster);    
 438   1      ////////////////////////////////////////////////////////////////
 439   1              
 440   1              ThisFile.StartCluster=cnum;
 441   1              ThisFile.LengthInByte=0;
 442   1              ThisFile.ClusterPointer=ThisFile.StartCluster;
 443   1              ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.StartCluster);
 444   1              ThisFile.OffsetofSector=0;
 445   1              ThisFile.SectorofCluster=0;
 446   1              ThisFile.bFileOpen=1;
 447   1              ThisFile.pointer=0;
 448   1              ThisFile.FatSectorPointer=0;
 449   1              
 450   1              return TRUE;
 451   1      }
 452          
 453          
 454          unsigned char WriteFile32(unsigned long writeLength,unsigned char *pBuffer)
 455          {
 456   1              unsigned int  len,sector,i,tlen;
 457   1              unsigned char bSuccess,bStop;
 458   1              unsigned long cnum;
 459   1              
 460   1              if(!bFlags.bits.SLAVE_IS_ATTACHED)
 461   1                      return FALSE;           
 462   1              if(!ThisFile.bFileOpen)
 463   1                      return FALSE;
 464   1              ThisFile.bFileOpen=0;
 465   1              bSuccess=1;
 466   1              bStop=0;
 467   1              tlen=0;
 468   1      
 469   1              while(writeLength>0)
 470   1              {
 471   2                      if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
 472   2                              len=DeviceInfo.BPB_BytesPerSec;
 473   2                      else
 474   2                              len=writeLength+ThisFile.OffsetofSector;
 475   2                         
 476   2                       //////////////////////////////////////////////////////
 477   2                       if(ThisFile.OffsetofSector>0)
 478   2                              {

⌨️ 快捷键说明

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