📄 hpi32.lst
字号:
479 3 if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
480 3 {
481 4
482 4 len=len-ThisFile.OffsetofSector;
483 4 for(i=0;i<len;i++)
484 4 DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
485 4 if(!RBC_Write(ThisFile.SectorPointer,1,DBUF))
486 4 return FALSE;
487 4 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
488 4 }
C51 COMPILER V7.06 HPI32 08/10/2005 23:25:29 PAGE 9
489 3 else
490 3 return FALSE;
491 3 }
492 2 else
493 2 {
494 3 if(!RBC_Write(ThisFile.SectorPointer,1,pBuffer+tlen))
495 3 return FALSE;
496 3 ThisFile.OffsetofSector=len;
497 3 }
498 2 /////////////////////////////////////////////////////
499 2 writeLength-=len;
500 2 tlen+=len;
501 2 /////////////更新文件指针 //////////////////////////////
502 2 if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
503 2 {
504 3 ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
505 3 ThisFile.SectorofCluster+=1;
506 3 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
507 3 {
508 4 ThisFile.SectorofCluster=0;
509 4 ThisFile.ClusterPointer=CreateClusterLink32(ThisFile.ClusterPointer);
510 4 if(ThisFile.ClusterPointer==0x00)
511 4 return FALSE;
512 4 ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer);
513 4 }
514 3 else
515 3 ThisFile.SectorPointer=ThisFile.SectorPointer+1;
516 3 }
517 2
518 2
519 2 }//end while
520 1 ThisFile.pointer+=tlen;
521 1 ///////////更新文件目录信息/////////////////////////////
522 1 if(bSuccess==1)
523 1 {
524 2 NowCluster32=DirStartCluster32;
525 2 do
526 2 {
527 3 NowSector=FirstSectorofCluster32(NowCluster32);
528 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
529 3 {
530 4 if(!RBC_Read(NowSector+sector,1,DBUF))
531 4 return FALSE;
532 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
533 4 {
534 5 cnum=LSwapINT32(DBUF[i+26],DBUF[i+27],DBUF[i+20],DBUF[i+21]);
535 5 if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
536 5 {
537 6 if(ThisFile.pointer>ThisFile.LengthInByte)
538 6 ThisFile.LengthInByte=ThisFile.pointer;
539 6 DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
540 6 DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
541 6 DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
542 6 DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
543 6 if(!RBC_Write(NowSector+sector,1,DBUF))
544 6 return FALSE;
545 6 bStop=1;
546 6 break;
547 6 }
548 5 }
549 4 if(bStop==1)break;
550 4 }
C51 COMPILER V7.06 HPI32 08/10/2005 23:25:29 PAGE 10
551 3 if(bStop==1)break;
552 3 NowCluster32=GetNextClusterNum32(NowCluster32);
553 3 }while(NowCluster32<=DeviceInfo.TotCluster);
554 2
555 2 if(NowCluster32>DeviceInfo.TotCluster)
556 2 return FALSE;
557 2 }
558 1
559 1 ThisFile.bFileOpen=1;
560 1 //////////////////////////////////////////////
561 1 return TRUE;
562 1 }
563
564
565 unsigned char RemoveFile32(unsigned char *pBuffer)
566 {
567 1 unsigned int sector,i;
568 1 unsigned char bStop,j;
569 1 int k;
570 1
571 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
572 1 return FALSE;
573 1 ////////////// 清除目录/////////////////////////////////////
574 1 NowCluster32=DirStartCluster32;
575 1 do
576 1 {
577 2 NowSector=FirstSectorofCluster32(NowCluster32);
578 2 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
579 2 {
580 3 if(!RBC_Read(NowSector+sector,1,DBUF))
581 3 return FALSE;
582 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
583 3 {
584 4 if(DBUF[i]==0x00)
585 4 return FALSE;
586 4 j=0;
587 4 while(DBUF[i+j]==*(pBuffer+j))
588 4 {
589 5 j=j+1;
590 5 if(j>10)
591 5 break;
592 5 }
593 4 if(j>10)
594 4 {
595 5 DBUF[i]=0xE5;
596 5 ThisFile.StartCluster=LSwapINT32(DBUF[i+26],DBUF[i+27],DBUF[i+20],DBUF[i+21]);
597 5 for(k=(i-32);k>=0;k=k-32)
598 5 {
599 6 if(DBUF[k+11]==0x0F)
600 6 DBUF[k]=0xE5;
601 6 else
602 6 break;
603 6 }
604 5 DelayMs(15);
605 5 if(!RBC_Write(NowSector+sector,1,DBUF))
606 5 return FALSE;
607 5 //////////////////// 清除FAT中的纪录////////////////////////
608 5 DelayMs(10);
609 5 if(!DeleteClusterLink32(ThisFile.StartCluster))
610 5 return FALSE;
611 5 bStop=1;
612 5 break;
C51 COMPILER V7.06 HPI32 08/10/2005 23:25:29 PAGE 11
613 5 }
614 4 }
615 3 if(bStop==1)break;
616 3 }
617 2 if(bStop==1)break;
618 2 NowCluster32=GetNextClusterNum32(NowCluster32);
619 2 }while(NowCluster32<=DeviceInfo.TotCluster);
620 1
621 1 if(NowCluster32>DeviceInfo.TotCluster)
622 1 return FALSE;
623 1
624 1 return TRUE;
625 1 }
626
627
628 unsigned char GetCapacity32(void)
629 {
630 1 unsigned int sectorNum,i;
631 1 unsigned long FreeSize,Freesectorcnt;
632 1
633 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
634 1 return FALSE;
635 1
636 1 ////////////////////////////////////////////////////////////////////////
637 1 sectorNum=DeviceInfo.FatStartSector;
638 1 Freesectorcnt=0;
639 1 while(sectorNum<DeviceInfo.BPB_FATSz32+DeviceInfo.FatStartSector)
640 1 {
641 2
642 2 if(RBC_Read(sectorNum,1,DBUF))
643 2 {
644 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+4)
645 3 {
646 4 if((DBUF[i]||DBUF[i+1]||DBUF[i+2]||DBUF[i+3])==0x00)
647 4 {
648 5 Freesectorcnt++;
649 5 }
650 4 }
651 3 }
652 2 else
653 2 return FALSE;
654 2 sectorNum++;
655 2 }
656 1
657 1 ////////////////////////////////////////////////////////////////////////
658 1 FreeSize=DeviceInfo.BPB_BytesPerSec*DeviceInfo.BPB_SecPerClus;
659 1 FreeSize=Freesectorcnt*FreeSize;
660 1
661 1 UARTBUF[0]=(unsigned char)((FreeSize>>24)&0xff);
662 1 UARTBUF[1]=(unsigned char)((FreeSize>>16)&0xff);
663 1 UARTBUF[2]=(unsigned char)((FreeSize>>8)&0xff);
664 1 UARTBUF[3]=(unsigned char)(FreeSize&0xff);
665 1 Response.len=4;
666 1 return TRUE;
667 1 }
668
669
670 unsigned char CreateDir32(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
671 {
672 1 unsigned int sector,i,j,DirCount;
673 1 unsigned long cnum;
674 1 unsigned char xdata bstop,InByte,bwrite;
C51 COMPILER V7.06 HPI32 08/10/2005 23:25:29 PAGE 12
675 1 unsigned long ClusterPointer;
676 1
677 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
678 1 return FALSE;
679 1 if((len%32)!=0)
680 1 return FALSE;
681 1 if((len+32)>DeviceInfo.BPB_BytesPerSec)
682 1 return FALSE;
683 1
684 1 ThisFile.bFileOpen=0;
685 1 ThisFile.FatSectorPointer=0;
686 1
687 1 cnum=GetFreeCusterNum32();
688 1 if(cnum<0x02)
689 1 return FALSE;
690 1
691 1 pBuffer[11]=0x10;
692 1 pBuffer[21]=(unsigned char)(cnum>>24);
693 1 pBuffer[20]=(unsigned char)(cnum>>16);
694 1 pBuffer[27]=(unsigned char)(cnum>>8);
695 1 pBuffer[26]=(unsigned char)(cnum);
696 1 pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
697 1 bstop=0;
698 1
699 1 NowCluster32=DirStartCluster32;
700 1 do
701 1 {
702 2 NowSector=FirstSectorofCluster32(NowCluster32);
703 2 ClusterPointer=NowCluster32;
704 2 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
705 2 {
706 3 if(!RBC_Read(NowSector+sector,1,DBUF))
707 3 return FALSE;
708 3 DirCount=0;bwrite=0;
709 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
710 3 {
711 4 if(len==0)
712 4 {
713 5 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
714 5 {
715 6 for(j=0;j<32;j++)
716 6 DBUF[i+j]=*(pBuffer+j);
717 6 if(!RBC_Write(NowSector+sector,1,DBUF))
718 6 return FALSE;
719 6 bstop=1;
720 6 break;
721 6 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -