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

📄 base.h

📁 汉字内码转换:GB、big5、unicode三者间任意转换
💻 H
📖 第 1 页 / 共 2 页
字号:
{ unsigned char *vp=(unsigned char *)malloc(256*sizeof(unsigned char));
  if(vp==NULL) { printf("Possibly insufficient memory!\n");exit(0);}
  reg.h.ah=0x4f;
  reg.h.al=0;
  sreg.es=FP_SEG(vp);
  reg.x.di=FP_OFF(vp);
  int86x(0X10,&reg,&reg,&sreg);
  if(reg.x.ax!=0x004f){printf("This video card not support VESA mode!\n");exit(0);}
  free(vp);
  reg.h.ah=0x4f;
  reg.h.al=2;
  reg.x.bx=x;
  int86(0X10,&reg,&reg);
  if(reg.x.ax!=0x004f){printf("Possibly insufficient video memory!\n");exit(0);}
}

unsigned  char get_pixel_256(unsigned x,unsigned  y)
{ unsigned long add=(unsigned long)MAXX*y+x;
  int page=add>>16;
  if(x>MAXX||y>MAXY) return(0);
  if(page!=lastpage)
    { lastpage=page;
      reg.h.ah=0x4f;
      reg.h.al=5;
      reg.x.bx=0;
      reg.x.dx=page;
      int86(0X10,&reg,&reg);
     }
  return(peekb(0xa000,add));
}

void put_pixel_256(unsigned x,unsigned y,unsigned char color)
{ unsigned long add=(unsigned long)MAXX*y+x;
  int page=add>>16;
  if(x>MAXX||y>MAXY) return;
  if(page!=lastpage)
    { lastpage=page;
      reg.h.ah=0x4f;
      reg.h.al=5;
      reg.x.bx=0;
      reg.x.dx=page;
      int86(0X10,&reg,&reg);
     }
   if (writemode==1) color^=get_pixel_256(x,y);
   pokeb(0xa000,add,color);
//pokeb(unsigned int segment,unsigned int offset,unsigned char c); offset only 16 bit;
// ==>unsigned char far *p=(unsigned char far *)(0xa0000000+add&0xffff); *p=color;
}
unsigned char get_pixel_16(unsigned x,unsigned y)
{//reg.h.ah=13;reg.x.cx=x;reg.x.dx=y;int86(0x10,&reg,&reg);return(reg.h.al);
  unsigned char far *p=(unsigned char far *)(0xa0000000|(unsigned)((MAXX>>3)*y+(x>>3)));
  unsigned char  color=0,n=7-x&7,i=0;
  if(x>MAXX||y>MAXY) return(0);
  outportb(0x3ce,4);
  for (;i<4;i++)
   {outportb(0x3cf,3-i);
    color=(color<<1)|((*p>>n)&0x01);
   }
  return(color);
}

void put_pixel_16(unsigned x,unsigned y,unsigned char color)
{ unsigned char far *p=(unsigned char far *)(0xa0000000|(unsigned)((MAXX>>3)*y+(x>>3)));
  if(x>MAXX||y>MAXY) return;
  outportb(0x3ce,5);
  outportb(0x3cf,2);
  outportb(0x3ce,8);
  outportb(0x3cf,0x80>>(x&7));
  unsigned_char_data=*p;
  if (writemode==1) color^=get_pixel_16(x,y);
  *p=color;
  outportb(0x3ce,5);
  outportb(0x3cf,0);
}
void setmode(int mode)
{ screenmode=mode;
  palnum=(mode==0x12)?16:256;
  if(mode>=0x100||mode==0x6a)
   { setvesa(mode);getvesa(mode);}
  else {setvga(mode);getvga();}
  if (mode==0x12)   {putpixel=put_pixel_16;  getpixel=get_pixel_16;}
  else  {putpixel=put_pixel_256;  getpixel=get_pixel_256;}

}
void setpalette(unsigned char i,unsigned char r,unsigned char g,unsigned char b)
{ if (screenmode==0x12)
   { if (i==6) i=20;
     else if(i>15) return;
     else if(i>7) i+=48;
   }
  outportb(0x3c8,i);
  outportb(0x3c9,r);
  outportb(0x3c9,g);
  outportb(0x3c9,b);
}
void getpalette(unsigned char i,unsigned char *r,unsigned char *g,unsigned char *b)
{ if (screenmode==0x12)
   { if (i==6) i=20;
     else if(i>15) return;
     else if(i>7) i+=48;
   }
  outportb(0x3c7,i);
  *r=inportb(0x3c9);
  *g=inportb(0x3c9);
  *b=inportb(0x3c9);
}

