News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ENABLE MOUSE INPUT - MASM611

Started by Elite Commando, November 24, 2009, 07:01:03 PM

Previous topic - Next topic

Elite Commando

Hi, I am trying to mouse input at runtime in my program, could I get the code used to do that so that I can embed it in my code? Please keep in mind that I am bound to use MASM611, THANKS!  :toothy

z941998

When I was reading the Windows SDK, I learned that the mouse system automatically talks to the operating system and provides messages to update apps and procedures.  This means all you have to do is capture these messages and react accordingly.

As an example: Drawing with the mouse, you press the left button, drag the mouse, and then release the button.  These three feature can be captured and reacted to.  The SDK has a working example of this.


MichaelW

One simple method is to use the functions that are provided by the mouse driver, called using software interrupt 33h. Most of the necessary information can be found in Ralf Brown's Interrupt list.

An HTML version is here:

http://www.ctyme.com/rbrown.htm

And the download version here:

http://www-2.cs.cmu.edu/~ralf/files.html

Running under Windows it's probably safe to assume that a mouse driver will be present, but running under DOS your application needs to check this first. See the documentation for interrupt 33h, function 0.

As a minimum your application will probably need a way to read the mouse cursor position and button status, see the documentation for interrupt 33h, function 3. In text (alphanumeric) mode the mouse driver works with the mouse cursor position in terms of a 640x200 virtual screen with the upper left corner as row 0, column 0. To get the cursor position in terms of an 80x25 text-mode screen you simply divide the row and column values returned in DX and CX by 8. For a graphics mode you will probably need some additional information not provided by the Interrupt list.
eschew obfuscation

Elite Commando

Thanks a lot Michael, I have been able to sort out this code:

mov ax,03h;
  int 33h;
  mov m,bx;
  mov y,dx;
  mov x,cx;

where m, y, x are unsigned integers, (x = x-coordinate, y = y coordinate, m = mouse state (click/release)), however I do not understand how this works and how an "unsigned" integer is declared in assembly, what do I do after dividing x/y coordinate with 8? please help me, I'm very new to assembly language
, Thanks!

dedndave

a 16-bit word can be either signed or unsigned - it is a matter of context
otherwise they are declared the same

WordVal DW 0FFFFh

notice that 0FFFFh can be either 65535, or -1, depending on how it is used and interpreted

MichaelW

For multiplying or dividing an integer by a power of 2 you can use shifts. Compared to the MUL, IMUL, DIV, and IDIV instructions, the shift instructions are easier to set up and execute faster. For a multiply you shift left, and for a divide you shift right. For the 8086/8088 the source operand (shift count) can be CL or 1. For any later processor it can be CL or an 8-bit constant. The default processor is the 8086/8088. To enable the assembly of instructons for a later processor you must specify a .186 or higher processor directive somewhere above the first line where you use such an instruction.
eschew obfuscation