dos已经很长时间不用了,应catcat要求,贴出来,希望对大家有所帮助。
以下代码在dos/turbo_C2.0编译通过,并使用良好,只是没有注释,
我也忘了,大家根据函数名猜吧。
http://leadgenius.cublog.cn//* morse.c */
#include
#include
#include
#include
#include
#include"mouse.h"
int mouse_text_x;
int mouse_text_y;
int mouse_grph_x;
int mouse_grph_y;
int mouse_initialized;
static int prev_cursor_state=0;
static char far *bios_video_area=(char far *)0x00400049L;
static int low_resolution=0;
static void set_mouse_posn(int *x,int *y);
static int low_res_mode(int gd,int gm);
void mouse(int *m1,int *m2,int *m3,int *m4)
{union REGS inregs,outregs;
inregs.x.ax=*m1;
inregs.x.bx=*m2;
inregs.x.cx=*m3;
inregs.x.dx=*m4;
int86(0x33,&inregs,&outregs);
*m1=outregs.x.ax;
*m2=outregs.x.bx;
*m3=outregs.x.cx;
*m4=outregs.x.dx;
}
int check_mouse_driver(int need_mouse)
{void far *address;
address=getvect(0x33);
if((address==NULL)||(*(unsigned char *) address==0xcf)){
if(need_mouse){
printf("mouse driver not install
");
exit(1);
}
else return 0;
}
return 1;
}
int init_mouse(int need_mouse,int gd,int gm)
{int m1;
mouse_initialized=0;
if(check_mouse_driver(need_mouse)){
if(gd==7) *bios_video_area=6;
if(low_res_mode(gd,gm)) low_resolution=1;
m1=mouse_reset();
if(m1){
mouse_initialized=1;
move_mouse(0,0);
mouse_on(0);
}
else{
if(need_mouse){
printf("ERROR activating mouse......
");
exit(1);
}
}
}
return mouse_initialized;
}
static int low_res_mode(int gd,int gm)
{ if((gd==1 || gd==2 ||gd==8) && (gm>=0 && gm<=3)) return 1;
return 0;
}
int mouse_reset(void)
{int x1,m1,m2,m3,m4;
mouse_off(1);
m1=M_reset;
mouse( &m1,&m2,&m3,&m4);
set_mouse_posn(&m3,&m4);
return m1;
}
void move_mouse(int x,int y)
{int m1,m2,m3,m4;
if (!mouse_initialized) return;
m1=M_set_curs;
m3=x*8;
m4=y*8;
mouse(&m1,&m2,&m3,&m4);
set_mouse_posn(&m3,&m4);
}
void mouse_on(int restoreflag)
{int m1,m2,m3,m4;
if(mouse_initialized){
if (!restoreflag||prev_cursor_state){
m1=M_show_curs;
mouse(&m1,&m2,&m3,&m4);
prev_cursor_state=1;
}
}
}
void mouse_off(int tempflag)
{int m1,m2,m3,m4;
if(mouse_initialized){
if(prev_cursor_state){
m1=M_hide_curs;
mouse(&m1,&m2,&m3,&m4);
if(!tempflag) prev_cursor_state=0;
}
}
}
void mouse_grph_posn(int *x,int *y)
{int m1,m2;
if(mouse_initialized){
m1=M_get_status;
mouse(&m1,&m2,x,y);
set_mouse_posn(x,y);
}
else{
*x=0;
*y=0;
}
return;
}
void mouse_txt_posn(int *x,int *y)
{ mouse_grph_posn(x,y);
*x=mouse_text_x;
*y=mouse_text_y;
return;
}
int mouse_in_box(int graphflag,int left,int top,int right,int bottom)
{int x,y;
if(mouse_initialized){
if(graphflag){
x=mouse_grph_x;
y=mouse_grph_y;
}
else{
x=mouse_text_x;
y=mouse_text_y;
}
if((y>=top)&&(y<=bottom)&&(x>=left)&&(x<=right))
return 1;
}
return 0;
}
int button_release(int b)
{int m1,m2,m3,m4;
if(mouse_initialized){
m1=M_get_rel;
m2=b;
mouse(&m1,&m2,&m3,&m4);
set_mouse_posn(&m3,&m4);
if(m2) return 1;
}
return 0;
}
int button_press(int b)
{ int m1,m2,m3,m4;
if (mouse_initialized){
m1=M_get_press;
m2=b;
mouse(&m1,&m2,&m3,&m4);
set_mouse_posn(&m3,&m4);
if(m2) return 1;
}
return 0;
}
int button_state()
{int m1,m2,m3,m4;
if(mouse_initialized){
m1=M_get_status;
mouse(&m1,&m2,&m3,&m4);
set_mouse_posn(&m3,&m4);
return m2;
}
return 0;
}
static void set_mouse_posn(int *x,int *y)
{if(low_resolution) *x>>=1;
mouse_grph_x=*x;
mouse_grph_y=*y;
mouse_text_x=*x/8;
mouse_text_y=*y/8;
}
int mouse_trigger(int button_dir)
{ int k;
if(bioskey(1)){
k=bioskey(0);
}
else{
k=0;
if(button_dir){
if(button_press(0)) k=Left_mouse_press;
else if(button_press(1)) k=Right_mouse_press;
}
else{
if(button_release(0)) k=Left_mouse_rel;
else if(button_release(1)) k=Right_mouse_rel;
}
}
return k;
}
阅读(1385) | 评论(0) | 转发(0) |