Mouse in TC++

Posted on April 24, 2008. Filed under: Programming | Tags: , , , , , , |

Want to use mouse in C/C++ in DOS ? This section gives the basics to use a mouse in the 16-bit DOS world using C. The graphics mode used here is 640x480x16 color.

We use the int86() function to handle interrupts. Lets start. Put the declarations below first in your mouse header file.

REGS I,O;

SREGS s;

int visible,state;

1. To initialize the mouse, the function reset is defined as follows.

int reset()
{
I.x.ax=0;visible=0;
int86(0x33,&I,&O);
return 1;
}

2. To show the mouse pointer

void show()
{
if(!visible)
{
visible=1;
I.x.ax=1;
int86(0x33,&I,&O);
}
}

3. To hide…

void hide()
{
if(visible)
{
visible=0;
I.x.ax=2;
int86(0x33,&I,&O);
}
}

4. Get status. Returns 0 for no event, 1 for left click, and 2 for right click

int status()
{
I.x.ax=3;
int86(0x33,&I,&O);
return O.x.bx;
}

5. Get X and Y coordinates

int x()
{
I.x.ax=3;
int86(0x33,&I,&O);
return O.x.cx;
}

int y()
{
I.x.ax=3;
int86(0x33,&I,&O);
return O.x.dx;
}

6. Restricting pointer to (x1,y1) – (x2,y2)

void restrict(int x1,int y1,int x2,int y2)
{
I.x.ax=7;
I.x.cx=x1;
I.x.dx=x2;
int86(0x33,&I,&O);
I.x.ax=8;
I.x.cx=y1;
I.x.dx=y2;
int86(0x33,&I,&O);
}

7. Placing pointer at a coordinate (x,y)

void place(int x,int y)
{
I.x.ax=4;
I.x.cx=x;
I.x.dx=y;
int86(0x33,&I,&O);
}

Now the mouse can be initialised by the following calls…

mouse.reset();
mouse.show();

Read Full Post | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...