Blog Archive

Thursday, May 6, 2010

How to use mouse in turbo c program.

This is very interesting to know how to use mouse in your turbo c program. In windows programs mouse support is inbuilt to program. But Turbo c is a 16 bit dos environment ide. So how can you do so in a dos application. We know that Turbo c is itself a dos based program. And it uses mouse,
so it is possible to use mouse in dos application.
You can use mouse in your turbo c program through issue a interrupt 0x33 which is mouse interrupt number in x86 architecture.
int86() function defined in dos.h is used to raise interrupts. But we also need to access and modify CPU registers like ax,bx etc. So there is a union called REGS in dos.h by which we can access CPU registers.
So by the use of this function int86() and union REGS you can write program to use mouse.

Following is an example of turbo c using mouse.

Try this and use mouse in your application. good luck!!!

#include<stdio.h>
#include<dos.h>
#define INTIALIZE 1
#define BUTTON_PRESS 5
#define LEFT_BUTTON_PRESS 0
#define RIGHT_BUTTON_PRESS 1
#define BUTTON_PRESSED 1

//unions to acces cpu registers
union REGS output,input;
void main()
{
//Setting value to intialize mouse device.
input.x.ax=INTIALIZE;
//int86 function function used to raise a interrupt.
//0x33 is mouse interrupt number.
int86(0x33,&input,&output);
printf("Press left mouse button to exit...");
//loop untile left mouse button is pressed
while(output.x.bx != BUTTON_PRESSED)
{
//setting register value to check for button press
input.x.ax=BUTTON_PRESS;
//setting register value to check for left mouse button press
input.x.bx=LEFT_BUTTON_PRESS;
//raising interrupt to check for mouse button press
int86(0x33,&input,&output);
}

}

1 comment:

  1. It's amazing...... Thanks a lot.......

    ReplyDelete