Friday, February 21, 2020 | Toby Opferman

Mouse Programming

Toby Opferman

                        How To Use The Mouse

        This Tutorial is a tutorial on how to use the mouse
in your assembly (or C) programs.  The mouse is extremely simple
if you use the Microsoft Mouse Driver or Compat, which all
applications and computers use.  It's always installed.  You COULD
access the ports directly and poll the IRQ and set up an Interrupt
handler to keep track, but that is not nessary unless you are
developing your own OS.

 INT 33h is the Mouse Driver's Interupt and it does EVERYTHING
         for you.

 To Initialize/Reset the Mouse:
 XOR AX, AX     ; Set AX = 0
 INT 33h        ; Call Mouse Driver
 TEST AX, AX    ; Test For Error (AX = FFFFh on Success or AX = 0 For Failure)

 NOTE: BX = Number of buttons

 Now, you have the mouse Initialized.  All you have to do is display the
 mouse pointer.

 MOV AX, 1    ; Display Mouse Pointer
 INT 33h

 That's it.  The driver will take care of the mouse movement and such.
 There is one note though, If you go to update the Video Screen,
 You will want to Hide the Mouse pointer or else it will leave an
 image of itself on the screen.  To Hide the Mouse, just:

 MOV AX, 2    ; Hide Mouse Pointer
 INT 33h

 Very Simple.  Now, one last thing you will want to do is get the
 mouse X Y location and what buttons are pressed.

 MOV AX, 3    ; Get Mouse Status
 INT 33h
 BX = Button Status

    Bit 2 = Center Button, 1 = Pressed, 0 = No
    Bit 1 = Right Button,  1 = Pressed, 0 = No
    Bit 0 = Left Button,   1 = Pressed, 0 = No

 CX = Absolute X Position  (NOTE: in Mode 13h, you will probably want to
                                  SHR CX, 1 Because it returns a value of 0-639
                                  and not 0-319)
 DX = Absolute Y Position

And that's it.  There are other functions, such as changing the Mouse Pointer
bitmap, Mouse Sensitivity or etc.  Those are easy to do as well, you just
call the INT 33h Functions.  There are a lot of functions for the mouse,
You may want to get Ralf Browns' Interrupt list or Another Kind of
Interrupt list that will list all the Functions of INT 33h in simple
About Toby Opferman

Professional software engineer with over 15 years...

Learn more »
Codeproject Articles

Programming related articles...

Articles »

Resume »

Email: codeproject(at)opferman(dot)com