home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / open / hdparker.lzh / SHOWHARD.C < prev    next >
C/C++ Source or Header  |  1987-09-15  |  4KB  |  156 lines

  1. /* SHOWHARD.C
  2.  
  3.    program to show hard disk parameters of bios extension
  4.    hard disk drives
  5.  
  6.    portions Copyright (c) Thomas P. Keller 1987
  7.    portions Copyright (c) Borland International 1987
  8.    All Rights Reserved.
  9. */
  10.  
  11. /**********************************************************************
  12.  
  13. This program reads the hard disk parameters from the drive parameter
  14. table by invoking bios interupt 0x13 function 0x8.
  15. **********************************************************************/
  16.  
  17.  
  18. #include <stdio.h>
  19. #include <dos.h>
  20.  
  21. void main()
  22.     {
  23.     union REGS outregs;
  24.  
  25.     unsigned int drive_no, max_drives,error_flag,error_code;
  26.  
  27.     void get_drive_parms(unsigned int drive_no, union REGS *regs);
  28.     void print_drive_parms(unsigned int drive_no, union REGS *regs);
  29.     void print_drive_error(unsigned char error_code);    
  30.  
  31.     printf("\nHard Disk Parameter Table Information ver. 1.0\n");
  32.     printf("Copyright (c) Thomas P. Keller & Borland International 1987\n");
  33.     printf("All Rights Reserved\n");
  34.     drive_no = 0;    /* drive c: */
  35.  
  36.     get_drive_parms( drive_no, &outregs);
  37.  
  38.     max_drives = outregs.h.dl;
  39.     error_flag = outregs.x.cflag;
  40.     error_code = outregs.h.ah;
  41.  
  42.     if (error_flag != 0)
  43.         print_drive_error(error_code);
  44.     else {
  45.  
  46.         if (max_drives == 0)
  47.             printf("\nNo hard disks installed\n");
  48.         else {
  49.             printf("\nNumber of drives is :  %4hu\n",max_drives);
  50.             do {
  51.                 get_drive_parms( drive_no, &outregs);
  52.                  print_drive_parms( drive_no, &outregs);
  53.                 drive_no = drive_no + 1;
  54.             } while (drive_no < max_drives);
  55.         }
  56.     }
  57.     return;
  58. }
  59. /* end of main */
  60.  
  61. /* functions */
  62.  
  63. void get_drive_parms(unsigned int drive_no, union REGS *regs)
  64. {
  65.     #define DISK    0x13
  66.  
  67.     regs->h.ah = 0x08;    /* get drive parameters */
  68.     regs->h.al = 0x00;
  69.     regs->h.dh = 0x00;
  70.     regs->h.dl = 0x80+drive_no;    /* drive number +0x80 */
  71.     regs->h.cl = 0x00;
  72.     regs->h.ch = 0x00;
  73.     regs->x.cflag = 0x00;
  74.  
  75.     int86(DISK, regs, regs);
  76.  
  77.     return;
  78. }
  79.  
  80. void print_drive_parms(unsigned int drive_no, union REGS *regs)
  81. {
  82.  
  83.     unsigned char error_code;
  84.  
  85.     unsigned int error_flag,max_heads,max_sectors,max_cylinders,max_tracks;
  86.  
  87.     void print_drive_error(unsigned char error_code);    
  88.  
  89.     printf("\nParameters for drive %u\n",drive_no+1);
  90.  
  91.     printf("\n");
  92.     printf("CF = %03hXh\t\t\t",regs->x.cflag);
  93.     printf("AH = %03hXh\t",regs->h.ah);
  94.     printf("AL = %03hXh\n",regs->h.al);
  95.     printf("CH = %03hXh\t",regs->h.ch);
  96.     printf("CL = %03hXh\t",regs->h.cl);
  97.     printf("DH = %03hXh\t",regs->h.dh);
  98.     printf("DL = %03hXh\n",regs->h.dl);
  99.     printf("\n");
  100.  
  101.     error_flag = regs->x.cflag;
  102.     error_code = regs->h.ah;
  103.     max_heads = regs->h.dh + 1;
  104.     max_sectors = regs->h.cl & 0x3f;
  105.     max_tracks = regs->h.ch + ((regs->h.cl & 0xc0)<<2) + 1;
  106.  
  107.     if (error_flag == 0) {
  108.         printf("Number of heads   :  %4hu\n",max_heads);
  109.         printf("Number of sectors :  %4hu\n",max_sectors);
  110.         printf("Number of tracks  :  %4hu\n",max_tracks);
  111.     }
  112.     else
  113.         print_drive_error(error_code);
  114.  
  115.     return;
  116. }
  117.  
  118. /* end of  */
  119.  
  120.  
  121. void print_drive_error(unsigned char error_code)
  122. {
  123.  
  124.     printf("\nBios Interrupt 19 Error Code Recieved\n");
  125.  
  126.     if ((error_code & 0x01) == 0x01)
  127.         printf("Bad Command\n");
  128.     if ((error_code & 0x02) == 0x02) 
  129.         printf("Address Mark Not Found\n");
  130.     if ((error_code & 0x03) == 0x03) 
  131.         printf("Write Attempted on Write-Protected Disk\n");
  132.     if ((error_code & 0x04) == 0x04)
  133.         printf("Sector Not Found\n");
  134.     if ((error_code & 0x06) == 0x06) 
  135.         printf("Diskette Removed\n");
  136.     if ((error_code & 0x08) == 0x08) 
  137.         printf("DMA Overrun\n");
  138.     if ((error_code & 0x09) == 0x09) 
  139.         printf("DMA Across 64k Boundary\n");
  140.     if ((error_code & 0x10) == 0x10) 
  141.         printf("Bad CRC\n");
  142.     if ((error_code & 0x20) == 0x20) 
  143.         printf("Controller Failure\n");
  144.     if ((error_code & 0x40) == 0x40)
  145.         printf("Seek Failed\n");
  146.     if ((error_code & 0x80) == 0x80) 
  147.         printf("Time Out\n");
  148.     if ((error_code & 0xFF) == 0xFF) 
  149.         printf("Unknown Error\n");
  150.  
  151.     return ;
  152.  
  153. }
  154.  
  155. /* end of program */
  156.