intro to devlop mose+progrs=amming

Upload: ramakant-singh

Post on 05-Apr-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Intro to Devlop Mose+Progrs=Amming

    1/1

    The above program declares two variables of type union REGS which is declared indos.h, It contains two structures (struct WORDREGS x, struct BYTEREGS h).Thesetwo structures contain some 1-byte long and 2-byte long variables which indirectly represent CPU's registers. By placing 0 (sub-function) in ax register and invoking mouse interrupt(33h),we can check whether mouse driver is loaded or not. we used int86() function to invoke the interrupt.int86() takes 3 arguements:interrupt no and two union REGS type variables. If mouse driver is not loaded,it returns 0 in ax register.All return values are accessed using 'out' i.e why we haveout.x.ax==0 in if statement.In the above program, we used standard library function initgraph() to initialize graphics system. This function takes 3 arguments; graphics driver, graphics mode, 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 used, no need to assign anything to graphics mode. Path is null since the driver files are located in the current directory.

    We used the same sub-function 3 and invoked mouse interrupt. This sub function even returns button press information in bx register. Entire button press information is stored in the first 3 bits of the bx register. So we ANDED bx with 7 toseparate the first 3 bits and stored them in button variable.

    If the first bit's value is 1 then the left button is pressed, if the value is 0then it is not pressed. If the second bit's value is 1 then the right button ispressed, if value is 0 then it is not pressed. If the last bit's value is 1 the

    n the middle button is pressed, if value is 0 then it is not pressed.

    We used the same sub-function 3 and invoked mouse interrupt. This sub function even returns button press information in bx register. Entire button press information is stored in the first 3 bits of the bx register. So we ANDED bx with 7 toseparate the first 3 bits and stored them in button variable.

    If the first bit's value is 1 then the left button is pressed, if the value is 0then it is not pressed. If the second bit's value is 1 then the right button ispressed, if value is 0 then it is not pressed. If the last bit's value is 1 then the middle button is pressed, if value is 0 then it is not pressed.

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