for command "FloppyRead(2, 1, Buf);"
FDCResulsts: 0 0 0 0 0 3 2
Ill be glad if someone check my code. I couldnt find where Im wrong. Ill become crazyyy.....
Code: Select all
void motoron(void)
{
out(FDC_DOR, CMD_MOTORON);
delay(1500);
}
void motoroff(void)
{
delay(1500);
out(FDC_DOR, CMD_MOTOROFF);
}
bool recalibrate(void)
{
int recalibratemaxtry = 10;
motoron();
for(; recalibratemaxtry > 0; recalibratemaxtry--) {
JobDone = FALSE;
sendbyte(CMD_RECAL);
sendbyte(0); // [......00]DriveNo 0->A
while(!JobDone);
if(CheckInterruptStatus())
break;
}
motoroff();
if(CurrentCylindir != 0)
return FALSE;
//SetError(FDC_RECALIBRATE_FAIL);
return TRUE;
}
bool sendbyte(byte fByte)
{
int FloppyTimeOut = 128;
char Buf[50];
for(;FloppyTimeOut > 0; FloppyTimeOut--) {
if((in(FDC_MSR) & (ST_DATAREGREADY | ST_DIR)) == ST_DATAREGREADY) {
out(FDC_DATA, fByte);
return TRUE;
}
in(0x80); //Delay
}
// SetError(FLOPPY_TIME_OUT);
Print("\nSend byte error!!!");
Print(FormatString(Buf, "-> %d\n", (in(FDC_MSR))));
return FALSE;
}
byte getbyte(void)
{
int FloppyTimeOut = 128;
for(;FloppyTimeOut > 0; FloppyTimeOut--) {
if((in(FDC_MSR) & (ST_DATAREGREADY | ST_DIR | ST_BUSY)) == (ST_DATAREGREADY | ST_DIR | ST_BUSY))
return in(FDC_DATA);
in(0x80); //Delay
}
// SetError(FLOPPY_TIME_OUT);
Print("Get byte error\n");
return FALSE;
}
bool seek(unsigned int CylindirNo)
{
if(CurrentCylindir == CylindirNo)
return TRUE;
JobDone = FALSE;
sendbyte(CMD_SEEK);
sendbyte(0); //[.....0..]HeadNo(0), [......00]DriveNo(A)
sendbyte(CylindirNo);
while(!JobDone);
if(CheckInterruptStatus()) {
if((CurrentCylindir == CylindirNo) && (status[0] == 0x20))
return TRUE;
}
Print("\nFDC error!");
return FALSE;
}
void FloppyHandler(void)
{
JobDone = TRUE;
Print("\n!IRQ6!->[Done]");
ResetPIC(MASTER_PIC);
}