📄 main.lst
字号:
466 4 for(k=0;data_buf[32*k]!=0 && k<16;k++)
467 4 {
468 5 memcpy(&sub_dir, data_buf+k*32,32);
469 5 if((sub_dir.file_attribute==0x20 || sub_dir.file_attribute==0x10)
470 5 && (unsigned char)sub_dir.file_name[0]!=0xe5)
471 5 {
472 6 if(strncmp(file_name,(unsigned char*)(&sub_dir),11)==0x00)
473 6 {
474 7 *file_record_sec=i+current_clustor;
475 7 *file_record_pos=k;
476 7 return sub_dir.first_clust[1]*256+sub_dir.first_clust[0];
477 7 }
478 6 }
479 5 }
480 4 }
481 3 clustor=current_clustor-(bootinfo.fat_num*bootinfo.fat_size+bootinfo.root_dir_size*32/512+1);
C51 COMPILER V7.07 MAIN 12/01/2005 22:22:50 PAGE 9
482 3 clustor=clustor/bootinfo.sec_per_clust+2;
483 3 fat_sector=(clustor*2)/512;
484 3 in_sector_pos=(clustor*2)%512;
485 3 if(ReadOneSec(fat_sector+1)==0) //read FAT table
486 3 {
487 4 return 0xffff;
488 4 }
489 3 current_clustor=(next_clustor-2)*bootinfo.sec_per_clust+(bootinfo.fat_size*bootinfo.fat_num+bootinfo.ro
-ot_dir_size*32/512+1);
490 3 next_clustor=data_buf[in_sector_pos+1]*256+data_buf[in_sector_pos];
491 3 }
492 2 if(out_count>=20)
493 2 {
494 3 return 0xffff;
495 3 }
496 2 if(next_clustor==0xffff)
497 2 {
498 3 for(i=0;i<bootinfo.sec_per_clust;i++) //read one clustor
499 3 {
500 4 if(ReadOneSec(i+current_clustor)==0) //read one sector
501 4 {
502 5 return 0xffff;
503 5 }
504 4 for(k=0;data_buf[32*k]!=0 && k<16;k++)
505 4 {
506 5 #ifdef DEBUG
printf("\nk=%x\n",k);
#endif
509 5 memcpy(&sub_dir,data_buf+k*32,32);
510 5 if((sub_dir.file_attribute==0x20 || sub_dir.file_attribute==0x10)
511 5 && (unsigned char)sub_dir.file_name[0]!=0xe5)
512 5 {
513 6 if(strncmp(file_name,(unsigned char*)(&sub_dir),11)==0x00)
514 6 {
515 7 #ifdef DEBUG
printf("succ\n");
#endif
518 7 *file_record_sec=i+dir_clustor;
519 7 *file_record_pos=k;
520 7 return sub_dir.first_clust[1]*256+sub_dir.first_clust[0];
521 7 }
522 6 }
523 5 }
524 4 if(data_buf[32*k]==0)
525 4 return 0xffff;
526 4 }
527 3 }
528 2 }
529 1 }
530
531
532 // format cf card
533 // success return 1,error return -1
534 char FormatCF()
535 {
536 1 xdata struct sBoot boot_sector;
537 1 unsigned long total_sec,temp;
538 1 if(ReadCIS()==0)
539 1 return -1;
540 1 memcpy((unsigned char*)(&boot_sector),BPB,512);
541 1 boot_sector.bsJump[0]=0xeb;
542 1 boot_sector.bsJump[1]=0x3e;
C51 COMPILER V7.07 MAIN 12/01/2005 22:22:50 PAGE 10
543 1 boot_sector.bsJump[2]=0x90;
544 1 boot_sector.OemName[0]='S';
545 1 boot_sector.OemName[1]='u';
546 1 boot_sector.OemName[2]='p';
547 1 boot_sector.OemName[3]='c';
548 1 boot_sector.OemName[4]='o';
549 1 boot_sector.OemName[5]='n';
550 1 boot_sector.OemName[6]='y';
551 1 boot_sector.OemName[7]='b';
552 1 boot_sector.bsBytesPerSec[0]=((struct sCIS *)data_buf)->uf_bytes_per_sector[0];
553 1 boot_sector.bsBytesPerSec[1]=((struct sCIS *)data_buf)->uf_bytes_per_sector[1];
554 1 boot_sector.bsSecPerClust=4;
555 1 boot_sector.bsResSectors[0]=1;
556 1 boot_sector.bsResSectors[1]=0;
557 1 boot_sector.bsFATs=2;
558 1 boot_sector.bsRootDirEnts[0]=0;
559 1 boot_sector.bsRootDirEnts[1]=2;
560 1 total_sec=((struct sCIS *)data_buf)->sector_per_card[1]*16777216
561 1 +((struct sCIS *)data_buf)->sector_per_card[0]*65536
562 1 +((struct sCIS *)data_buf)->sector_per_card[3]*256
563 1 +((struct sCIS *)data_buf)->sector_per_card[2];
564 1 if(total_sec<=65536)
565 1 {
566 2 boot_sector.bsSectors[0]=((struct sCIS *)data_buf)->sector_per_card[2];
567 2 boot_sector.bsSectors[1]=((struct sCIS *)data_buf)->sector_per_card[3];
568 2 boot_sector.bsHugeSectors[0]=0;
569 2 boot_sector.bsHugeSectors[1]=0;
570 2 boot_sector.bsHugeSectors[2]=0;
571 2 boot_sector.bsHugeSectors[3]=0;
572 2 }
573 1 else
574 1 {
575 2 boot_sector.bsSectors[0]=0;
576 2 boot_sector.bsSectors[1]=0;
577 2 boot_sector.bsHugeSectors[0]=((struct sCIS *)data_buf)->sector_per_card[2];
578 2 boot_sector.bsHugeSectors[1]=((struct sCIS *)data_buf)->sector_per_card[3];
579 2 boot_sector.bsHugeSectors[2]=((struct sCIS *)data_buf)->sector_per_card[0];
580 2 boot_sector.bsHugeSectors[3]=((struct sCIS *)data_buf)->sector_per_card[1];
581 2 }
582 1 boot_sector.bsMedia=0xf8;
583 1 temp=(total_sec-31+2*boot_sector.bsSecPerClust)/(256*boot_sector.bsSecPerClust+2);
584 1 boot_sector.bsFATsecs[0]=temp%256;
585 1 boot_sector.bsFATsecs[1]=temp/256;
586 1 boot_sector.bsSecPerTrack[0]=((struct sCIS*)data_buf)->cur_sector_per_track[0];
587 1 boot_sector.bsSecPerTrack[1]=((struct sCIS*)data_buf)->cur_sector_per_track[1];
588 1 boot_sector.bsHeads[0]=((struct sCIS*)data_buf)->cur_head_num[0];
589 1 boot_sector.bsHeads[1]=((struct sCIS*)data_buf)->cur_head_num[1];
590 1 boot_sector.bsHiddenSecs[0]=0;
591 1 boot_sector.bsHiddenSecs[1]=0;
592 1 boot_sector.bsBootCode[0]=0;
593 1 boot_sector.bsBootCode[1]=0;
594 1 boot_sector.bsDriveNumber=0x80; //harddisk use 0x8x
595 1 boot_sector.bsReserved1=0;
596 1 boot_sector.bsBootSignature=0x29;
597 1 boot_sector.bsVolumeID[0]=0x11;
598 1 boot_sector.bsVolumeID[1]=0x11;
599 1 boot_sector.bsVolumeID[2]=0x11;
600 1 boot_sector.bsVolumeID[3]=0x11;
601 1 boot_sector.bsVolumeLabel[0]='c';
602 1 boot_sector.bsVolumeLabel[1]='f';
603 1 boot_sector.bsVolumeLabel[2]=' ';
604 1 boot_sector.bsVolumeLabel[3]='c';
C51 COMPILER V7.07 MAIN 12/01/2005 22:22:50 PAGE 11
605 1 boot_sector.bsVolumeLabel[4]='a';
606 1 boot_sector.bsVolumeLabel[5]='r';
607 1 boot_sector.bsVolumeLabel[6]='d';
608 1 boot_sector.bsVolumeLabel[7]=' ';
609 1 boot_sector.bsFileSysType[0]='F';
610 1 boot_sector.bsFileSysType[1]='A';
611 1 boot_sector.bsFileSysType[2]='T';
612 1 boot_sector.bsFileSysType[3]='1';
613 1 boot_sector.bsFileSysType[4]='6';
614 1 boot_sector.bsFileSysType[5]=' ';
615 1 boot_sector.bsFileSysType[6]=' ';
616 1 boot_sector.bsFileSysType[7]=' ';
617 1 boot_sector.bsSign[0]=0x55;
618 1 boot_sector.bsSign[1]=0xaa;
619 1 if(WriteOneSec((unsigned char*)(&boot_sector),0)==0)
620 1 return -1;
621 1
622 1 if(EraseSec(1,256)==0)
623 1 // printf("sss1\n");
624 1 if(EraseSec(256,256)==0)
625 1 // printf("sss2\n");
626 1 if(EraseSec(512,256)==0)
627 1 // printf("sss3\n");
628 1 if(EraseSec(768,256)==0)
629 1 // printf("sss4\n");
630 1 if(EraseSec(1024,256)==0)
631 1 // printf("sss5\n");
632 1 for(temp=0;temp<512;temp++)
633 1 {
634 2 data_buf[temp]=0;
635 2 }
636 1 #ifdef CLEAR_FAT
for(temp=1;temp<500;temp++)
{
zxPutChar(0x2e);
if(WriteOneSec(data_buf,temp)==0)
return -1;
}
#endif
644 1 data_buf[0]=0xf8;
645 1 data_buf[1]=0xff;
646 1 data_buf[2]=0xff;
647 1 data_buf[3]=0xff;
648 1 if(WriteOneSec(data_buf,1)==0) //init Fat1
649 1 return -1;
650 1 if(WriteOneSec(data_buf,(boot_sector.bsFATsecs[1]*256+boot_sector.bsFATsecs[0]+1))==0) //init Fat2
651 1 return -1;
652 1 for(temp=0;temp<4;temp++)
653 1 {
654 2 data_buf[temp]=0;
655 2 }
656 1 if(WriteOneSec(data_buf,(2*(boot_sector.bsFATsecs[1]*256+boot_sector.bsFATsecs[0])+1))==0)
657 1 return -1;
658 1 return 1;
659 1 }
660
661 //FDT_pos存放返回的目录登记表的扇区号,record_pos存放在扇区中的目录登记项号
662 //返回值:1成功,0失败
663 bit SerchFreeFDT(unsigned int *FDT_pos,unsigned int *record_pos,unsigned int start_sec)
664 {
665 1 bit return_value=0;
666 1 unsigned int i,j,k;
C51 COMPILER V7.07 MAIN 12/01/2005 22:22:50 PAGE 12
667 1 if(start_sec==0x0) //serch in root
668 1 {
669 2 for(j=bootinfo.fat_size*2+1;j<=bootinfo.fat_size*2+1+bootinfo.root_dir_size*32/512;j++)
670 2 {
671 3 ReadOneSec(j);
672 3 for(i=0; i<=bootinfo.root_dir_size*32/512; i++)
673 3 {
674 4 if(data_buf[32*i]==0x00 || data_buf[32*i]==0xe5)
675 4 {
676 5 *FDT_pos=j;
677 5 *record_pos=i;
678 5 return_value=1;
679 5 break;
680 5 }
681 4 }
682 3 if(return_value==1)
683 3 {
684 4 break;
685 4 }
686 3 }
687 2 }
688 1 else //serch in sub
689 1 {
690 2 for(k=0;k<bootinfo.sec_per_clust;k++)
691 2 {
692 3 if(ReadOneSec(start_sec+k)==0)
693 3 {
694 4 return 0;
695 4 }
696 3 for(j=0;j<32;j++)
697 3 {
698 4 for(i=0;i<32;i++)
699 4 {
700 5 if(data_buf[32*i]==0x00 || data_buf[32*i]==0xe5)
701 5 {
702 6 *FDT_pos=start_sec+k;
703 6 *record_pos=i;
704 6 return_value=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -