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