Information Technology Reference
In-Depth Information
word FATread(DISK *dsk, word ccls)
{
word
c;
word
d;
dword
l;
word
p;
byte
q;
// Get the address of the file's current cluster.
// The address is two bytes, LSB first.
p = ccls;
// The LBA of the FAT sector containing the cluster's data is the FAT's starting address
// plus the high byte of the current cluster.
// (Each sector contains 256 two-byte entries.)
l = dsk -> fat + (p >> 8);
// Read the sector.
if ( SectorRead( l, dsk -> buffer) != sdcValid)
return CLUSTER_FAIL;
// To get the value stored in the cluster's entry,
// read 2 bytes in the buffer of retrieved data
// beginning at offset = low byte of current cluster's address << 1.
// Shift left 1 (multiply by 2) because each entry is 2 bytes.
c = RAMreadW(dsk -> buffer, ((p & 0xFF) << 1));
if (c >= LAST_CLUSTER_FAT16)
// The entry is an EOC marker.
c = LAST_CLUSTER;
return c;
}
Search WWH ::




Custom Search