#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <string.h>
int check_for_ems(void)
{
union REGS inregs, outregs;
struct SREGS segs;
int major, minor; // DOS version
struct DeviceHeader {
struct DeviceHeader far *link;
unsigned attributes;
unsigned strategy_offset;
unsigned interrupt_offset;
char name_or_number_of_units[8];
} far *dev;
int i;
char driver_name[9];
// Get the DOS version
inregs.x.ax = 0x3001;
intdos (&inregs, &outregs);
major = outregs.h.al;
minor = outregs.h.ah;
if (major < 2)
return(0); // Requires DOS 2.0
else
{
// Get the list of lists
inregs.h.ah = 0x52;
intdosx (&inregs, &outregs, &segs);
if (major == 2)
dev = (struct DeviceHeader far *)
MK_FP(segs.es + 1, outregs.x.bx + 7);
else if ((major == 3) && (minor == 0))
dev = (struct DeviceHeader far *)
MK_FP(segs.es + 2, outregs.x.bx + 8);
else
dev = (struct DeviceHeader far *)
MK_FP(segs.es + 2, outregs.x.bx + 2);
while (FP_OFF(dev) != 0xFFFF)
{
if (dev->attributes & 0x8000)
{ // Character device
for (i = 0; i < 8; i++)
driver_name[i] = dev->name_or_number_of_units[i];
driver_name[8] = NULL;
}
if (! strcmp(driver_name, "EMMXXXX0"))
return(1); // Found driver
dev = dev->link;
}
}
return(0);
}
void main (void)
{
union REGS inregs, outregs;
struct SREGS segs;
unsigned handle;
unsigned page;
unsigned index, page_number;
unsigned page_frame_address;
char far *data;
if (check_for_ems())
{
inregs.h.ah = 0x40;
int86 (0x67, &inregs, &outregs);
// Make sure EMS is functional
if (outregs.h.ah == 0)
{
// Allocate a handle for 5 pages
inregs.h.ah = 0x43;
inregs.x.bx = 5;
int86 (0x67, &inregs, &outregs);
if (outregs.h.ah == 0)
{
handle = outregs.x.dx;
// Get the page frame address
inregs.h.ah = 0x41;
int86 (0x67, &inregs, &outregs);
if (outregs.h.ah == 0)
{
page_frame_address = outregs.x.bx;
// map the first 4 pages
for (page_number = 0; page_number < 4; page_number++)
{
inregs.h.ah = 0x44;
inregs.h.al = page_number; // Physical page
inregs.x.bx = page_number; // Logical page
inregs.x.dx = handle;
int86 (0x67, &inregs, &outregs);
if (outregs.h.ah != 0)
{
printf ("Error mapping pages %xH\n",
outregs.h.ah);
// Release the handle
inregs.h.ah = 0x45;
inregs.x.dx = handle;
int86 (0x67, &inregs, &outregs);
exit(0);
}
}
// Fill the first four pages
data = (char far *) MK_FP(page_frame_address, 0);
for (index = 0; index < 16384; index++)
data[index] = 'A';
for (index = 16384; index < 32768; index++)
data[index] = 'B';
for (index = 32768; index < 49152; index++)
data[index] = 'C';
for (index = 49152; index != 0; index++)
data[index] = 'D';
// Map logical page 4 into physical page 1
inregs.h.ah = 0x44;
inregs.h.al = 1; // Physical page
inregs.x.bx = 4; // Logical page
inregs.x.dx = handle;
int86 (0x67, &inregs, &outregs);
if (outregs.h.ah != 0)
{
printf ("Error mapping page %xH\n",
outregs.h.ah);
// Release the handle
inregs.h.ah = 0x45;
inregs.x.dx = handle;
int86 (0x67, &inregs, &outregs);
exit(0);
}
// Fill page 4 which resides in page 1
for (index = 16384; index < 32768; index++)
data[index] = 'E';
// Display the first 20 bytes of each page
printf ("Physical Page Zero\n");
for (index = 0; index < 20; index++)
printf ("%c ", data[index]);
printf ("\nPhysical Page One\n");
for (index = 16384; index < 16404; index++)
printf ("%c ", data[index]);
printf ("\nPhysical Page Two\n");
for (index = 32768; index < 32788; index++)
printf ("%c ", data[index]);
printf ("\nPhysical Page Three\n");
for (index = 49152; index < 49172; index++)
printf ("%c ", data[index]);
// Map logical page 1 into physical page 3
inregs.h.ah = 0x44;
inregs.h.al = 3; // Physical page
inregs.x.bx = 1; // Logical page
inregs.x.dx = handle;
int86 (0x67, &inregs, &outregs);
if (outregs.h.ah != 0)
{
printf ("Error mapping page %xH\n",
outregs.h.ah);
// Release the handle
inregs.h.ah = 0x45;
inregs.x.dx = handle;
int86 (0x67, &inregs, &outregs);
exit(0);
}
printf ("\nMapping logical page 1 to physical page 3");
printf ("\nPhysical Page Three\n");
for (index = 49152; index < 49162; index++)
printf ("%c ", data[index]);
}
else
printf ("Error getting base address %xH\n",
outregs.h.ah);
// Release the handle
inregs.h.ah = 0x45;
inregs.x.dx = handle;
int86 (0x67, &inregs, &outregs);
}
else
printf ("Error allocating 5 pages %xH\n",
outregs.h.ah);
}
else
printf ("EMM not functional\n");
}
else
printf ("EMS driver not present\n");
}
没有合适的资源?快使用搜索试试~ 我知道了~
C语言经典练习例子教学
共205个文件
c:195个
pdb:2个
obj:1个
需积分: 0 0 下载量 98 浏览量
2024-03-23
17:36:42
上传
评论
收藏 91KB 7Z 举报
温馨提示
计算机二级c语言资料,各类练习例程,初学者学习教程
资源推荐
资源详情
资源评论
收起资源包目录
C语言经典练习例子教学 (205个子文件)
SHOWEMS.C 6KB
XMSDEMO.C 5KB
SYSTABLE.C 2KB
DELTREE.C 2KB
COPYDOS.C 2KB
SHOWCMOS.C 2KB
ALLFILES.C 1KB
FILETABL.C 1KB
SPLIT.C 975B
LOWCOPY.C 965B
DTBITS.C 938B
ALLTYPES.C 877B
HEAPNODE.C 845B
JULY4_94.C 840B
DOSCOPY.C 827B
MATHERR.C 803B
UMASK.C 791B
ACCESS.C 765B
FILLHEAP.C 736B
FILEDT.C 726B
FERROR.C 709B
PUTWGETW.C 706B
PUTCH.C 705B
TELLATTR.C 702B
DUP.C 699B
FMALLOC.C 689B
FUNCTOVR.C 680B
CALLOC.C 680B
MALLOC.C 668B
ADDVALUE.C 652B
CHK_DISK.C 648B
TRYAUTO.C 644B
DTIN.C 642B
CPRINTF.C 640B
CPUTS.C 630B
PUTS.C 630B
DTINF.C 613B
FSCANF.C 594B
UNGETCH.C 591B
AUTOINFO.C 573B
CONFCOPY.C 565B
LOCKING.C 551B
HEAPCHK.C 550B
SHOW_POS.C 546B
HANDLES.C 544B
SOPEN.C 543B
ALLOCA.C 542B
TELL.C 536B
TEXTCOPY.C 509B
DTOUT.C 506B
TEXTINFO.C 497B
HUGEINT.C 490B
SETVBUF.C 488B
PUTTEXT.C 481B
CHGPARAM.C 476B
DTOUTF.C 474B
USEADDR.C 470B
REALLOC.C 470B
NO_RECUR.C 469B
OK_RECUR.C 467B
DISKFREE.C 463B
NOCHANGE.C 461B
SETBACK.C 459B
NO_SPACE.C 456B
SETBUF.C 442B
FILENO.C 441B
FILELEN.C 440B
SHOWFACT.C 435B
SCR_POKE.C 434B
RANDSEED.C 433B
FULLNAME.C 407B
FREE.C 403B
CHSIZE.C 401B
HEAPWALK.C 399B
FPRINTF.C 398B
SHOWDIR.C 397B
NEWCHDIR.C 395B
GETCHE.C 394B
USEPARAM.C 391B
LOCKAUTO.C 390B
SAVESCR.C 390B
FILE_SCR.C 372B
SHOWSINH.C 365B
CGETS.C 356B
STRARRAY.C 348B
MAKEPATH.C 340B
WHEREXY.C 336B
STATIC.C 330B
USEPROTO.C 329B
MKTEMP.C 327B
GETFATD.C 323B
DELLINE.C 323B
MINMAX.C 322B
TWOCOUNT.C 321B
LOOPFACT.C 321B
MAP_RAND.C 317B
MEMCMP.C 317B
INSLINE.C 316B
SWAB.C 315B
CREATTMP.C 313B
共 205 条
- 1
- 2
- 3
资源评论
小驹德尔驾
- 粉丝: 15
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功