void line(int x1,int y1,int x2,int y2,int color)
{
  int dx=x2-x1,dy=y2-y1,stepx=1,stepy=1,change;
  if (dx<0)  {dx=-dx;stepx=-1;}
  if (dy<0)  {dy=-dy;stepy=-1;}
  putpixel(x2,y2,color);
  if (dx>dy)
    {
      change=dx>>1;
      while (x1!=x2)
	{
	  putpixel(x1,y1,color);
	  x1+=stepx;change+=dy;
	  if (change>dx)  { y1+=stepy;change-=dx; }
	}
    }
  else
    {
       change=dy>>1;
       while (y1!=y2)
	 {
	    putpixel(x1,y1,color);
	    y1+=stepy;change+=dx;
	    if (change>dy)  {x1+=stepx; change-=dy;}
	  }
    }
}

void lines(int x1,int y1,int x2,int y2,int color,int k)
{
  register int j;
  if(x2-x1<y2-y1) for(j=0;j<k;j++) line(x1+j,y1,x2+j,y2,color);
  else for(j=0;j<k;j++)	line(x1,y1+j,x2,y2+j,color);
}
void bar(int x1,int y1,int x2,int y2,int color)
{
  register int i,j;
  for (j=y1;j<=y2;j++)
  for (i=x1;i<=x2;i++)  putpixel(i,j,color);
}

void polyline(int N,int *BUFF,int color,int k)
{
  int i;
  for(i=0;i<N-1;i++) lines(BUFF[2*i],BUFF[2*i+1],BUFF[2*i+2],BUFF[2*i+3],color,k);
}
void ellipse(int x,int y,int A,int B,int color,int k)
{
 int i,j;
  unsigned long A1,B1,A2,B2;
  for(j=0;j<B;j++)
  for(i=0;i<A;i++)
    { A1=(unsigned long)(A+1+k)*(A+1+k);B1=(unsigned long)(B+1+k)*(B+1+k);A2=(unsigned long)A*A;B2=(unsigned long)B*B;
      if(B1*i*i+A1*j*j>A2*B2&&B2*i*i+A2*j*j<A2*B2)
	{ putpixel(x+i,y+j,color);
	  putpixel(x-i,y+j,color);
	  putpixel(x-i,y-j,color);
	  putpixel(x+i,y-j,color);
	}
    }
}


void circle(int x,int y,int A,int color,int k)
{
  ellipse(x,y,A,A,color,k);
}

void rec3D(int x1,int y1,int x2,int y2,int color,int colour,int k)
{
  int i;
  for(i=0;i<k;i++)
   { line(x1+i,y1+i,x2-i,y1+i,color);
     line(x1+i,y1+i,x1+i,y2-i,color);
     line(x1+i,y2-i,x2-i,y2-i,colour);
     line(x2-i,y1+i,x2-i,y2-i,colour);
   }
}

void rectangle(int x1,int y1,int x2,int y2,int color,int k)
{
  lines(x1,y1,x1,y2,color,k);
  lines(x1+k,y1,x2,y1,color,k);
  lines(x1+k,y2-k+1,x2,y2-k+1,color,k);
  lines(x2-k+1,y1+k,x2-k+1,y2-k+1,color,k);
}

void drawbutton(int x1,int y1,int x2,int y2,int OUT,int k)
{
//  rectangle(x1++,y1++,x2--,y2--,BLACK,1);
  if (OUT==0) rec3D(x1,y1,x2,y2,WHITE,DARKGRAY,k);
  else rec3D(x1,y1,x2,y2,DARKGRAY,WHITE,k);
  bar(x1+k,y1+k,x2-k,y2-k,LIGHTGRAY);
  line(x1,y2+1,x2,y2+1,BLACK);
  line(x2+1,y1,x2+1,y2+1,BLACK);
}
//////////////////////////////////////////////////
void  openfontfile(char *filename)
{  if((fontfile=fopen(filename,"rb"))==NULL){fclose(fontfile); printf("open error");return;}
}

void  closefontfile()
{ fclose(fontfile);
}
#if defined NO_FONT_FILE
void  putword(int x,int y,unsigned long number,unsigned char color)
{ unsigned char i,j,n;
  for(n=0;fontarray[n*17+1]!=number&&n<fontarray[0];n++);
  for(j=0;j<16;j++,y++)
  for(i=0;i<16;i++)
  if (fontarray[n*17+2+j]&(0x8000>>i))  putpixel(x+i,y,color);
}
#else
void  putword(int x,int y,unsigned long number,unsigned char color)
{ unsigned char i,j,buffer[32];
  fseek(fontfile,number<<5,0);
  fread(buffer,1,32,fontfile);
  for(j=0;j<16;j++,y++)
  for(i=0;i<16;i++)
  if (buffer[(j<<1)+(i>>3)]&(0x80>>(i&0x7)))  putpixel(x+i,y,color);
  getfontarray(number);
}
#endif
void  putword24(int x,int y,unsigned long number,unsigned char color)
{ unsigned char i,j,buffer[72];
  fseek(fontfile,(number<<6)+(number<<3),0);
  fread(buffer,1,72,fontfile);
  for(j=0;j<24;j++,y++)
  for(i=0;i<24;i++)
  if (buffer[j*3+(i>>3)]&(0x80>>(i&0x7))) putpixel(x+i,y,color);
}

