Sei sulla pagina 1di 1

The above program declares two variables of type union REGS which is declared in dos.

h, It contains two structures (struct WORDREGS x, struct BYTEREGS h).These two structures contain some 1-byte long and 2-byte long variables which indirect ly represent CPU's registers. By placing 0 (sub-function) in ax register and inv oking mouse interrupt(33h),we can check whether mouse driver is loaded or not. w e used int86() function to invoke the interrupt.int86() takes 3 arguements:inter rupt no and two union REGS type variables. If mouse driver is not loaded,it retu rns 0 in ax register.All return values are accessed using 'out' i.e why we have out.x.ax==0 in if statement. In the above program, we used standard library function initgraph() to initializ e graphics system. This function takes 3 arguments; graphics driver, graphics mo de, path to the driver file. By using DETECT which is a macro defined in graphics .h , we tell the function to select a suitable driver by itself. When DETECT is us ed, no need to assign anything to graphics mode. Path is null since the driver f iles are located in the current directory. We used the same sub-function 3 and invoked mouse interrupt. This sub function e ven returns button press information in bx register. Entire button press informa tion is stored in the first 3 bits of the bx register. So we ANDED bx with 7 to separate the first 3 bits and stored them in button variable. If the first bit's value is 1 then the left button then it is not pressed. If the second bit's value pressed, if value is 0 then it is not pressed. If n the middle button is pressed, if value is 0 then is pressed, if the value is 0 is 1 then the right button is the last bit's value is 1 the it is not pressed.

We used the same sub-function 3 and invoked mouse interrupt. This sub function e ven returns button press information in bx register. Entire button press informa tion is stored in the first 3 bits of the bx register. So we ANDED bx with 7 to separate the first 3 bits and stored them in button variable. If the first bit's value is 1 then the left button then it is not pressed. If the second bit's value pressed, if value is 0 then it is not pressed. If n the middle button is pressed, if value is 0 then is pressed, if the value is 0 is 1 then the right button is the last bit's value is 1 the it is not pressed.

In the above program we have a while loop. This loop continues until a key is hi t. In loop, we used sub-function 3 and invoked mouse interrupt. Sub-function 3 r eturns X->co-ordinate in cx register and Y->co-ordinate in dx register. printf s tatements prints x and y co-ordinates as long as the loop continues. Maximum scr een resolution for mouse in text mode is 640x200 and in graphics mode is 640x480 .

Potrebbero piacerti anche