What is wrong with this floppy read function

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
earlz

What is wrong with this floppy read function

Post by earlz »

I am having some problems with this floppy disk read function
can anyon see something wrong with it

it ends at wait_for_fdd
wait_for_fdd waits for the floppy irq

Code: Select all

unsigned int fdd_read(drive_geometry g,unsigned char drive){
   fdd_wr_status rety;DMA_block info;unsigned char tmp;unsigned char secnum;
   info.page=0xB;
   info.offset=800;
   info.length=512;
   if (drive>1){rety.worked=0;return 0;}
   fdd_motor_timer=0;
   outportb(CcrReg,0);
   rety.status=0x80;
   if(fdd_seek(g.track,drive)==0){rety.worked=0;return 0;}
   tmp=inportb(MsReg);
   //test tmp
     fdd_motor_on();
   StartDMA(2,info,0x44);
   //read sector command
   if(fdc_send_byte_ready()==0){return 0;}
   outportb(DtReg,0xE6);
   //drive
   if(fdc_send_byte_ready()==0){return 0;}
   outportb(DtReg,drive);
   //track
   if(fdc_send_byte_ready()==0){return 0;}
   outportb(DtReg,g.track);
   //head
   if(fdc_send_byte_ready()==0){return 0;}
   outportb(DtReg,g.head);
   //sector
   if(fdc_send_byte_ready()==0){return 0;}
   outportb(DtReg,g.sector);
   //sector size
   if(fdc_send_byte_ready()==0){return 0;}
   outportb(DtReg,0x02);
   //sectors to a track
   if(fdc_send_byte_ready()==0){return 0;}
   outportb(DtReg,0x12);
   //gap length
   if(fdc_send_byte_ready()==0){return 0;}
   outportb(DtReg,0x1B);
   //data length
   if(fdc_send_byte_ready()==0){return 0;}
   outportb(DtReg,0xFF);
   //wait for floppy irq
   fdd_done=0;
     printf("8");
   if(wait_for_fdd()==0){return 0;}
   printf("9");
   if(fdc_get_byte_ready()==0){return 0;}
   tmp=inportb(DtReg);
   if(fdc_get_byte_ready()==0){return 0;}
   inportb(DtReg);
   if(fdc_get_byte_ready()==0){return 0;}
   inportb(DtReg);
   if(fdc_get_byte_ready()==0){return 0;}
   inportb(DtReg);
     if(fdc_get_byte_ready()==0){return 0;}
   inportb(DtReg);
   if(fdc_get_byte_ready()==0){return 0;}
   secnum=inportb(DtReg);
   if(fdc_get_byte_ready()==0){return 0;}
   inportb(DtReg);
   fdd_motor_off();
     return secnum;
}
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:What is wrong with this floppy read function

Post by bubach »

could you try to make it more readable, and maybe post the rest of the code aswell?
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:What is wrong with this floppy read function

Post by Pype.Clicker »

[me=Pype.Clicker]suggests[/me]

Code: Select all

#define inb_or_die(REG) ({if(!fdc_get_byte_ready())return 0; inportb(REG);})
#define outb_or_die(REG,v) ...
that would then mean

Code: Select all

   outb_or_die(DtReg,0xe6); //read sector command
   outb_or_die(DtReg,drive); //drive
// ...
  secnum=inb_or_die(DtReg);
  inb_or_die(DtReg);
  fdd_motor_off();
earlz

Re:What is wrong with this floppy read function

Post by earlz »

thats a good idea
except for the inb part because sometimes i need the value
paulbarker

Re:What is wrong with this floppy read function

Post by paulbarker »

In gcc, code between ({ and }) evaluates to the final statement. So

Code: Select all

secnum=inb_or_die(DtReg);
Would work like:

Code: Select all

if(!fdc_get_byte_ready())
     return 0;
secnum=inportb(DtReg);
Post Reply