⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fat.c

📁 这是atmel公司的89C51SND1C的mp3源程序
💻 C
📖 第 1 页 / 共 5 页
字号:
  Hard_write_byte(0x00);                    /* Start Cylinder */
  if (fat_is_fat16)
  {
    if (nb_total_sectors > 0xFFFF)          /* Total Sectors */
    {
      Hard_write_byte(FAT16_SUP32M);        /* FAT16 > 32 Mbytes */
    }
    else
    {
      Hard_write_byte(FAT16_INF32M);        /* FAT16 < 32 Mbytes */
    }
  }
  else
  {
    Hard_write_byte(FAT12);                 /* FAT12 */
  }
  Hard_write_byte((Byte)(FORMAT_NB_HEAD - 1)); /* Endhead-Zero-based(0)head number */
  Hard_write_byte((Byte)((((FORMAT_NB_CYLINDER - 1) / 0x04) & 0xC0) +  FORMAT_NB_SECTOR));  
                                                            /* EndSector-Zero-based(1) sector number */
  Hard_write_byte((Byte)((FORMAT_NB_CYLINDER - 1) & 0xFF)); /* EndCylinder */
  Hard_write_byte((Byte)(FORMAT_NB_HIDDEN_SECTOR ));        /* Start sector */
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  
  Hard_write_byte((Byte)((nb_total_sectors - FORMAT_NB_HIDDEN_SECTOR)));
  Hard_write_byte((Byte)((nb_total_sectors - FORMAT_NB_HIDDEN_SECTOR)>>8));
  Hard_write_byte((Byte)((nb_total_sectors - FORMAT_NB_HIDDEN_SECTOR)>>16));
  Hard_write_byte((Byte)((nb_total_sectors - FORMAT_NB_HIDDEN_SECTOR)>>24));

  /* Second Partition entry */
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);

  /* Third Partition entry */
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);

  /* Fourth Partition entry */
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  
  Hard_write_byte(0x55);                    /* Signature Word */
  Hard_write_byte(0xAA);

  /* -- HIDDEN SECTORS -- */
  for (j = FORMAT_NB_HIDDEN_SECTOR - 1; j != 0; j--)
  {
    for (i = (SECTOR_SIZE / 4); i != 0; i--)
    {
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
    }
  }
 
  /* -- PARTITION BOOT RECORD -- */
  Hard_write_byte(0xEB);                    /* JMP inst to PBR boot code */
  Hard_write_byte(0x3C);
  Hard_write_byte(0x90);
  Hard_write_byte('O');                     /* OEM name */
  Hard_write_byte('E');
  Hard_write_byte('M');
  Hard_write_byte(' ');
  Hard_write_byte('N');
  Hard_write_byte('A');
  Hard_write_byte('M');
  Hard_write_byte('E');
  Hard_write_byte(SECTOR_SIZE);             /* number of bytes per sector */
  Hard_write_byte(SECTOR_SIZE >> 8);
  Hard_write_byte(fat_cluster_size);        /* Number of sector per cluster */
  Hard_write_byte(NB_RESERVED);             /* number of reserved sector */
  Hard_write_byte(NB_RESERVED >> 8);
  Hard_write_byte(NB_FATS);                 /* Number of FAT */
  Hard_write_byte(NB_ROOT_ENTRY);           /* number of root directory entries */
  Hard_write_byte(NB_ROOT_ENTRY >> 8);
                                                            
  if (nb_total_sectors > 0xFFFF)            /* Total Sectors */
  {
    Hard_write_byte(0x00);
    Hard_write_byte(0x00);
  }
  else
  {
    Hard_write_byte((Byte)((nb_total_sectors - FORMAT_NB_HIDDEN_SECTOR)));
    Hard_write_byte((Byte)((nb_total_sectors - FORMAT_NB_HIDDEN_SECTOR) >> 8));
  }

  Hard_write_byte(HARD_DISK);               /* Media Byte */
  /* Number of sector in each FAT */
  if (fat_is_fat16) 
    nb_sector_fat = (((nb_total_sectors - FORMAT_NB_HIDDEN_SECTOR) / fat_cluster_size) * 2 / 512) + 1;
  else
    nb_sector_fat = (((nb_total_sectors - FORMAT_NB_HIDDEN_SECTOR) / fat_cluster_size) * 3 / 1024) + 1;
  Hard_write_byte((Byte)(nb_sector_fat));
  Hard_write_byte((Byte)(nb_sector_fat >> 8));
  Hard_write_byte((Byte)(FORMAT_NB_SECTOR));              /* Number of sectors on a track */
  Hard_write_byte((Byte)(FORMAT_NB_SECTOR >> 8));
  Hard_write_byte((Byte)(FORMAT_NB_HEAD));                /* Number of heads */
  Hard_write_byte((Byte)(FORMAT_NB_HEAD >> 8));
  Hard_write_byte((Byte)(FORMAT_NB_HIDDEN_SECTOR));       /* Number of hidden sectors */
  Hard_write_byte((Byte)(FORMAT_NB_HIDDEN_SECTOR >> 8));
  Hard_write_byte((Byte)(FORMAT_NB_HIDDEN_SECTOR >> 16));
  Hard_write_byte((Byte)(FORMAT_NB_HIDDEN_SECTOR >> 24));
  if (nb_total_sectors > 0xFFFF)
  { /* number of sectors > 65535 */
    Hard_write_byte((Byte)((nb_total_sectors - FORMAT_NB_HIDDEN_SECTOR)));
    Hard_write_byte((Byte)((nb_total_sectors - FORMAT_NB_HIDDEN_SECTOR) >> 8));
    Hard_write_byte((Byte)((nb_total_sectors - FORMAT_NB_HIDDEN_SECTOR) >> 16));
    Hard_write_byte((Byte)((nb_total_sectors - FORMAT_NB_HIDDEN_SECTOR) >> 24));
  }
  else
  { /* number of sectors < 65535 */
    Hard_write_byte(0x00);
    Hard_write_byte(0x00);
    Hard_write_byte(0x00);
    Hard_write_byte(0x00);
  }
  Hard_write_byte(FAT_DRIVE_NUMBER);        /* Driver number */ 
  Hard_write_byte(0x00);                    /* not used */
  Hard_write_byte(FAT_EXT_SIGN);            /* extended boot signature */
  Hard_write_byte(0x00);                    /* volume ID */
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte(0x00);
  Hard_write_byte('N');                     /* Volume Label */
  Hard_write_byte('O');
  Hard_write_byte(' ');
  Hard_write_byte('N');
  Hard_write_byte('A');
  Hard_write_byte('M');
  Hard_write_byte('E');
  Hard_write_byte(' ');
  Hard_write_byte(' ');
  Hard_write_byte(' ');
  Hard_write_byte(' ');
  Hard_write_byte('F');                     /* File System Type in ASCII */
  Hard_write_byte('A');
  Hard_write_byte('T');
  Hard_write_byte('1');
  if (fat_is_fat16)
  {
    Hard_write_byte('6');
  }
  else
  {
    Hard_write_byte('2');
  }
  Hard_write_byte(' ');
  Hard_write_byte(' ');
  Hard_write_byte(' ');
  for (i = 448/2; i != 0; i--)              /* Boot Code */
  {
    Hard_write_byte(0x00);
    Hard_write_byte(0x00);
  }
  Hard_write_byte(0x55);                    /* Signature word */
  Hard_write_byte(0xAA);
   
  /* -- FATS -- */
  /* -- FAT 1 -- */
  Hard_write_byte(0xF8);                    /* reserved clusters 0 & 1 */
  Hard_write_byte(0xFF);
  Hard_write_byte(0xFF);
  if (fat_is_fat16)
  { /* FAT16 */
    Hard_write_byte(0xFF);
  }
  else
  { /* FAT12 */
    Hard_write_byte(0x00);
  }
  /* free clusters in first FAT sector */
  for (i = (SECTOR_SIZE - 4) / 2; i != 0; i--)
  {
    Hard_write_byte(0x00);
    Hard_write_byte(0x00);
  }
  /* free clusters in other FAT sectors */
  for (j = nb_sector_fat - 1; j != 0; j--)
  {
    for (i = SECTOR_SIZE / 8; i != 0; i--)
    {
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
    }
  }

  /* -- FAT 2 -- */
  Hard_write_byte(0xF8);                    /* reserved clusters 0 & 1 */
  Hard_write_byte(0xFF);
  Hard_write_byte(0xFF);
  if (fat_is_fat16)
  { /* FAT16 */
    Hard_write_byte(0xFF);
  }
  else
  { /* FAT12 */
    Hard_write_byte(0x00);
  }
  /* free clusters in first FAT sector */
  for (i = (SECTOR_SIZE - 4) / 2; i != 0; i--)
  {
    Hard_write_byte(0x00);
    Hard_write_byte(0x00);
  }
  /* free clusters in other FAT sectors */
  for (j = nb_sector_fat - 1; j != 0; j--)
  {
    for (i = SECTOR_SIZE / 8; i != 0; i--)
    {
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
    }
  }


  /* -- ROOT DIRECTORY ENTRIES -- */
  for (j = NB_ROOT_ENTRY / 4; j != 0 ; j--)
  {
    for (i = DIR_SIZE; i != 0; i--)
    {
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
      Hard_write_byte(0x00);
    }
  }
  Hard_write_close();

  /* FORMAT WITH VOICE: CREATE WAV FILES ENTRIES */
  if (voice)
  {
    /* FATS UPDATE */
    if (fat_is_fat16)
    {
      /* FAT1 update in FAT16 */
      fat_ptr_fats = FORMAT_NB_HIDDEN_SECTOR + 1; /* compute FAT1 address */
      Hard_write_open(fat_ptr_fats);
      Hard_write_byte(0xF8);                /* reserved clusters 0 & 1 */
      Hard_write_byte(0xFF);
      Hard_write_byte(0xFF);
      Hard_write_byte(0xFF);
      t = WAV_CLUST_SIZE;
      for (s = 3; s != ((WAV_CLUST_SIZE * WAV_FILE_NB) + 3); s++)
      {
        t--;
        if (t != 0)
        {
          Hard_write_byte(LOW(s));          /* occupied cluster */
          Hard_write_byte(HIGH(s));
        }
        else
        {
          Hard_write_byte(0xFF);            /* end of file cluster */
          Hard_write_byte(0xFF);
          t = WAV_CLUST_SIZE;
        }
      }
      Hard_write_close();
      /* FAT2 update in FAT16 */
      fat_ptr_fats += nb_sector_fat;        /* compute FAT2 address */
      Hard_write_open(fat_ptr_fats);
      Hard_write_byte(0xF8);                /* reserved clusters 0 & 1 */
      Hard_write_byte(0xFF);
      Hard_write_byte(0xFF);
      Hard_write_byte(0xFF);
      t = WAV_CLUST_SIZE;
      for (s = 3; s != ((WAV_CLUST_SIZE * WAV_FILE_NB) + 3); s++)
      {
        t--;
        if (t != 0)
        {
          Hard_write_byte(LOW(s));          /* occupied cluster */
          Hard_write_byte(HIGH(s));
        }
        else
        {
          Hard_write_byte(0xFF);            /* end of file cluster */
          Hard_write_byte(0xFF);
          t = WAV_CLUST_SIZE;
        }
      }
      Hard_write_close();
    }
    else
    {
      /* FAT1 update in FAT12 */
      fat_ptr_fats = FORMAT_NB_HIDDEN_SECTOR + 1; /* compute FAT1 address */
      Hard_write_open(fat_ptr_fats);
      Hard_write_byte(0xF8);                /* reserved clusters 0 & 1 */
      Hard_write_byte(0xFF);
      Hard_write_byte(0xFF);
      t = WAV_CLUST_SIZE;
      for (s = 3; s != ((WAV_CLUST_SIZE * WAV_FILE_NB) + 3); s++)
      {
        t--;
        if (t != 0)
        {
          if ((LOW(s) & 0x01) == 1)
          {
            Hard_write_byte(LOW(s));        /* occupied cluster */
            i = HIGH(s);
          }
          else
          {
            Hard_write_byte(i | (LOW(s) << 4));
            Hard_write_byte(LOW(s >> 4));
          }
        }
        else
        {
          if ((LOW(s) & 0x01) == 1)
          {
            Hard_write_byte(0xFF);          /* end of file cluster */
            i = 0x0F;
          }
          else
          {
            Hard_write_byte(i | 0xF0);
            Hard_write_byte(0xFF);
          }
          t = WAV_CLUST_SIZE;
        }
      }
      Hard_write_close();
      /* FAT2 update in FAT12 */
      fat_ptr_fats += nb_sector_fat;        /* compute FAT2 address */
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -