我打算调用 BIOS 中断函数来检测鼠标的位置,我认为如果我恢复屏幕上显示的鼠标的原始区域然后在新位置“绘制”它,它会起作用。
但这是我的程序的结果:鼠标的图像将显示在屏幕上,图像将响应移动一次。然后程序将被卡住,直到我强行结束它。
我用dosbox模拟dos环境。我的开发环境是turbo c 3.0。我在vesa vbe下编程以支持svga模式(turbo c不完全支持)。代码:
#define MOUSEX 200
#define MOUSEY 200
int MouseInit() // checking if the driver of mouse is installed
{
int retcode;
asm{
mov AX,0
INT 33h
mov retcode,AX
}
if(retcode==0) // uninstalled
return 0;
return retcode;
}
void SetXY() // set range of mouse movement
{
asm{
mov AX,7
mov CX,0
mov DX,639 // range of x:0-639
INT 33h
mov AX,8
mov CX,0
mov DX,479 // range of y:0-479
INT 33h
}
}
void setmouse(INT16 x,INT16 y) // set the location of mouse
{
asm{
MOV CX,x
MOV DX,y
MOV AX,4
INT 33H
}
xpos = x;
ypos = y;
}
/*
INT 33H:
AX = 000Ch // go to user's function when certain acts of the mouse occur
CX = call mask // define the conditions that will trigger user's interrupt function
bit 0 call if mouse moves
bit 1 call if left button pressed
bit 2 call if left button released
bit 3 call if right button pressed
bit 4 call if right button released
bit 5 call if middle button pressed (Mouse Systems/Logitech
mouse)
bit 6 call if middle button released (Mouse Sys/Logitech mouse)
ES:DX -> FAR routine
Notes: when the subroutine is called, it is passed the following values
AX = condition mask (same bit assignments as call mask
BX = button state
CX = cursor column
DX = cursor row
SI = horizontal mickey count
DI = vertical mickey count
*/
void interrupt mousehandler()
{
int newevent,newxpos,newypos;
int i,j;
asm{
MOV newevent,AX
MOV newxpos,CX
MOV newypos,DX
}
switch(_AX){
case 0x01:
ConcealMouse(xpos,ypos,origin); //clear former mouse image
xpos=newxpos;ypos=newypos; // obtain new location of mouse
for(i=0;i<16;i++) // save original image of the screen in that new location
for(j=0;j<16;j++)
origin[i*16+j]= GetPixel(xpos+j,ypos+i);
DrawMouse(xpos,ypos); // display mouse in new location(draw the 16*16 lattice on the screen)
}
}
void installtask(INT16 mask)
{
asm{
MOV AX,0CH
MOV CX,mask
MOV BX,SEG mousehandler
MOV ES,BX
LEA DX,mousehandler
INT 33H
}
}
void ShowMouse()
{
int i,j;
if(MouseInit()==0){
SetSVGAMode(3);
printf("no mouse available!\n");
exit(1);
}
SetXY();
setmouse(MOUSEX,MOUSEY);
for(i=0;i<16;i++) // save original image of the screen
for(j=0;j<16;j++)
origin[i*16+j]= GetPixel(xpos+j,ypos+i);
DrawMouse(xpos,ypos); // draw mouse in the given location
installtask(0x007f); // waiting for interruption
}
我很确定绘制鼠标和隐藏它的功能是正确的,因为我已经测试过它。中断功能是失败的原因吗?希望得到您的答复,非常感谢。