[zz]dos.h函数详解

dos.h函数详解(1/6)
2009-04-13 18:18
@函数名称: absread
函数原型: int absread(int drive, int nsects, int sectnum, void *buffer)
函数功能: 对磁盘扇区读数据
函数返回: 0-操作成功,其他-操作失败
参数说明: driver-读取的驱动器号 0-表示驱动器A,以此类推
sectnum-读取的扇区号
msects-读取的扇区数
所属文件: <dos.h>

#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dos.h>
int main()
{
int i,strt,ch_out,sector;char buf[512];
printf("Insert a diskette into drive A and press any key");
getch();
sector=0;
if(absread(0,1,sector,&buf)!=0)
{
perror("Disk problem");
exit(1);
}
printf("Read OK");
strt=3;
for (i=0;i<80;i++)
{
ch_out=buf[strt+i];
putchar(ch_out);
}
printf("\n");
return(0);
}


@函数名称: abswrite
函数原型: int abswrite(int drive, int nsects, int sectnum, void *buffer)
函数功能: 对磁盘扇区写数据
函数返回: 0-操作成功,其他-操作失败
参数说明: driver-写入的驱动器号
sectnum-写入的扇区号
msects-写入的扇区数
buf-写入内容
所属文件: <dos.h>

#include <dos.h>
#include <stdio.h>

unsigned char buff[512];
/* 此程企图将FAT区和ROOT区清空从而快速格式化磁盘 */
int main()
{
int i;char c;
printf("Quick Format 1.44MB");
printf("ALL DATA IN THE FLOPPY DISK WILL BE LOST!!");
printf("Insert a diskette for drive A:");
printf("and press ENTER when ready. . .");c=getchar();
printf("Cleaning FAT area. . .");
buff[0]=0xf0;buff[1]=buff[2]=0xff;
for(i=3;i<512;i++)buff=0;
abswrite(0,1,1,buff);
abswrite(0,1,10,buff);
for(i=0;i<512;i++)buff=0;
for(i=2;i<10;i++)abswrite(0,1,i,buff);
for(i=11;i<19;i++)abswrite(0,1,i,buff);
printf("Cleaning ROOT area. . .");
for(i=19;i<33;i++)abswrite(0,1,i,buff);
printf("QuickFormat Completed!");
return 0;
}


@函数名称: allocmem
函数原型: int allocmem(unsigned size, unsigned * seg)
函数功能: 按节(16字节)分配内存块
函数返回: -1:分配成功,其他数值:实际分配的节数
参数说明: size-分配的节数,seg-分配后的段地址
所属文件: <dos.h>

#include <dos.h>
#include <malloc.h>
#include <stdio.h>
int main()
{
unsigned int size,segp;
int stat;
size=64; /* (64 x 16)=1024 bytes */
stat=allocmem(size,&segp);
if (stat==-1)
printf("Allocated memory at segment: %x",segp);
else
printf("Failed: maximum number of paragraphs available is %u",stat);
return 0;
}


@函数名称: bdos
函数原型: int bdos(int fnum, unsigned dx, unsigned al)
函数功能: 执行DOS系统调用INT 21H
函数返回: 寄存器AX的值
参数说明: fnum-系统调用号,dx,al-赋给DX,AL寄存器的值
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
char current_drive(void)
{
char curdrive;
curdrive=bdos(0x19,0,0);
return('A'+curdrive);
}
int main()
{
printf("The current drive is %c:",current_drive());
return 0;
}


@函数名称: country
函数原型: struct country *country(int countrycode, struct country *countryptr)
函数功能: 用于设置一些与国家相关的项目,如货币,时间日期的表示方式等
函数返回: 国家相关信息
参数说明: 结构定义:struct country{
int co_date; /*日期格式*/
char co_curr[5]; /*货币符号*/
char co_thsep[2]; /*数字分隔符*/
char co_desep[2]; /*小数点*/
char co_dtsep[2]; /*日期分隔符*/
char co_tmsep[2]; /*时间分隔符*/
char co_currstyle; /*货币形式*/
char co_digits; /*有效数字*/
int (far *co_case)(); /*事件处理函数*/
char co_dasep; /*数据分隔符*/
char co_fill[10]; /*补充字符*/
}
所属文件: <dos.h>

#include <dos.h>
#include <stdio.h>
#define USA 0
int main()
{
struct COUNTRY country_info;
country(USA,&country_info);
printf("The currency symbol for the USA is: %s",country_info.co_curr);
return 0;
}


@函数名称: ctrlbrk
函数原型: void ctrlbrk(int (*pfun)(vpod))
函数功能: 设置当Ctrl-Break组合键按下时,应执行的函数
函数返回:
参数说明: pfun-要执行的函数指针,该函数应返回0值
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
#define ABORT 0
int c_break()
{
printf("Control-Break pressed. Program aborting ...");
return (ABORT);
}
int main()
{
ctrlbrk(c_break);
for(;;)
printf("Looping... Press <Ctrl-Break> to quit:");
return 0;
}


@函数名称: dosexterr
函数原型: int dosexterr(struct DOSERR *err)
函数功能: 得到DOS扩展调用失败时的错误信息
函数返回: 错误信息保存在err结构中
参数说明: err-用于保存错误信息的结构指针
关于DOS extended error代码(即:struct DOSERR.exterror)各系统差别极大,不一一列出
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
FILE *fp;
struct DOSERROR info;
fp=fopen("perror.dat","r");
if (!fp) perror("Unable to open file for reading");
dosexterr(&info);
printf("Extended DOS error information:\n");
printf("Extended error: %d\t",info.exterror);
printf("Class: %x\n",info.class);
printf("Action: %x\t",info.action);
printf("Error Locus: %x\n",info.locus);
return 0;
}


@函数名称: getcbrk
函数原型: int getcbrk(void)
函数功能: 检测对Ctrl-Break按下的检测是否允许
函数返回: 0-允许检测,1-不允许检测
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
if (getcbrk())
printf("Cntrl-brk flag is on");
else
printf("Cntrl-brk flag is off");
return 0;
}


@函数名称: getdate
函数原型: void getdate(struct date *d)
函数功能: 得到系统日期
函数返回:
参数说明: d 存放得到的日期信息
所属文件: <dos.h>

#include <dos.h>
#include <stdio.h>
int main()
{
struct date d;
getdate(&d);
printf("The current year is: %d",d.da_year);
printf("The current day is: %d",d.da_day);
printf("The current month is: %d",d.da_mon);
return 0;
}


@函数名称: setdate
函数原型: void setdate(struct date *datep)
函数功能: 设置DOS日期
函数返回:
参数说明: datep-要设置的日期数值,struct date定义格式如下:
struct date{
int da_year;
char da_day;
char da_mon;
};
所属文件: <dos.h>

#include <stdio.h>
#include <process.h>
#include <dos.h>
int main()
{
struct date reset;
struct date save_date;
getdate(&save_date);
printf("Original date:");
system("date");
reset.da_year=2001;
reset.da_day=1;
reset.da_mon=1;
setdate(&reset);
printf("Date after setting:");
system("date");
setdate(&save_date);
printf("Back to original date:");
system("date");
return 0;
}


@函数名称: settime
函数原型: void settime(struct time *timep)
函数功能: 设置DOS时间
函数返回:
参数说明: timep-要设置的时间数值,struct time定义格式如下:
struct time{
unsigned char ti_min;
unsigned char ti_hour;
unsigned char ti_hund;
unsigned char ti_sec;
};
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
struct time t;
gettime(&t);
printf("The current minute is: %d",t.ti_min);
printf("The current hour is: %d",t.ti_hour);
printf("The current hundredth of a second is: %d",t.ti_hund);
printf("The current second is: %d",t.ti_sec);
t.ti_min++;
settime(&t);
return 0;
}


