Page 1 of 1

Figuring out if the floppy controller is ready ..[fixed]

Posted: Sat Jul 15, 2006 9:59 pm
by earlz
hi I have made some functions to tell me when the floppy controller is ready for data, the only problem is they always return an error when I want it to return 1

Code: Select all

//sligfhtly condensed
#define MAIN_STAT 0x3F4 

unsigned char FDD_ReadyGet(){
	unsigned int delay;
	delay=timer_ticks+2000; //2second timeout
	while(delay>timer_ticks){
		if(inportb(MAIN_STAT)&0x80!=0){
			if(inportb(MAIN_STAT)&0x40!=0){
				return 1;
			}else{
				return 2;
               }
		}
	}
	return 0;
}

unsigned char FDD_ReadySend(){
	unsigned int delay;
	delay=timer_ticks+2000; //2second timeout
	while(delay>timer_ticks){
		if(inportb(MAIN_STAT)&0x80!=0){
			if(inportb(MAIN_STAT)&0x40==0){
				return 1;
			}else{
				return 2;}
		}
	}
	return 0;
}
the problem is it always times out(returns 0)



edit:
ok I figured out the problem(I think)
you need ()'s for if stuff
this is my final code

Code: Select all

unsigned char FDD_ReadyGet(){
	unsigned int delay;
	delay=timer_ticks+2000; //2second timeout
	while(delay>timer_ticks){
          if(inportb(MAIN_STAT)&0xC0==0xC0){return 1;}
	}
	em_printf("c");
	return 0;
}

unsigned char FDD_ReadySend(){
	unsigned int delay;
	delay=timer_ticks+2000; //2second timeout
	while(delay>timer_ticks){
		if((inportb(MAIN_STAT)&0xC0)==0x80){return 1;}
	}
	em_printf("c");
	return 0;
}