#include <process.h>
#include <stdio.h>
#include <dos.h>
#include <io.h>
#include <mem.h>
#include <conio.h>
#include <string.h>
#include <dir.h>
#include <math.h>
char EMS=0;
unsigned PHYMEMADDR;
unsigned handle;
unsigned char sbyt0(int n)
{switch(n)
{ case 0:return 0x00;
case 1:return 0x80;
case 2:return 0xc0;
case 3:return 0xe0;
case 4:return 0xf0;
case 5:return 0xf8;
case 6:return 0xfc;
case 7:return 0xfe;
}
}
unsigned char cbyt0(int n)
{switch(n)
{ case 0:return 0xff;
case 1:return 0x7f;
case 2:return 0x3f;
case 3:return 0x1f;
case 4:return 0x0f;
case 5:return 0x07;
case 6:return 0x03;
case 7:return 0x01;
}
}
unsigned char sbyt1(int n)
{switch(n)
{ case 0:return 0x00;
case 1:return 0x01;
case 2:return 0x03;
case 3:return 0x07;
case 4:return 0x0f;
case 5:return 0x1f;
case 6:return 0x3f;
case 7:return 0x7f;
}
}
unsigned char cbyt1(int n)
{switch(n)
{ case 0:return 0xff;
case 1:return 0xfe;
case 2:return 0xfc;
case 3:return 0xf8;
case 4:return 0xf0;
case 5:return 0xe0;
case 6:return 0xc0;
case 7:return 0x80;
}
}
char test_ems()
{ int i;
union REGS inregs,outregs;
struct SREGS segs;
struct DeviceHeader {
struct DeviceHeader far *link;
unsigned attributes;
unsigned strategy_offset;
unsigned interrupt_offset;
char name_of_number_of_units[8];
} far *dev;
unsigned char major,minor,c[13];
inregs.x.ax=0x3001;
intdos(&inregs,&outregs);
major=outregs.h.al;
minor=outregs.h.ah;
if (major<2) return(0);
else
{
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);
c[8]=NULL;
while (FP_OFF(dev)!=0xffff)
{
if (dev->attributes & 0x8000)
{
for (i=0;i<8;i++)
c[i]=dev->name_of_number_of_units[i];
}
if (!strcmp(c,"EMMXXXX0"))
{
EMS=1;
return(1);
}
dev=dev->link;
}
}
return(0);
}
char get_EMS_status()
{ union REGS regs;
char tmp=0xff;
if (EMS)
{ regs.h.ah=0x40;
int86(0x67,®s,®s);
tmp=regs.h.ah;
}
return(tmp);
}
char get_page_frame_segment(unsigned *segment)
{ union REGS regs;
char tmp=0xff;
if (EMS)
{ regs.h.ah=0x40;
int86(0x67,®s,®s);
tmp=regs.h.ah;
*segment=regs.x.bx;
}
return(tmp);
}
char get_number_of_pages(unsigned *avail,unsigned *total)
{ union REGS regs;
char tmp=0xff;
if (EMS)
{ regs.h.ah=0x42;
int86(0x67,®s,®s);
tmp=regs.h.ah;
*avail=regs.x.bx;
*total=regs.x.dx;
}
return(tmp);
}
char allocate_memory(unsigned *handle,unsigned page_numbers)
{ union REGS regs;
char tmp=0xff;
if (EMS)
{ regs.h.ah=0x43;
regs.x.bx=page_numbers;
int86(0x67,®s,®s);
tmp=regs.h.ah;
*handle=regs.x.dx;
}
return(tmp);
}
char map_memory(char physical_page,unsigned logical_page,unsigned handle)
{ union REGS regs;
char tmp=0xff;
if (EMS)
{ regs.h.ah=0x44;
regs.h.al=physical_page;
regs.x.bx=logical_page;
regs.x.dx=handle;
int86(0x67,®s,®s);
tmp=regs.h.ah;
}
return(tmp);
}
char release_memory(unsigned handle)
{ union REGS regs;
char tmp=0xff;
if (EMS)
{ regs.h.ah=0x45;
regs.x.dx=handle;
int86(0x67,®s,®s);
tmp=regs.h.ah;
}
return(tmp);
}
char get_EMM_version(unsigned char *version)
{ union REGS regs;
char tmp=0xff;
if (EMS)
{ regs.h.ah=0x46;
int86(0x67,®s,®s);
tmp=regs.h.ah;
*version=regs.h.al;
}
return(tmp);
}
char save_mapping_context(unsigned handle)
{ union REGS regs;
char tmp=0xff;
if (EMS)
{ regs.h.ah=0x47;
regs.x.dx=handle;
int86(0x67,®s,®s);
tmp=regs.h.ah;
}
return(tmp);
}
char restore_mapping_context(unsigned handle)
{ union REGS regs;
char tmp=0xff;
if (EMS)
{ regs.h.ah=0x48;
regs.x.dx=handle;
int86(0x67,®s,®s);
tmp=regs.h.ah;
}
return(tmp);
}
char get_number_of_EMM_handles(unsigned *handle_numbers)
{ union REGS regs;
char tmp=0xff;
if (EMS)
{ regs.h.ah=0x4b;
int86(0x67,®s,®s);
tmp=regs.h.ah;
*handle_numbers=regs.x.bx;
}
return(tmp);
}
char get_pages_owned_by_handle(unsigned handle,unsigned *page_numbers)
{ union REGS regs;
char tmp=0xff;
if (EMS)
{ regs.h.ah=0x4c;
regs.h.dh=handle/256;
regs.h.dl=handle%256;
int86(0x67,®s,®s);
tmp=regs.h.ah;
*page_numbers=regs.x.bx;
}
return(tmp);
}
char get_pages_for_all_handles(unsigned char *buffer,unsigned *handle_numbers)
{
char tmp=0xff;
union REGS regs,oregs;
struct SREGS seg;
if (EMS)
{
unsigned bseg=FP_SEG(buffer),boff=FP_OFF(buffer);
regs.h.ah=0x4d;
regs.x.di=boff;
seg.es=bseg;
int86x(0x67,®s,&oregs,&seg);
*handle_numbers=oregs.x.bx;
}
return(tmp);
}
void EMS_Init()
{ unsigned segment;
unsigned page_numbers,handle_numbers;
test_ems();
get_EMS_status();
/* get_EMM_version(&version); */
/* get_number_of_pages(&avail,&total);*/
get_page_frame_segment(&segment);
PHYMEMADDR=segment;
get_number_of_EMM_handles(&handle_numbers);
page_numbers=16;
allocate_memory(&handle,page_numbers);
printf("page_number=%d\n",page_numbers);
get_number_of_EMM_handles(&handle_numbers);
printf("hangle_numbers=%d",handle_numbers);
}
void ScrToLog()
{ int k,t;
long i;
unsigned logical_page,physical_page;
char far *ph,*scr;
for(k=0;k<4;k++)
{ for(i=0;i<4;i++)
{ logical_pa
ge=i+k*4;
physical_page=i;
map_memory(physical_page,logical_page,handle);
}
scr=(char far *)0xa0000000L;
ph=(char far *)0xe0000000L;
outportb(0x3ce,4);
outportb(0x3cf,k);
for(i=0;i<38400L;i++)
{ *ph=*scr;
ph++;
scr++;
}
save_mapping_context(handle);
}
}
void FileToPhy(int x0,int y0,int x1,int y1,unsigned char *fname)
{ FILE *fp;
long ss0,ss1,n;
int i,k=1;
char far *ptr,*scr;
if((fp=fopen(fname,"rb+"))==NULL)
{printf("Can't open the file %s!",fname);
exit(0);
}
ss0=x1-x0;
ss1=y1-y0;
ss0=ss0*ss1*4;
ptr=(char far *)0xe0000000L;
for(n=0;n<ss0;n++)
{ *ptr=fgetc(fp);
ptr++;
}
fclose(fp);
ptr=(char far *)0xe0000000L;
for(i=0;i<4;i++)
{ outportb(0x3c4,2);
outportb(0x3c5,k);
for(n=y0;n<y1;n++)
{ ss0=ceil(x1/8)-floor(x0/8);
ss1=(long)(80.0*n+ceil(x0/8));
scr=(char far *)(0xe0000000L+ss1);
r=x0-floor(x0/8)*8;
ch=*ptr;
ptr++;
*scr=((cbyt0(r))|(*scr))&ch;
scr++;
for(j=0;j<ss0-2;j++)
{ *scr=*ptr;
ptr++;
scr++;
}
r=ceil(x1)-x1;
ch=*ptr;
ptr++;
*scr=((cbyt1(r))|(*scr))&ch;
scr++;
}
k*=2;
}
outportb(0x3c5,0xf);
}
void FileToLog(int x0,int y0,int x1,int y1,unsigned char *fname)
{int n,r,j,i;
char far *ptr;
long ss0,ss1;
unsigned char ch;
unsigned logical_page,physical_page,handles;
FILE *fp;
if((fp=fopen(fname,"rb+"))==NULL)
{printf("Can't open the file %s!",fname);
exit(0);
}
for(i=0;i<4;i++)
{ for(n=0;n<4;n++)
{ logical_page=n+4*i;
physical_page=n;
map_memory(physical_page,logical_page,handle);
}
/* restore_mapping_context(handle);
*/ ptr=(char far *)0xe0000000L;
for(n=y0;n<y1;n++)
{ ss0=ceil(x1/8)-floor(x0/8);
ss1=(long)(80.0*n+ceil(x0/8));
ptr=(char far *)(0xe0000000L+ss1);
r=x0-floor(x0/8)*8;
ch=fgetc(fp);
*ptr=((cbyt0(r))|(*ptr))&ch;
ptr++;
for(j=0;j<ss0-2;j++)
{ *ptr=fgetc(fp);
ptr++;
}
r=ceil(x1)-x1;
ch=fgetc(fp);
*ptr=((cbyt1(r))|(*ptr))&ch;
ptr++;
}
save_mapping_context(handle);
}
fclose(fp);
}
void LogToSCR()
{int i;
int k=1;
long n;
unsigned handles;
char far *ph,*scr;
unsigned logical_page,physical_page;
for(i=0;i<4;i++)
{ for(n=0;n<4;n++)
{ logical_page=n+i*4;
physical_page=n;
map_memory(physical_page,logical_page,handle);
}
restore_mapping_context(handle);
outportb(0x3c4,2);
outportb(0x3c5,k);
ph=(char far *)0xe0000000L;
scr=(char far *)0xa0000000L;
for(n=0;n<38400L;n++)
{ *scr=*ph;
scr++;
ph++;
}
k*=2;
}
outportb(0x3c5,0xf);
}
#include <graphics.h>
void Main_Init()
{
int driver=DETECT,mode;
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"c:\\tc");
}
main()
{ int i=0,key,l=0;
Main_Init();
setcolor(10);
line(0,0,640,479);
setcolor(5);
line(0,479,640,0);
EMS_Init();
ScrToLog();
while(1)
{if(i==0)
{ FileToLog(48,100,592,335,"c:\\crc\\calibtem.bak");
i=3;
}
if(i==1)
{ FileToLog(224,102+20,624,260+20,"c:\\crc\\collmap.bak");
i=3;
}
if(i==2)
{ i=3;
FileToLog(240,99,632,275,"c:\\crc\\anasmap.bak");
}
if(i==3) LogToSCR();
if(kbhit())
{ key=getch();
if(key==27) break;
l++;
if(l>2) l=0;
i=l;
}
}
release_memory(handle);
closegraph();
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |