一个编程函数集(包含大量C实用函数)

又一个编程函数集(包含大量实用函数)

编程函数集,详细内容如下:


格式化字符串转换
鼠标驱动
西文模式下输出汉字(BGI)
三维窗体
时钟中断服务
取得键盘扫描码
文本模式光标定位
显示的关闭与开启
文本模式的直接写屏技术
TVGA直接写屏图形引擎
ExpandedBlockStart.gif ContractedBlock.gif /**/ /*-------------------------------------------------------------------------*/
ExpandedBlockStart.gifContractedBlock.gif
/**/ /* Head */
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*-------------------------------------------------------------------------*/
None.gif
None.gif#include 
< stdio.h >
None.gif#include 
< conio.h >
None.gif#include 
< stdarg.h >
None.gif#include 
< dos.h >
None.gif#include 
< graphics.h >
None.gif#include 
< stdio.h >
None.gif#include 
< iostream.h >
None.gif#include 
< stdlib.h >
None.gif#include 
< time.h >
None.gif#include 
< bios.h >
None.gif#include 
< string .h >
None.gif#include 
< math.h >
None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*---------------------------格式化字符串转换------------------------------*/
None.gif
None.gif
int  vsprint( char   * buffer, char   * fmt, dot.gif)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifva_list argptr;
InBlock.gif
int cnt;
InBlock.gifva_start(argptr, fmt);
InBlock.gifcnt 
= vsprintf(buffer, fmt, argptr);
InBlock.gifva_end(argptr);
InBlock.gif
return(cnt);
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*-------------------------------鼠标驱动----------------------------------*/
None.gif
None.gif
int  mouse( int  a, int  b, int  c, int  d)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifasm mov ax,a
InBlock.gifasm mov bx,b
InBlock.gifasm mov cx,c
InBlock.gifasm mov dx,d
InBlock.gifasm 
int 33h
InBlock.gif
return _AX;
ExpandedBlockEnd.gif}

None.gif
None.gif
#if  defined(MOUSESHAPE)  // 光标形状设定
None.giftypedef 
struct
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifunsigned 
int shape[32];
InBlock.gif
char hotx;
InBlock.gif
char hoty;
ExpandedBlockEnd.gif}
SHAPE;
None.gif
ExpandedBlockStart.gifContractedBlock.gifSHAPE pen1
= dot.gif {dot.gif{0x0fff,0x07ff,0x03ff,0x01ff,0x80ff,0xc07f,0xe03f,0xf01f,
InBlock.gif
0xf80f,0xfc07,0xfe03,0xff01,0xff80,0xffc1,0xffe3,0xfff7,
InBlock.gif
0xf000,0xe800,0xd400,0xaa00,0x5500,0x2a80,0x1540,0x0aa0,
ExpandedBlockEnd.gif
0x0550,0x02a8,0x0154,0x00aa,0x0055,0x002a,0x0014,0x0008}
,0,0 }
;
ExpandedBlockStart.gifContractedBlock.gifSHAPE pen2
= dot.gif {dot.gif{0xe1ff,0xe1ff,0xe1ff,0xe1ff,0xe000,0xe000,0xe000,0xe000,
InBlock.gif
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
InBlock.gif
0x1e00,0x1200,0x1200,0x1200,0x1200,0x13ff,0x1249,0x1249,
ExpandedBlockEnd.gif
0x1249,0x9001,0x9001,0x9001,0x8001,0x8001,0x8001,0xffff}
,5,0}
;
None.gif
None.gif
None.gif
void  mouseshape(SHAPE sp)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif_BX
=sp.hotx;
InBlock.gif_CX
=sp.hoty;
InBlock.gif_ES
=FP_SEG(&sp.shape);
InBlock.gif_DX
=FP_OFF(&sp.shape);
InBlock.gif_AX
=0x09;
InBlock.gifgeninterrupt(
0x33);
ExpandedBlockEnd.gif}

