I intended to call BIOS interrupt function to detect the position of mouse and I thought it would work if I recover the original area of the mouse displayed on the screen and then "draw" it in its new location.
But here is the result of my program:the image of mouse will be dispayed on the screen and the image will move in response just for one time.Then the program will be stuck until I end it forcibly.
I was using dosbox to simulate dos environment.My develop environment is turbo c 3.0.I was programing under vesa vbe to support svga mode(which turbo c does not totally support).code:
#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
}
I am pretty sure that the function of drawing mouse and concealing it is correct as I have tested it. Was the interrupt function the cause of failure? Wish for your answer,many thanks.