谁能帮我解释一下这段简单代码,搞明白大意了就结贴 ( 积分: 200 )

  • 主题发起人 主题发起人 finity
  • 开始时间 开始时间
F

finity

Unregistered / Unconfirmed
GUEST, unregistred user!
c语言我搞不懂,如果解释中能带"相当于delphi 的什么什么"最好:)
#include "stdio.h"
#include "dos.h"
char *GetAscii(unsigned int inData[], int offStart, int offEnd);
int main(void)
{
unsigned int diskData[256];
/* Disk data */
unsigned int offset;
/* Disk data offset */
int loop;
int numDrv;
/* Number of IDE hard drives */
union REGS registers;
unsigned int biosCyl[2];
/* Cylinders, Heads, Sectors */
unsigned int biosHead[2];
unsigned int biosSec [2];
numDrv = peekb(0x40, 0x75);
/* BIOS Data area, Number of Hard disks */
for (loop = 0;
loop < numDrv;
loop++)
{
while (inp(0x01f7) != 0x50);
/* Wait for controller not busy */
outp(0x01f6, (loop == 0 ? 0xa0 : 0xb0));
/* Get first/second drive */
outp(0x01f7, 0xec);
/* Get drive info data */
while (inp(0x1f7) != 0x58);
/* Wait for data ready */
for (offset = 0;
offset != 256;
offset++) /* Read &quot;sector&quot;
*/
diskData[offset] = inp(0x1f0);
/* Get BIOS drive info */
registers.h.ah = 0x08;
/* Get drive info */
registers.h.dl = 0x80 + loop;
/* Drive is 80H for Disk 0, 81H for Disk 1 */
int86(0x13, &amp;reg;isters,&amp;reg;isters);
if (!registers.x.cflag) /* All OK if carry not set */
{
biosHead[loop] = registers.h.dh + 1;
/* Heads are from 0 */
biosSec[loop] = registers.h.cl &amp;
0x3f;
/* sec is bits 5 - 0 */
/* +1 because starts from 0 and +1 for FDISK leaving one out */
biosCyl[loop] = ((registers.h.cl &amp;
0xc0) << 2) + registers.h.ch + 2;
} /* end of if */
printf(&quot;DRIVE %d:/n&quot;, loop);
printf(&quot;Model Number______________________: %s/n&quot;, GetAscii(diskData, 27, 46));
printf(&quot;Serial Number_____________________: %s/n&quot;, GetAscii(diskData, 10, 19));
printf(&quot;Controller Revision Number________: %s/n/n&quot;, GetAscii(diskData, 23, 26));
printf(&quot;Able todo
do
uble Word Transfer___: %6s/n&quot;, (diskData[48] == 0 ? &quot;No&quot;
: &quot;Yes&quot;));
printf(&quot;Controller type___________________: %04X/n&quot;, diskData[20]);
printf(&quot;Controller buffer size (bytes)____: %6u/n&quot;, diskData[21] * 512);
printf(&quot;Number of ECC bytes transferred___: %6u/n&quot;, diskData[22]);
printf(&quot;Number of sectors per interrupt___: %6u/n/n&quot;, diskData[47]);
printf(&quot;Hard Disk Reports/n&quot;);
printf(&quot;Number of Cylinders (Fixed)_______: %6u/n&quot;, diskData[1]);
printf(&quot;Number of Heads___________________: %6u/n&quot;, diskData[3]);
printf(&quot;Number of Sectors per Track_______: %6u/n/n&quot;, diskData[6]);
printf(&quot;BIOS Reports/n&quot;);
printf(&quot;Number of Cylinders_______________: %6u/n&quot;, biosCyl[loop]);
printf(&quot;Number of Heads___________________: %6u/n&quot;, biosHead[loop]);
printf(&quot;Number of Sectors per Track_______: %6u/n/n&quot;, biosSec[loop]);
printf(&quot;Press any key to continue.../n/n&quot;);
getch();
} /* end of for */
return 0;
} /* main() */
char *GetAscii(unsigned int inData[], int offStart, int offEnd)
{
static char retVal[255];
int loop, loop1;
for (loop = offStart, loop1 = 0;
loop <= offend;
loop++)
{
retVal[loop1++] = (char )(inData[loop] / 256);
/* Get High byte */
retVal[loop1++] = (char )(inData[loop] % 256);
/* Get Low byte */
} /* end of for */
retVal[loop1] = '/0';
/* Make sure it ends in a NULL character */
return retVal;
} /* GetAscii() */
=========================================================================
就是上面这段,请帮帮忙
这个贴在 ms.net-c# 也有,也是200分:)
 