None.gif
#endif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*--------------------------西文模式下输出汉字(BGI)------------------------*/
None.gif
None.gif
void  initgraphics( int  gdriver, int  gmode, char   * drvpath = "" )
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifinitgraph(
&gdriver,&gmode,drvpath);
ExpandedBlockEnd.gif}

None.gif
None.gifcouttextxy(FILE 
* library, int  x, int  y,unsigned  char  far  * string , char  color)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifregister 
int i,j;
InBlock.gifunsigned 
long int locate;
InBlock.gif
int k=0;
InBlock.gif
char l=0,buffer[32];
InBlock.gif
if(library==NULL) return 0;
InBlock.gif
while(string[k]!='\0')
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.giflocate
=(string[k]-161)*94+string[k+1]-161;
InBlock.giffseek(library,(
long int)locate*32,SEEK_SET);
InBlock.giffread(buffer,
32,sizeof(char),library);
InBlock.gifk
+=2;
InBlock.gif
for(i=0;i<16;i++)
InBlock.gif
for(j=0;j<2;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifl
=buffer[i*2+j];
InBlock.gif
if((l&0x80)!=0) putpixel(x+j*8,y+i,color);
InBlock.gif
if((l&0x40)!=0) putpixel(x+j*8+1,y+i,color);
InBlock.gif
if((l&0x20)!=0) putpixel(x+j*8+2,y+i,color);
InBlock.gif
if((l&0x10)!=0) putpixel(x+j*8+3,y+i,color);
InBlock.gif
if((l&0x08)!=0) putpixel(x+j*8+4,y+i,color);
InBlock.gif
if((l&0x04)!=0) putpixel(x+j*8+5,y+i,color);
InBlock.gif
if((l&0x02)!=0) putpixel(x+j*8+6,y+i,color);
InBlock.gif
if((l&0x01)!=0) putpixel(x+j*8+7,y+i,color);
ExpandedSubBlockEnd.gif}

InBlock.gifx
+=16;
ExpandedSubBlockEnd.gif}

InBlock.gif
return 1;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*-------------------------------三维窗体----------------------------------*/
None.gif
None.gif
void  window3d( int  x, int  y, int  length, int  width, char   * title)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifsetcolor(
7);
InBlock.gifline(x,y,x
+length,y);
InBlock.gifline(x,y,x,y
+width);
InBlock.gifsetcolor(
0);
InBlock.gifline(x,y
+width,x+length,y+width);
InBlock.gifline(x
+length,y,x+length,y+width);
InBlock.gifsetcolor(
15);
InBlock.gifline(x
+1,y+1,x+length-1,y+1);
InBlock.gifline(x
+1,y+1,x+1,y+width-1);
InBlock.gifsetcolor(
8);
InBlock.gifline(x
+1,y+width-1,x+length-1,y+width-1);
InBlock.gifline(x
+length-1,y+1,x+length-1,y+width-1);
InBlock.gifsetfillstyle(
1,7);
InBlock.gifbar(x
+2,y+2,x+length-2,y+width-2);
InBlock.gifsetfillstyle(
1,1);
InBlock.gifbar(x
+4,y+4,x+length-4,y+20);
InBlock.gifsetcolor(
15);
InBlock.gifouttextxy(x
+8,y+8,title);
ExpandedBlockEnd.gif}

None.gif
None.gif
void  textwindow3d( int  x, int  y, int  length, int  width, char   * title, int  bargin)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifwindow3d(x,y,length,width,title);
InBlock.gifsetfillstyle(
1,15);
InBlock.gifbar(x
+bargin,y+bargin+20,x+length-bargin,y+width-bargin);
InBlock.gifsetcolor(
0);
InBlock.gifline(x
+bargin-1,y+bargin+19,x+length-bargin+1,y+bargin+19);
InBlock.gifline(x
+bargin-1,y+bargin+19,x+bargin-1,y+width-bargin+1);
InBlock.gifsetcolor(
7);
InBlock.gifline(x
+length-bargin+1,y+bargin+19,x+1+length-bargin,y+width-bargin+1);
InBlock.gifline(x
+bargin-1,y+width-bargin+1,x+1+length-bargin,y+width-bargin+1);
InBlock.gifsetcolor(
8);
InBlock.gifline(x
+bargin-2,y+bargin+18,x+2+length-bargin,y+18+bargin);
InBlock.gifline(x
+bargin-2,y+18+bargin,x+bargin-2,y+2+width-bargin);
InBlock.gifsetcolor(
15);
InBlock.gifline(x
+2+length-bargin,y+18+bargin,x+2+length-bargin,y+2+width-bargin);
InBlock.gifline(x
+bargin-2,y+2+width-bargin,x+2+length-bargin,y+2+width-bargin);
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*-----------------------------时钟中断服务--------------------------------*/
None.gif
None.gif
#if  defined(INTERRUPT)
None.gif
void  interrupt ( * old)();
None.gif
// void interrupt hand(){(*old)();}
None.gif

None.gif
void  uninstall()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifdisable();
InBlock.gifsetvect(
0x1c,(*old));
InBlock.gifenable();
ExpandedBlockEnd.gif}

None.gif
None.gif
void  install()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifdisable();
InBlock.gifold
=getvect(0x1c);
InBlock.gifsetvect(
0x1c,hand);
InBlock.gifenable();
ExpandedBlockEnd.gif}

None.gif
#endif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*-----------------------------取得键盘扫描码------------------------------*/
None.gif
None.gif
int  keydown()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int key;
InBlock.gif
if(bioskey(1)==0return -1;
InBlock.gif
else 
InBlock.gifkey
=bioskey(0);
InBlock.gifkey
=key&0xff?key&0xff:key>>8;
InBlock.gif
return key;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*----------------------------文本模式光标定位-----------------------------*/
None.gif
None.gif
void  goto_xy( char  x, char  y)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifasm mov ah,
2
InBlock.gifasm mov dl,x
InBlock.gifasm mov dh,y
InBlock.gifasm mov bh,
0
InBlock.gifasm 
int 10h
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*----------------------------显示的关闭与开启-----------------------------*/
None.gif
None.gif
#define  CLOSE 0x1201
None.gif
#define  OPEN 0x1200
None.gif
void  video( int  mode)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifasm mov bl,36h
InBlock.gifasm mov ax,mode
InBlock.gifasm 
int 10h
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*---------------------------文本模式的直接写屏技术------------------------*/
None.gif
None.gif
int  video_mode( void )
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifunion REGS r;
InBlock.gifr.h.ah
=15;
InBlock.gif
return int86(0x10,&r,&r)&255;
ExpandedBlockEnd.gif}

None.gif
None.gif
char  far  * set_v_ptr()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int vmode;
InBlock.gif
char far *vid_mem;
InBlock.gifvmode
=video_mode();
InBlock.gif
if((vmode!=2)&&(vmode!=3)&&(vmode!=7))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifprintf(
"Video must be in 80 column text mode!");
InBlock.gifexit(
1);
ExpandedSubBlockEnd.gif}

InBlock.gif
if(vmode==7) vid_mem=(char far *)0xb0000000;
InBlock.gif
else vid_mem=(char far *)0xb8000000;
InBlock.gif
return vid_mem;
ExpandedBlockEnd.gif}

None.gif
None.gif
void  write_char( char  far  * vid_mem, int  x, int  y, char  ch, int  attrib)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
char far *v;
InBlock.gifv
=vid_mem;
InBlock.gifv
+=(y*160)+x*2;
InBlock.gif
*v++=ch;
InBlock.gif
*v=attrib;
ExpandedBlockEnd.gif}

None.gif
None.gif
void  write_string( char  far  * vid_mem, int  x, int  y, char   * string , int  color)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i;
InBlock.gif
for(i=0;i<strlen(string);i++)
InBlock.gifwrite_char(vid_mem,x
+i,y,*(string+i),color);
ExpandedBlockEnd.gif}

None.gif
None.gif
int  read_color( char  far  * vid_mem, int  x, int  y)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
char far *v;
InBlock.gifv
=vid_mem;
InBlock.gifv
+=(y*160)+x*2;
InBlock.gif
return *(++v);
ExpandedBlockEnd.gif}

None.gif
None.gif
char  read_char( char  far  * vid_mem, int  x, int  y)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
char far *v;
InBlock.gifv
=vid_mem;
InBlock.gifv
+=(y*160)+x*2;
InBlock.gif
return *v;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*-------------------------TVGA直接写屏图形引擎--------------------------*/
None.gif
None.gif
void  _setgraphmode( int  mode, int   * xmax, int   * ymax)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifunion REGS regs;
InBlock.gifunsigned 
char video;
InBlock.gif
switch(mode)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
case 0: video=0x5c;
InBlock.gif
*xmax=640;
InBlock.gif
*ymax=400;break//640x400
InBlock.gif
case 1: video=0x5d;
InBlock.gif
*xmax=640;
InBlock.gif
*ymax=480;break//640x480
InBlock.gif
case 2: video=0x5e;
InBlock.gif
*xmax=800;
InBlock.gif
*ymax=600;break//800x600
InBlock.gif
case 3: video=0x62;
InBlock.gif
*xmax=1024;
InBlock.gif
*ymax=768;break//1024x768
InBlock.gif
default:video=0x5d;
InBlock.gif
*xmax=640;
InBlock.gif
*ymax=480;break//Default: 640x480
ExpandedSubBlockEnd.gif
}

InBlock.gifregs.h.ah
=0;
InBlock.gifregs.h.al
=video;
InBlock.gifint86(
0x10,®s,®s);
InBlock.gifoutportb(
0x3c4,0x0b);
InBlock.gifinportb(
0x3c5);
InBlock.gif
return;
ExpandedBlockEnd.gif}

None.gif
None.gif
void  _putpixel( int  x, int  y, int  color, int  xmax)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifunsigned 
long int result=y;
InBlock.gif
char far *offset;
InBlock.gif
char temp;
InBlock.gifresult
*=xmax;
InBlock.gifresult
+=x;
InBlock.gifoffset
=(char far *)MK_FP(0xa000,(unsigned)result&0xffff);
InBlock.gifoutportb(
0x3c4,0x0e);
InBlock.giftemp
=((result>>16)&0x0f)^0x02;
InBlock.gifoutportb(
0x3c5,temp);
InBlock.giftemp
=*offset;
InBlock.gif
*offset=(char)color;
InBlock.gif
return;
ExpandedBlockEnd.gif}

None.gif
None.gif
int  _getpixel( int  x, int  y, int  xamx)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifunsigned 
long int result=y;
InBlock.gif
char far *offset;
InBlock.gif
char temp;
InBlock.gifresult
*=xmax;
InBlock.gifresult
+=x;
InBlock.gifoffset
=(char far *)MK_FP(0xa000,(unsigned)result&0xffff);
InBlock.gifoutportb(
0x3c4,0x0e);
InBlock.giftemp
=((result>>16)&0x0f)^0x02;
InBlock.gifoutportb(
0x3c5,temp);
InBlock.giftemp
=*offset;
InBlock.gif
return (int)temp;
ExpandedBlockEnd.gif}

None.gif
None.gif
void  _closegraph()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifunion REGS regs;
InBlock.gifregs.h.ah
=0x00;
InBlock.gifregs.h.al
=0x03;
InBlock.gifint86(
0x10,®s,®s);
InBlock.gif
return;
ExpandedBlockEnd.gif}

None.gif
None.gif
void  _outtextxy( int  x, int  y, char  far  * string , int  color, int  xmax)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifregister 
int i,j;
InBlock.gif
char huge *ptr;
InBlock.gif
int k=0;
InBlock.gif
while(string[k]!='\0')
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifptr
=(char huge *)MK_FP(0xf000,0xfa6e+(string[k]<<3));
InBlock.gif
for(i=0;i<8;i++)
InBlock.gif
for(j=0;j<8;j++)
InBlock.gif
if((ptr[i]&(0x80>>j))!=0)
InBlock.gif_putpixel(x
+(k<<3)+j,y+i,color,xmax);
InBlock.gifk
++;
ExpandedSubBlockEnd.gif}