void text(int x,int y,unsigned char *s,unsigned char color)
{unsigned deltx=16,delty=16,leftx=x,i=0,fuhao,length,data;
 for(length=0;s[length]!='\0';length++);
 while(i<length)
   { if (s[i]>160&&s[i+1]>160)
       { putword(x,y,s[i]*94L+s[i+1]-15295L,color);
	 i+=2;
	 x+=deltx;
       }
     else if (s[i]=='<')
       { if (s[i+1]=='p')
	   { y+=delty;x=leftx;i+=3;
	   }
	 else if(s[i+1]>47&&s[i+1]<58)
	   { for(data=0,i+=1;s[i]!='>';i++)data=data*10+s[i]-48;
	     putword(x,y,data,color);
	     x+=deltx;i+=1;
	   }
	 else if(s[i+1]=='c'&&s[i+3]=='l')
	  {  for(color=0,i+=7;s[i]!='>';i++)color=color*10+s[i]-48;
	     i=i+1;
	  }
	 else if(s[i+1]=='c'&&s[i+3]=='o')
	  { if (s[i+8]!='#') for(x=0,i+=8;s[i]>47&&s[i]<58;i++)x=x*10+s[i]-48;
	    else i+=9;
	    fuhao=s[i];
	    if (fuhao!=',')
	      { for(data=0,i+=1;s[i]>47&&s[i]<58;i++)data=data*10+s[i]-48;
		if (fuhao=='+')x+=data;
		else if(fuhao=='-') x-=data;
	      }
	    if (s[i+1]!='#') for(y=0,i+=1;s[i]>47&&s[i]<58;i++)y=y*10+s[i]-48;
	    else i+=2;
	    fuhao=s[i];
	    if (fuhao!='>')
	      { for(data=0,i+=1;s[i]>47&&s[i]<58;i++)data=data*10+s[i]-48;
		if (fuhao=='+')y+=data;
		else if(fuhao=='-')y-=data;
	      }
	    i++;
	  }
	 else if(s[i+1]=='d'&&s[i+3]=='l')
	  { if (s[i+6]!='#') for(deltx=0,i+=6;s[i]>47&&s[i]<58;i++)deltx=deltx*10+s[i]-48;
	    else i+=7;
	    fuhao=s[i];
	    if (fuhao!=',')
	      { for(data=0,i+=1;s[i]>47&&s[i]<58;i++)data=data*10+s[i]-48;
		if (fuhao=='+')deltx+=data;
		else if(fuhao=='-')deltx-=data;
	      }
	    if (s[i+1]!='#') for(delty=0,i+=1;s[i]>47&&s[i]<58;i++)delty=delty*10+s[i]-48;
	    else i+=2;
	    fuhao=s[i];
	    if (fuhao!='>')
	      { for(data=0,i+=1;s[i]>47&&s[i]<58;i++)data=data*10+s[i]-48;
		if (fuhao=='+')delty+=data;
		else if(fuhao=='-')delty-=data;
	      }
	    i++;
	  }
	 else {text(x,y,"<",color);i+=1;x+=deltx;}
       }
     else
       { if (s[i]>32&&s[i]<127)putword(x,y,155+s[i],color);
	 x+=deltx-6;
	 i++;
       }
   }
}
void text24(int x,int y,unsigned char *s,unsigned char color)
{unsigned deltx=24,delty=24,leftx=x,i=0,fuhao,length,data;
 for(length=0;s[length]!='\0';length++);
 while(i<length)
   { if (s[i]>128&&s[i+1]>63)
       { if(s[i+1]<=0x7f)  putword24(x,y,s[i]*190L+s[i+1]-24574,color);
	 else putword24(x,y,s[i]*190L+s[i+1]-24575,color);
	 i+=2;
	 x+=deltx;
       }
     else if (s[i]=='<')
       { if (s[i+1]=='p')
	   { y+=delty;x=leftx;i+=3;
	   }
	 else if(s[i+1]>47&&s[i+1]<58)
	   { for(data=0,i+=1;s[i]!='>';i++)data=data*10+s[i]-48;
	     putword24(x,y,data,color);
	     x+=deltx;i+=1;
	   }
	 else if(s[i+1]=='c'&&s[i+3]=='l')
	  {  for(color=0,i+=7;s[i]!='>';i++)color=color*10+s[i]-48;
	     i=i+1;
	  }
	 else if(s[i+1]=='c'&&s[i+3]=='o')
	  { if (s[i+8]!='#') for(x=0,i+=8;s[i]>47&&s[i]<58;i++)x=x*10+s[i]-48;
	    else i+=9;
	    fuhao=s[i];
	    if (fuhao!=',')
	      { for(data=0,i+=1;s[i]>47&&s[i]<58;i++)data=data*10+s[i]-48;
		if (fuhao=='+')x+=data;
		else if(fuhao=='-') x-=data;
	      }
	    if (s[i+1]!='#') for(y=0,i+=1;s[i]>47&&s[i]<58;i++)y=y*10+s[i]-48;
	    else i+=2;
	    fuhao=s[i];
	    if (fuhao!='>')
	      { for(data=0,i+=1;s[i]>47&&s[i]<58;i++)data=data*10+s[i]-48;
		if (fuhao=='+')y+=data;
		else if(fuhao=='-')y-=data;
	      }
	    i++;
	  }
	 else if(s[i+1]=='d'&&s[i+3]=='l')
	  { if (s[i+6]!='#') for(deltx=0,i+=6;s[i]>47&&s[i]<58;i++)deltx=deltx*10+s[i]-48;
	    else i+=7;
	    fuhao=s[i];
	    if (fuhao!=',')
	      { for(data=0,i+=1;s[i]>47&&s[i]<58;i++)data=data*10+s[i]-48;
		if (fuhao=='+')deltx+=data;
		else if(fuhao=='-')deltx-=data;
	      }
	    if (s[i+1]!='#') for(delty=0,i+=1;s[i]>47&&s[i]<58;i++)delty=delty*10+s[i]-48;
	    else i+=2;
	    fuhao=s[i];
	    if (fuhao!='>')
	      { for(data=0,i+=1;s[i]>47&&s[i]<58;i++)data=data*10+s[i]-48;
		if (fuhao=='+')delty+=data;
		else if(fuhao=='-')delty-=data;
	      }
	    i++;
	  }
	 else {text24(x,y,"<",color);i+=1;x+=deltx;}
       }
     else
       { if (s[i]>32&&s[i]<127)putword24(x,y,6523L+s[i],color);
	 x+=deltx;
	 i++;
       }
   }
}

