Line 41:
Line 41:
Following the header is two FATs, which are FAT12/FAT16 (depending on total volume size). Each FAT size is determined by the below algo. Following the FATs is the root [http://en.wikipedia.org/wiki/File_Allocation_Table#Directory_table directory] cluster, 0x1000 bytes long. Following the root cluster is the data "clusters". The data "clusters" have are 0x200 bytes long each. The size of the FAT is determined by the following algorithm:
Following the header is two FATs, which are FAT12/FAT16 (depending on total volume size). Each FAT size is determined by the below algo. Following the FATs is the root [http://en.wikipedia.org/wiki/File_Allocation_Table#Directory_table directory] cluster, 0x1000 bytes long. Following the root cluster is the data "clusters". The data "clusters" have are 0x200 bytes long each. The size of the FAT is determined by the following algorithm:
−
u32 WC24_GetVFF_FATSize(u32 filesize)
+
<source lang="c">
+
#define ALIGN_FORWARD(x,align) \
+
((typeof(x))((((u32)(x)) + (align) - 1) & (~((align)-1))))
+
#define CLUSTER_SIZE 0x200
+
+
u32 WC24_GetVFF_FATSize(u32 filesize)
{
{
−
if(filesize < 0x100000)
+
u32 num_clusters = filesize / CLUSTER_SIZE;
−
{//This block is executed for filesizes less than 1MB.
+
u32 fat_bits = 32;
−
u32 base = (filesize / 0x200) - 8;
+
if (num_clusters < 0xFFF5) fat_bits = 16;
−
u32 fatsz = base;
+
if (num_clusters < 0xFF5) fat_bits = 12;
−
if(base % 0x200)//Should always be executed.
+
−
{
+
return ALIGN_FORWARD(num_clusters * fat_bits / 8, CLUSTER_SIZE);
−
if(base<0x200)
−
{
−
fatsz = 0x200;
−
}
−
else
−
{
−
fatsz++;
−
}
−
}
−
return fatsz;
−
}
−
else
−
{
−
return filesize >> 8;//VFF files larger than 1MB must be aligned to a MB, since this algo doesn't work right with filesizes not aligned.
−
}
}
}
+
</source>