c语言我搞不懂,如果解释中能带&quot;相当于delphi 的什么什么&quot;最好:)
#include &quot;stdio.h&quot;
#include &quot;dos.h&quot;
char *GetAscii(unsigned int inData[], int offStart, int offEnd);
int main(void)
{
unsigned int diskData[256];
/* Disk data */
unsigned int offset;
/* Disk data offset */
int loop;
int numDrv;
/* Number of IDE hard drives */
union REGS registers;
unsigned int biosCyl[2];
/* Cylinders, Heads, Sectors */
unsigned int biosHead[2];
unsigned int biosSec [2];
numDrv = peekb(0x40, 0x75);
/* BIOS Data area, Number of Hard disks */
for (loop = 0;
loop < numDrv;
loop++)
{
while (inp(0x01f7) != 0x50);
/* Wait for controller not busy */
outp(0x01f6, (loop == 0 ? 0xa0 : 0xb0));
/* Get first/second drive */
outp(0x01f7, 0xec);
/* Get drive info data */
while (inp(0x1f7) != 0x58);
/* Wait for data ready */
for (offset = 0;
offset != 256;
offset++) /* Read &quot;sector&quot;
*/
diskData[offset] = inp(0x1f0);
/* Get BIOS drive info */
registers.h.ah = 0x08;
/* Get drive info */
registers.h.dl = 0x80 + loop;
/* Drive is 80H for Disk 0, 81H for Disk 1 */
int86(0x13, &amp;reg;isters,&amp;reg;isters);
if (!registers.x.cflag) /* All OK if carry not set */
{
biosHead[loop] = registers.h.dh + 1;
/* Heads are from 0 */
biosSec[loop] = registers.h.cl &amp;
0x3f;
/* sec is bits 5 - 0 */
/* +1 because starts from 0 and +1 for FDISK leaving one out */
biosCyl[loop] = ((registers.h.cl &amp;
0xc0) << 2) + registers.h.ch + 2;
} /* end of if */
printf(&quot;DRIVE %d:/n&quot;, loop);
printf(&quot;Model Number______________________: %s/n&quot;, GetAscii(diskData, 27, 46));
printf(&quot;Serial Number_____________________: %s/n&quot;, GetAscii(diskData, 10, 19));
printf(&quot;Controller Revision Number________: %s/n/n&quot;, GetAscii(diskData, 23, 26));
printf(&quot;Able todo
do
uble Word Transfer___: %6s/n&quot;, (diskData[48] == 0 ? &quot;No&quot;
: &quot;Yes&quot;));
printf(&quot;Controller type___________________: %04X/n&quot;, diskData[20]);
printf(&quot;Controller buffer size (bytes)____: %6u/n&quot;, diskData[21] * 512);
printf(&quot;Number of ECC bytes transferred___: %6u/n&quot;, diskData[22]);
printf(&quot;Number of sectors per interrupt___: %6u/n/n&quot;, diskData[47]);
printf(&quot;Hard Disk Reports/n&quot;);
printf(&quot;Number of Cylinders (Fixed)_______: %6u/n&quot;, diskData[1]);
printf(&quot;Number of Heads___________________: %6u/n&quot;, diskData[3]);
printf(&quot;Number of Sectors per Track_______: %6u/n/n&quot;, diskData[6]);
printf(&quot;BIOS Reports/n&quot;);
printf(&quot;Number of Cylinders_______________: %6u/n&quot;, biosCyl[loop]);
printf(&quot;Number of Heads___________________: %6u/n&quot;, biosHead[loop]);
printf(&quot;Number of Sectors per Track_______: %6u/n/n&quot;, biosSec[loop]);
printf(&quot;Press any key to continue.../n/n&quot;);
getch();
} /* end of for */
return 0;
} /* main() */
char *GetAscii(unsigned int inData[], int offStart, int offEnd)
{
static char retVal[255];
int loop, loop1;
for (loop = offStart, loop1 = 0;
loop <= offend;
loop++)
{
retVal[loop1++] = (char )(inData[loop] / 256);
/* Get High byte */
retVal[loop1++] = (char )(inData[loop] % 256);
/* Get Low byte */
} /* end of for */
retVal[loop1] = '/0';
/* Make sure it ends in a NULL character */
return retVal;
} /* GetAscii() */
=========================================================================
就是上面这段,请帮帮忙
这个贴在 ms.net-c# 也有,也是200分:)
 
获取硬盘信息
 
楼上的很搞笑
 
哪里搞笑了?说出来
对了,它那个代码不完整
还要加上一个头文件 conio.h
 
我想他的意思是怎样把这些信息取出来而不是实现取信息这个功能吧
 
不要忘了楼主只是想搞明白大意
另:int86(0x13, &amp;reg;isters,&amp;reg;isters);这句里的&amp;registers应该为&amp;+register
不知道为什么在这里连在一起就会变成&amp;register
 
后退
顶部