InBlock.gif
return;
ExpandedBlockEnd.gif}

None.gif
None.gif
int  _couttextxy(FILE  * library, int  x, int  y,unsigned  char  far  * string , char  color, int  xmax)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifregister 
int i,j;
InBlock.gifunsigned 
long int locate;
InBlock.gif
int k=0;
InBlock.gif
char l=0,buffer[32];
InBlock.gif
if(library==NULL) return 0;
InBlock.gif
while(string[k]!='\0')
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.giflocate
=(string[k]-161)*94+string[k+1]-161;
InBlock.giffseek(library,(
long int)locate*32,SEEK_SET);
InBlock.giffread(buffer,
32,sizeof(char),library);
InBlock.gifk
+=2;
InBlock.gif
for(i=0;i<16;i++)
InBlock.gif
for(j=0;j<2;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifl
=buffer[i*2+j];
InBlock.gif
if((l&0x80)!=0) _putpixel(x+j*8,y+i,color,xmax);
InBlock.gif
if((l&0x40)!=0) _putpixel(x+j*8+1,y+i,color,xmax);
InBlock.gif
if((l&0x20)!=0) _putpixel(x+j*8+2,y+i,color,xmax);
InBlock.gif
if((l&0x10)!=0) _putpixel(x+j*8+3,y+i,color,xmax);
InBlock.gif
if((l&0x08)!=0) _putpixel(x+j*8+4,y+i,color,xmax);
InBlock.gif
if((l&0x04)!=0) _putpixel(x+j*8+5,y+i,color,xmax);
InBlock.gif
if((l&0x02)!=0) _putpixel(x+j*8+6,y+i,color,xmax);
InBlock.gif
if((l&0x01)!=0) _putpixel(x+j*8+7,y+i,color,xmax);
ExpandedSubBlockEnd.gif}

InBlock.gifx
+=16;
ExpandedSubBlockEnd.gif}

InBlock.gif
return 1;
ExpandedBlockEnd.gif}

None.gif
None.gif
#if  defined(TVGAMOUSE)
None.gif
char  image[ 55 ];
ExpandedBlockStart.gifContractedBlock.gif
char  cursorshape[ 55 ] = dot.gif {14,14,14,14,0,14,
InBlock.gif
14,0,0,14,14,0,
InBlock.gif
0,0,14,14,0,0,
InBlock.gif
0,0,14,14,0,0,
InBlock.gif
0,0,0,14,14,0,
InBlock.gif
0,0,0,0,0,14,14,
InBlock.gif
0,0,0,0,0,0,0,14,
InBlock.gif
14,14,14,14,14,14,
ExpandedBlockEnd.gif
14,14,14,14}
;
None.gif
None.gif
void  _putimage( int  x, int  y)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i,j,k=0;
InBlock.gif
for(j=y;j<y+10;j++)
InBlock.gif
for(i=x;i-x<j-y+1;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif_putpixel(i,j,image[k
++]);
ExpandedSubBlockEnd.gif}

InBlock.gif
return;
ExpandedBlockEnd.gif}

None.gif
None.gif
void  cursor( int  x, int  y)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
static int cf=0,oldx=-1,oldy=-1;
InBlock.gif
if(!cf) cf=1;
InBlock.gif
else if(x!=oldx||y!=oldy) _putimage(oldx,oldy);
InBlock.gif
if(x!=oldx||y!=oldy) draw(x,y);
InBlock.gifoldx
=x;oldy=y;
InBlock.gif
return;
ExpandedBlockEnd.gif}

None.gif
#endif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*-------------------------------------------------------------------------*/

转载于:https://www.cnblogs.com/zhangyin/archive/2007/02/15/650869.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值