I have a 32GB SDHC with several .wav files on it and using assembly on a dsPIC to read them. Some files are small enough (60kB) to fit in their own single cluster but most others are larger, up to 8MB. Sum total of files is 240MB and so far each file seems to be stored in contiguous clusters. However, if any fragmentation occurs I won't be able to simply issue consecutive read addresses, so I'd like to know how to access and use the FAT. I've read several explanations of the FAT system (eg fatgen.pdf amongst others), which has been very helpful, but I'm still royally confused about the FAT array, eg how to find it.
Here are a couple of screen shots of what I've got so far. Note that the Frhed display is offset by 0x2000
Directory, file details Sector 1164
So, I can get the start of a file and process it. Scrolling up from sector0, the first non-zero data I find is at d1164, which happens to be the "reserved sectors" figure. The data continues until ending in sector d1224, which is (I reckon) to be about 1,900 * 4-byte entries. I understand that the FAT array is a table of pointers, but I'm having trouble reconciling the data I find (if indeed I've found a FAT) and a file's first cluster address in the directory. For example SW15NT.WAV has its first data at 0x00000656, and I would find its .wav header based on that. But how exactly would I find the next cluster using the FAT ?
Here's what's dawning on me, rightly or wrongly, as I write this. 0x656 = d1622. The d1622nd (d1621st ?) 4-byte entry from the d1164 base is SW15NT's next cluster after 0x656. So I would /128 (ie 512/4) to find whole 512-byte sectors and a remainder. It happens to be 12*128 + 0. => sector d1176. At byte 0x000 in that sector is 01060000 (0x601). At byte 0x158 (the sector 86th entry) is 57060000 (0x657, following 0x656 at 0x154) which "I think" might actually be the next cluster.
I feel I'm close and would really appreciate being shown how to finish the puzzle
TIA, best regards
Read FAT documentation Tried some calculations