@函数名称: gettime
函数原型: void gettime(struct date *t)
函数功能: 得到系统时间
函数返回:
参数说明: d 存放得到的日期信息
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
struct time t;
gettime(&t);
printf("The current time is: %2d:%02d:%02d.%02d",t.ti_hour,t.ti_min,t.ti_sec,t.ti_hund);
return 0;
}


@函数名称: getdfree
函数原型: void getdfree(int drive, struct dfree *dfptr)
函数功能: 得到驱动器的剩余磁盘空间
函数返回: 以结构返回:struct dfree{
unsigned df_avail; /* 可用簇数 */
unsigned df_total; /* 总簇数 */
unsigned df_bsec; /* 每扇区字节数 */
unsigned df_sclus; /* 每簇扇区数 */
}
参数说明: drive-驱动器号:1-A盘,2-B盘……
所属文件: <dos.h>

#include <stdio.h>
#include <stdlib.h>
#include <dir.h>
#include <dos.h>

int main()
{
struct dfree free;
long avail;
int drive;

drive=getdisk();
getdfree(drive+1,&free);
if(free.df_sclus==0xFFFF)
{
printf("Error in getdfree() call\n");
exit(1);
}
avail=(long)free.df_avail * (long)free.df_bsec * (long)free.df_sclus;
printf("Drive %c: has %ld bytes available\n",'A'+drive,avail);
return 0;
}


@函数名称: setdta
函数原型: void setdta(char far *dta)
函数功能: 设置DTA(磁盘传送区)地址
函数返回:
参数说明: dta-缓冲区地址指针
所属文件: <dos.h>

#include <process.h>
#include <string.h>
#include <stdio.h>
#include <dos.h>

int main()
{
char line[80],far *save_dta;
char buffer[256]="SETDTA test!";
struct fcb blk;
int result;
/* get new file name from user */
printf("Enter a file name to create:");
gets(line);
/* pass the new file name to the dta */
parsfnm(line,&blk,1);
printf("%d %s\n",blk.fcb_drive,blk.fcb_name);
/* request DOS services to create file */
if(bdosptr(0x16,&blk,0)==-1)
{
perror("Error creating file");
exit(1);
}
/* save old dta and set new dta */
save_dta=getdta();
setdta(buffer);
/* write new records */
blk.fcb_recsize=256;
blk.fcb_random=0L;
result=randbwr(&blk,1);
printf("result=%d\n",result);
if (!result)
printf("Write OK\n");
else
{
perror("Disk error");
exit(1);
}
/* request DOS services to close the file */
if (bdosptr(0x10,&blk,0)==-1)
{
perror("Error closing file");
exit(1);
}
/* reset the old dta */
setdta(save_dta);
return 0;
}


@函数名称: getdta
函数原型: char far * getdta(void)
函数功能: 得到磁盘传送地址(DTA)的指针
函数返回: 磁盘传送地址(DTA)的指针
参数说明:
所属文件: <dos.h>

#include <dos.h>
#include <stdio.h>
int main()
{
char far *dta;
dta=getdta();
printf("The current disk transfer address is: %Fp",dta);
return 0;
}


@函数名称: getfat
函数原型: void getfat(int drive, struct fatinfo *fptr)
函数功能: 得到磁盘驱动器的信息
函数返回:
参数说明: drive-驱动器号:1-A盘,2-B盘,以此类推.fptr-磁盘驱动器的信息
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
struct fatinfo diskinfo;
int flag=0;
printf("lease insert disk in drive A");
getchar();
getfat(1,&diskinfo);
printf("Drive A: is ");
switch((unsigned char) diskinfo.fi_fatid)
{
case 0xFD:printf("360K low density");break;
case 0xF9:printf("1.2 Meg high density");break;
default:printf("unformatted");flag=1;
}
if(!flag)
{
printf("sectors per cluster %5d",diskinfo.fi_sclus);
printf("number of clusters %5d",diskinfo.fi_nclus);
printf("bytes per sector %5d",diskinfo.fi_bysec);
}
return 0;
}

dos.h函数详解(2/6)
2009-04-13 18:19
@函数名称: getfatd
函数原型: void getfatd(struct fatinfo *fptr)
函数功能: 得到缺省驱动磁盘驱动器的信息
函数返回:
参数说明: fptr-磁盘驱动器的信息
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
struct fatinfo diskinfo;
int flag=0;
printf("lease insert disk in drive A");
getchar();
getfat(1,&diskinfo);
printf("Drive A: is ");
switch((unsigned char) diskinfo.fi_fatid)
{
case 0xFD:printf("360K low density");break;
case 0xF9:printf("1.2 Meg high density");break;
default:printf("unformatted");flag=1;
}
if(!flag)
{
printf("sectors per cluster %5d",diskinfo.fi_sclus);
printf("number of clusters %5d",diskinfo.fi_nclus);
printf("bytes per sector %5d",diskinfo.fi_bysec);
}
return 0;
}


@函数名称: getpsp
函数原型: unsigned getpsp(void)
函数功能: 得到程序段前缀PSP的段地址(dos3.0的产物)
函数返回: PSP的段地址
参数说明:
所属文件: <dos.h>

include <stdio.h>
#include <dos.h>

int main()
{
static char command[128];
char far *cp;
int len,i;

printf("The program segment prefix is: %u\n",getpsp());

/* _psp is preset to segment of the PSP
Command line is located at offset 0x81 from start of PSP */
cp=(char *)MK_FP(_psp, 0x80);
len=*cp;
for(i=0;i<len;i++)
command=cp[i+1];
printf("Command line: %s\n",command);
return 0;
}


@函数名称: setverify
函数原型: void setverify(int value)
函数功能: 设置DOS磁盘操作中确认标志的状态
函数返回:
参数说明: value=0:磁盘操作无需确认,value=1:磁盘操作需要确认
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define INTR 0X1C
void interrupt(*oldhandler)();
int count=0;
void interrupt handler()
{
count++;
oldhandler();
}
int main()
{
oldhandler=getvect(INTR);
setvect(INTR,handler);
while (count<20)
printf("count is %d",count);
setvect(INTR,oldhandler);
return 0;
}


@函数名称: getverify
函数原型: int getverify(void)
函数功能: 得到DOS确认标志的状态
函数返回: 0-标识为off,1-标识为on
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
if (getverify())
printf("DOS verify flag is on");
else
printf("DOS verify flag is off");
return 0;
}


@函数名称: geninterrupt
函数原型: void geninterrupt(int intr)
函数功能: 产生DOS软中断
函数返回:
参数说明: intr-中断号
所属文件: <dos.h>

#include <conio.h>
#include <dos.h>
void writechar(char ch);
int main()
{
clrscr();
gotoxy(80,25);
writechar('*');
getch();
return 0;
}
void writechar(char ch)
{
struct text_info ti;
gettextinfo(&ti);
_AH=9;
_AL=ch;
_BH=0;
_BL=ti.attribute;
_CX=1;
geninterrupt(0x10);
}


@函数名称: enable
函数原型: void enable(void)
函数功能: 允许中断
函数返回:
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define INTR 0X1C
void interrupt (*oldhandler)();
int count=0;
void interrupt handler()
{
disable();
count++;
enable();
oldhandler();
}
int main()
{
oldhandler=getvect(INTR);
setvect(INTR,handler);
while (count<20)
printf("count is %d",count);
setvect(INTR,oldhandler);
return 0;
}


