home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 February / PCWorld_2002-02_cd.bin / Software / Vyzkuste / ranish / SOURCES.ZIP / PART_IDE.C < prev    next >
C/C++ Source or Header  |  1998-05-18  |  4KB  |  138 lines

  1. #include "part.h"
  2.  
  3. #include <bios.h>
  4.  
  5. /*
  6.  This piece of code was derived from program
  7.  part.zip by gary@brolga.cc.uq.oz.au
  8.  I am still looking for a document which would
  9.  tell me why it works.
  10. */
  11.  
  12.  
  13. char *getascii(unsigned int in_data[], int off_start, int off_end);
  14.  
  15. void print_ide_info(void)
  16. {
  17.  int i, n, hd;
  18.  unsigned long l;
  19.  unsigned *dd=(unsigned*)buf; /* 2048 bytes */
  20.  unsigned port_base, hd_id;
  21.  struct disk_addr daddr;
  22.  
  23.  fprintf(stderr,"Querying BIOS.  Wait...\n");
  24.  
  25.  printf("\n");
  26.  
  27.  hd=0x80;
  28.  i=0;
  29.  do
  30.    {
  31.     printf("Int13 0x%02X  -> ",hd);
  32.     if( (n=get_disk_info(hd,&dinfo,buf))==-1 )
  33.        printf("Error!\n");
  34.     else
  35.       {
  36.        printf("%5d cyl x %3d heads x %2d sects = %4ldM = %10s sectors\n",
  37.               dinfo.num_cyls, dinfo.num_heads, dinfo.num_sects,
  38.               dinfo.total_sects/2048, sprintf_long(tmp,dinfo.total_sects) );
  39.  
  40.        daddr.disk=hd;
  41.        daddr.cyl=0;
  42.        daddr.head=0;
  43.        daddr.sect=1;
  44.      
  45.        disk_read(&daddr,buf,1);  /* Wake up if disk is sleeping */
  46.       }
  47.     hd++;
  48.     i++;
  49.    }
  50.  while( n==-1 && i<4 || i<n );
  51.  
  52.  if( detected_os==SYS_WIN95 )
  53.    {
  54.     fprintf(stderr,"Please exit from Win95 to query IDE controller.\n");
  55.     return;
  56.    }
  57.  
  58.  printf("\n");
  59.  
  60.  fprintf(stderr,"Querying IDE controller.  Wait...\n");
  61.  
  62.  printf("\n");
  63.  
  64.  for( hd=0x80 ; hd<=0x83 ; hd++ )
  65.     {
  66.      if( hd==0x80 ) { port_base=0x1F0; hd_id=0xA0; printf("Pri Master  -> ");}
  67.      if( hd==0x81 ) { port_base=0x1F0; hd_id=0xB0; printf("Pri Slave   -> ");}
  68.      if( hd==0x82 ) { port_base=0x170; hd_id=0xA0; printf("Sec Master  -> ");}
  69.      if( hd==0x83 ) { port_base=0x170; hd_id=0xB0; printf("Sec Slave   -> ");}
  70.      
  71.  
  72.      /* Wait for controller not busy */
  73.      l=0;
  74.      while( inportb(port_base+7)!=0x50 && l<20000) 
  75.         { 
  76.          l++;
  77.          if( l%4000==0 ) sleep(1);
  78.         }
  79.  
  80.      if( l==20000 ) { printf("Time out!\n\n"); continue; }
  81.  
  82.      /* Get first/second drive */
  83.      outportb(port_base+6, hd_id);
  84.  
  85.      /* Get drive info data */
  86.      outportb(port_base+7, 0xEC);         
  87.  
  88.      /* Wait for data ready */
  89.      l=0;
  90.      while( inportb(port_base+7)!=0x58 && l<20000)
  91.         { 
  92.          l++;
  93.          if( l%4000==0 ) sleep(1);
  94.         }
  95.      if( l==20000 ) { printf("Time out!\n\n"); continue; }
  96.      
  97.  
  98.      /* Read "sector" */
  99.      for( i=0 ; i<256 ; i++ ) dd[i] = inport(port_base);
  100.  
  101.      printf("%5d cyl x %3d heads x %2d sects = %4ldM = %10s sectors\n",
  102.      dd[1], dd[3], dd[6],
  103.      ((long) dd[1] * (long) dd[3] * (long) dd[6])/2048,
  104.      sprintf_long(tmp,((long) dd[1] * (long) dd[3] * (long) dd[6]) ) );
  105.  
  106.      printf("\n          Hard Disk Model: %s\n\n", getascii(dd, 27, 46));
  107. /* 
  108.  printf("Model Number ---------------------> %s\n", getascii(dd, 27, 46));
  109.  printf("Serial Number --------------------> %s\n", getascii(dd, 10, 19));
  110.  printf("Controller Revision Number -------> %s\n", getascii(dd, 23, 26));
  111.  printf("Able to do Double Word Transfer --> %6s\n",
  112.     (dd[48] == 0 ? "No" : "Yes"));
  113.  printf("Controller type ------------------>   %04X\n", dd[20]);
  114.  printf("Controller buffer size (bytes) ---> %6u\n", dd[21] * 512);
  115.  printf("Number of ECC bytes transferred --> %6u\n", dd[22]);
  116.  printf("Number of sectors per interrupt --> %6u\n", dd[47]);
  117. */
  118.      }
  119. }
  120.  
  121.  
  122. char *getascii(unsigned int in_data[], int off_start, int off_end)
  123. {
  124. register int i ;
  125. char *pnt ;
  126. static char ret_val[255];
  127.  
  128. pnt = ret_val ;
  129.  
  130. for (i = off_start; i <= off_end; i++) {
  131.     *(pnt++) = (char) (in_data[i] / 256);  /* Get High byte */
  132.     *(pnt++) = (char) (in_data[i] % 256);  /* Get Low byte */
  133. }
  134. *pnt = '\0';  /* Make sure it ends in a NULL character */
  135.  
  136. return(ret_val);
  137. } /* --- end of the subroutine "getascii" --- */
  138.