News:

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

Of Mice and Messages

Started by NoCforMe, October 04, 2011, 07:36:55 PM

Previous topic - Next topic

NoCforMe

I made a small improvement to your routine:



B2A4 PROC

MOV ECX, 4 ;4 digits
JMP SHORT b2a11
b2a10: OR EAX, EAX
        JZ      b2a12
b2a11: PUSH ECX
MOV CL, 10
XOR EDX, EDX
DIV ECX
OR DL, '0' ;Binary--> ASCII
POP ECX
MOV [EDI], DL
DEC EDI
LOOP b2a10
RET

b2a12: MOV BYTE PTR [EDI],  ' '
DEC EDI
LOOP b2a12
RET

B2A4 ENDP



Do you see what it is? (Hint: it gives a tiny speed improvement as well as code size reduction.)

dedndave

there ya go   :P

let me find another one...........

dedndave

some code by drizz...
http://www.masm32.com/board/index.php?topic=12234.msg93949#msg93949
i squeezed 2 clock cycles out of it - lol

B2Asc   PROC

        push    ebx
        mov     edx,4294968          ;2^32/1000
        mov     ebx,10               ;per digit
        mul     edx                  ;extend first digit
        mov     ecx,edx              ;digit 1 in CL
        mul     ebx                  ;second digit
        mov     ch,dl                ;digit 2 in CH
        mul     ebx                  ;third digit
        bswap   ecx                  ;digits 1 & 2 up high
        mov     ch,dl                ;digit 3 in CH
        mul     ebx                  ;digit 4 in DL
        lea     ecx,[edx+ecx+'0000'] ;combine and make ASCII
        bswap   ecx                  ;re-order bytes
        pop     ebx
        ret

B2Asc   ENDP


you'll want to take out the EDI stuff from the calling code
you still call it with the value in EAX, but you have to place the results from ECX when done

        mov     eax,9999
        call    B2Asc
        mov     SomeLabel,ecx


it takes about 30 clock cycles   :bg

dedndave

MOV EAX, lParam ;Yep, get new X & Y pos.
MOV EDX, EAX ;Make a copy for later
AND EAX, 0FFFFH ;Mask off high word
CWDE ;Sign-extend to DWORD
MOV pt.x, EAX
MOV EAX, EDX ;Get back copy
SHR EAX, 16 ;High word--> low word
CWDE
MOV pt.y, EAX


i just noticed your code here   :P
ouch !

replace all of this...
domousemove:
; First, get current mouse position (from lParam):
MOV EAX, lParam ;Yep, get new X & Y pos.
MOV EDX, EAX ;Make a copy for later
AND EAX, 0FFFFH ;Mask off high word
CWDE ;Sign-extend to DWORD
MOV pt.x, EAX
MOV EAX, EDX ;Get back copy
SHR EAX, 16 ;High word--> low word
CWDE
MOV pt.y, EAX

; Display current pos:
        PUSH    EDI
        MOV EAX, pt.x
        MOV     EDI, OFFSET StatusXpos + 3
        CALL    B2A4
        MOV EAX, pt.y
        MOV EDI, OFFSET StatusYpos + 3
        CALL    B2A4
        INVOKE  SendMessage, StatusHandle, SB_SETTEXT, 0, offset StatusMessage
        POP     EDI

and this
B2A4 PROC

        MOV ECX, 4 ;4 digits

b2a10: CMP     CL,4
        JZ      b2a11

        OR      EAX,EAX
        JZ      b2a12

b2a11:  PUSH ECX
MOV ECX, 10
XOR EDX, EDX
DIV ECX
OR DL, '0' ;Binary--> ASCII
POP ECX
MOV [EDI], DL
DEC EDI
LOOP b2a10

        RET

b2a12:  MOV BYTE PTR [EDI],20h
        DEC     EDI
        LOOP    b2a12

        RET

B2A4 ENDP


with this
domousemove:
        movzx   eax,word ptr lParam
        push    ebx
        mov     pt.x,eax
        call    B2As4
        movzx   eax,word ptr lParam+2
        mov dword ptr StatusXpos,ecx
        mov     pt.y,eax
        call    B2As4
        mov dword ptr StatusYpos,ecx
        pop     ebx
        INVOKE  SendMessage,StatusHandle,SB_SETTEXT,0,offset StatusMessage

