Page 1 of 1

ide :)

Posted: Sun Aug 25, 2002 1:40 pm
by frank
I read that someone was interested in an ide example in C,
well here it is :) (written by me, still messy ;))
it reads the first sec of my disk and puts it onto the screen...

Code: Select all

void initIDEdrive()
{
   
}

int readsec()
{
 unsigned char c=0x0,c2=0x00;
 unsigned short int b;
   
 int i=0;  
   
//
//  1F0 -> 1F7
//  170 -> 177 (the other disk) 
//      
//            
// outportb(0x1F6,0x101+drive+head);
// [101] [01] [000]
// 
//  1*2*2*2*2*2*2*2   = 128
//  1*2*2*2*2*2       =  32
//  1*2*2*2*2         =  16
//                    -------
//                      176
//   
// outportb(0x1F6,176);
 outportb(0x1F6,176);         
 outportb(0x1F2,1);                    /* 1 sector to read */
 outportb(0x1F3,1);                    /* sector nr        */
 outportb(0x1F4,0x00);                 /* cylinder low     */
 outportb(0x1F5,0x00);                 /* cylinder high    */
 outportb(0x1F7,0x20);                 /* read with retry  */  

  c = 208;
  while (c==208){ c = inportb(0x1F7); }
 
   printf("\n--------\n");
   for (i=0; i<512; i++)
   {
     b = inportdd(0x1F0);   
     
      asm volatile("movw %%ax,%%bx"::"b" (b));    
      asm volatile("mov %%al,%%bh":"=b" (c));
      asm volatile("mov %%ah,%%bl":"=b" (c2));
      putc(c);
      putc(c2);
//    buf[i] = c;
//    buf[i+2] = c2;
   }
 
   printf("\n--------\n");   
// return * buf;
}


Re:ide :)

Posted: Mon Aug 26, 2002 9:57 am
by Cyber_Ghost
Thanks. :)

Does your os has a site?

Re:ide :)

Posted: Mon Aug 26, 2002 10:45 am
by frank
Thanks.
Does your os has a site?
Not yet...
It will be released with bsl. (open-source,free)

Btw change this:

Code: Select all

  c = 208;
  while (c==208){ c = inportb(0x1F7); }
into this:

Code: Select all

  c = 209;
   while (c>208){ c = inportb(0x1F7); }

I suggest you put it into a function called "device_ready()" (since this is needed in a lot of functions (read/write))

Best,
Frank :)

Re:ide :)

Posted: Mon Aug 26, 2002 11:28 am
by Cyber_Ghost
do you have a write sector too?

Re:ide :)

Posted: Mon Aug 26, 2002 11:34 am
by frank
not yet...