📄 hpi.lst
字号:
423 1 //////////////////////////////////////////////
424 1 Response.len=blen;
425 1
426 1 return TRUE;
C51 COMPILER V7.06 HPI 08/10/2005 23:25:28 PAGE 8
427 1 }
428
429 unsigned char SetFilePointer(unsigned long pointer)
430 {
431 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
432 1 return FALSE;
433 1 if(!ThisFile.bFileOpen)
434 1 return FALSE;
435 1 ///////////////////////////////////////////////////////////
436 1 ThisFile.pointer=pointer;
437 1 if(ThisFile.pointer>ThisFile.LengthInByte)
438 1 return FALSE;
439 1
440 1 if(!GoToPointer(ThisFile.pointer))
441 1 {
442 2 ThisFile.bFileOpen=0;
443 2 return FALSE;
444 2 }
445 1 //////////////////////////////////////////////
446 1 return TRUE;
447 1 }
448
449 unsigned char CreateFile(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
450 {
451 1 unsigned int sector,i,j,DirCount;
452 1 unsigned int cnum,ClusterPointer;
453 1 unsigned char xdata bstop,InByte,bwrite;
454 1
455 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
456 1 return FALSE;
457 1 if((len%32)!=0)
458 1 return FALSE;
459 1 if((len+32)>DeviceInfo.BPB_BytesPerSec)
460 1 return FALSE;
461 1
462 1 ThisFile.bFileOpen=0;
463 1
464 1 cnum=GetFreeCusterNum();
465 1 if(cnum<0x02)
466 1 return FALSE;
467 1
468 1 pBuffer[26]=(unsigned char)(cnum);
469 1 pBuffer[27]=(unsigned char)(cnum>>8);
470 1 pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
471 1 bstop=0;
472 1
473 1 if(DirStartCluster==0)
474 1 {
475 2 /////// Search a free space in the root dir space and build the item ///
476 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
477 2 {
478 3 if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
479 3 return FALSE;
480 3 DirCount=0;bwrite=0;
481 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
482 3 {
483 4 if(len==0)
484 4 {
485 5 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
486 5 {
487 6 for(j=0;j<32;j++)
488 6 DBUF[i+j]=*(pBuffer+j);
C51 COMPILER V7.06 HPI 08/10/2005 23:25:28 PAGE 9
489 6 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
490 6 return FALSE;
491 6 bstop=1;
492 6 break;
493 6 }
494 5 }
495 4 else
496 4 {
497 5 if(DirCount==0)
498 5 InByte=i;
499 5 if(DBUF[i]==0xE5)
500 5 DirCount++;
501 5 else if(DBUF[i]==0x00)
502 5 {
503 6 DirCount++;
504 6 DBUF[i]=0xE5;
505 6 bwrite=1;
506 6 }
507 5 else
508 5 DirCount=0;
509 5
510 5 if((DirCount*32)>=(len+32))
511 5 {
512 6 for(j=0;j<len;j++)
513 6 DBUF[InByte+j]=*(pName+j);
514 6
515 6 for(j=0;j<32;j++)
516 6 DBUF[InByte+len+j]=*(pBuffer+j);
517 6
518 6 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
519 6 return FALSE;
520 6 bstop=1;
521 6 break;
522 6 }
523 5 }
524 4 }
525 3 if(bstop==1)break;
526 3
527 3 if((len!=0)&&(bwrite==1))
528 3 {
529 4 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
530 4 return FALSE;
531 4 }
532 3 }
533 2
534 2 if(sector>=DeviceInfo.BPB_RootEntCnt)
535 2 return FALSE;
536 2 }
537 1 ////////////////////////////////////////////////////////////
538 1 else
539 1 {
540 2 NowCluster=DirStartCluster;
541 2 do
542 2 {
543 3 NowSector=FirstSectorofCluster(NowCluster);
544 3 ClusterPointer=NowCluster;
545 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
546 3 {
547 4 if(!RBC_Read(NowSector+sector,1,DBUF))
548 4 return FALSE;
549 4 DirCount=0;
550 4
C51 COMPILER V7.06 HPI 08/10/2005 23:25:28 PAGE 10
551 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
552 4 {
553 5 if(len==0)
554 5 {
555 6 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
556 6 {
557 7 for(j=0;j<32;j++)
558 7 DBUF[i+j]=*(pBuffer+j);
559 7 if(!RBC_Write(NowSector+sector,1,DBUF))
560 7 return FALSE;
561 7 bstop=1;
562 7 break;
563 7 }
564 6 }
565 5 else
566 5 {
567 6 if(DirCount==0)
568 6 InByte=i;
569 6 if(DBUF[i]==0xE5)
570 6 DirCount++;
571 6 else if(DBUF[i]==0x00)
572 6 {
573 7 DirCount++;
574 7 DBUF[i]=0xE5;
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(!RBC_Write(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)
595 4 {
596 5 if(!RBC_Write(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(!RBC_Write(NowSector+sector,1,DBUF))
C51 COMPILER V7.06 HPI 08/10/2005 23:25:28 PAGE 11
613 5 return FALSE;
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -