/*
XMS.INC
*/
int xms_init() /* 检测扩充内存服务程序 */
{ union REGS r;
r.x.ax=0x4300;
int86(0x2f,&r,&r);
if(r.h.al!=0x80) return(ERROR); /* 无HIMEM.SYS */
if( (xms_2_basemem_buffer=malloc(XMS_BUF))==NULL ) return(ERROR);
return(OK);
}
int end_xms()
{
free(xms_2_basemem_buffer);
}
int xms_free(int xms_handle) /* 释放由句柄占用的扩充内存 */
{ union REGS r;
r.h.ah=0x0a;
r.x.dx=xms_handle;
xms_interface(&r,&r);
if(r.x.ax==0) return(ERROR);
return(OK);
}
int xms_movedata( struct xms_move *m ) /*将数据在扩充内在与基本内存之间传送*/
{ union REGS r; /* 需要将xms_move结构传送过来 */
r.h.ah=0x0b;
r.x.si=(unsigned)m;
xms_interface(&r,&r);
if(r.x.ax==0) return(ERROR);
return(OK);
}
int xms_malloc( UINT memKB ) /*分配以KB计量的扩充内存,如不为ERROR,则返回句柄*/
{ union REGS r;
r.h.ah=9;
r.x.dx=memKB; /* must kb */
xms_interface(&r,&r);
if(r.x.ax==0) return(ERROR);
return(r.x.dx); /* return mem fp */
}
void xms_interface(union REGS *inregs,union REGS *outregs)
{ union REGS in,out; /* 提供扩充内存服务的接口函数 */
struct SREGS sregs;
void far (*xms)(void);
in.x.ax=0x4310;
int86x(0x2f,&in,&out,&sregs);
xms=(void far *)( ((long)(sregs.es)<<16)+out.x.bx );
_AX=inregs->x.ax;
_CX=inregs->x.cx;
_DX=inregs->x.dx;
_SI=inregs->x.si;
_DI=inregs->x.di;
_BX=inregs->x.bx;
xms();
outregs->x.ax=_AX;
outregs->x.bx=_BX;
outregs->x.cx=_CX;
outregs->x.dx=_DX;
outregs->x.si=_SI;
outregs->x.di=_DI;
}
本文地址:http://com.8s8s.com/it/it25145.htm