如何显示汉字
在模式 13H 下, 直接写屏显示汉字.
其中 hzk16 是 UCDOS 的字库, 把它放在当前目录下
显示汉字用的是 区位码, 稍加修改可变成显示其它码.
// Graphics Mode 13h Test, Display a Chinese String, Wildrose Inc.
// Compile it with Watcom C/C++ 10.0 compiler
// Copyright(c) Jan. 1997 ZhangWei
// All rights reserved
#if !defined(__WATCOMC__)' '!defined(__386__)
#error "This Program needs Watcom C/C++ 10.0 Compiler"
#endif
#include
#include
#include
#include
#include
#include
#include
char c=1;
int orig_mode=3;
char *pv=(char *)(0x0A0000L);
FILE *fp; char buffer[32];
void PutPixel(int x, int y, char c)
{
*(pv+y*320+x)=c; //put pixel color
}
void InitGraph()//Set 320x200 256 colors Mode
{
union REGS regs;
//Test if it is VGA Adapter.
regs.w.ax = 0x1A00;
int386(0x10, ®s, ®s);
if(regs.h.al != 0x1A)
{
puts("This Program needs VGA Adapter ");
exit(1);
}
// get original video mode
regs.w.ax = 0x0F00;
int386(0x10, ®s, ®s);
orig_mode = regs.h.al;
// set graphic mode 13h
regs.w.ax = 0x0013;
int386(0x10, ®s, ®s);
}
void CloseGraph()
{
union REGS regs;
regs.h.ah = 0x00;
regs.h.al = orig_mode;
int386(0x10, ®s, ®s);
}
void CoutTextxy(int x, int y, int *qwm) //Display Chinese Character String
{
int pos=0;
long addr;
register p;
unsigned char bit;
while(qwm[pos])
{
if(((qwm[pos]>=101)&&(qwm[pos]<=994))||((qwm[pos]>=1601)&&(qwm[pos]<=8794)
{
addr=((long)(qwm[pos]/100-1)*94+(long)(qwm[pos]%100-1))*32; //Calculate
pos++; if(fseek(fp,addr,SEEK_SET))return; //Failed
for(register i=0;i<32;i++)
{
buffer[i]=fgetc(fp);
}
for(i=0;i<16;i++)
{
bit=0x80;
for(register k=0;k<8;k++,bit>>=1)
{
if((buffer[2*i]&bit))PutPixel(x+k,y+i,c);
if((buffer[2*i+1]&bit))PutPixel(x+k+8,y+i,c);
}
}
}
x+=16;
}
}
void main()
{
int x=120, y=60;
char filename[]="hzk16";
int sd[]={4168,2181,5102,4859,2011,0};
if((fp=fopen(filename,"rb"))==NULL)
{
printf("Can't open file %s ",filename);
return;
}
InitGraph();
CoutTextxy(x,y,sd);
c=2; CoutTextxy(x,y+16,sd);
c=3; CoutTextxy(x,y+32,sd);
c=4; CoutTextxy(x,y+48,sd);
getch();
CloseGraph();
fclose(fp);
}