📄 hzktype.c
字号:
#define VGA256 0x13
#define TEXT_MODE 0x03
#include<dos.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<process.h>
int color=YELLOW;
unsigned char far *video_buffer=(char far *)0xA0000000L;
void outctextxy(x_size,y_size,color,x,y,s)
int x_size,y_size,color,x,y;
char *s;
{char mat[32];
char *cads;
FILE *fp;
unsigned char qh,wh;
unsigned long offset;
unsigned char mask[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
int startx,x0,starty,y0,i,j,k,d,o,pos;
if((fp=fopen("HZK16","rb"))==0)
{clrscr();
printf("The hzk16 isn't exist or can't open it!");
exit(1);
}
startx=x;starty=y;cads=s;
while(*cads!=0)
{d=0;
while((d<6)&&(*cads!=0))
{qh=*cads-0xa0;
wh=*(cads+1)-0xa0;
offset=(94*(qh-1)+(wh-1))*32l;
//计算字在字库中的地址
fseek(fp,offset,SEEK_SET);
fread(mat,32,1,fp);
y0=starty;
for(i=0;i<16;i++)
for(o=0;o<y_size;o++)
{pos=2*i;
x0=startx;
for(j=0;j<16;j++)
for(k=0;k<x_size;k++)
{if(mask[j%8]&mat[pos+j/8])
video_buffer[((y0<<8)+(y0<<6))+x0]=color;
x0++;
}
y0++;
}
startx+=24*x_size;
cads+=2;
d++;
}
startx=x;
starty+=20*x_size;
}
fclose(fp);
}
void Coutctextxy(x_size,y_size,x,y,s)
int x_size,y_size,x,y;
char *s;
{char mat[32];
char *cads;
FILE *fp;
unsigned char qh,wh;
unsigned long offset;
unsigned char mask[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
int startx,x0,starty,y0,i,j,k,d,o,pos;
if((fp=fopen("HZK16","rb"))==0)
{clrscr();
printf("The hzk16 isn't exist or can't open it!");
exit(1);
}
startx=x;starty=y;cads=s;
while(*cads!=0)
{d=0;
while((d<6)&&(*cads!=0))
{qh=*cads-0xa0;
wh=*(cads+1)-0xa0;
offset=(94*(qh-1)+(wh-1))*32l;
//计算字在字库中的地址
fseek(fp,offset,SEEK_SET);
fread(mat,32,1,fp);
y0=starty;
for(i=0;i<16;i++)
for(o=0;o<y_size;o++)
{pos=2*i;
x0=startx;
for(j=0;j<16;j++)
for(k=0;k<x_size;k++)
{if(mask[j%8]&mat[pos+j/8])
video_buffer[((y0<<8)+(y0<<6))+x0]=rand()%100;
x0++;
}
y0++;
}
startx+=24*x_size;
cads+=2;
d++;
}
startx=x;
starty+=20*x_size;
}
fclose(fp);
}
void Ioutctextxy(x_size,y_size,color,x,y,s)
int x_size,y_size,color,x,y;
char *s;
{char mat[32];
char *cads;
FILE *fp;
unsigned char qh,wh;
unsigned long offset;
unsigned char mask[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
int startx,x0,starty,y0,i,j,k,d,o,pos;
if((fp=fopen("HZK16","rb"))==0)
{clrscr();
printf("The hzk16 isn't exist or can't open it!");
exit(1);
}
startx=x;starty=y;cads=s;
while(*cads!=0)
{d=0;
while((d<6)&&(*cads!=0))
{qh=*cads-0xa0;
wh=*(cads+1)-0xa0;
offset=(94*(qh-1)+(wh-1))*32l;
//计算字在字库中的地址
fseek(fp,offset,SEEK_SET);
fread(mat,32,1,fp);
y0=starty;
for(i=0;i<16;i++)
for(o=0;o<y_size;o++)
{pos=2*i;
x0=startx;
for(j=0;j<16;j++)
for(k=0;k<x_size;k++)
{if(mask[j%8]&mat[pos+j/8])
video_buffer[((y0<<8)+(y0<<6))+x0+16-i]=color;
x0++;
}
y0++;
}
startx+=24*x_size;
cads+=2;
d++;
}
startx=x;
starty+=20*x_size;
}
fclose(fp);
}
void Boutctextxy(x_size,y_size,color,x,y,s)
int x_size,y_size,color,x,y;
char *s;
{char mat[32];
char *cads;
FILE *fp;
unsigned char qh,wh;
unsigned long offset;
unsigned char mask[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
int startx,x0,starty,y0,i,j,k,d,o,pos;
if((fp=fopen("HZK16","rb"))==0)
{clrscr();
printf("The hzk16 isn't exist or can't open it!");
exit(1);
}
startx=x;starty=y;cads=s;
while(*cads!=0)
{d=0;
while((d<6)&&(*cads!=0))
{qh=*cads-0xa0;
wh=*(cads+1)-0xa0;
offset=(94*(qh-1)+(wh-1))*32l;
//计算字在字库中的地址
fseek(fp,offset,SEEK_SET);
fread(mat,32,1,fp);
y0=starty;
for(i=0;i<16;i++)
for(o=0;o<y_size;o++)
{pos=2*i;
x0=startx;
for(j=0;j<16;j++)
for(k=0;k<x_size;k++)
{if(mask[j%8]&mat[pos+j/8])
{
video_buffer[((y0<<8)+(y0<<6))+x0]=color;
video_buffer[((y0<<8)+(y0<<6))+x0+1]=color;
}
x0++;
}
y0++;
}
startx+=24*x_size;
cads+=2;
d++;
}
startx=x;
starty+=20*x_size;
}
fclose(fp);
}
void Set_Video_Mode(int mode)
{
union REGS inregs,outregs;
inregs.h.ah=0;
inregs.h.al=(unsigned char)mode;
int86(0x10,&inregs,&outregs);
}
void main(void)
{
int x=100,y=20,x_size=1,y_size=1,mode;
char *a="游戏编程";
Set_Video_Mode(VGA256);
outctextxy(x_size,y_size,color,x,y,a);
Boutctextxy(x_size,y_size,color,x,y+30,a);
Ioutctextxy(x_size,y_size,color,x,y+60,a);
Coutctextxy(x_size,y_size,x,y+90,a);
outctextxy(2,2,color,x,y+120,a);
getch();
Set_Video_Mode(TEXT_MODE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -