enum FloppyCommands {
FIX_DRIVE_DATA = 0x03,
- HECK_DRIVE_STATUS = 0x04,
+ CHECK_DRIVE_STATUS = 0x04,
CALIBRATE_DRIVE = 0x07,
CHECK_INTERRUPT_STATUS = 0x08,
SEEK_TRACK = 0x0F,
void FDD_UnloadModule()
{
int i;
- //DevFS_DelDevice( &gFDD_DriverInfo );
+ DevFS_DelDevice( &gFDD_DriverInfo );
Mutex_Acquire(&glFDD);
for(i=0;i<4;i++) {
Time_RemoveTimer(gFDD_Devices[i].timer);
// Read Data from DMA
LOG("Setting DMA for read");
- DMA_SetChannel(2, 512, !Write); // Read 512 Bytes from channel 2
+ DMA_SetChannel(2, 512, !Write); // Read/Write 512 Bytes from channel 2
LOG("Sending command");
- //Threads_Wait(100); // Wait for Head to settle
- Time_Delay(100);
-
for( i = 0; i < FDD_MAX_READWRITE_ATTEMPTS; i ++ )
{
if( Write )
st1 = FDD_int_GetByte(base);
st2 = FDD_int_GetByte(base);
- // Cylinder, Head and Sector (mutilated in some way
+ // Cylinder, Head and Sector (mutilated in some way)
rcy = FDD_int_GetByte(base);
rhe = FDD_int_GetByte(base);
rse = FDD_int_GetByte(base);
// Don't turn the motor off now, wait for a while
gFDD_Devices[Disk].timer = Time_CreateTimer(MOTOR_OFF_DELAY, FDD_int_StopMotor, (void*)(tVAddr)Disk);
+ // Error check
if( i < FDD_MAX_READWRITE_ATTEMPTS ) {
LEAVE('i', 0);
return 0;
// Set Track in structure
gFDD_Devices[disk].track[head] = track;
+
+ // Wait for Head to settle
+ Time_Delay(100);
+
return 1;
}
void FDD_SensInt(int base, Uint8 *sr0, Uint8 *cyl)
{
+ Uint8 byte;
FDD_int_SendByte(base, CHECK_INTERRUPT_STATUS);
- if(sr0) *sr0 = FDD_int_GetByte(base);
- else FDD_int_GetByte(base);
- if(cyl) *cyl = FDD_int_GetByte(base);
- else FDD_int_GetByte(base);
+ byte = FDD_int_GetByte(base);
+ if(sr0) *sr0 = byte;
+ byte = FDD_int_GetByte(base);
+ if(cyl) *cyl = byte;
}
/**
*/
void FDD_int_SendByte(int base, char byte)
{
- volatile int state;
- int timeout = 128;
- for( ; timeout--; )
+ int timeout = 128;
+
+ while( (inb(base + PORT_MAINSTATUS) & 0xC0) != 0x80 && timeout-- )
+ inb(0x80); //Delay
+
+ if( timeout >= 0 )
{
- state = inb(base + PORT_MAINSTATUS);
- if ((state & 0xC0) == 0x80)
- {
- outb(base + PORT_DATA, byte);
- return;
- }
- inb(0x80); //Delay
+ #if 0 && DEBUG
+ static int totalTimeout = 0;
+ static int totalCount = 0;
+ totalTimeout += timeout;
+ totalCount ++;
+ LOG("timeout = %i, average %i", timeout, totalTimeout/totalCount);
+ #endif
+ outb(base + PORT_DATA, byte);
+ }
+ else
+ {
+ Log_Warning("FDD", "FDD_int_SendByte: Timeout sending byte 0x%x to base 0x%x\n", byte, base);
}
-
- #if WARN
- Warning("FDD_int_SendByte - Timeout sending byte 0x%x to base 0x%x\n", byte, base);
- #endif
}
/**
*/
int FDD_int_GetByte(int base)
{
- volatile int state;
- int timeout;
- for( timeout = 128; timeout--; )
+ int timeout = 128;
+
+ while( (inb(base + PORT_MAINSTATUS) & 0xd0) != 0xd0 && timeout-- )
+ inb(0x80); //Delay
+
+ if( timeout >= 0 )
{
- state = inb((base + PORT_MAINSTATUS));
- if ((state & 0xd0) == 0xd0)
- return inb(base + PORT_DATA);
- inb(0x80);
+ #if 0 && DEBUG
+ static int totalTimeout = 0;
+ static int totalCount = 0;
+ totalTimeout += timeout;
+ totalCount ++;
+ LOG("timeout = %i, average %i", timeout, totalTimeout/totalCount);
+ #endif
+ return inb(base + PORT_DATA);
+ }
+ else
+ {
+ Log_Warning("FDD", "FDD_int_GetByte: Timeout reading byte from base 0x%x\n", base);
+ return -1;
}
- return -1;
}
/**