16 bit Assembly

Home   Feedback   Site Map   Instruction Index  


Mouse Callback

One of the most useful routines is an Interrupt callback.
The ability to receive an instruction triggered by an interrupt enables users to continue working until the interrupt occurs.

The most usefull of these is the mouse interrupt. The mouse uses interrupt 33h.

The following code example show how to start the callback procedure and how to handle it.

This code tracks the movement by displaying a yellow symbol on a text display.
When a button is pressed it diplays the AX, BX, CX and DX registers at the current mouse position.

In the screen shot below the 4 registers show these values, A left button click starting with a 2 button down and folowed by the button up.
Then the right button click starting with an 8. The mouse symbol here is a yellow X.

The callback routine handling the request must return as a FAR RET for locall calls or an IRET for drivers in a different segment.

Initialize and Register the mouse callback handler.

To start a callback the mouse drivers must be Initialized, and then register the address of the callback routine.

Handle the Mouse Callback.

The callback handler should either handle the request itself or pass the request to an appropriate sub routine.
This example compares the mouse action in AX and redirects the callback to the correct sub routine.

Handle Mouse Movement

Tracking the mouse is relatively easy with the callback. Every movement of the mouse triggers a callback.
The CX register holds the horizontal position (usually multiplied by 8 pixels).
The DX register holds the vertical position (usually multiplied by 8 pixels).

Handle Mouse Button Presses.

The mouse button clicks are reported on button down and button up. These can be detected independantly when required.
This example passes them to the same routine.

The callback provides the following registers. AX=Mouse Action, BX=Mouse Down or Up, CX=Horizontal position, DX=Vertical position.

The left and right mouse buttons are handle in the same way.

Cancelling the Callback.

You can cancel the callback by registering the callback again with CX set to NULL.




Last Update 9/03/2023