Hardware Interaction C

# include
# include
# include
# include
# include
void main()
{
clrscr();
union REGS regs;
int ans;
char arr[1000];
outp(0x3f2,0x1c); //Motor On
delay(200);
outp(0x3f5,0x0f); //Command Code
delay(200);
outp(0x3f5,0x00); //Command Code
delay(200);
outp(0x3f5,0); //Cylinder no.
delay(200);
outp(0x3f5,0x08); //Sense Interrupt Command
delay(200);
ans=inp(0x3f5); //Reading ST0 in data register
delay(100);
ans=inp(0x3f5); //pcn
cout< delay(200);
outportb(0x12,0); /*initialization of DMA Mode*/
delay(200);
outportb(0x11,10); /*supplying Mode Byte*/
int ar=FP_OFF(arr);
int ar1=FP_SEG(arr);
outportb(0x10,2); /*supplying channel no. on port 10*/
regs.h.ch = (ar1)&(0x0f00);
regs.x.ax = regs.h.ah+ar;
(regs.h.ch)++;
outportb(0x04,regs.h.al);
delay(200);
outportb(0x04,regs.h.ah);
delay(200);
outportb(0x81,regs.h.ch);
delay(200);
outportb(0x05,1);
// DMA End
//READ command
delay(200);
outportb(0x3f5,46); //Command Code
delay(200);
outportb(0x3f5,0); //Command Code
delay(200);
outportb(0x3f5,0); //Cylinder no.
delay(200);
outportb(0x3f5,0); //Head Addr
delay(200);
outportb(0x3f5,3); //Record
delay(200);
outportb(0x3f5,2); //Sector size
delay(200);
outportb(0x3f5,5); //EOT
delay(200);
outportb(0x3f5,21); //GPL
delay(200);
outportb(0x3f5,10); //DTL
//result
delay(200);
// st0
int st0 = inportb(0x3f5);
printf("
st0 = %x",st0);
if(inportb(0x3f5) & (192)!=0)
{
printf("
st0= %d",st0);
cout<<"
Abnormal termination st0";
delay(200);
outp(0x3f2,0x0c); //Motor off
exit(0);
}
delay(200);
int st1 = inportb(0x3f5);
printf("
st1 = %x",st1);
if((st1=inportb(0x3f5)) !=0)
{
printf("
st1=%d ",st1);
cout<<"
Abnormal termination st1";
delay(200);
outp(0x3f2,0x0c); //Motor off
exit(0);
}
delay(200);
int st2 = inportb(0x3f5);
printf("
st2 = %x",st2);
if((st2=inportb(0x3f5)) != 0)
{
cout<<"st2= "< cout<<"
Abnormal termination st2";
delay(200);
outp(0x3f2,0x0c); //Motor off
exit(0);
}
cout<<"
Successful Termination";
delay(200);
cout<<"
c= "< delay(200);
cout<<"
h= "< delay(200);
cout<<"
r= "< delay(200);
cout<<"
n= "< delay(200);
outp(0x3f2,0x0c); //Motor off
getch();
}