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