and this
B2As4   PROC

        mov     edx,4294968          ;2^32/1000
        mov     ebx,10               ;per digit
        mul     edx                  ;extend first digit
        mov     ecx,edx              ;digit 1 in CL
        mul     ebx                  ;second digit
        mov     ch,dl                ;digit 2 in CH
        mul     ebx                  ;third digit
        bswap   ecx                  ;digits 1 & 2 up high
        mov     ch,dl                ;digit 3 in CH
        mul     ebx                  ;digit 4 in DL
        lea     ecx,[edx+ecx+'0000'] ;combine and make ASCII
        bswap   ecx                  ;re-order bytes
        ret

B2As4   ENDP

it probably does both strings in about the same time as a single DIV instruction - lol
(not including the SendMessage)

you'll have to use .586 (or .486) instead of .386

NoCforMe

Well, OK. But remember that at this point the plan is to get this working, not super-optimizing it. It'll be a while before this goes to market ...

dedndave

yah - sorry about that - can't help it - lol

i notice the status message stops updating when the cursor is over one of the child windows
that's because the child proc gets the messages
we can fix that, easy enough

at this point, i may take a different tack

NoCforMe

As promised, style definitions:

  • Main window: WS_OVERLAPPEDWINDOW OR WS_CLIPCHILDREN
  • Main window extended: WS_EX_OVERLAPPEDWINDOW
  • Child windows:  WS_BORDER OR WS_CHILD OR WS_VISIBLE
  • Child windows extended: WS_EX_WINDOWEDGE
  • Status bar: WS_CHILD OR WS_VISIBLE
That's it. Pretty vanilla.

dedndave

my problem up til now has been trying to understand everything you are doing
it is consuming too much time   :P

so - i am going to take one of my little "standard" window programs...
first, i'll confine the mouse movement when it's being dragged
then, i'll put 2 static text boxes on it and make it so you can drag one over the top of the other
after that, i'll make it so the boxes, themselves, are confined to the client area

these are all things that i have not had to do yet - lol
it's sort of a "start at the beginning and make each step work" approach
by using one of my own window programs, i do not have to spend time familiarizing myself with someone elses code

dedndave

before i start working on that, i added leading zero suppression to the B2As4 routine above...
B2As4   PROC

        mov     edx,4294968          ;2^32/1000
        mov     ebx,10               ;per digit
        mul     edx                  ;extend first digit
        mov     ecx,edx              ;digit 1 in CL
        mul     ebx                  ;second digit
        mov     ch,dl                ;digit 2 in CH
        mul     ebx                  ;third digit
        bswap   ecx                  ;digits 1 & 2 up high
        mov     ch,dl                ;digit 3 in CH
        mul     ebx                  ;digit 4 in DL
        lea     ecx,[edx+ecx+'0000'] ;combine and make ASCII
        bswap   ecx                  ;re-order bytes
        cmp     cl,30h
        jnz     B2As42

        cmp     ch,30h
        jnz     B2As41

        test    ecx,0F0000h
        jnz     B2As40

        and     ecx,03F202020h
        ret

B2As40: mov     cx,2020h
        ret

B2As41: mov     cl,20h

B2As42: ret

B2As4   ENDP

dedndave


dedndave

and, that's step 1
i even made it stay above the status bar   :P
(only when left button is down, of course)


jj2007

Quote from: NoCforMe on October 08, 2011, 06:34:05 AM
Already in there. Look in WindowProc, under "domousemove".

Yep, ClipCursor is there. Can't test it, though - Error A2087: Cannot open include file '\techstuff\masm32\include\kernel32.inc'

NoCforMe

Well, sorry about that. I guess at this point I had planned on playing this game (learning assembly language forWindows) my way, by my rules, on my computer. I hadn't envisioned joining a "community"  just yet.

You could just change the include statement. The program does assemble and link OK.

OK, here's a copy with the standard includes ("\masm32\include ...") just for you. It should be build-able. Then you can see the problem with moving the child windows.

NoCforMe

Interesting.

If anyone out there is actually playing with my little testbed program, notice the difference between using



INVOKE InvalidateRect, ChildHandle, NULL, TRUE



and



INVOKE RedrawWindow, ChildHandle,  NULL, NULL, RDW_FRAME OR RDW_INVALIDATE



immediately after using MoveWindow() on the child window.