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