void getfontarray (unsigned number)
{ unsigned char i,buffer[32];
  for(i=0;i<fontarray[0];i++)if (fontarray[i*17+1]==number)return;
  fseek(fontfile,(unsigned long)number<<5,0);
  fread(buffer,1,32,fontfile);
  for(i=0;i<16;i++) fontarray[fontarray[0]*17+2+i]=((unsigned)buffer[i<<1]<<8)+(buffer[(i<<1)+1]);
  fontarray[fontarray[0]*17+1]=number;
  fontarray[0]++;
}
void writefontarray(char *filename)
{FILE *f;
 unsigned char j;
 unsigned long i,length=fontarray[0]*17L+1;
 f=fopen(filename,"w");
 fprintf(f,"/*****put following to the head of the file*****/\n");
 fprintf(f,"#define NO_FONT_FILE\nunsigned fontarray[]={\n");
 for(i=0,j=1;i<length;i++,j++)
   { fprintf(f,"%5u,",fontarray[i]);
     if (j==100) {j=0;fprintf(f,"\n");}
   }
 fprintf(f,"\n};\n/////////////////////");
 fclose(f);
}


void intm(int x,int y)
{int i,j;
 for (i=0;i<15;i++)
 for (j=0;j<20;j++)
  putpixel(x+i,y+j,4^getpixel(x+i,y+j));
}
void showcur(int mode)
{static lastx=0,lasty=0;
  getmcoords();
 if (mode==0) intm(lastx,lasty);
 else if (mx!=lastx||my!=lasty)
   {intm(lastx,lasty);
    lastx=mx;lasty=my;
    intm(mx,my);
   }
}

/////////////////////////////////////////////////
#endif





/*
void main()
{ setmode(0x101);
  resetmouse();
  showmc();
  openfontfile("gb.16");
  text(0,0,"asd踏遍青山人未老风景这边独好fsdfgsdfg",5);
  closefontfile();
  limitmouse(0,0,MAXX-15,MAXY-15);
  intm(0,0);
  for (;pressedkey!=27;)
    { getmcoords();
      showcur(1);
      getmbs(1);
      if (getkey()==1) putpixel(mx,my,5);
      if ((lastbutton[0])>0)
      { gotoxy(10,0);
	putpixel(lastbutton[1],lastbutton[2],4);
	printf("%d,%d,%d,%d,%d        ",lastbutton[0],lastbutton[1],lastbutton[2],mx,my);
      }
    }
  setmode(0x3);
}

*/

⌨️ 快捷键说明

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