typedef byte * DataBlock;
|
Read
Read returns a DataBlock (really a byte *) containing the sector read. Because I do not yet have malloc implemented, I simply return a pointer to the memory the DMA used to read from the floppy drive. You'll of course want to change this.
ReadWrite
Because read and write operations are so similar, this function handles both (to be honest, I didn't think of doing this; the idea came from Mr. Nunez's code). However, I only know reading works; writing may or may not. You'll need your Write function to copy the memory to be written to the memory the DMA will use. Note that LBA is converted to head, cylinder, and sector in this function. The order of reading/writing is:
Code
Floppy::DataBlock Floppy::Read(unsigned int BlockIndex) {
ReadWrite(BlockIndex, modRead);
return (DataBlock) (addrDMAStart + 65536 * 2); // TEMP!!! Returns a pointer to the memory the DMA used.
}
bool Floppy::ReadWrite(unsigned int BlockIndex, Mode ReadOrWrite) {
unsigned int Head, Cylinder, Sector;
unsigned int Tries = 0, Continue = true;
Sector = BlockIndex % 18 + 1;
Head = (BlockIndex / 18) % 2;
Cylinder = BlockIndex / 36;
if (ReadOrWrite == modRead) {
DMA::Start(2, 512, DMA::dmaWriteToMemory); // Channel, Length, Mode
}
else {
DMA::Start(2, 512, DMA::dmaReadFromMemory);
}
Start(); // Start the motor and set everything up.
while ((Tries < MaximumReadWriteTries) && Continue) {
if (SeekCylinder(Head, Cylinder)) {
PendingInterrupt = true;
if (SendData(cmdReadSector | cmdMultitrack | cmdDoubleDensityMode | cmdSkipDeletedSectors)) {
if (SendData((Head << cmdHeadShift) | DriveIndex)) {
if (SendData(Cylinder)) {
if (SendData(Head)) {
if (SendData(Sector)) {
if (SendData(2)) { // Sector size = 128 * pow(2, <argument to SendData>)
if (SendData(Sector)) {
if (SendData(cmdGAP3Length)) {
if (SendData(255)) { // Doesn't matter unless the sector size is 128 bytes
while(PendingInterrupt);
Continue = !ReadSectorStatus(Head, Sector, 2);
}
}
}
}
}
}
}
}
}
}
if (Continue)
Recalibrate();
Tries++;
}
Stop();
return Tries < MaximumReadWriteTries;
}
|