📄 basdrvpa.c
字号:
/* 用基本13中断获取硬盘参数 */
#include <dos.h>
#include <stdio.h>
int int13DriveParameter(unsigned int driveNum,
unsigned long *maxCylinder,
unsigned long *maxHead,
unsigned long *maxSector,
unsigned long *totalSector)
{
unsigned long cylinder=0;
unsigned long head=0;
unsigned long sector=0;
unsigned long totalSectorVar=0;
union REGS regs;
regs.h.ah=0x08;
regs.h.dl=driveNum;
int86(0x13,®s,®s); /*调用中断*/
if(regs.h.ah!=0) return regs.h.ah;
if(regs.h.bl==0x01) printf("This is 360KB model.\n");
if(regs.h.bl==0x02) printf("This is 1.2MB model.\n");
if(regs.h.bl==0x03) printf("This is 720KB model.\n");
if(regs.h.bl==0x04) printf("This is 1.44MB model.\n");
/* 需先读取这些值,再赋给后面的变量,否则无效,不知何故 */
cylinder=((((unsigned int)regs.h.cl)>>6<<8) | regs.h.ch) + 1;
head=regs.h.dh+1;
sector=regs.h.cl & 0x3F;
totalSectorVar=(unsigned long)cylinder * (unsigned long)head * (unsigned long)sector;
printf("Cylinders=%lu Heads=%lu Sectors=%lu\nTotal sectors=%lu (%lu MB)\n\n",
cylinder,head,sector,totalSectorVar,totalSectorVar/2/1024);
*maxCylinder=cylinder;
*maxHead=head;
*maxSector=sector;
*totalSector=totalSectorVar;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -