📄 te_fun.c
字号:
#include "te.h"
char border[3][3]={ 0xda,0xc2,0xbf,
0xc3,0xc5,0xb4,
0xc0,0xc1,0xd9
},l[2]={0xc4,0xb3};
unsigned int chkkey(unsigned int t);
void bell(void)
{
nosound();
sound(1000);
delay(100);
nosound();
}
void outsn(int x,int y,int attrib,char *p,int l) /*输出指定长度的字符串*/
{unsigned cc,j,num=0,is_break=0;
char far *sc;
x--,y--;
sc=(char far *)(0xB8000000+(x+y*80)*2l); /*直接写屏*/
while((cc=*p++)!=0&&!is_break)
{
switch(cc)
{
case '\t':
for(j=0;j<8;j++)
{
*(sc+num*2)=' ';
*(sc+num*2+1)=attrib;
num++;
}
break;
default:
*(sc+num*2)=cc;
*(sc+num*2+1)=attrib;
num++;
if(num>=l)is_break=1;
break;
}
}
}
void clr(void) /* 清屏函数比 C语言的clrscr()速度快 */
{
unsigned char *screen=(char *)0xb8000000;
register int x,y;
struct text_info text;
gettextinfo(&text);
for(y=text.wintop;y<=text.winbottom;y++)
for(x=text.winleft;x<=text.winright;x++)
{*(screen+((y-1)*80+x-1)*2)=0;
*(screen+((y-1)*80+x-1)*2+1)=text.attribute;}
}
/****************************************
* outs() 输入字符串函数
* 参数说明:
* x,y -位置
* atrib -字符串的颜色属性如: 0x1f 1为背景色,f变前景色
* spe_attrib -特殊颜色属性用 \v和 ~表示,
* p -字符串
*
*/
int outs(int x,int y,int attrib,int spe_attrib,char *p)
{unsigned cc,i=0,is_rev=0,j;
int hotkey;
char far *sc;
x--,y--;
sc=(char far *)(0xB8000000+(x+y*80)*2l);
while((cc=*p++)!=NULL)
{
if(cc=='\v'){is_rev=!is_rev;continue;}
else if(cc=='\r'){i=0;y++;
sc=(char far *)(0xb8000000+(x+y*80)*2l);
continue;
}
else if(cc=='~')
{ cc=*p++;
*(sc+i*2)=cc;
*(sc+i*2+1)=spe_attrib;
hotkey=cc;
}
else if(cc=='\t')
{cc=*p++;
for(j=0;j<cc;j++)
{
*(sc+i*2)=' ';
*(sc+i*2+1)=is_rev?spe_attrib:attrib;
i++;
}
i--;
}
else {*(sc+i*2)=cc;
*(sc+i*2+1)=is_rev?spe_attrib:attrib;
}
i++;
}
return toupper(hotkey);
}
void outxy(int x,int y,int attrib,char c) /*输出字符 */
{char far *screen;
x--,y--;
screen=(char far *)(0xb8000000l+(x+y*80)*2l);
*screen=c;
*(screen+1)=attrib;
}
/********************
*画框函数
* x1,y1 框的左上角坐标
* x2,y2 框的右下角坐标
* line 框的式样
* color 框的前景和背景颜色
* shadow 是否有影子
*/
int box(int x1,int y1,int x2,int y2,int line,int color,int shadow)
{void clr(void);
char *screen=(char *)0xb8000000;
register tmp1,tmp2;
if(shadow==1){for(tmp1=x1+1;tmp1<=x2+1;tmp1++)*(screen+(y2*80+tmp1-1)*2+1)=8;
for(tmp1=y1+1;tmp1<=y2+1;tmp1++)*(screen+((tmp1-1)*80+x2)*2+1)=8;
}
else if(shadow==2){for(tmp1=x1+1;tmp1<=x2+1;tmp1++)*(screen+(y2*80+tmp1-1)*2+1)=0;
for(tmp1=y1+1;tmp1<=y2+1;tmp1++)*(screen+((tmp1-1)*80+x2)*2+1)=0;
}
switch(line)
{
case 0:
window(x1,y1,x2,y1);
textattr(0x70);
clr();
window(x1,y1+1,x2,y2);
textattr(color);
clr();
window(x1,y1,x2,y2);
break;
case 1:
window(x1,y1,x2,y2);
textattr(0x70);
clr();
window(x1+1,y1,x2-1,y2-1);
textattr(color);
clr();
outxy(x2+1,y1,shadow==1?0x80:0x08,' ');
break;
case 2:
window(x1,y1,x2,y2);
textattr(0x70);
clr();
window(x1+1,y1+1,x2-1,y2-1);
textattr(color);
clr();
outxy(x2+1,y1,shadow==1?0x80:0x08,' ');
break;
case 3:
window(x1,y1,x2,y2);
textattr(color);
clr();
for(tmp1=x1;tmp1<x2;tmp1++)
{
outxy(tmp1,y1,color,l[0]);
outxy(tmp1,y2,color,l[0]);
}
for(tmp1=y1;tmp1<y2;tmp1++)
{
outxy(x1,tmp1,color,l[1]);
outxy(x2,tmp1,color,l[1]);
}
outxy(x1,y1,color,border[0][0]);
outxy(x1,y2,color,border[2][0]);
outxy(x2,y1,color,border[0][2]);
outxy(x2,y2,color,border[2][2]);
window(x1+1,y1+1,x2-1,y2-1);
break;
case 4:
for(tmp1=y1;tmp1<=y2;tmp1++)
{*(screen+((tmp1-1)*80+x1-1)*2+1)=0x70;
*(screen+((tmp1-1)*80+x2-1)*2+1)=0x70;
}
window(x1+1,y1,x2-1,y2);
textattr(color);
clr();
break;
default:
window(x1,y1,x2,y2);
textattr(color);
clr();
}
return(0);
}
/**********************
* 设光标的样式
* x=0 隐藏
* x=1 插入方式
* 2 改写方式
*/
void cur(int x)
{
union REGS cur;
switch(x)
{
case 0:
cur.h.ah=1;
cur.h.ch=127;
cur.h.cl=15;
int86(0x10,&cur,&cur);
break;
case 1:
cur.h.ah=1;
cur.h.ch=6;
cur.h.cl=7;
int86(0x10,&cur,&cur);
break;
case 2:
cur.x.ax=0x100;
cur.x.bx=0;
cur.x.cx=0x0113;
int86(0x10,&cur,&cur);
break;
}
}
void DosShell(void) /*Dos shell*/
{
window(1,1,80,25);
textattr(0x7);
clr();
system("");
mainmenu(1);
}
/*****************************
消息对话框
msg 提示信息
title 消息框的标题
line 类型同box()
wide 消息框框宽度
mode 是否指定按键
k 若指定按键,k为按键队列(键盘扫描码)
*/
unsigned char MsgBox(char *msg,char *szTitle,unsigned char line,char wide,unsigned int attrib,char mode,char *k)
{
struct text_info tf;
unsigned char *buff,i,code,is_break,ret=0;
unsigned char normal_color=attrib>>8,special_color=attrib&0xff;
buff=(unsigned char *)farmalloc((wide+2)*(5+line)*2);
if(buff==NULL)quit(1);
gettextinfo(&tf);
gettext(20,10,20+wide+1,13+line,buff);
cur(0);
box(20,10,20+wide,12+line,0,normal_color,1);
outs(20,10,0x70,0,szTitle);
outs(20,11,normal_color,special_color,msg);
textattr(0x4F);
if(mode&2)bell();
clrkey();
if(mode&1){is_break=0;
while(1)
{code=getkey(NULL);
for(i=0;i<slen(k);i++)
{if(code==k[i])
{is_break=1;
ret=code;
break;}
}
if(is_break)break;
}
}
else getch();
puttext(20,10,20+wide+1,13+line,buff);
farfree(buff);
window(tf.winleft,tf.wintop,tf.winright,tf.winbottom);
textattr(tf.attribute);
cur(cur_type);
return(ret);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -