Floppy problem
Posted: Sun Sep 21, 2003 1:48 pm
Hi again,
now i'll try to explain my problem that you could help me. explanation will be in the code i'll provide.
i tried waiting the MSR to change but it is useless, cause i get infinity loop. i just have no idea what to do to make that thing work. maybe i missed smth (although i think that everything is done from the manual). What is more, irq are working fine, cause timer and keyboard are in working stage.
i would be really appreciated if someone took a look at my code and gave me an advice.
thank in advance.
now i'll try to explain my problem that you could help me. explanation will be in the code i'll provide.
Code: Select all
#define DOR 0x3f2;
#define MOTA 16;
#define DMA_IRQ 8;
#define RESET 4;
#define MAINSTATUS 0x3f4;
#define DATAREGISTER 0x3f5;
bool Floppy::Main_(){
initFl(); // this is the main function where i want to initialize my floppy drive
Sf -> printf("initialiation ended \n");
}
bool Floppy::MRQ_(){
???getStatus();
???if(MRQ) return true;
???return false;
}
void Floppy::getStatus(){
???__u8 mainreg; __u16 adr = MAINSTATUS;
???__asm__("inb %%dx, %%al \t\n":"=a"(mainreg):"d"(adr));
???((mainreg&128) == 128)? MRQ = true : MRQ = false;
???((mainreg&64) == 64) ? DIO = true : DIO = false; // true: controller => CPU
???((mainreg&16) == 16) ? BUSY = true : BUSY = false;
}
void Floppy::initFl(){
???motor = false;
???// stop the motor and disable irq's
???__u16 adr = DOR;
???outb(adr, 0);
???TickCounter = 0;
//data rate 500(Kb/s)
???outb(0x3f4, 0);
???/* re-enable interrupts */
???outb(adr, 0x0c);
/* resetting triggered an interrupt - handle it */
???FDD_intFlag = 1;
???WaitFDCInterrupt(true);
//specify drive timings
???while(!MRQ_());
???Command_Byte = 0x03;
???send2CCommandByte();
???while(!MRQ_());
???Command_Byte = 0x0D + 0x0F;
???send2CCommandByte();
???while(!MRQ_());
???Command_Byte = 0x02;
???send2CCommandByte();
???while(!MRQ_());
???Sf -> printf("---------------------------------------------------- \n");
???FDD_Track = 1;
???seekparkTrack(); // now this is the place where i have problems
}
void Floppy::send2CCommandByte(){
???FDC_Status = FDC_Normal;
???for(int i =0; i<128; i++){
??????getStatus();
??????if(MRQ && !DIO ){
?????? __u16 adr = DATAREGISTER;
?????????__asm__("outb %%al, %%dx"::"a"(Command_Byte),"d"(adr));
?????????Sf -> printf("prinial\n");
?????????return;
??????}
??????inb(0x80);
???}
???FDC_Status = 1;
}
int Floppy::fromController(){
FDC_Status = 0;
???for(int i=0; i<128; i++){
??????getStatus();
??????if(MRQ && DIO){
?????????__u16 adr = DATAREGISTER; __u8 mainreg;
?????????__asm__("inb %%dx, %%al \t\n":"=a"(mainreg):"d"(adr));
?????????Sf -> printf("wyslal\n");
?????????return mainreg;
??????}
??????__asm__("inb $80, %al \t\n");
???}
// time out
???FDC_Status = 1;
???return -1;
}
void Floppy::WaitFDCInterrupt(bool sensei){
???FDC_Status = FDC_Normal;
???TickCounter = 0;
/* wait for IRQ6 handler to signal command finished */
???while(!FDD_intFlag && TickCounter < 36){
???}
/* read in command result bytes */
???int i = 0; getStatus();
???while((i<7) && BUSY){
??????status[i++] = fromController();
??????getStatus();
???}
???if(sensei){ // sence interrupt status
/* send a "sense interrupt status" command */
??????Command_Byte = 0x08;
??????send2CCommandByte();
??????FDC_ST0 = fromController();
??????FDC_C = fromController();
???}
???FDD_intFlag = 0;
???if(TickCounter > 36){ // time out
??????FDC_Status = 1;
???}else{
?????????FDC_Status = 0;
?????? }
}
// buggy function
void Floppy::seekparkTrack(){ // 3 byte command
???while(!MRQ_());???
???startMotor();
// after starting the motor if i am trying to read MSR
// i get value 16 in Bochs and value 0 on real PC
// maybe there is smth i should do?
???Command_Byte = 0x0f;
???send2CCommandByte();
//further code is useless cause i can't send this byte
// i get time out
}
i would be really appreciated if someone took a look at my code and gave me an advice.
thank in advance.