@函数名称: disable
函数原型: void disable(void)
函数功能: 禁止所有中断(不包括NMI中断)
函数返回:
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define INTR 0X1C
void interrupt (*oldhandler)();
int count=0;
void interrupt handler()
{
disable();
count++;
enable();
oldhandler();
}
int main()
{
oldhandler=getvect(INTR);
setvect(INTR,handler);
while (count<20)
printf("count is %d",count);
setvect(INTR,oldhandler);
return 0;
}


@函数名称: interrupt
函数原型: void interrupt(*getvect(int intr)) (void)
函数功能: 申明一个函数为中断函数,该中断函数的中断号为intr
函数返回: 以上不是一个函数,实际上是说明了中断函数的格式,
比如我们要将一个函数fun()说明成中断函数,可写成: void interrupt( *fun )();
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
void interrupt yourisr() /* Interrupt Service Routine (ISR) */
{
disable();
/* Body of ISR goes here */
oldhandler();
outportb(0x20,0x20); /* Send EOI to PIC1 */
enable();
}

#define INTNO 0x0B

int main()
{
oldhandler = getvect(INTNO); /* Save Old Interrupt Vector */
setvect(INTNO, yourisr); /* Set New Interrupt Vector Entry */
outportb(0x21,(inportb(0x21) & 0xF7)); /* Un-Mask (Enable) IRQ3 */

/* Set Card - Port to Generate Interrupts */

/* Body of Program Goes Here */

/* Reset Card - Port as to Stop Generating Interrupts */

outportb(0x21,(inportb(0x21) | 0x08)); /* Mask (Disable) IRQ3 */
setvect(INTNO, oldhandler); /* Restore old Interrupt Vector Before Exit */
return 0;
}


@函数名称: setvect,getvect
函数原型: void setvect(int interruptno, void interrupt (*isr)())
函数功能: 为指定的中断向量设置中断服务函数
函数返回: getvect返回interruptno中保存的4字节值
参数说明: interruptno-中断向量,isr-中断函数,该函数应使用interrupt关键字声明
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
#include <conio.h>

#define INTR 0X1C /* The clock tick interrupt */

#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif

void interrupt ( *oldhandler)(__CPPARGS);

int count=0;

void interrupt handler(__CPPARGS)
{ /* increase the global counter */
count++;
/* call the old routine */
oldhandler();
}

int main()
{
/* save the old interrupt vector */
oldhandler = getvect(INTR);
/* install the new interrupt handler */
setvect(INTR,handler);
/* loop until the counter exceeds 20 */
while (count<20)
printf("count is %d\n",count);
/* reset the old interrupt handler */
setvect(INTR,oldhandler);
return 0;
}

用户名: 密码: 登录 注册
Change Your MindWhere could you find my heart?主页博客相册个人档案好友i贴吧

查看文章

dos.h函数详解(3/6)
2009-04-13 18:21
@函数名称: inport
函数原型: int inport(int port)
函数功能: 返回从指定的I/O端口读入一个字(16位数)
函数返回: 读入的字数值
参数说明: port-I/O端口地址
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
int result;
int port=0;
result=inport(port);
printf("Word read from port %d=0x%X",port,result);
return 0;
}


@函数名称: inportb
函数原型: int inportb(int port)
函数功能: 返回从指定的I/O端口读入一个字节(8位数))
函数返回: 读入的字数值
参数说明: port-I/O端口地址
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
int result;
int port=0;
result=inportb(port);
printf("Word read from port %d=0x%X",port,result);
return 0;
}


@函数名称: outport
函数原型: void outport(int port, int value)
函数功能: 向port地址的接口输出value
函数返回:
参数说明: port-端口地址,value-要输出的16位数
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
int value=64;
int port=0;
outportb(port,value);
printf("Value %d sent to port number %d",value,port);
return 0;
}


@函数名称: outportb
函数原型: void outportb(unsigned char port, unsigned char value)
函数功能: 向port地址的接口输出value
函数返回:
参数说明: port-端口地址,value-要输出的8位数
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
int value=64;
int port=0;
outportb(port,value);
printf("Value %d sent to port number %d",value,port);
return 0;
}


@函数名称: intdos
函数原型: int intdos(union REGS *inregs, union REGS *outregs)
函数功能: 调用DOS的INT21中断
函数返回: AX
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int delete_file(char near *filename)
{
union REGS regs;
int ret;
regs.h.ah=0x41;
regs.x.dx=(unsigned) filename;
ret=intdos(&regs,&regs);
return(regs.x.cflag ? ret : 0);
}
int main()
{
int err;
err=delete_file("NOTEXIST.$$$");
if (!err)
printf("Able to delete NOTEXIST.$$$");
else
printf("Not Able to delete NOTEXIST.$$$");
return 0;
}


@函数名称: intdosx
函数原型: int intdosx(union REGS *inregs, union REGS *outregs, struct SREGS *segregs)
函数功能: 调用DOS的INT21中断,主要用于大编译模式
函数返回: AX
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int delete_file(char far *filename)
{
union REGS regs;struct SREGS sregs;
int ret;
regs.h.ah=0x41;
regs.x.dx=FP_OFF(filename);
sregs.ds=FP_SEG(filename);
ret=intdosx(&regs,&regs,&sregs);
return(regs.x.cflag ? ret : 0);
}
int main()
{
int err;
err=delete_file("NOTEXIST.$$$");
if (!err)
printf("Able to delete NOTEXIST.$$$");
else
printf("Not Able to delete NOTEXIST.$$$");
return 0;
}


@函数名称: int86
函数原型: int int86(int intno, union REGS *inregs, union REGS *outregs)
函数功能: 调用中断号为intno的DOS软中断
函数返回: AX
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <conio.h>
#include <dos.h>
#define VIDEO 0x10
void movetoxy(int x,int y)
{
union REGS regs;
regs.h.ah=2;
regs.h.dh=y;
regs.h.dl=x;
regs.h.bh=0;
int86(VIDEO,&regs,&regs);
}
int main()
{
clrscr();
movetoxy(35,10);
printf("Hello");
return 0;
}


@函数名称: int86x
函数原型: int int86x(int intno, union REGS *inregs, union, REGS *outregs, struct SREGS *segregs)
函数功能: 调用中断号为intno的DOS软中断,主要用于大编译模式
函数返回: AX
参数说明:
所属文件: <dos.h>

#include <dos.h>
#include <process.h>
#include <stdio.h>
int main()
{
char filename[80];
union REGS inregs,outregs;
struct SREGS segregs;
printf("Enter filename: ");
gets(filename);
inregs.h.ah=0x43;
inregs.h.al=0x21;
inregs.x.dx=FP_OFF(filename);
segregs.ds=FP_SEG(filename);
int86x(0x21,&inregs,&outregs,&segregs);
printf("File attribute: %X",outregs.x.cx);
return 0;
}


@函数名称: intr
函数原型: void intr(int intno, struct REGPACK *preg)
函数功能: 调用中断号为intno的DOS软中断,是int86函数的一个替代函数
函数返回:
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <string.h>
#include <dir.h>
#include <dos.h>
#define CF 1
int main()
{
char directory[80];
struct REGPACK reg;
printf("Enter directory to change to: ");
gets(directory);
reg.r_ax=0x3B<<8;
reg.r_dx=FP_OFF(directory);
reg.r_ds=FP_SEG(directory);
intr(0x21,&reg);
if (reg.r_flags&CF)
printf("Directory change failed");
getcwd(directory,80);
printf("The current directory is: %s",directory);
return 0;
}


