At first, little comment to my code, I dont choose drive, because you should choose drive only one. You can choose master drive(hard disc are usually on it) with:
Code:
//base is 0x1F0
outb(base+6, 0x40);
on start you operation system.
ABOUT NUMBERS OF SECTORS
If you want read/write from hard disc, you must tell it three things:
1. First sector who you want read
2. Numbers of sectors from first sector
3. If you want read or write
Now read driver code:
Code:
outb(base+2, (unsigned char)(number_of_sectors >> 8));
outb(base+2, (unsigned char)number_of_sectors);
I am sending number of sectors. If I want read only 1 sector, same result is with:
Code:
outb(base+2, 0); //0x0001 >> 8 = 0x00
outb(base+2, 1); //0x0001 & 0xFF = 0x01
Next code is send first sector and command for read/write.
Now hard disc have all values and it start work. In PIO48 hard disc use port base+0 (0x1F0) for sending data if we reading or getting data if we writing.
One sector have 512 bytes, and port base+0 is word type, than we must read for one sector port base+0 256 times. But sometimes we have in numbers of sectors more sectors than 1 and we must read/write all data. I use two cycles, but too same is:
Code:
for(int i=0; i< (number_of_sectors * 256); i++) { //one sector is reading/writing 256 times
if(type==READ) {
buffer[offset] = inw(base + 0);
}
else {
outw(base + 0, buffer[offset]);
}
offset++;
}
E. g. You want read 10 sectors. One sector must be read from port base+0 256 times, so you must read base+0 2560 times. Did you see how it work?
Summary: Number of sectors defines how times you must read output for read/ write input for write to port base+0.
If you have heavy head from something, ask me.