| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 458 人关注过本帖
标题:XMS不好使呀!
只看楼主 加入收藏
beyondabcd
Rank: 1
等 级:新手上路
帖 子:112
专家分:0
注 册:2007-5-19
收藏
 问题点数:0 回复次数:1 
XMS不好使呀!

现存程序可以正常运行了,可是当图片复原后和图片的背景不完全一样呀!大家帮忙给看一看
最下面是整个程序包


#include "graphics.h"
#include<dos.h>

#include<conio.h>

#include "stdio.h"
#include "fcntl.h"
#include "malloc.h"
#include "io.h"
#include "showbmp.c"
#include "rsvga256.h"

typedef unsigned int XMS_HANDLE;
XMS_HANDLE xms_handle; /* 伪指针 */
XMS_HANDLE xms_save_restore_handle; /* 伪指针 */

typedef struct emm {
unsigned int length;
unsigned source_handle;
unsigned long source_offset;
unsigned dest_handle;
unsigned long dest_offset;
} xmm;
xmm xms;

int far(* XMS_Function)( );
int xms_installed( )
{
_AX=0x4300;
geninterrupt(0x2f);
if(_AL==0x80)
{
_AX=0x4310;
geninterrupt(0x2f);
XMS_Function=MK_FP(_ES,_BX);
return(1);
}
else
{
printf("XMS is not installed\n!");
return(0);
}
}

int test_xms(unsigned int size)
{
_AH=8;
XMS_Function( );
if(_AX<size)
{
printf("No enough XMS to be used!\n");
return(0);
}
else
return(1);
}

unsigned int alloc_xms(unsigned int size)
{
_DX=size;
_AH=9;
XMS_Function( );
if(_AX!=1)
{
printf("XMS allocation is error\n");
return(0);
}
else
return(_DX);
}


int move_xms()
{
if(XMS_Function( ))
{
_DS=FP_SEG(&xms);
_SI=FP_OFF(&xms);
_AH=0x0b;
XMS_Function( );

if(_AX!=1)
{
printf("XMS move error! %d\n",_BL);
return(0);
}

return(1);
}
else
return(0);
}

void free_xms(unsigned int handle)
{
_DX=handle;
_AH=0x0a;
XMS_Function( );
}


/*----------------------------------------------------------- */
/* 从常规内存缓冲区buf装载到扩充内存 */
/*-----------------------------------------------------------*/


void Write_To_XMS(char *buf, unsigned int size,unsigned handle,unsigned long offset)
{
xms.length=size;
xms.source_handle = 0;
xms.source_offset = FP_SEG((void far *)buf);
xms.source_offset <<= 16;
xms.source_offset += FP_OFF((void far *)buf);
xms.dest_handle = handle;
xms.dest_offset = offset;
move_xms(&xms);
}


/*----------------------------------------------------------- */
/* 从扩充内存中读取信息到常规内存缓冲区buf */
/*-----------------------------------------------------------*/
void Read_From_XMS(char *buf,unsigned int size,unsigned handle,unsigned long offset)
{
xms.length = size;
xms.source_handle = handle;
xms.source_offset = offset;
xms.dest_handle = 0;
xms.dest_offset = FP_SEG((void far *)buf);
xms.dest_offset <<= 16;
xms.dest_offset += FP_OFF((void far *)buf);
move_xms(&xms);
}


char sssbuf[300];
void Save_Image_XMS(int POPUP_x1,int POPUP_x2,int POPUP_y1,int POPUP_y2 )
{
int i,j;
unsigned int size;
unsigned long offset = 0;
char *pp;

size = (POPUP_x2-POPUP_x1+1)*(POPUP_y2-POPUP_y1+1)/1024+1;

if (test_xms(size)==0)
puts("not enough XMS");
if ((xms_save_restore_handle = alloc_xms(size)) == 0)
puts("XMS handle Error...\n");
for (i= POPUP_y1; i<=POPUP_y2;i++)
{
size = POPUP_x2-POPUP_x1;
pp = sssbuf;
for (j= POPUP_x1; j<=POPUP_x2;j++)
*pp++ = getpixel(j,i);
Write_To_XMS(sssbuf,size,xms_save_restore_handle,offset);
offset += size;
}
}


void Restore_Image_XMS(int POPUP_x1,int POPUP_x2,int POPUP_y1,int POPUP_y2)
{
int i,j;
unsigned short size;
unsigned long offset = 0;
char *pp;

size = POPUP_x2-POPUP_x1;
for (i= POPUP_y1; i<=POPUP_y2;i++)
{
Read_From_XMS(sssbuf,size,xms_save_restore_handle,offset);
offset += size;
pp = sssbuf;
for (j= POPUP_x1; j<=POPUP_x2;j++)
putpixel(j,i,*pp++);/* sssbuf[j-POPUP_x1]); */
}
free_xms(xms_save_restore_handle);
}


int huge rReturn_SVGA256(void)
{
return(SVGA640x480x256);
}

void main()
{ int iii=DETECT, jjj=0;
int aa=30;
installuserdriver("Svga256", rReturn_SVGA256); /* 对于svga256必需执行该函数以安装BGI驱动 */
initgraph(&iii, &jjj, "");
xms_installed( ); /*初始化一定要写上*/

show_bmp("main.bmp",0,0);
Save_Image_XMS(50,139,50,176 );
getch();
show_bmp("bell.bmp",50,50);
getch();
Restore_Image_XMS(50,139,50,176);
getch();
closegraph();
}

大家帮帮忙吧,我实在是能不出来呀

lZHKrql8.rar (15.62 KB) XMS不好使呀!


搜索更多相关主题的帖子: 图片 include 
2007-09-22 13:18
beyondabcd
Rank: 1
等 级:新手上路
帖 子:112
专家分:0
注 册:2007-5-19
收藏
得分:0 
有明白的吗?自己顶一下
2007-09-23 09:15
快速回复:XMS不好使呀!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041455 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved