please translation to masm32

LRESULT NFOCtrl_OnPaint(WPARAM wParam, LPARAM lParam) // same as WM_PAINT
{
HDC hdcPaint, hdcMem;
HBITMAP hbmMem;
RECT rc;

GetClientRect(m_hWnd, &rc);
hdcPaint = GetDC(m_hWnd);

if(!IsIconic(GetParent(m_hWnd))){
hdcMem = CreateCompatibleDC(hdcPaint);
hbmMem = CreateCompatibleBitmap(hdcPaint, rc.right, rc.bottom);
HBITMAP hOldBmp = (HBITMAP)SelectObject(hdcMem, hbmMem);

HBRUSH hbBackground = CreateSolidBrush(m_crBackground);
FillRect(hdcMem, &rc, hbBackground);
DeleteBrush(hbBackground);

if((m_hFile != NULL) && (m_lpLines != NULL)){
HDC hdcChars = CreateCompatibleDC(hdcPaint);
HBITMAP hNullBmp = (HBITMAP)SelectObject(hdcChars, m_hCharBitmap);
int nX = 0, nY = 0;
for(int nLine = m_nVScrollPos; nLine < m_nVScrollPos+m_nWindowLines; nLine++){
LPBYTE lpLine = m_lpLines;
while(*lpLine >= ' '){
if(*lpLine > ' '){
BitBlt(hdcMem, nX, nY, m_nCharWidth, m_nCharHeight, hdcChars,
(((*lpLine - ' ') % 16) * m_nCharWidth),
(((*lpLine - ' ') / 16) * m_nCharHeight), SRCCOPY);
}
nX += m_nCharWidth; lpLine++;
}
nY += m_nCharHeight;
nX = 0;
}
SelectObject(hdcChars, hNullBmp);
DeleteDC(hdcChars);
}

BitBlt(hdcPaint, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hOldBmp);
DeleteBitmap(hbmMem);
DeleteDC(hdcMem);
}

ReleaseDC(m_hWnd, hdcPaint);
ValidateRect(m_hWnd, NULL);

return TRUE;
}
Posted on 2006-06-16 13:14:45 by fabinho
Most of the stuff can be translated directly...

ie., something like
GetClientRect(m_hWnd, &rc); translated into
invoke GetClientRect, m_hWnd, addr rc

...is there anything in particular you need help with? Some of the C code you don't understand? Show a little effort yourself :)
Posted on 2006-06-16 13:24:07 by f0dder
If you don't want to put any effort, use a compiler.  There are many free C compilers around, all of which can produce assembly listing.

BTW, do they stop teaching kids about what compilers do?  I have seen this kind of posting frequently, not just here but at other places I hang out too.
Posted on 2006-06-16 14:29:17 by Starless
fabinho,
?  ?  ? OK here it is.?  Ask if you have any questions.?  Ratch


;-- -----------------------------------------------------------------------------
; This subprogram assumes that EBX=wParam, EDX=lParam, ESI=m_hWnd, EBP=0
NFOC STRUCT
return  DWORD ?
NFOC$3        = $
hdcPaint DWORD ?
hdcMem  DWORD ?
hbmMem  DWORD ?
rc      RECT  {}
NFOC$4        = $
NFOC ENDS

NF EQU ESP.NFOC                    ;save some typing

.DATA?
hOldBmp        DWORD ?
hbBackground  DWORD ?
hdcChars      DWORD ?
hNullBmp      DWORD ?
m_hWnd        DWORD ?
m_hCharBitmap  DWORD ?
m_nVScrollPos  DWORD ?
m_nCharWidth  DWORD ?
m_nCharHeight  DWORD ?
m_nWindowLines DWORD ?
m_crBackground DWORD ?
m_hFile        DWORD ?
m_lpLines      DWORD ?
nLine          DWORD ?
lpLine        DWORD ?
nX            DWORD ?
nY            DWORD ?

.CODE
NFOCtrl_OnPaint:
LEA EAX,
INVOKE GetClientRect,ESI,EAX
INVOKE GetDC,ESI
MOV ,EAX

INVOKE GetParent,ESI
INVOKE IsIconic,EAX

.IF !EAX
  INVOKE CreateCompatibleDC,
  INVOKE CreateCompatibleBitmap,,\
                                ,
  INVOKE SelectObject,,
  INVOKE CreateSolidBrush,
  MOV ,EAX
  PUSH EAX                        ;***push param for DeleteObject below
  LEA ECX,
  INVOKE FillRect,,ECX,EAX
  INVOKIT DeleteObject,;***parameter pushed above

  .IF ( != EBP) && ( != EBP)
    INVOKE CreateCompatibleDC,
    MOV ,EAX
    INVOKE SelectObject,,

    MOV EAX,
    MOV ECX,
    MOV ,EBP
    MOV ,EBP
    ADD ECX,
    MOV ,EAX
    PUSH ECX                      ;loop counter on stack

    .WHILE TRUE
      MOV EAX,
    .BREAK .IF EAX >=
      MOV ECX,
      MOV ,ECX

      .WHILE BYTE PTR >= ' '
        PUSH SRCCOPY
        MOVZX EAX,BYTE PTR
        SUB EAX,' '
        AND EAX,0FH
        MUL
        PUSH EAX
        MOVZX EAX,BYTE PTR
        SUB EAX,' '
        SHR EAX,4
        MUL
        PUSH EAX
        INVOKIT BitBlt,,,,\
                        ,,
        MOV EAX,
        INC ,EAX]
        MOV ECX,
      .ENDW

      MOV EAX,
      MOV ,EBP
      ADD ,EAX
      INC
    .ENDW
    POP EAX                      ;stack cleared of loop counter

    INVOKE SelectObject,,
    INVOKE DeleteDC,
  .ENDIF

  INVOKE BitBlt,,EBP,EBP,,,,EBP,EBP,SRCCOPY
  INVOKE SelectObject,,
  INVOKE DeleteObject,
  INVOKE DeleteDC,
.ENDIF

INVOKE ReleaseDC,,
INVOKE ValidateRect,,EBP

MOV EAX,ESP
RET NFOC$4-NFOC$3

END
Posted on 2006-06-17 08:25:58 by Ratch
Ratch - well done, I just noticed this posting, and you beat me to it.
fabinho, there's nothing particularly C++ about this function.
We can write object-oriented code in asm too ;)
Posted on 2006-06-17 09:45:49 by Homer
Homer,
    Thank you.  I just corrected some mistakes in my submission.  By the way, your bottom line should read "or you don't get any spending cash" in order to be gramatically correct.  Ratch
Posted on 2006-06-17 13:04:34 by Ratch
Yackety Yack :P
Posted on 2006-06-17 13:38:49 by Homer