📄 hpi.lst
字号:
424 1 }
425
426 unsigned char SetFilePointer(unsigned long pointer)
427 {
C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 8
428 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
429 1 return FALSE;
430 1 if(!ThisFile.bFileOpen)
431 1 return FALSE;
432 1 ///////////////////////////////////////////////////////////
433 1 ThisFile.pointer=pointer;
434 1 if(ThisFile.pointer>ThisFile.LengthInByte)
435 1 return FALSE;
436 1
437 1 if(!GoToPointer(ThisFile.pointer))
438 1 {
439 2 ThisFile.bFileOpen=0;
440 2 return FALSE;
441 2 }
442 1 //////////////////////////////////////////////
443 1 return TRUE;
444 1 }
445
446 unsigned char CreateFile(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
447 {
448 1 unsigned int sector,i,j,DirCount;
449 1 unsigned int cnum,ClusterPointer;
450 1 unsigned char xdata bstop,InByte,bwrite;
451 1
452 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
453 1 return FALSE;
454 1 if((len%32)!=0)
455 1 return FALSE;
456 1 if((len+32)>DeviceInfo.BPB_BytesPerSec)
457 1 return FALSE;
458 1
459 1 ThisFile.bFileOpen=0;
460 1
461 1 cnum=GetFreeCusterNum();
462 1 if(cnum<0x02)
463 1 return FALSE;
464 1
465 1 pBuffer[26]=(unsigned char)(cnum);
466 1 pBuffer[27]=(unsigned char)(cnum>>8);
467 1 pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
468 1 bstop=0;
469 1
470 1 if(DirStartCluster==0)
471 1 {
472 2 /////// Search a free space in the root dir space and build the item ///
473 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
474 2 {
475 3 if(!SdReadSector(DeviceInfo.RootStartSector+sector,1,DBUF))
476 3 return FALSE;
477 3 DirCount=0;bwrite=0;
478 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
479 3 {
480 4 if(len==0)
481 4 {
482 5 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
483 5 {
484 6 for(j=0;j<32;j++)
485 6 DBUF[i+j]=*(pBuffer+j);
486 6 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
487 6 return FALSE;
488 6 bstop=1;
489 6 break;
C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 9
490 6 }
491 5 }
492 4 else
493 4 {
494 5 if(DirCount==0)
495 5 InByte=i;
496 5 if(DBUF[i]==0xE5)
497 5 DirCount++;
498 5 else if(DBUF[i]==0x00)
499 5 {
500 6 DirCount++;
501 6 DBUF[i]=0xE5;
502 6 bwrite=1;
503 6 }
504 5 else
505 5 DirCount=0;
506 5
507 5 if((DirCount*32)>=(len+32))
508 5 {
509 6 for(j=0;j<len;j++)
510 6 DBUF[InByte+j]=*(pName+j);
511 6
512 6 for(j=0;j<32;j++)
513 6 DBUF[InByte+len+j]=*(pBuffer+j);
514 6
515 6 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
516 6 return FALSE;
517 6 bstop=1;
518 6 break;
519 6 }
520 5 }
521 4 }
522 3 if(bstop==1)break;
523 3
524 3 if((len!=0)&&(bwrite==1))
525 3 {
526 4 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
527 4 return FALSE;
528 4 }
529 3 }
530 2
531 2 if(sector>=DeviceInfo.BPB_RootEntCnt)
532 2 return FALSE;
533 2 }
534 1 ////////////////////////////////////////////////////////////
535 1 else
536 1 {
537 2 NowCluster=DirStartCluster;
538 2 do
539 2 {
540 3 NowSector=FirstSectorofCluster(NowCluster);
541 3 ClusterPointer=NowCluster;
542 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
543 3 {
544 4 if(!SdReadSector(NowSector+sector,1,DBUF))
545 4 return FALSE;
546 4 DirCount=0;bwrite=0;
547 4
548 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
549 4 {
550 5 if(len==0)
551 5 {
C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 10
552 6 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
553 6 {
554 7 for(j=0;j<32;j++)
555 7 DBUF[i+j]=*(pBuffer+j);
556 7 if(!SdWriteSector(NowSector+sector,1,DBUF))
557 7 return FALSE;
558 7 bstop=1;
559 7 break;
560 7 }
561 6 }
562 5 else
563 5 {
564 6 if(DirCount==0)
565 6 InByte=i;
566 6 if(DBUF[i]==0xE5)
567 6 DirCount++;
568 6 else if(DBUF[i]==0x00)
569 6 {
570 7 DirCount++;
571 7 DBUF[i]=0xE5;
572 7 bwrite=1;
573 7 }
574 6 else
575 6 DirCount=0;
576 6
577 6 if((DirCount*32)>=(len+32))
578 6 {
579 7 for(j=0;j<len;j++)
580 7 DBUF[InByte+j]=*(pName+j);
581 7 for(j=0;j<32;j++)
582 7 DBUF[InByte+len+j]=*(pBuffer+j);
583 7 if(!SdWriteSector(NowSector+sector,1,DBUF))
584 7 return FALSE;
585 7 bstop=1;
586 7 break;
587 7 }
588 6 }
589 5 }
590 4 if(bstop==1)break;
591 4
592 4 if((len!=0)&&(bwrite==1))
593 4 {
594 5 if(!SdWriteSector(NowSector+sector,1,DBUF))
595 5 return FALSE;
596 5 }
597 4 }
598 3 if(bstop==1)break;
599 3
600 3 NowCluster=GetNextClusterNum(NowCluster);
601 3 if(NowCluster>0xffef)
602 3 {
603 4 NowCluster=CreateClusterLink(ClusterPointer);
604 4 if(NowCluster==0x00)
605 4 return FALSE;
606 4 NowSector=FirstSectorofCluster(NowCluster);
607 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i++) DBUF[i]=0x00;
608 4 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
609 4 {
610 5 if(!SdWriteSector(NowSector+sector,1,DBUF))
611 5 return FALSE;
612 5 }
613 4 }
C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 11
614 3 }while(NowCluster<=0xffef);
615 2
616 2
617 2 if(NowCluster>0xffef)
618 2 return FALSE;
619 2 }
620 1 ////////////////////////////////////////////////////////////////
621 1
622 1 ThisFile.StartCluster=cnum;
623 1 ThisFile.LengthInByte=0;
624 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
625 1 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.StartCluster);
626 1 ThisFile.OffsetofSector=0;
627 1 ThisFile.SectorofCluster=0;
628 1 ThisFile.bFileOpen=1;
629 1 ThisFile.pointer=0;
630 1 ThisFile.FatSectorPointer=0;
631 1
632 1 return TRUE;
633 1 }
634
635 unsigned char WriteFile(unsigned long writeLength,unsigned char *pBuffer)
636 {
637 1 unsigned int len,sector,i,cnum,tlen;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -