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