home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hall of Fame
/
HallofFameCDROM.cdr
/
open
/
hdparker.lzh
/
SHOWHARD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1987-09-15
|
4KB
|
156 lines
/* SHOWHARD.C
program to show hard disk parameters of bios extension
hard disk drives
portions Copyright (c) Thomas P. Keller 1987
portions Copyright (c) Borland International 1987
All Rights Reserved.
*/
/**********************************************************************
This program reads the hard disk parameters from the drive parameter
table by invoking bios interupt 0x13 function 0x8.
**********************************************************************/
#include <stdio.h>
#include <dos.h>
void main()
{
union REGS outregs;
unsigned int drive_no, max_drives,error_flag,error_code;
void get_drive_parms(unsigned int drive_no, union REGS *regs);
void print_drive_parms(unsigned int drive_no, union REGS *regs);
void print_drive_error(unsigned char error_code);
printf("\nHard Disk Parameter Table Information ver. 1.0\n");
printf("Copyright (c) Thomas P. Keller & Borland International 1987\n");
printf("All Rights Reserved\n");
drive_no = 0; /* drive c: */
get_drive_parms( drive_no, &outregs);
max_drives = outregs.h.dl;
error_flag = outregs.x.cflag;
error_code = outregs.h.ah;
if (error_flag != 0)
print_drive_error(error_code);
else {
if (max_drives == 0)
printf("\nNo hard disks installed\n");
else {
printf("\nNumber of drives is : %4hu\n",max_drives);
do {
get_drive_parms( drive_no, &outregs);
print_drive_parms( drive_no, &outregs);
drive_no = drive_no + 1;
} while (drive_no < max_drives);
}
}
return;
}
/* end of main */
/* functions */
void get_drive_parms(unsigned int drive_no, union REGS *regs)
{
#define DISK 0x13
regs->h.ah = 0x08; /* get drive parameters */
regs->h.al = 0x00;
regs->h.dh = 0x00;
regs->h.dl = 0x80+drive_no; /* drive number +0x80 */
regs->h.cl = 0x00;
regs->h.ch = 0x00;
regs->x.cflag = 0x00;
int86(DISK, regs, regs);
return;
}
void print_drive_parms(unsigned int drive_no, union REGS *regs)
{
unsigned char error_code;
unsigned int error_flag,max_heads,max_sectors,max_cylinders,max_tracks;
void print_drive_error(unsigned char error_code);
printf("\nParameters for drive %u\n",drive_no+1);
printf("\n");
printf("CF = %03hXh\t\t\t",regs->x.cflag);
printf("AH = %03hXh\t",regs->h.ah);
printf("AL = %03hXh\n",regs->h.al);
printf("CH = %03hXh\t",regs->h.ch);
printf("CL = %03hXh\t",regs->h.cl);
printf("DH = %03hXh\t",regs->h.dh);
printf("DL = %03hXh\n",regs->h.dl);
printf("\n");
error_flag = regs->x.cflag;
error_code = regs->h.ah;
max_heads = regs->h.dh + 1;
max_sectors = regs->h.cl & 0x3f;
max_tracks = regs->h.ch + ((regs->h.cl & 0xc0)<<2) + 1;
if (error_flag == 0) {
printf("Number of heads : %4hu\n",max_heads);
printf("Number of sectors : %4hu\n",max_sectors);
printf("Number of tracks : %4hu\n",max_tracks);
}
else
print_drive_error(error_code);
return;
}
/* end of */
void print_drive_error(unsigned char error_code)
{
printf("\nBios Interrupt 19 Error Code Recieved\n");
if ((error_code & 0x01) == 0x01)
printf("Bad Command\n");
if ((error_code & 0x02) == 0x02)
printf("Address Mark Not Found\n");
if ((error_code & 0x03) == 0x03)
printf("Write Attempted on Write-Protected Disk\n");
if ((error_code & 0x04) == 0x04)
printf("Sector Not Found\n");
if ((error_code & 0x06) == 0x06)
printf("Diskette Removed\n");
if ((error_code & 0x08) == 0x08)
printf("DMA Overrun\n");
if ((error_code & 0x09) == 0x09)
printf("DMA Across 64k Boundary\n");
if ((error_code & 0x10) == 0x10)
printf("Bad CRC\n");
if ((error_code & 0x20) == 0x20)
printf("Controller Failure\n");
if ((error_code & 0x40) == 0x40)
printf("Seek Failed\n");
if ((error_code & 0x80) == 0x80)
printf("Time Out\n");
if ((error_code & 0xFF) == 0xFF)
printf("Unknown Error\n");
return ;
}
/* end of program */