词条 | dos.h |
释义 | 这是一个头文件,里面包含了很多BIOS和DOS调用函数 概述这是一个头文件,里面包含了很多BIOS和DOS调用函数 文件内容/* * dos.h * This file has no copyright assigned and is placed in the Public Domain. * This file is a part of the mingw-runtime package. * No warranty is given; refer to the file DISCLAIMER within the package. * * DOS-specific functions and structures. * */ #ifndef _DOS_H_ #define _DOS_H_ /* All the headers include this file. */ #include <_mingw.h> #define __need_wchar_t #ifndef RC_INVOKED #include <stddef.h> #endif /* Not RC_INVOKED */ /* For DOS file attributes */ #include <io.h> #ifndef RC_INVOKED #ifdef __cplusplus extern "C" { #endif #ifndef __MSVCRT__ /* these are in CRTDLL, but not MSVCRT */ #ifndef __DECLSPEC_SUPPORTED extern unsigned int *_imp___basemajor_dll; extern unsigned int *_imp___baseminor_dll; extern unsigned int *_imp___baseversion_dll; extern unsigned int *_imp___osmajor_dll; extern unsigned int *_imp___osminor_dll; extern unsigned int *_imp___osmode_dll; #define _basemajor (*_imp___basemajor_dll) #define _baseminor (*_imp___baseminor_dll) #define _baseversion (*_imp___baseversion_dll) #define _osmajor (*_imp___osmajor_dll) #define _osminor (*_imp___osminor_dll) #define _osmode (*_imp___osmode_dll) #else /* __DECLSPEC_SUPPORTED */ __MINGW_IMPORT unsigned int _basemajor_dll; __MINGW_IMPORT unsigned int _baseminor_dll; __MINGW_IMPORT unsigned int _baseversion_dll; __MINGW_IMPORT unsigned int _osmajor_dll; __MINGW_IMPORT unsigned int _osminor_dll; __MINGW_IMPORT unsigned int _osmode_dll; #define _basemajor _basemajor_dll #define _baseminor _baseminor_dll #define _baseversion _baseversion_dll #define _osmajor _osmajor_dll #define _osminor _osminor_dll #define _osmode _osmode_dll #endif /* __DECLSPEC_SUPPORTED */ #endif /* ! __MSVCRT__ */ #ifndef _DISKFREE_T_DEFINED /* needed by _getdiskfree (also in direct.h) */ struct _diskfree_t { unsigned total_clusters; unsigned avail_clusters; unsigned sectors_per_cluster; unsigned bytes_per_sector; }; #define _DISKFREE_T_DEFINED #endif _CRTIMP unsigned __cdecl _getdiskfree (unsigned, struct _diskfree_t *); #ifndef _NO_OLDNAMES # define diskfree_t _diskfree_t #endif #ifdef __cplusplus } #endif #endif /* Not RC_INVOKED */ #endif /* Not _DOS_H_ */ 包含的函数peekb函数名称: 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函数名称: 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函数名称: 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; } ranbrd函数名称: 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函数名称: 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函数名称: 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函数名称: 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函数名称: 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; } unlike函数名称: 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函数名称: 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; } unixtodo函数名称: 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; } 未完待续. |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。