⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dos.part2.h

📁 C语言库函数介绍
💻 H
📖 第 1 页 / 共 2 页
字号:
    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[i]);
    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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -