提供几个tc汉字显示函数:
以下函数可以在图形模式下输出12点阵和16点阵的汉字,需要汉字字库的支持:hzk12和hzk16,这两个文件可以在ucdos中找到,也可以从这下载
将这两个文件放在程序目录下就可以了。
主要函数有:
void disphz12(int x,int y,unsigned char* bytes,int color):在屏幕上显示12点阵汉字,x,y为屏幕位置,bytes为汉字内容
color为汉字颜色。该函数需要字库hzk12
void disphz16(int x,int y,unsigned char* bytes,int color):16点阵汉字。该函数需要字库hzk16
void disphz12bk(int x,int y,unsigned char* bytes,int color,int bkcolor):可以修改背景颜色bkcolor的12点阵显示
void disphz16bk(int x,int y,unsigned char* bytes,int color,int bkcolor):同上的16点阵
void d12(int x0,int y0,unsigned char *bytes,int color) {/*12x12点阵汉字直接写vram */
char far *p;
register int i,j;
p=(char far*)(0xa0000000+80*y0+x0/5);
for(i=0;i<12;++i) {
for(j=0;j<2;++j) {
outportb(0x3c4,0x02);
outportb(0x3c5,color);
*(p+80*i+j)=bytes[2*i+j];
}
}
outportb(0x3c4,0xff02);
}
void disphz12(int x,int y,unsigned char* bytes,int color) {
unsigned char qh,wh;
unsigned long offset;
char mat[24];
int hzk_p;
hzk_p=open("hzk12",O_BINARY|O_RDONLY);
if(hzk_p==-1) puts("Openfile Error!"),getch(), exit(1);
while(*bytes) {
qh=*bytes-0xa0;
wh=*(bytes+1)-0xa0;
offset=(94*(qh-1)+(wh-1))*24L;
lseek(hzk_p,offset,SEEK_SET);
read(hzk_p,mat,24);
d12(x,y,mat,color);
x+=10; bytes+=2;
}
close(hzk_p);
}
void d12bk(int x0,int y0,unsigned char *bytes,int color,int bkcolor) {/*12x12点阵汉字直接写vram */
char far *p;
register int i,j;
p=(char far*)(0xa0000000+80*y0+x0/5);
for(i=0;i<12;++i) {
for(j=0;j<2;++j) {
outportb(0x3ce,0x05);
outportb(0x3cf,0x02);
outportb(0x3ce,0x08);
outportb(0x3cf,bytes[2*i+j]);
*(p+80*i+j)=color;
outportb(0x3ce,0x08);
outportb(0x3cf,~bytes[2*i+j]);
*(p+80*i+j)=bkcolor;
}
}
outportb(0x3ce,0x05);
outportb(0x3ce,0xff08);
}
void disphz12bk(int x,int y,unsigned char* bytes,int color,int bkcolor) {
unsigned char qh,wh;
unsigned long offset;
char mat[24];
int hzk_p;
hzk_p=open("hzk12",O_BINARY|O_RDONLY);
if(hzk_p==-1) puts("Openfile Error!"),getch(), exit(1);
while(*bytes) {
qh=*bytes-0xa0;
wh=*(bytes+1)-0xa0;
offset=(94*(qh-1)+(wh-1))*24L;
lseek(hzk_p,offset,SEEK_SET);
read(hzk_p,mat,24);
d12bk(x,y,mat,color,bkcolor);
x+=10; bytes+=2;
}
close(hzk_p);
}
void d16(int x0,int y0,unsigned char *bytes,int color) {
char far *p;
register int i,j;
p=(char far*)(0xa0000000+80*y0+x0/8);
for(i=0;i<16;++i) {
for(j=0;j<2;++j) {
outportb(0x3c4,0x02);
outportb(0x3c5,color);
*(p+80*i+j)=bytes[2*i+j];
}
}
outportb(0x3c4,0xff02);
}
void disphz16(int x,int y,unsigned char* bytes,int color) {
unsigned char qh,wh;
unsigned long offset;
char mat[32];
int hzk_p;
hzk_p=open("hzk16",O_BINARY|O_RDONLY);
if(hzk_p==-1) puts("Openfile Error!"),getch(), exit(1);
while(*bytes) {
qh=*bytes-0xa0;
wh=*(bytes+1)-0xa0;
offset=(94*(qh-1)+(wh-1))*32L;
lseek(hzk_p,offset,SEEK_SET);
read(hzk_p,mat,32);
d16(x,y,mat,color);
x+=16; bytes+=2;
}
close(hzk_p);
}
void d16bk(int x0,int y0,unsigned char *bytes,int color,int bkcolor) {/*12x12点阵汉字直接写vram */
char far *p;
register int i,j;
p=(char far*)(0xa0000000+80*y0+x0/8);
for(i=0;i<16;++i) {
for(j=0;j<2;++j) {
outportb(0x3ce,0x05);
outportb(0x3cf,0x02);
outportb(0x3ce,0x08);
outportb(0x3cf,bytes[2*i+j]);
*(p+80*i+j)=color;
outportb(0x3ce,0x08);
outportb(0x3cf,~bytes[2*i+j]);
*(p+80*i+j)=bkcolor;
}
}
outportb(0x3ce,0x05);
outportb(0x3ce,0xff08);
}
void disphz16bk(int x,int y,unsigned char* bytes,int color,int bkcolor) {
unsigned char qh,wh;
unsigned long offset;
char mat[32];
int hzk_p;
hzk_p=open("hzk16",O_BINARY|O_RDONLY);
if(hzk_p==-1) puts("Openfile Error!"),getch(), exit(1);
while(*bytes) {
qh=*bytes-0xa0;
wh=*(bytes+1)-0xa0;
offset=(94*(qh-1)+(wh-1))*32L;
lseek(hzk_p,offset,SEEK_SET);
read(hzk_p,mat,32);
d16bk(x,y,mat,color,bkcolor);
x+=16; bytes+=2;
}
close(hzk_p);
}
[此贴子已经被作者于2006-4-27 14:16:20编辑过]