@函数名称: keep
函数原型: void keep(unsigned char status, unsigned size)
函数功能: 执行INT31中断来中止程序,但程序仍然驻留在内存中
函数返回:
参数说明: size-要驻留程序的大小,srarus-返回该DOS的状态数值
所属文件: <dos.h>

#include <dos.h>
#define INTR 0x1C
#define ATTR 0x7900
extern unsigned _heaplen=1024;
extern unsigned _stklen =512;
void interrupt (*oldhandler)();
void interrupt handler(void)
{
unsigned int(far *screen)[80];
static int count;
screen=MK_FP(0xB800,0);
count++;
count%=10;
screen[0][79]=count+'0'+ATTR;
oldhandler();
}
int main()
{
oldhandler=getvect(INTR);
setvect(INTR,handler);
keep(0,(_SS+(_SP/16)-_psp));
return 0;
}


@函数名称: parsfnm
函数原型: char *parsfnm(const char *cmdline, struct fcb *fcb, int opt)
函数功能: 该函数使用DOS中断调用0x29来将命令行字符转换为FCB格式
函数返回: 多项式的计算结果
参数说明: cmdline-命令行参数.opt-用于设置AL寄存器的数值
所属文件: <dos.h>

#include <process.h>
#include <string.h>
#include <stdio.h>
#include <dos.h>
int main()
{
char line[80];
struct fcb blk;
printf("Enter drive and file name");
gets(line);
if (parsfnm(line,&blk,1)==NULL)
printf("Error in parsfm call");
else
printf("Drive #%d Name: %11s",blk.fcb_drive,blk.fcb_name);
return 0;
}


@函数名称: peek
函数原型: int peek(unsigned segment, unsigned offset)
函数功能: 内存中读出一个字(16位)
函数返回: 读出的字内容
参数说明: segmemt-段地址,offset-段内偏移地址
所属文件: <dos.h>

#include <stdio.h>
#include <conio.h>
#include <dos.h>
int main()
{
int value=0;
printf("The current status of your keyboard is:");
value=peek(0x0040,0x0017);
if (value&1)
printf("Right shift on");
else
printf("Right shift off");
if (value&2)
printf("Left shift on");
else
printf("Left shift off");
if (value&4)
printf("Control key on");
else
printf("Control key off");
if (value&8)
printf("Alt key on");
else
printf("Alt key off");
if (value&16)
printf("Scroll lock on");
else
printf("Scroll lock off");
if (value&32)
printf("Num lock on");
else
printf("Num lock off");
if (value&64)
printf("Caps lock on");
else
printf("Caps lock off");
return 0;
}

类别:默认分类||添加到搜藏 |分享到i贴吧|浏览(481)|评论 (0)

上一篇:dos.h函数详解(2/6) 下一篇:dos.h函数详解(4/6)

最近读者:

网友评论:
发表评论:
姓 名: 注册 | 登录
网址或邮箱: (选填)
内 容:

 


帮助中心 | 空间客服 | 投诉中心 | 空间协议
?2012 Baidu

用户名: 密码: 登录 注册
Change Your MindWhere could you find my heart?主页博客相册个人档案好友i贴吧

查看文章

dos.h函数详解(4/6)
2009-04-13 18:22
@函数名称: peekb
函数原型: int peekb(unsigned segment, unsigned offset)
函数功能: 内存中读出一个字(8位)
函数返回: 读出的字内容
参数说明: segmemt-段地址,offset-段内偏移地址
所属文件: <dos.h>

#include <stdio.h>
#include <conio.h>
#include <dos.h>
int main()
{
int value=0;
printf("The current status of your keyboard is:");
value=peek(0x0040,0x0017);
if (value&1)
printf("Right shift on");
else
printf("Right shift off");
if (value&2)
printf("Left shift on");
else
printf("Left shift off");
if (value&4)
printf("Control key on");
else
printf("Control key off");
if (value&8)
printf("Alt key on");
else
printf("Alt key off");
if (value&16)
printf("Scroll lock on");
else
printf("Scroll lock off");
if (value&32)
printf("Num lock on");
else
printf("Num lock off");
if (value&64)
printf("Caps lock on");
else
printf("Caps lock off");
return 0;
}


@函数名称: poke
函数原型: void poke(unsigned segment, unsigned offset,int word)
函数功能: 往内存中写入一个字(16位)
函数返回:
参数说明: segmemt-段地址,offset-段内偏移地址,word-要写入的字
所属文件: <dos.h>

#include <dos.h>
#include <conio.h>
int main()
{
clrscr();
cprintf("Make sure the scroll lock key is off and press any key");
getch();
poke(0x0000,0x0417,16);
cprintf("The scroll lock is now on");
return 0;
}


@函数名称: pokeb
函数原型: void pokeb(unsigned segment, unsigned offset,char ch)
函数功能: 往内存中写入一个字(8位)
函数返回:
参数说明: segmemt-段地址,offset-段内偏移地址,ch-要写入的字
所属文件: <dos.h>

#include <dos.h>
#include <conio.h>
int main()
{
clrscr();
cprintf("Make sure the scroll lock key is off and press any key");
getch();
pokeb(0x0000,0x0417,16);
cprintf("The scroll lock is now on");
return 0;
}


@函数名称: randbrd
函数原型: int randbrd(struct fcb *fcb, int rcnt)
函数功能: 使用DOS 0x27中断,将文件内容读入磁盘缓冲区
函数返回: 0-读取所有记录
1-文件结束
2-循环读取
3-文件结束,但最后一条记录未完成
参数说明: rcnt-记录条数
所属文件: <dos.h>

#include <process.h>
#include <string.h>
#include <stdio.h>
#include <dos.h>
int main()
{
char far *save_dta;
char line[80],buffer[256];
struct fcb blk;
int i,result;
printf("Enter drive and file name");
gets(line);
if (!parsfnm(line,&blk,1))
{
printf("Error in call to parsfnm");
exit(1);
}
printf("Drive #%d File: %s",blk.fcb_drive,blk.fcb_name);
bdosptr(0x0F,&blk,0);
save_dta=getdta();
setdta(buffer);
blk.fcb_recsize=128;
blk.fcb_random=0L;
result=randbrd(&blk,1);
if (!result)
printf("Read OK");
else
{
perror("Error during read");
exit(1);
}
printf("The first 128 characters are:");
for (i=0;i<128;i++)
putchar(buffer);
setdta(save_dta);
return 0;
}


@函数名称: randbwr
函数原型: int randbwr(struct fcb *fcb, int rcnt)
函数功能: 使用DOS 0x28中断,将磁盘缓冲区内容写入文件
函数返回: 0-写完所有记录
1-磁盘空间不足,未操作
2-写记录绕回 0xFFFF
参数说明: rcnt-记录条数
所属文件: <dos.h>

#include <process.h>
#include <string.h>
#include <stdio.h>
#include <dos.h>
int main()
{
char far *save_dta;
char line[80];
char buffer[256]="RANDBWR test!";
struct fcb blk;
int result;
printf("Enter a file name to create");
gets(line);
parsfnm(line,&blk,1);
printf("Drive #%d File: %s",blk.fcb_drive,blk.fcb_name);
if (bdosptr(0x16,&blk,0)==-1)
{
perror("Error creating file");
exit(1);
}
save_dta=getdta();
setdta(buffer);
blk.fcb_recsize=256;
blk.fcb_random=0L;
result=randbwr(&blk,1);
if (!result)
printf("Write OK");
else
{
perror("Disk error");
exit(1);
}
if (bdosptr(0x10,&blk,0)==-1)
{
perror("Error closing file");
exit(1);
}
setdta(save_dta);
return 0;
}


@函数名称: segread
函数原型: void segread(struct SREGS *segp)
函数功能: 按SREGS格式设置断寄存器的数值
函数返回:
参数说明: 该函数得到的segp参数供intdosx和int86函数使用segp段寄存器内容,结构SREGS定义如下:
struct SREGS{
unsigned int es;
unsigned int cs;
unsigned int ss;
unsigned int ds;
};
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
struct SREGS segs;
segread(&segs);
printf("Current segment register settings");
printf("CS: %X DS: %X",segs.cs,segs.ds);
printf("ES: %X SS: %X",segs.es,segs.ss);
return 0;
}


@函数名称: sleep
函数原型: void sleep(unsigned seconds)
函数功能: seconds-停止运行的秒数
函数返回:
参数说明:
所属文件: <dos.h>

#include <dos.h>
#include <stdio.h>
int main()
{
int i;
for (i=1;i<5;i++)
{
printf("Sleeping for %d seconds",i);
sleep(i);
}
return 0;
}


@函数名称: setblock
函数原型: int setblock(unsigned segx,unsigned newsize)
函数功能: 修改段地址为segx的内存块的大小
函数返回:
参数说明: segx-内存块的段地址,该地址是使用allocmem分配的
所属文件: <dos.h>

#include <dos.h>
#include <alloc.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned int size,segp;
int stat;
size=64; /* (64 x 16)=1024 bytes */
stat=allocmem(size,&segp);
if (stat==-1)
printf("Allocated memory at segment: %X",segp);
else
{
printf("Failed: maximum number of paragraphs available is %d",stat);
exit(1);
}
stat=setblock(segp,size*2);
if (stat==-1)
printf("Expanded memory block at segment: %X",segp);
else
printf("Failed: maximum number of paragraphs available is %d",stat);
freemem(segp);
return 0;
}


@函数名称: unlink
函数原型: int unlink(const char *fname)
函数功能: 删除一个指定文件
函数返回: 0:操作成功,-1:操作失败
参数说明: fname-要删除的文件名称
所属文件: <dos.h>

#include <stdio.h>
#include <io.h>
int main()
{
FILE *fp=fopen("junk.jnk","w");
int status;
fprintf(fp,"junk");
status=access("junk.jnk",0);
if (status == 0)
printf("File exists");
else
printf("File doesn't exist");
fclose(fp);
unlink("junk.jnk");
status=access("junk.jnk",0);
if (status==0)
printf("File exists");
else
printf("File doesn't exist");
return 0;
}


@函数名称: dostounix
函数原型: long dostounix(struct data *d,struct time *t)
函数功能: 将DOS的日期和时间格式转换成UNIX标准
函数返回:
参数说明: d,t-日期和时间指针
所属文件: <dos.h>

#include <time.h>
#include <stddef.h>
#include <dos.h>
#include <stdio.h>
int main()
{
time_t t;
struct time d_time;
struct date d_date;
struct tm *local;
getdate(&d_date);
gettime(&d_time);
t=dostounix(&d_date,&d_time);
local=localtime(&t);
printf("Time and Date: %s",asctime(local));
return 0;
}


@函数名称: unixtodos
函数原型: void unixtodos(long utime, struct date *d, struct time *t)
函数功能: 将UNIX格式的时间和日期转换成DOS格式
函数返回:
参数说明: utime-UNIX格式的时间日期.d,t-DOS格式的日期时间
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
char *month[]={"---","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
#define SECONDS_PER_DAY 86400L
struct date dt;
struct time tm;
int main()
{
unsigned long val;
getdate(&dt);
gettime(&tm);
printf("today is %d %s %d",dt.da_day,month[dt.da_mon],dt.da_year);
val=dostounix(&dt,&tm);
val-=(SECONDS_PER_DAY*42);
unixtodos(val,&dt,&tm);
printf("42 days ago it was %d %s %d",dt.da_day,month[dt.da_mon],dt.da_year);
return 0;
}

类别:默认分类||添加到搜藏 |分享到i贴吧|浏览(128)|评论 (0)

上一篇:dos.h函数详解(3/6) 下一篇:dos.h函数详解(5/6)

最近读者:

网友评论:
发表评论:
姓 名: 注册 | 登录
网址或邮箱: (选填)
内 容:

 


帮助中心 | 空间客服 | 投诉中心 | 空间协议
?2012 Baidu

用户名: 密码: 登录 注册
Change Your MindWhere could you find my heart?主页博客相册个人档案好友i贴吧

查看文章

dos.h函数详解(5/6)
2009-04-13 18:22
@函数名称: absread
函数原型: int absread(int drive, int nsects, int sectnum, void *buffer)
函数功能: 对磁盘扇区读数据
函数返回: 0-操作成功,其他-操作失败
参数说明: driver-读取的驱动器号 0-表示驱动器A,以此类推
sectnum-读取的扇区号
msects-读取的扇区数
所属文件: <dos.h>

#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dos.h>
int main()
{
int i,strt,ch_out,sector;char buf[512];
printf("Insert a diskette into drive A and press any key");
getch();
sector=0;
if(absread(0,1,sector,&buf)!=0)
{
perror("Disk problem");
exit(1);
}
printf("Read OK");
strt=3;
for (i=0;i<80;i++)
{
ch_out=buf[strt+i];
putchar(ch_out);
}
printf("\n");
return(0);
}


@函数名称: abswrite
函数原型: int abswrite(int drive, int nsects, int sectnum, void *buffer)
函数功能: 对磁盘扇区写数据
函数返回: 0-操作成功,其他-操作失败
参数说明: driver-写入的驱动器号
sectnum-写入的扇区号
msects-写入的扇区数
buf-写入内容
所属文件: <dos.h>

#include <dos.h>
#include <stdio.h>

unsigned char buff[512];
/* 此程企图将FAT区和ROOT区清空从而快速格式化磁盘 */
int main()
{
int i;char c;
printf("Quick Format 1.44MB");
printf("ALL DATA IN THE FLOPPY DISK WILL BE LOST!!");
printf("Insert a diskette for drive A:");
printf("and press ENTER when ready. . .");c=getchar();
printf("Cleaning FAT area. . .");
buff[0]=0xf0;buff[1]=buff[2]=0xff;
for(i=3;i<512;i++)buff=0;
abswrite(0,1,1,buff);
abswrite(0,1,10,buff);
for(i=0;i<512;i++)buff=0;
for(i=2;i<10;i++)abswrite(0,1,i,buff);
for(i=11;i<19;i++)abswrite(0,1,i,buff);
printf("Cleaning ROOT area. . .");
for(i=19;i<33;i++)abswrite(0,1,i,buff);
printf("QuickFormat Completed!");
return 0;
}


@函数名称: allocmem
函数原型: int allocmem(unsigned size, unsigned * seg)
函数功能: 按节(16字节)分配内存块
函数返回: -1:分配成功,其他数值:实际分配的节数
参数说明: size-分配的节数,seg-分配后的段地址
所属文件: <dos.h>

#include <dos.h>
#include <malloc.h>
#include <stdio.h>
int main()
{
unsigned int size,segp;
int stat;
size=64; /* (64 x 16)=1024 bytes */
stat=allocmem(size,&segp);
if (stat==-1)
printf("Allocated memory at segment: %x",segp);
else
printf("Failed: maximum number of paragraphs available is %u",stat);
return 0;
}


@函数名称: bdos
函数原型: int bdos(int fnum, unsigned dx, unsigned al)
函数功能: 执行DOS系统调用INT 21H
函数返回: 寄存器AX的值
参数说明: fnum-系统调用号,dx,al-赋给DX,AL寄存器的值
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
char current_drive(void)
{
char curdrive;
curdrive=bdos(0x19,0,0);
return('A'+curdrive);
}
int main()
{
printf("The current drive is %c:",current_drive());
return 0;
}


@函数名称: country
函数原型: struct country *country(int countrycode, struct country *countryptr)
函数功能: 用于设置一些与国家相关的项目,如货币,时间日期的表示方式等
函数返回: 国家相关信息
参数说明: 结构定义:struct country{
int co_date; /*日期格式*/
char co_curr[5]; /*货币符号*/
char co_thsep[2]; /*数字分隔符*/
char co_desep[2]; /*小数点*/
char co_dtsep[2]; /*日期分隔符*/
char co_tmsep[2]; /*时间分隔符*/
char co_currstyle; /*货币形式*/
char co_digits; /*有效数字*/
int (far *co_case)(); /*事件处理函数*/
char co_dasep; /*数据分隔符*/
char co_fill[10]; /*补充字符*/
}
所属文件: <dos.h>

#include <dos.h>
#include <stdio.h>
#define USA 0
int main()
{
struct COUNTRY country_info;
country(USA,&country_info);
printf("The currency symbol for the USA is: %s",country_info.co_curr);
return 0;
}


@函数名称: ctrlbrk
函数原型: void ctrlbrk(int (*pfun)(vpod))
函数功能: 设置当Ctrl-Break组合键按下时,应执行的函数
函数返回:
参数说明: pfun-要执行的函数指针,该函数应返回0值
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
#define ABORT 0
int c_break()
{
printf("Control-Break pressed. Program aborting ...");
return (ABORT);
}
int main()
{
ctrlbrk(c_break);
for(;;)
printf("Looping... Press <Ctrl-Break> to quit:");
return 0;
}


@函数名称: dosexterr
函数原型: int dosexterr(struct DOSERR *err)
函数功能: 得到DOS扩展调用失败时的错误信息
函数返回: 错误信息保存在err结构中
参数说明: err-用于保存错误信息的结构指针
关于DOS extended error代码(即:struct DOSERR.exterror)各系统差别极大,不一一列出
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
FILE *fp;
struct DOSERROR info;
fp=fopen("perror.dat","r");
if (!fp) perror("Unable to open file for reading");
dosexterr(&info);
printf("Extended DOS error information:\n");
printf("Extended error: %d\t",info.exterror);
printf("Class: %x\n",info.class);
printf("Action: %x\t",info.action);
printf("Error Locus: %x\n",info.locus);
return 0;
}


@函数名称: getcbrk
函数原型: int getcbrk(void)
函数功能: 检测对Ctrl-Break按下的检测是否允许
函数返回: 0-允许检测,1-不允许检测
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
if (getcbrk())
printf("Cntrl-brk flag is on");
else
printf("Cntrl-brk flag is off");
return 0;
}


@函数名称: getdate
函数原型: void getdate(struct date *d)
函数功能: 得到系统日期
函数返回:
参数说明: d 存放得到的日期信息
所属文件: <dos.h>

#include <dos.h>
#include <stdio.h>
int main()
{
struct date d;
getdate(&d);
printf("The current year is: %d",d.da_year);
printf("The current day is: %d",d.da_day);
printf("The current month is: %d",d.da_mon);
return 0;
}


@函数名称: setdate
函数原型: void setdate(struct date *datep)
函数功能: 设置DOS日期
函数返回:
参数说明: datep-要设置的日期数值,struct date定义格式如下:
struct date{
int da_year;
char da_day;
char da_mon;
};
所属文件: <dos.h>

#include <stdio.h>
#include <process.h>
#include <dos.h>
int main()
{
struct date reset;
struct date save_date;
getdate(&save_date);
printf("Original date:");
system("date");
reset.da_year=2001;
reset.da_day=1;
reset.da_mon=1;
setdate(&reset);
printf("Date after setting:");
system("date");
setdate(&save_date);
printf("Back to original date:");
system("date");
return 0;
}


@函数名称: settime
函数原型: void settime(struct time *timep)
函数功能: 设置DOS时间
函数返回:
参数说明: timep-要设置的时间数值,struct time定义格式如下:
struct time{
unsigned char ti_min;
unsigned char ti_hour;
unsigned char ti_hund;
unsigned char ti_sec;
};
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
struct time t;
gettime(&t);
printf("The current minute is: %d",t.ti_min);
printf("The current hour is: %d",t.ti_hour);
printf("The current hundredth of a second is: %d",t.ti_hund);
printf("The current second is: %d",t.ti_sec);
t.ti_min++;
settime(&t);
return 0;
}


@函数名称: gettime
函数原型: void gettime(struct date *t)
函数功能: 得到系统时间
函数返回:
参数说明: d 存放得到的日期信息
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
struct time t;
gettime(&t);
printf("The current time is: %2d:%02d:%02d.%02d",t.ti_hour,t.ti_min,t.ti_sec,t.ti_hund);
return 0;
}


@函数名称: getdfree
函数原型: void getdfree(int drive, struct dfree *dfptr)
函数功能: 得到驱动器的剩余磁盘空间
函数返回: 以结构返回:struct dfree{
unsigned df_avail; /* 可用簇数 */
unsigned df_total; /* 总簇数 */
unsigned df_bsec; /* 每扇区字节数 */
unsigned df_sclus; /* 每簇扇区数 */
}
参数说明: drive-驱动器号:1-A盘,2-B盘……
所属文件: <dos.h>

#include <stdio.h>
#include <stdlib.h>
#include <dir.h>
#include <dos.h>

int main()
{
struct dfree free;
long avail;
int drive;

drive=getdisk();
getdfree(drive+1,&free);
if(free.df_sclus==0xFFFF)
{
printf("Error in getdfree() call\n");
exit(1);
}
avail=(long)free.df_avail * (long)free.df_bsec * (long)free.df_sclus;
printf("Drive %c: has %ld bytes available\n",'A'+drive,avail);
return 0;
}


类别:默认分类||添加到搜藏 |分享到i贴吧|浏览(135)|评论 (0)

上一篇:dos.h函数详解(4/6) 下一篇:dos.h函数详解(6/6)

最近读者:

网友评论:
发表评论:
姓 名: 注册 | 登录
网址或邮箱: (选填)
内 容:

 


帮助中心 | 空间客服 | 投诉中心 | 空间协议
?2012 Baidu

用户名: 密码: 登录 注册
Change Your MindWhere could you find my heart?主页博客相册个人档案好友i贴吧

查看文章

dos.h函数详解(6/6)
2009-04-13 18:23
@函数名称: setdta
函数原型: void setdta(char far *dta)
函数功能: 设置DTA(磁盘传送区)地址
函数返回:
参数说明: dta-缓冲区地址指针
所属文件: <dos.h>

#include <process.h>
#include <string.h>
#include <stdio.h>
#include <dos.h>

int main()
{
char line[80],far *save_dta;
char buffer[256]="SETDTA test!";
struct fcb blk;
int result;
/* get new file name from user */
printf("Enter a file name to create:");
gets(line);
/* pass the new file name to the dta */
parsfnm(line,&blk,1);
printf("%d %s\n",blk.fcb_drive,blk.fcb_name);
/* request DOS services to create file */
if(bdosptr(0x16,&blk,0)==-1)
{
perror("Error creating file");
exit(1);
}
/* save old dta and set new dta */
save_dta=getdta();
setdta(buffer);
/* write new records */
blk.fcb_recsize=256;
blk.fcb_random=0L;
result=randbwr(&blk,1);
printf("result=%d\n",result);
if (!result)
printf("Write OK\n");
else
{
perror("Disk error");
exit(1);
}
/* request DOS services to close the file */
if (bdosptr(0x10,&blk,0)==-1)
{
perror("Error closing file");
exit(1);
}
/* reset the old dta */
setdta(save_dta);
return 0;
}


@函数名称: getdta
函数原型: char far * getdta(void)
函数功能: 得到磁盘传送地址(DTA)的指针
函数返回: 磁盘传送地址(DTA)的指针
参数说明:
所属文件: <dos.h>

#include <dos.h>
#include <stdio.h>
int main()
{
char far *dta;
dta=getdta();
printf("The current disk transfer address is: %Fp",dta);
return 0;
}


@函数名称: getfat
函数原型: void getfat(int drive, struct fatinfo *fptr)
函数功能: 得到磁盘驱动器的信息
函数返回:
参数说明: drive-驱动器号:1-A盘,2-B盘,以此类推.fptr-磁盘驱动器的信息
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
struct fatinfo diskinfo;
int flag=0;
printf("lease insert disk in drive A");
getchar();
getfat(1,&diskinfo);
printf("Drive A: is ");
switch((unsigned char) diskinfo.fi_fatid)
{
case 0xFD:printf("360K low density");break;
case 0xF9:printf("1.2 Meg high density");break;
default:printf("unformatted");flag=1;
}
if(!flag)
{
printf("sectors per cluster %5d",diskinfo.fi_sclus);
printf("number of clusters %5d",diskinfo.fi_nclus);
printf("bytes per sector %5d",diskinfo.fi_bysec);
}
return 0;
}


@函数名称: getfatd
函数原型: void getfatd(struct fatinfo *fptr)
函数功能: 得到缺省驱动磁盘驱动器的信息
函数返回:
参数说明: fptr-磁盘驱动器的信息
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
struct fatinfo diskinfo;
int flag=0;
printf("lease insert disk in drive A");
getchar();
getfat(1,&diskinfo);
printf("Drive A: is ");
switch((unsigned char) diskinfo.fi_fatid)
{
case 0xFD:printf("360K low density");break;
case 0xF9:printf("1.2 Meg high density");break;
default:printf("unformatted");flag=1;
}
if(!flag)
{
printf("sectors per cluster %5d",diskinfo.fi_sclus);
printf("number of clusters %5d",diskinfo.fi_nclus);
printf("bytes per sector %5d",diskinfo.fi_bysec);
}
return 0;
}


@函数名称: getpsp
函数原型: unsigned getpsp(void)
函数功能: 得到程序段前缀PSP的段地址(dos3.0的产物)
函数返回: PSP的段地址
参数说明:
所属文件: <dos.h>

include <stdio.h>
#include <dos.h>

int main()
{
static char command[128];
char far *cp;
int len,i;

printf("The program segment prefix is: %u\n",getpsp());

/* _psp is preset to segment of the PSP
Command line is located at offset 0x81 from start of PSP */
cp=(char *)MK_FP(_psp, 0x80);
len=*cp;
for(i=0;i<len;i++)
command=cp[i+1];
printf("Command line: %s\n",command);
return 0;
}


@函数名称: setverify
函数原型: void setverify(int value)
函数功能: 设置DOS磁盘操作中确认标志的状态
函数返回:
参数说明: value=0:磁盘操作无需确认,value=1:磁盘操作需要确认
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define INTR 0X1C
void interrupt(*oldhandler)();
int count=0;
void interrupt handler()
{
count++;
oldhandler();
}
int main()
{
oldhandler=getvect(INTR);
setvect(INTR,handler);
while (count<20)
printf("count is %d",count);
setvect(INTR,oldhandler);
return 0;
}


@函数名称: getverify
函数原型: int getverify(void)
函数功能: 得到DOS确认标志的状态
函数返回: 0-标识为off,1-标识为on
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
int main()
{
if (getverify())
printf("DOS verify flag is on");
else
printf("DOS verify flag is off");
return 0;
}


@函数名称: geninterrupt
函数原型: void geninterrupt(int intr)
函数功能: 产生DOS软中断
函数返回:
参数说明: intr-中断号
所属文件: <dos.h>

#include <conio.h>
#include <dos.h>
void writechar(char ch);
int main()
{
clrscr();
gotoxy(80,25);
writechar('*');
getch();
return 0;
}
void writechar(char ch)
{
struct text_info ti;
gettextinfo(&ti);
_AH=9;
_AL=ch;
_BH=0;
_BL=ti.attribute;
_CX=1;
geninterrupt(0x10);
}


@函数名称: enable
函数原型: void enable(void)
函数功能: 允许中断
函数返回:
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define INTR 0X1C
void interrupt (*oldhandler)();
int count=0;
void interrupt handler()
{
disable();
count++;
enable();
oldhandler();
}
int main()
{
oldhandler=getvect(INTR);
setvect(INTR,handler);
while (count<20)
printf("count is %d",count);
setvect(INTR,oldhandler);
return 0;
}


@函数名称: disable
函数原型: void disable(void)
函数功能: 禁止所有中断(不包括NMI中断)
函数返回:
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define INTR 0X1C
void interrupt (*oldhandler)();
int count=0;
void interrupt handler()
{
disable();
count++;
enable();
oldhandler();
}
int main()
{
oldhandler=getvect(INTR);
setvect(INTR,handler);
while (count<20)
printf("count is %d",count);
setvect(INTR,oldhandler);
return 0;
}


@函数名称: interrupt
函数原型: void interrupt(*getvect(int intr)) (void)
函数功能: 申明一个函数为中断函数,该中断函数的中断号为intr
函数返回: 以上不是一个函数,实际上是说明了中断函数的格式,
比如我们要将一个函数fun()说明成中断函数,可写成: void interrupt( *fun )();
参数说明:
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
void interrupt yourisr() /* Interrupt Service Routine (ISR) */
{
disable();
/* Body of ISR goes here */
oldhandler();
outportb(0x20,0x20); /* Send EOI to PIC1 */
enable();
}

#define INTNO 0x0B

int main()
{
oldhandler = getvect(INTNO); /* Save Old Interrupt Vector */
setvect(INTNO, yourisr); /* Set New Interrupt Vector Entry */
outportb(0x21,(inportb(0x21) & 0xF7)); /* Un-Mask (Enable) IRQ3 */

/* Set Card - Port to Generate Interrupts */

/* Body of Program Goes Here */

/* Reset Card - Port as to Stop Generating Interrupts */

outportb(0x21,(inportb(0x21) | 0x08)); /* Mask (Disable) IRQ3 */
setvect(INTNO, oldhandler); /* Restore old Interrupt Vector Before Exit */
return 0;
}


@函数名称: setvect,getvect
函数原型: void setvect(int interruptno, void interrupt (*isr)())
函数功能: 为指定的中断向量设置中断服务函数
函数返回: getvect返回interruptno中保存的4字节值
参数说明: interruptno-中断向量,isr-中断函数,该函数应使用interrupt关键字声明
所属文件: <dos.h>

#include <stdio.h>
#include <dos.h>
#include <conio.h>

#define INTR 0X1C /* The clock tick interrupt */

#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif

void interrupt ( *oldhandler)(__CPPARGS);

int count=0;

void interrupt handler(__CPPARGS)
{ /* increase the global counter */
count++;
/* call the old routine */
oldhandler();
}

int main()
{
/* save the old interrupt vector */
oldhandler = getvect(INTR);
/* install the new interrupt handler */
setvect(INTR,handler);
/* loop until the counter exceeds 20 */
while (count<20)
printf("count is %d\n",count);
/* reset the old interrupt handler */
setvect(INTR,oldhandler);
return 0;
}

