dos.h

dos.h

這是一個頭檔案,裡面包含了很多BIOS和DOS調用函式

檔案介紹,檔案內容,包含的函式,peekb,poke,pokeb,ranbrd,randbwr,segread,sleep,setblock,unlink,dostounix,unixtodos,

檔案介紹

這是一個頭檔案,裡面包含了很多BIOSDOS調用函式

檔案內容

/*
* 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;
}

unlink

函式名稱: 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;
}

unixtodos

函式名稱: 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;
}
未完待續.

相關詞條

熱門詞條

聯絡我們