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

📄 xms.h

📁 c游戏编程从入门到精通_全部源代码和文档
💻 H
字号:
#ifndef TOTEM_XMS

#define TOTEM_XMS

#include <dos.h>

char XMS=0,HMA=0,UMB=0;

void (far *xms)(void);

char test_xms()
{
  asm {
    mov ax,0x4300
    int 0x2f
  }
  if (_AL==0x80) XMS=1;
  return(XMS);
}

void get_driver_address()
{
  if (XMS)
  {
    asm {
      mov ax,0x4310
      int 0x2f
    }
    xms=(void (far *)())(((long)(_ES)<<16)+_BX);
  }
}


void get_xms_version(unsigned *xms_ver,unsigned *int_ver)
{
  if (XMS)
  {
    asm mov ah,0x00
    xms();
    *xms_ver=_AX;
    *int_ver=_BX;
    HMA=_DX;
  }
}

char Request_HMA(unsigned size)
{
  char error_code=0xff;
  if (XMS)
  {
    asm {
      mov ah,0x01
      mov dx,size
    }
    xms();
    error_code=_BL;
  }
  return(error_code);
}

char Release_HMA()
{
  char error_code=0xff;
  if (XMS)
  {
    asm mov ah,0x02
    xms();
    error_code=_BL;
  }
  return(error_code);
}

char global_enable_A20()
{
  char error_code=0xff;
  if (XMS)
  {
    asm mov ah,0x03
    xms();
    error_code=_BL;
  }
  return(error_code);
}

char global_disable_A20()
{
  char error_code=0xff;
  if (XMS)
  {
    asm mov ah,0x04
    xms();
    error_code=_BL;
  }
  return(error_code);
}

char local_enable_A20()
{
  char error_code=0xff;
  if (XMS)
  {
    asm mov ah,0x05
    xms();
    error_code=_BL;
  }
  return(error_code);
}

char local_disable_A20()
{
  char error_code=0xff;
  if (XMS)
  {
    asm mov ah,0x06
    xms();
    error_code=_BL;
  }
  return(error_code);
}

char query_A20_state(unsigned *state)
{
  char error_code=0xff;
  if (XMS)
  {
    asm mov ah,0x07
    xms();
    *state=_AX;
    error_code=_BL;
  }
  return(error_code);
}

char query_free_xms(unsigned *max_block,unsigned *total)
{
  char error_code=0xff;
  if (XMS)
  {
    asm mov ah,0x08
    xms();
    *max_block=_AX;
    *total=_DX;
    error_code=_BL;
  }
  return(error_code);
}

char allocate_xms(unsigned size,unsigned *handle)
{
  char error_code=0xff;
  if (XMS)
  {
    asm {
      mov ah,0x09
      mov dx,size
    }
    xms();
    *handle=_DX;
    error_code=_BL;
  }
  return(error_code);
}

char free_xms(unsigned handle)
{
  char error_code=0xff;
  if (XMS)
  {
    asm {
      mov ah,0x0a
      mov dx,handle
    }
    xms();
    error_code=_BL;
  }
  return(error_code);
}

typedef struct xms_mov {
  unsigned long byte_count;             //移动的字节数
  unsigned source_handle;     		//源句柄
  unsigned long source_offset;          //源偏移量
  unsigned destination_handle;          //目的句柄
  unsigned long destination_offset;     //目的偏移量
} xmm;

char move_xms(xmm *xmm_ptr)
{
  char error_code=0xff;
  if (XMS)
  {
    unsigned xseg=FP_SEG(xmm_ptr),xoff=FP_OFF(xmm_ptr);
    asm {
      mov ah,0x0b
      mov si,xoff
      mov ds,xseg
    }
    xms();
    error_code=_BL;
  }
  return(error_code);
}

char lock_XMS_block(unsigned handle)
{
  char error_code=0xff;
  if (XMS)
  {
    asm {
      mov ah,0x0c
      mov dx,handle
    }
    xms();
    error_code=_BL;
  }
  return(error_code);
}

char unlock_XMS_block(unsigned handle)
{
  char error_code=0xff;
  if (XMS)
  {
    asm {
      mov ah,0x0d
      mov dx,handle
    }
    xms();
    error_code=_BL;
  }
  return(error_code);
}

typedef struct XMS_handle_info {
  unsigned char lock_count; 	//块锁定计数值
  unsigned char free_handle;	//可用的句柄
  unsigned size;                //句柄分配的块的容量(单位:K)
}xhi;
char get_handle_info(unsigned handle,xhi *handle_info)
{
  char error_code=0xff;
  if (XMS)
  {
    asm {
      mov ah,0x0e
      mov dx,handle
    }
    xms();
    error_code=_BL;
    handle_info->lock_count=_BH;
    handle_info->free_handle=_BL;
    handle_info->size=_DX;
  }
  return(error_code);
}

char reallocate_xms_block(unsigned handle,unsigned size)
{
  char error_code=0xff;
  if (XMS)
  {
    asm {
      mov ah,0x0f
      mov dx,handle
      mov bx,size
    }
    xms();
    error_code=_BL;
  }
  return(error_code);
}

typedef struct UMB_info {
  unsigned UMB_segment;
  unsigned size;
}ui;
char request_UMB(unsigned size,ui *info)
{
  char error_code=0xff;
  if (XMS)
  {
    asm {
      mov ah,0x10
      mov dx,size
    }
    xms();
    error_code=_BL;
    info->UMB_segment=_BX;
    info->size=_DX;
  }
  return(error_code);
}

char release_UMB(unsigned segment)
{
  char error_code=0xff;
  if (XMS)
  {
    asm {
      mov ah,0x10
      mov dx,segment
    }
    xms();
    error_code=_BL;
  }
  return(error_code);
}

#endif

⌨️ 快捷键说明

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