DOS下的鼠标程序

软件开发大郭
0 评论
/
23 阅读
/
6593 字
18 2021-10

DOS下的鼠标程序

unsigned short cursor[] =
{
    0x0000,  /*0000000000000000*/ /* 16 words of cursor mask */
    0x4000,  /*0100000000000000*/
    0x6000,  /*0110000000000000*/
    0x7000,  /*0111000000000000*/
    0x7800,  /*0111100000000000*/
    0x7c00,  /*0111110000000000*/
    0x7e00,  /*0111111000000000*/
    0x7f00,  /*0111111100000000*/
    0x7c00,  /*0111110000000000*/
    0x4600,  /*0100011000000000*/
    0x0600,  /*0000011000000000*/
    0x0300,  /*0000001100000000*/
    0x0300,  /*0000001100000000*/
    0x0180,  /*0000000110000000*/
    0x0180,  /*0000000110000000*/
    0x00c0,  /*0000000011000000*/
};
struct Mouse
{
 char show;                              //mouse 光标显示/不显示
 char left;                              //mouse左键
 char right                              //mouse右键
 char middle;                            //mouse中键
 int x;                                  //mouseX坐标
 int y;                                  //mouseY坐标
 unsigned char color;            //mouse光标颜色
}mouse;
int mouse_page;
/*-------------------------------------------------------------------------------*/
void set_mouse_xy(int x_min,int x_max,int y_min,int y_max)
{
 REGS regs;
 if (x_min<0) x_min=0;
 if (x_max>SCR_H) x_max=SCR_H;
 if (y_min<0) y_min=0;
 if (y_max>SCR_V) y_max=SCR_V;
//Define H min-max
 regs.w.ax=0x07;
 regs.w.cx=x_min;
 regs.w.dx=x_max;
 int386(0x33,&regs,&regs);
//Define V min-max
 regs.w.ax=0x08;
 regs.w.cx=y_min;
 regs.w.dx=y_max;
 int386(0x33,&regs,&regs);
//POSITION MOUSE CURSOR
 regs.w.ax=0x04;
 regs.w.cx=(x_max-x_min)>>1;
 regs.w.dx=(y_max-y_min)>>1;
 int386(0x33,&regs,&regs);
}
/*-------------------------------------------------------------------------------*/
void init_mouse(void)
{
 REGS regs;
 mouse.x=SCR_H/2;
 mouse.y=SCR_V/2;
 mouse.left=0;
 mouse.right=0;
 mouse.middle=0;
 mouse.color=255;
 mouse.show=0;
//mouse reset
 regs.w.ax=0x00;
 int386(0x33,&regs,&regs);
//old mouse hidden
 regs.w.ax=0x01;
 int386(0x33,&regs,&regs);
 set_mouse_xy(0,SCR_H,0,SCR_V);
//Define Mic/Piexl
 regs.w.ax=0x0F;
 regs.w.cx=4;
 regs.w.dx=4;
 int386(0x33,&regs,&regs);
}
/*-------------------------------------------------------------------------------*/
void hard_disp_mouse(void)
{
    int i,j,x,y;
    long addr,addr1,page;
    unsigned short temp;
    unsigned char color;
    unsigned int b[]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};
    unsigned char *video=(unsigned char *)0xA0000;
    color=mouse.color;
    y=mouse.y-1;
    addr=count_offest(SCR_H,mouse.x,mouse.y);
    mouse_page=addr>>16;
    set_page(mouse_page);
 for(i=0;i<16;i++)
 {
  x=mouse.x-1;
  temp=cursor[i];
  addr=count_offest(SCR_H,x,y);
  for(j=16;j>=0;j--)
  {
      if((b[j]&temp)&&(x>0)&&(x<SCR_H)&&(y>0)&&(y<SCR_V))
      {
    page=addr>>16;
    addr1=addr-(page<<16);
    if (mouse_page!=page)
    {
        mouse_page=page;
        set_page(mouse_page);
    }
    *(video+addr1)=color;
    *(buffer+addr)=color;
      }
   x++;
   addr++;
  }
  y++;
 }
}
/*-------------------------------------------------------------------------------*/
void read_mouse(void)
{
 REGS in,out;
 mouse.color=255;
 in.w.ax=0x03;
 int386(0x33,&in,&out);
 mouse.left=(out.w.bx&0x01);
 mouse.right=(out.w.bx&0x02);
 mouse.middle=(out.w.bx&0x04);
 
 mouse.x=out.w.cx;
 if (0>mouse.x) mouse.x=0;
 if (SCR_H<mouse.x) mouse.x=SCR_H;
 mouse.y=out.w.dx;
 if (0>mouse.y) mouse.y=0;
 if (SCR_V<mouse.y) mouse.y=SCR_V;
 if (mouse.show)   hard_disp_mouse();
}


    暂无数据