📄 font.cpp
字号:
#include <graphics.h>
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <string.h>
#include "xms.h"
#define FONTHIGH 18
extern FILETOXMS *font12;
//显示12点阵汉字和英文字符
void FontScanLine(int x,int y,unsigned int style,unsigned char color) // 以当前色画横线
{
asm{
mov ax,y
mov bx,80
mul bx
mov bx,x
mov cl,3
shr bx,cl
add ax,bx
mov di,ax // di = y*80+x/8
}
asm{
mov dx,0x3c4 // outportb(0x3c4,2);
mov ax,0x0f02 // outportb(0x3c5,0x0f);
out dx,ax // 使所有位面可写
mov dx,0x3ce // outportb(0x3ce,0x05);
mov ax,0x0305 // outportb(0x3cf,0x03);
out dx,ax // 选择写方式3: 设置/清除寄存器的值和位屏蔽
// 寄存器相与,并写入指定的适配器地址
mov ah,color // outportb(0x3ce,0);
mov al,0 // outportb(0x3cf,color);
out dx,ax // 使对应的颜色位面可写
mov ax,0xff08 // outportb(0x3ce,0x08);
out dx,ax // outportb(0x3cf,0xff);
// 使所有的象素可写 // 可用此设置线性
mov ax,0xa000
mov es,ax
}
asm{
mov cx,x
and cx,7
mov dx,style
mov bh,dl
mov bl,dh
shr bx,cl
mov ah,es:[di]
mov es:[di],bh
inc di
mov ah,es:[di]
mov es:[di],bl
inc di
mov dl,0
shr dx,cl
mov ah,es:[di]
mov es:[di],dl
}
asm{
mov dx,0x3ce // outportb(0x3ce,0x05);
mov ax,0x0005 // outportb(0x3cf,0x03);
out dx,ax // 选择写方式0: 恢复缺省值
}
}
void Outchar12(int x,int y,char *str,unsigned char color)
{
register int i;
long Len;
char cc[2];
unsigned *Buf=(unsigned *)malloc(24);
setcolor(color);
while(*str){
if((*str&0x80)&&(*(str+1)&0x80))
{
Len=( ( (*str-0xa1)&0x7f) * 94 + ( (*(str+1)-0xa1)&0x7f) ) * 24L;
font12->GetBuf(Buf,Len,24);
for(i=0;i<12;i++)
FontScanLine(x,y+i,Buf[i],color);
str+=2;
x+=13;
}
else {
sprintf(cc,"%c",*str);
disable();
outtextxy(x+2,y+3,cc);
enable();
str++;
x+=13;
}
}
free(Buf);
return;
}
void Outchar45(int x,int y,char* str,unsigned char color)
{
char *str1=str;
char temp[3];
for(int i=0;i<4;i++){
strncpy(temp,str1,2);
temp[2]='\0';
Outchar12(x+17*i,y,temp,color);
str1+=2;
}
}
void SuperOutchar(int x0,int y,int xl,int yl,char *str,unsigned char color)
{
char cc[2];
unsigned *Buf=(unsigned *)malloc(24);
long Len;
register int i;
int x=x0;
setcolor(color);
while(*str){
if((*str&0x80)&&(*(str+1)&0x80))
{
Len=( ( (*str-0xa1)&0x7f) * 94 + ( (*(str+1)-0xa1)&0x7f) ) * 24L;
font12->GetBuf(Buf,Len,24);
for(i=0;i<12;i++)
FontScanLine(x,y+i,Buf[i],color);
str+=2;
x+=13;
}
else {
switch(*str)
{
case '\n': x=x0;
y+=FONTHIGH;
break;
case '\r': x=x0;
break;
case ' ': x+=13;
break;
default: sprintf(cc,"%c",*str);
outtextxy(x,y+3,cc);
x+=8;
break;
}
str++;
}
if(x >= xl-13)
{
x=x0;
y+=FONTHIGH;
}
if(y >= yl-12)
break;
}
free(Buf);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -