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