FDC doesn't work on real PC
Posted: Sat May 27, 2006 8:13 am
Hello,
My FDC works on Bochs,VM-Ware,... but if I try it on a real PC it doesn't work ... Here is the FDC code, maybe somebody could tell me the error in the code:
My FDC works on Bochs,VM-Ware,... but if I try it on a real PC it doesn't work ... Here is the FDC code, maybe somebody could tell me the error in the code:
Code: Select all
void start_motor()
{
if( !motor_on )
{
outport((base_used + 0x2), 0x1C);
delay(500);
}
text( "Floppy Motor Ein\n" );
motor_on = 1;
}
void stop_motor()
{
if( motor_on != 0 )
{
outport((base_used + 0x2), 0x00);
delay(200);
}
text( "Floppy Motor Aus\n" );
motor_on = 0;
}
void sendbyte(char byte)
{
volatile int msr;
int tmo;
for(tmo = 0; tmo < 128; tmo++)
{
msr = inport((base_used + 0x04));
if ((msr & 0xC0) == 0x80)
{
outport((base_used + 0x05), byte);
return;
}
inport(0x80);
}
}
int getbyte()
{
volatile int msr;
int tmo;
for (tmo = 0; tmo < 128; tmo++)
{
msr = inport((base_used + 0x04));
if ((msr & 0xd0) == 0xd0)
return inport((base_used + 0x05));
inport(0x80);
}
return -1;
}
void waitfdc()
{
//wait_irq6();
statsz = 0;
while ((statsz < 7) && (inb(base_used+0x4) & (1<<4)))
{
status[statsz++] = getbyte();
}
sendbyte(0x08);
sr0 = getbyte();
current_track = getbyte();
}
int fdc_seek(int track)
{
if(current_track == track)
{
text_XY( floppy_x,text_Y() );
text( "Track bereits ausgew?hlt!!!" );
return 0;
}
start_motor();
text( "Track Suchvorgang gestartet\n" );
sendbyte(0x0F);
sendbyte(0x00);
sendbyte(track);
text( "Floppy Wartet\n" );
waitfdc();
delay(1000);
stop_motor();
if(sr0 != 0x20)
{
text( "\n\nFehler: Track suchvorgang abgebrochen!!!\n\n" );
return error;
}
text( "SR0 = 0x20\n" );
current_track = track;
return 0;
}
void fdc_recalibrate()
{
text( "Floppy Rekalibrieren\n" );
start_motor();
sendbyte(0x07);
sendbyte(0x00);
waitfdc();
stop_motor();
}
void fdc_reset()
{
text( "Floppy wird resetet\n" );
outport((base_used + 0x02), 0); // stop everything
motor_on = 0;
outport((base_used + 0x04), 0); // data rate (500K/s)
outport((base_used + 0x02), 0x0C); // restart ints
text( "Floppy wartet auf IRQ\n" );
waitfdc();
sendbyte(0x03); // timing
sendbyte(0xDF); // timing
sendbyte(0x02); // timing
while(fdc_seek(1) == error); // set track
fdc_recalibrate();
}
void Floppy_Laden()
{
floppy_x = text_X();
text( "Floppy Treiber wird initialisiert\n" );
base_used = 0x3F0;
//Floppy_typ();
fdc_reset();
}
void readsector( unsigned char *buffer, int position )
{
int sektor, track, head, a = 0;
unsigned char *p_tbaddr = (unsigned char *)0x80000;
sektor = (position % 18) + 1;
track = (position / 18) / 2;
head = (position / 18) % 2;
start_motor();
if( fdc_seek(track) == error )
{
stop_motor();
return;
}
outport( (base_used + 0x7),0 );
DMA_laden( (unsigned char *)tbaddr,512,0,2 );
sendbyte( 0xE6 );
sendbyte( head << 2 );
sendbyte( track );
sendbyte( head );
sendbyte( sektor );
sendbyte( 0x02 ); /* 512 bytes/sector */
sendbyte( 0x12 );
sendbyte( 0x1B );
sendbyte( 0xFF );
waitfdc();
if( (status[0] & 0xC0) == 0 ) a = 1; /* worked! outta here! */
if( !a )
{
text( "Ouch!!" );
fdc_recalibrate();
}
stop_motor();
memcpy2( (unsigned char *)(buffer),(unsigned char *)tbaddr,128 );
return;
}