类别:默认分类||添加到搜藏 |分享到i贴吧|浏览(410)|评论 (0)

上一篇:dos.h函数详解(5/6) 下一篇:bios.h函数详解(1/1)

最近读者:

网友评论:
发表评论:
姓 名: 注册 | 登录
网址或邮箱: (选填)
内 容:

 


帮助中心 | 空间客服 | 投诉中心 | 空间协议
?2012 Baidu

用户名: 密码: 登录 注册
Change Your MindWhere could you find my heart?主页博客相册个人档案好友i贴吧

查看文章

bios.h函数详解(1/1)
2009-04-13 18:26
@函数名称: bioscom
函数原型: int bioscom(int cmd,char byte,int port)
函数功能: RS232串口通信口操作
函数返回: 16位的串口状态信息,各位的含义分别如下:
当cmd=2时,低8位用于保存接收的数据
高8位 低8位(cmd=0,1,3时) B15-超时错误
B7-检测到线路信号 B14-发送移位寄存器空
B6-振铃指示 B13-发送保持寄存器空
B5-数据装置就绪 B12-中止检测错误
B4-数据发送结束 B11-帧错误
B3-线路信号变化 B10-奇偶错误
B2-脉冲后沿振铃检测 B9-溢出错误
B1-数据装置就绪变化 B8-数据准备就绪
B0-数据发送结束变化
参数说明: cmd-控制字:0-初始化串口,1-发送一个字符,2-接受一个字符,3-返回串口状态
byte-波特率和发送位数设置:
B7,B6,B5-波特率设置:
9600波特-111,4800波特-110,2400波特-101 ,1200波特-100,600波特-011,300波特-010
B4,B3-奇偶校验设置:
00或10-无奇偶,01-奇校验,11-偶校验
B2-停止位个数:1-2个停止位,0-1个停止位
B1,B0 10-7个数据位,11-8个数据位 port 串口号:0,1,2,3等
所属文件: <bios.h>

#include <bios.h>
#include <conio.h>
#define COM1 0
#define DATA_READY 0x100
#define TRUE 1
#define FALSE 0
#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)
int main()
{
int in,out,status,DONE=FALSE;
bioscom(0,SETTINGS,COM1);
cprintf("... BIOSCOM [ESC] to exit ...");
while (!DONE)
{
status=bioscom(3,0,COM1);
if (status&DATA_READY)
if ((out=bioscom(2,0,COM1)&0x7F)!=0)
putch(out);
if (kbhit())
{
if ((in=getch())==' ')
DONE=TRUE;
bioscom(1,in,COM1);
}
}
return 0;
}


@函数名称: biosdisk
函数原型: int biosdisk(int cmd,int driver,int head,int track,int sector,int nsets,void *buf)
函数功能: RS232串口通信口操作
函数返回: AH
参数说明: 使用INT13完成BIOS级的磁盘操作
所属文件: <bios.h>

#include <bios.h>
#include <stdio.h>
int main()
{
int result;
char buffer[512];
printf("Testing to see if drive a: is ready");
result=biosdisk(4,0,0,0,0,1,buffer);
result&=0x02;
(result) ? (printf("Drive A: Ready")) : (printf("Drive A: Not Ready"));
return 0;
}


@函数名称: biosequip
函数原型: int biosequip(void)
函数功能: 返回一个表示计算机设备配置的编码
函数返回: 一个字节:
FEDC BA98 7654 3210
---- ---- ---- ---1 磁盘已安装
---- ---- ---- --1- 浮点协处理器已安装
---- ---- ---- XX-- RAM:00=16k,01=32k,10=48k,11=64k
---- ---- --XX ---- 初始显示模式:01=40彩,10=80彩,11=单色
---- ---- XX-- ---- 磁盘数
---- ---1 ---- ---- 无DMA
---- XXX- ---- ---- 已安装的串口数
---1 ---- ---- ---- 游戏卡已安装
--1- ---- ---- ---- modem
XX-- ---- ---- ---- 并行打印机数
参数说明:
所属文件: <bios.h>

#include <bios.h>
#include <stdio.h>
int main()
{
int equip_check;
equip_check=biosequip();
if(equip_check & 0X0002)
printf("There is a math coprocessor installed.\n");
else
printf("No math coprocessor installed.\n");
return 0;
}


@函数名称: bioskey
函数原型: int bioskey(int cmd)
函数功能: 读取键盘值
函数返回: 当cmd=0时,按键的ascii值放在低位,扫描码放在高位
参数说明: cmd=0:返回一个键盘值,如无键盘按下,一直等
cmd=1:查询键盘是否按下:
0-无键按下,非0-有键按下
cmd=2:返回控制键状态,返回值保存在低8位中
0-右边的shift键按下 5-已打开Scroll_Lock
1-左边的shift键按下 6-已打开Num_Lock
3-Ctrl键按下 7-已打开Caps_Lock
4-Alt键按下 8-已打开Insert
所属文件: <bios.h>

#include <stdio.h>
#include <bios.h>
#include <ctype.h>
int main()
{
int key, shift;
int lastshift;
while (1)
{
shift=bioskey(2);
if(shift!=lastshift)
printf("Shift=0x% 02x\n",shift);
if(bioskey(1))
{
key=bioskey(0);
if((key&0xFF)=='q')
break;
printf("Key=0x% 04x",key);
}
lastshift=shift;
}
return 0;
}


@函数名称: biosmemory
函数原型: int biosmemory(void)
函数功能: 返回系统配置的内存大小(单位:KB)
函数返回: 内存大小值(KB)
参数说明:
所属文件: <bios.h>

#include <stdio.h>
#include <bios.h>
int main()
{
int memory_size;
memory_size=biosmemory();
printf("RAM size=%dK",memory_size);
return 0;
}


@函数名称: biostime
函数原型: long biostime(int cmd , long newtime)
函数功能: 设置和读取BIOS时钟
函数返回: cmd=0时,返回时钟值.该时钟为一个每秒18.2次的计数累计值,并在每日24时清零
参数说明: cmd=0:读取时钟,cmd=1:设置时钟
newtime-当cmd=1时,为新的设置数值
所属文件: <bios.h>

#include <stdio.h>
#include <bios.h>
#include <time.h>
#include <conio.h>
int main()
{
long bios_time;
clrscr();
cprintf("The number of clock ticks since midnight is:");
cprintf("The number of seconds since midnight is:");
cprintf("The number of minutes since midnight is:");
cprintf("The number of hours since midnight is:");
cprintf("ress any key to quit:");
while(!kbhit())
{
bios_time=biostime(0,0L);
gotoxy(50,1);
cprintf("%lu",bios_time);
gotoxy(50,2);
cprintf("%.4f",bios_time/CLK_TCK);
gotoxy(50,3);
cprintf("%.4f",bios_time/CLK_TCK/60);
gotoxy(50,4);
cprintf("%.4f",bios_time/CLK_TCK/3600);
}
return 0;
}

类别:默认分类||添加到搜藏 |分享到i贴吧|浏览(94)|评论 (0)

上一篇:dos.h函数详解(6/6) 下一篇:Eclipse环境下如何建立Robocode...

最近读者:

网友评论:
发表评论:
姓 名: 注册 | 登录
网址或邮箱: (选填)
内 容:

 


帮助中心 | 空间客服 | 投诉中心 | 空间协议
?2012 Baidu

posted @ 2012-05-18 20:17  quasi-mathematician  阅读(1092)  评论(0编辑  收藏  举报