* *
int86(0x10,&r,&r); }
unsigned char set_SVGA_mode(int vmode) /*设置SVGA屏幕模式*/ {
union REGS r; r.x.ax=0x4f02; r.x.bx=vmode; int86(0x10,&r,&r); return(r.h.ah); }
unsigned int get_SVGA_mode() /*获取当前SVGA屏幕模式*/ {
union REGS r; r.x.ax=0x4f03; int86(0x10,&r,&r); return(r.x.bx); }
drawbmp(int start_x,int start_y,char filename[]) {
char buffer[640];
int i,j,k,n,r,g,b,width,length; long position;
* *
FILE *fp;
if((fp=fopen(filename,\{
printf(\getch(); return; }
fseek(fp,28,SEEK_SET); fread(&i,2,1,fp);
if(i!=8) /*检查是否为256色位图*/ {
puts(\fclose(fp); getch(); exit(0); }
fseek(fp,18,SEEK_SET); fread(&width,4,1,fp); fread(&length,4,1,fp); if(firsttime)
* *
{
fseek(fp,54,SEEK_SET);
for(i=0;i<256;i++) /*按照该图片的DAC色表设置色彩寄存器*/ {
b=fgetc(fp);g=fgetc(fp);r=fgetc(fp); /*获取R、G、B分量*/ outportb(0x3c8,i);
outportb(0x3c9,r>>2); /*右移是要转化为VGA的6位寄存器形式*/ outportb(0x3c9,g>>2); outportb(0x3c9,b>>2); fgetc(fp); } } else
fseek(fp,300,SEEK_SET);
k=(width%4)?(4-width%4):0; /*宽度修正值*/ for(j=length-1+start_x;j>=start_x;j--) {
fread(buffer,width,1,fp);
for(i=start_y,n=0;i position=j*640l+i; /*计算要显示点的显存位置*/ page_new=position/65536; /*计算显示页*/ * * if(page_new!=page_old) /*当显示页不同时更换页面,提高一定的输出速度*/ {selectpage(page_new);page_old=page_new;} pokeb(0xa000,positione536,buffer[n]); /*写到显存位置*/ } fseek(fp,k,SEEK_CUR); /*每行绘制完后修正宽度*/ } fclose(fp); } init() { savemode=get_SVGA_mode(); /*先保存原来的屏幕模式*/ set_SVGA_mode(0x101); /*硬件无关性初始化屏幕为640*480 256色模式*/ } end() { set_SVGA_mode(savemode); /*恢复屏幕*/ } /*----------------------------------------------------*/ initpos() * * { int i,j; for(i=0;i<10;i++) for (j=0;j<9;j++) { position[i][j].x=35+i*39; position[i][j].y=43+j*40; } } initchessmap() { board[0][0]=BLACK_JU; board[0][1]=BLACK_MA; board[0][2]=BLACK_XIANG; board[0][3]=BLACK_SHI; board[0][4]=BLACK_JIANG; board[0][5]=BLACK_SHI; board[0][6]=BLACK_XIANG; board[0][7]=BLACK_MA; board[0][8]=BLACK_JU; board[2][1]=BLACK_PAO; board[2][7]=BLACK_PAO;