Hi again,
I have a question about tutorial part 7, mouse input. I've read through the code and I understand everything but one part; in the WndProc is this code:
.ELSEIF uMsg==WM_LBUTTONDOWN 

mov eax,lParam
and eax,0FFFFh
mov hitpoint.x,eax
mov eax,lParam
shr eax,16
mov hitpoint.y,eax
mov MouseClick,TRUE
invoke InvalidateRect,hWnd,NULL,TRUE

First it moves lParam to the eax register, then it does some and thing to eax, and moves eax to hitpoint.x (hitpoint was defined earlier as a POINT). In other words, it extracts the x out of lParam. Then it moves lParam to eax again and uses shr to shift the high-order word 16 bits to right, so it moves it to the low-order word part. After that, it moves eax to hitpoint.y. Now both coordinates are extracted, it sets MouseClick to TRUE and invalidates the rect to create a WM_PAINT message, the WM_PAINT handler sees that MouseClick has been set to true so it paints the app name in the coordinates we extracted.

So, what I don't understand is the and part. I understand what it does, sort of. It removes the high-order word part so that only the low-order one is left, and there is the x coordinate. But I don't understand how it does that... I would need somebody to explain that to me. Thanks in advance :)
Posted on 2004-05-15 11:57:38 by Justin Case
0 AND 1 = 0
1 AND 0 = 0
0 AND 0 = 0
1 AND 1 = 0

Since the bit mask is ffffh, only the values in the lower 16bit is retained.
Posted on 2004-05-15 12:19:24 by roticv
He means:

0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
Posted on 2004-05-15 12:23:54 by Scali
The instruction could also be replaced with:

movzx eax, ax

...or better yet replace:

mov eax,lParam
and eax,0FFFFh

...with:

movzx eax, WORD PTR lParam
Posted on 2004-05-15 12:24:22 by bitRAKE

0 AND 1 = 0
1 AND 0 = 0
0 AND 0 = 0
1 AND 1 = 0

Since the bit mask is ffffh, only the values in the lower 16bit is retained.

Ok, but I still don't understand how this mask works... could someone give me a link to some documentation or explain how it works?
Posted on 2004-05-15 12:34:30 by Justin Case
Posted on 2004-05-15 12:43:24 by roticv
ah, thanks! I understand better now :)
Posted on 2004-05-15 13:08:55 by Justin Case
:grin:

You can also do this:

; get y point
movzx eax, word ptr

; get x point
movzx eax, word ptr
Posted on 2004-05-15 13:36:19 by Petroizki
Note in some cases mouse coords can go negative; say for example I capture the mouse on WM_LBUTTONDOWN and handle WM_MOUSEMOVE (which also puts the mouse coords in lParam). If the user moves the mouse above or to the left of the client area, one or both of the coords will be negative. In this case it would probably be better to use:

movsx eax, word ptr
movsx eax, word ptr
Posted on 2004-05-16 12:20:23 by sirchess
yep, I remember had that bug with 9x->NT conversion
Posted on 2004-05-16 12:45:07 by comrade
hi justin case
just convert ffffh to its binary form its 00000000 00000000 11111111 11111111 and this to value of eax which will be of form xxxxxxxx xxxxxxxx yyyyyyyy yyyyyyyy when converted to binay form.

after the and operation only yyyyyyyy yyyyyyyy remains.
which is lower 16 bit of eax ie. al
by the way
0 and 0 is 0
0 and 1 is 0
1 and 0 is 0
1 and 1 is 1
thats it.
Posted on 2004-10-07 16:24:55 by nickdigital