![]() |
VOOZH | about |
Till now we have seen only static output on the black window in C/C++ without any peripheral device interaction(like mouse). Here static means that interaction with the output screen through the mouse to run a dynamic event or task. The goal will be to make the pointer of the mouse visible on our output screen, through which it can see any new event when the mouse is clicked on the same output window.
Requirement:Turbo C++ IDE or DOS BOX
Fundamental Knowledge:
The idea is to tell a mouse to do anything on the output screen. In actual the communication with the mouse directly is not possible but through the driver provided. The idea is to use interrupts to get access to this driver. Each device provided by a computer has a unique port which is a hexadecimal value that is designed to be machine-independent enhancing the portability of the program. Mouse has port 0X33 attached to it. Use of address registers is also required to access these port. These are basically UNION of type REGS defined in "dos.h". Use two registers to communicate to a device driver one for input and one for output and send value to device driver through the input register and receive information in it embedded in the output register.
Now there are two ways to display mouse pointer on C/C++ screen. First is the non-graphic mode and the second is Graphic mode, Here we use graphic mode. To switch our output window in Graphic mode steps are listed below:
Enable Graphic mode: For enabling the graphics mode use initgraph() function which is used to initialize the graphics mode. This function is present in "graphics.h"header file.
Syntax of initgraph():
void initgraph(int *gdriver, int *gmode, char *pathtodriver);
Program 1:
Output:
👁 Image: The various mouse functions can be access using different values of AX input Register and passing those values to mouse port using an interrupt. Functions are listed below in the table:
Here AX, BX, CX, and DX are members of UNION REGS.
| Interrupt | Service | Description |
0X33 OR 51 | 0 |
|
1 |
| |
2 |
| |
3 |
| |
4 |
| |
7 |
| |
8 |
|
: The int86() is a C library function that facilitates access to bare bone DOS and BIOS service interrupts. It is a wrapper over inline assembly interrupt call. It takes CPU register values with object to a structure where member variables are equivalent to CPU registers. It takes three arguments.
// Declaration syntax
int int86(int intno, union REGS* inregs, union REGS* outregs);
// intno - Interrupt vector /service number
// inregs - Input argument registers as REGS
// outregs - Output argument registers as REGS
There are various use cases of the Mouse Programming that are listed below:
Program 2:
Below is the program to check if a mouse driver is loaded or not: