Вы находитесь на странице: 1из 20

td_win32asm_150.

asm
;==============================================================================
;
Test Department's WINDOWS 32 BIT x86 ASSEMBLY EXAMPLE's
150
;==============================================================================
;==============================================================================
; ==> Part 150 : Mandelbrot fractal, FPU, Screen buffer !
;-----------------------------------------------------------------------------; Hello, why not analyze some complex values ...
; Clicking "Calculate" in the menu bar starts calculating.
; Choosing "Settings" will open a Popup menu, you can select your preferences.
; Press "Esc" to abort calculating.
; I wish you a nice journey through the world of Mr. Mandelbrot.
; In the windowproc WP1, reacting to a WM_CREATE message I get a
; MAIN device context for the client area of the window, creating a
; compatible BITMAP for that (!), creating a compatible (!) device context and
; now selecting an object (the BITMAP) into the compatible device context.
; Now I call API "FillRect" to clear (!?) the created back buffer and at last
; I call API "ReleaseDC" to release the MAIN device context for future use.
; Note: the compatible device context is still present (needed on WM_PAINT) !
; We delete this only on WM_DESTROY.
; On WM_PAINT I perform a simple Bit transfer (API "BitBlt" ) from the created
; back buffer to update the screen.
; Another interested part of this win32asm example is located on WM_COMMAND.
; Here I calculate the fractal using the FPU, the calculated pixel/color will
; be written to the back buffer and also to the screen, which will increase
; the time to calculate up to 25% (right, that's the drawback here...).
; Thanks to Wayne J. Radburn for the WNDCLASSEX.style CS_OWNDC tip.
;
; Test Department
td@crahkob.com
;==============================================================================
; Assembler directives
;-----------------------------------------------------------------------------.386
; specifies the processor our program want run on
.Model Flat ,StdCall
; Flat for Win9x (32 Bit), Calling Convention
option casemap:none
; case sensitive !
;==============================================================================
; Include all files where API functions resist you want use, set correct path
;-----------------------------------------------------------------------------include D:\Masm32\include\windows.inc
includelib kernel32.lib
includelib user32.lib
includelib gdi32.lib
;==============================================================================
; Declaration of used API functions,take a look into WIN32.HLP and *.inc files
;-----------------------------------------------------------------------------GetModuleHandleA
PROTO :DWORD
LoadIconA
PROTO :DWORD,:DWORD
CreateSolidBrush
PROTO :DWORD
LoadCursorA
PROTO :DWORD,:DWORD
RegisterClassExA
PROTO :DWORD
Page 1

CreateWindowExA
ShowWindow
UpdateWindow
GetMessageA
TranslateMessage
DispatchMessageA
PostQuitMessage
DefWindowProcA
ExitProcess
GetMenu
CheckMenuItem
InvalidateRect
FillRect
GetDC
SetPixel
ReleaseDC
CreateCompatibleDC
CreateCompatibleBitmap
SelectObject
DeleteObject
DeleteDC
BeginPaint
BitBlt
EndPaint
GetAsyncKeyState

td_win32asm_150.asm
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
PROTO :DWORD,:DWORD
PROTO :DWORD
PROTO :DWORD,:DWORD,:DWORD,:DWORD
PROTO :DWORD
PROTO :DWORD
PROTO :DWORD
PROTO :DWORD,:DWORD,:DWORD,:DWORD
PROTO :DWORD
PROTO :DWORD
PROTO :DWORD,:DWORD,:DWORD
PROTO :DWORD,:DWORD,:DWORD
PROTO :DWORD,:DWORD,:DWORD
PROTO :DWORD
PROTO :DWORD,:DWORD,:DWORD,:DWORD
PROTO :DWORD,:DWORD
PROTO :DWORD
PROTO :DWORD,:DWORD,:DWORD
PROTO :DWORD,:DWORD
PROTO :DWORD
PROTO :DWORD
PROTO :DWORD,:DWORD
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
:DWORD,:DWORD,:DWORD
PROTO :DWORD,:DWORD
PROTO :DWORD

;==============================================================================
; .const
= the constants area starts here, constants are defined and fixed
;-----------------------------------------------------------------------------.const
; - Parameter MAIN WINDOW CallBack Procedure ( API=RegisterClassExA ) WP1_CallBack
equ [ebp+4]
;return address
WP1_hWnd
equ [ebp+8]
;handle of window who receives message
WP1_uMsg
equ [ebp+12]
;the message number
WP1_wParam
equ [ebp+16]
;extra info about the message
WP1_lParam
equ [ebp+20]
;extra info about the message
;==============================================================================
; .Data
= the data area starts here, datas are defined but not fixed
;
MASM converts real4, real8, real10 values into FPU/IEEE standard.
;-----------------------------------------------------------------------------.Data
IconName
db "TDIcon",0
;icon name in rc file
MenuName
db "TDMenu",0
;menu name in rc file
Class
db "TDWinClass",0
;name of window class
WindowName db "Test Department - http://surf.to/TestD - Escape key stops calculating",0;
; - Screen parameter Xpos
Ypos
Xmax

dd 0
dd 0
dd 512

;X orgin point - RECT struc.


;Y orgin point - RECT struc.
;screen width - RECT struc.
Page 2

Ymax
Color
cmulti
_dx
_dy

dd 512
dd 0h
dd 00000F00h
real8 0.0
real8 0.0

td_win32asm_150.asm
;screen height - RECT struc.
;default color value (black)
;calculates color, CHANGE THIS
;calculated from Xmax
;calculated from Ymax

; - Mandelbrot parameter itmax


dd 256
it
dd 0
zr
real8 0.0
zi
real8 0.0
nolimit
real8 4.000000000
rmin
real8 -0.500000000
rmax
real8 2.000000000
imin
real8 -1.250000000
imax
real8 1.250000000
cr
real8 0.0
ci
real8 0.0

;iteration, maximal value


;iteration, start value
;real part of complex value
;imagin part of complex value
;border, result value is too far
;real min. value
;real max. value
;imagin min. value
;imagin max. value
;
;

; - Program parameter screenFlag


dd 1h
autocalcFlag
dd 1h
zoomCounter
dd 0h
zoom
real8 0.020000000
view
real8 0.020000000
org_rmin
real8 -0.500000000
org_rmax
real8 2.000000000
org_imin
real8 -1.250000000
org_imax
real8 1.250000000

;
;
;
;
;
;real min. value, default value
;real max. value, default value
;imagin min. value, default
;imagin max. value, default

;==============================================================================
; .Data?
= the data? area starts here, not defined and not fixed
;-----------------------------------------------------------------------------.data?
handleMenu
dd ?
;handle, menu
handleDC
dd ?
;handle, main device context
handleBitmap
dd ?
;handle, compatible bitmap
handleCDC
dd ?
;handle, compatible device context
handleOld
dd ?
;handle, old object
align 4
; - WndClassEx Structure ( API=RegisterClassExA ) cbSize
dd ?
;size in bytes of this structure
style
dd ?
;window style
lpfnWndProc
dd ?
;address of user proc function
cbclsExtra
dd ?
;extra bytes to allocate set to 0
cbWndExtra
dd ?
;extra bytes class directive, rc file
hInstance
dd ?
;program handle(API=GetModuleHandleA)
hIcon
dd ?
;handle of icon (API=LoadIconA)
hcursor
dd ?
;handle of cursor (API=LoadCursor)
hbrBackground
dd ?
;background color, 0=transparent
lpszMenuName
dd ?
;name of menu class in resource file
lpszClassName
dd ?
;name of windows this window class
Page 3

hIconSm
hdcDest

dd ?
dd ?

td_win32asm_150.asm
;iconhandle 0=search in resource file
;handle of dest. device context

align 4
; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structure
hWnd
dd ?
;handle of window who receives message
message
dd ?
;the message number
wParam
dd ?
;extra info about the message
lParam
dd ?
;extra info about the message
time
dd ?
;time the message was posted
xpt
dd ?
;cursor x-position, POINT struc
ypt
dd ?
;cursor x-position, POINT struc
align 4
; - Paint Structure ( API=BeginPaint ) - member rcPaint = RECT structure
hdc
dd ?
;id, display DC used for painting
fErase
dd ?
;must background must be erased
rcPaint_left
dd ?
;RECT,x-coordinate upper-left corner
rcPaint_top
dd ?
;RECT,y-coordinate upper-left corner
rcPaint_right
dd ?
;RECT,x-coordinate lower-right corner
rcPaint_bottom
dd ?
;RECT,y-coordinate lower-right corner
fRestore
dd ?
;reserved, used by Windows
fIncUpdate
dd ?
;reserved, used by Windows
rgbReserved
db 20h dup (?) ;reserved, used by Windows
;==============================================================================
; .CODE
= our code area starts here
Main = label of our program code
;-----------------------------------------------------------------------------.Code
Main:
;==============================================================================
; Always get your program ID first (API=GetModuleHandleA)
;-----------------------------------------------------------------------------push
0h
;lpModuleHandle, 0=get program handle
call
GetModuleHandleA
;- API Function mov
hInstance,eax
;return value in eax=handle of program
;==============================================================================
; Init the Floating Point Unit.
;-----------------------------------------------------------------------------finit
;init FPU
;==============================================================================
; The API function "RegisterClassExA" registers a window class.
; This API needs a "WNDCLASSEX" structure so we fill it with correct values.
;-----------------------------------------------------------------------------mov
cbSize,30h
;size in bytes of WNDCLASSEX structure
mov
style,23h
;window style,CS_OWNDC,CS_VREDRAW,CS_HREDRAW
mov
lpfnWndProc,OFFSET WP1
;address of user lpfnWndProc function
mov
cbclsExtra,0h
;extra bytes to allocate set to 0
mov
cbWndExtra,0h
;class directive in rc file
mov
lpszMenuName,OFFSET MenuName;menu name in resource file,0=no menu
Page 4

td_win32asm_150.asm
mov
lpszClassName,OFFSET Class ;name of windows class
mov
hIconSm,0h
;iconhandle 0=search in rc file
;-----------------------------------------------------------------------------; API "CreateSolidBrush" creates a logical brush with the specified solid color
;-----------------------------------------------------------------------------push
00000000h
;crColor, brush color value RGB
call
CreateSolidBrush
;- API Function mov
hbrBackground,eax
;handle brush, background color
;-----------------------------------------------------------------------------; API "LoadIconA" loads an icon defined in the resource file and stores the
; handle in the "WNDCLASSEX" structure
;-----------------------------------------------------------------------------push
OFFSET IconName
;icon-string or icon resource id
push
hInstance
;our program handle
call
LoadIconA
;- API Function mov
hIcon,eax
;store handle of newly loaded icon
;-----------------------------------------------------------------------------; API "LoadCursorA" loads a default system cursor, in this case we must set
; hInstance to 0 and lpCursorName to a default system cursor value, here 32512
; Then we store the cursor handle in the "WNDCLASSEX" structure
;-----------------------------------------------------------------------------push
32512
;lpCursorName, default value in dezimal
push
0h
;hInstance, 0=default system cursor
call
LoadCursorA
;- API Function mov
hcursor,eax
;store handle of the cursor
;-----------------------------------------------------------------------------; Now, after filled the "WNDCLASSEX" structure we call API "RegisterClassEx"
;-----------------------------------------------------------------------------push
OFFSET cbSize
;pointer to WNDCLASSEX structure
call
RegisterClassExA
;- API Function ;==============================================================================
; API "CreateWindowExA" creates an overlapped, pop-up, or child window with an
; extended style. The return value in EAX is the handle of the new window.
; This API sends a WM_CREATE message to the window procedure (WP1).
;-----------------------------------------------------------------------------push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
0h
;hMenu, handle window menu 0=class menu
push
0h
;hWndParent, handle parent window 0=no
push
00000230h
;intnHeight, window height pixel
push
0000020Ah
;intnWidth, window width pixel
push
20h
;inty, vertical position window
push
10h
;intx, horizontal position window
push
04CA0000h
;dwStyle, look into WIN32.HLP
push
OFFSET WindowName
;lpWindowName, pointer to window name
push
OFFSET Class
;lpClassName, pointer to class name
push
0300h
;dwExStyle, extra window style 0=no
call
CreateWindowExA
;- API Function mov
hWnd,eax
;hwnd,return value=handle of window
;==============================================================================
; API "ShowWindow" function sets the specified window's show state.
Page 5

td_win32asm_150.asm
;-----------------------------------------------------------------------------push
1h
;nCmdShow, show state 1=SW_SHOWNORMAL
push
hWnd
;hwnd, handle of window
call
ShowWindow
;- API Function ;==============================================================================
; API "UpdateWindow" updates the area of the specified window by sending a
; WM_PAINT message to the window if the window's update region is not empty.
;-----------------------------------------------------------------------------push
hWnd
;hwnd, handle of window
call
UpdateWindow
;- API Function LoopGetMessage:
;==============================================================================
; API "GetMessageA" retrieves a message + places it in the specified structure.
;-----------------------------------------------------------------------------push
0h
;wMsgFilterMax, highest message value
push
0h
;wMsgFilterMin, lowest message value
push
0h
;hWnd, handle of window who gets msg.
push
OFFSET hWnd
;lpMsg, pointer to MSG structure
call
GetMessageA
;- API Function cmp
eax,0h
;check if return value=0 (exit)
je
ExitPrg
;if return value is 0 goto LABEL
;==============================================================================
; API "TranslateMessage" translates virtual-key messages in character messages
;-----------------------------------------------------------------------------push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
TranslateMessage
;- API Function - keyboard code
;==============================================================================
; API "DispatchMessageA" function dispatches a message to a window procedure.
;-----------------------------------------------------------------------------push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
DispatchMessageA
;- API Function jmp
LoopGetMessage
;check for message again, goto LABEL
ExitPrg:
;==============================================================================
; Next we terminate our program (API=ExitProcess)
;-----------------------------------------------------------------------------push
hInstance
;push our programm handle to exit
call
ExitProcess
;- API Function ;##############################################################################
; The Window Procedure (API=RegisterClassExA) for this registered window.
;-----------------------------------------------------------------------------WP1:
push
ebp
;create stack frame
mov
ebp,esp
;
pushad
;push all register to the stack
mov

eax,WP1_uMsg

;move the message number to eax


Page 6

td_win32asm_150.asm
;==============================================================================
; WM_CREATE (value=01h) message received ?
;-----------------------------------------------------------------------------WP1_uMsg_01h:
cmp
eax,1h
;check if WM_CREATE message recieved
jne
WP1_uMsg_02h
;if not goto LABEL
;-----------------------------------------------------------------------------; API "GetMenu" retrieves the handle of the menu assigned to the given window.
;-----------------------------------------------------------------------------push
WP1_hWnd
;hWnd, handle of window
call
GetMenu
;- API Function mov
handleMenu,eax
;handle of menu
;-----------------------------------------------------------------------------; API "GetDC" retrieves a handle of a display device context (DC) for the
; client area of the specified window.
;-----------------------------------------------------------------------------push
WP1_hWnd
;hwnd, handle of window
call
GetDC
;- API Function mov
handleDC,eax
;handle of DC
;-----------------------------------------------------------------------------; API "CreateCompatibleBitmap" creates a bitmap compatible with the device that
; is associated with the specified device context.
;-----------------------------------------------------------------------------push
Ymax
;nHeight, height of bitmap, in pixels
push
Xmax
;nWidth, width of bitmap, in pixels
push
handleDC
;hdc, handle of device context
call
CreateCompatibleBitmap
;- API Function mov
handleBitmap,eax
;handle of bitmap
;-----------------------------------------------------------------------------; API "CreateCompatibleDC" creates a memory device context (DC) compatible with
; the specified device.
;-----------------------------------------------------------------------------push
handleDC
;hdc, handle memory device context,0=screen
call
CreateCompatibleDC
;- API Function mov
handleCDC,eax
;handle, compatible DC
;-----------------------------------------------------------------------------; API "SelectObject" selects an object into the specified device context.
; The new object replaces the previous object of the same type.
;-----------------------------------------------------------------------------push
handleBitmap
;hgdiobj, handle of object
push
handleCDC
;hdc, handle of device context
call
SelectObject
;- API Function mov
handleOld,eax
;handle of previously object
;-----------------------------------------------------------------------------; API "FillRect" fills a rectangle using the specified brush. Includes the left
; and top borders, but excludes the right and bottom borders of the rectangle.
;-----------------------------------------------------------------------------push
hbrBackground
;hbr, handle of brush
push
OFFSET Xpos
;lprc, address of structure with rectangle
push
handleCDC
;hDC, handle of device context
call
FillRect
;- API Function jmp
WP1_return
Page 7

td_win32asm_150.asm
;==============================================================================
; WM_DESTROY (value=02h) message received ?
;-----------------------------------------------------------------------------WP1_uMsg_02h:
cmp
eax,2h
;check if value=2h (WM_DESTROY)
jne
WP1_uMsg_0Fh
;if not 2h go to LABEL
call
My_CleanSystem
;- SubRoutine ;-----------------------------------------------------------------------------; API "PostQuitMessage" indicates to Windows a request to terminate
;-----------------------------------------------------------------------------push
0h
;nExitCode, exit code=wParam
call
PostQuitMessage
;- API Function popad
;pop all register back from stack
xor
eax,eax
;set eax to 0 to exit our program
mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
10h
;return and clear stack
;==============================================================================
; WM_PAINT (value=0Fh) message, used to repaint the window area
;-----------------------------------------------------------------------------WP1_uMsg_0Fh:
cmp
eax,0Fh
;check if WM_PAINT message recieved
jne
WP1_uMsg_111h
;if not goto label
;-----------------------------------------------------------------------------; API "BeginPaint" prepares the specified window for painting and fills a
; PAINTSTRUCT structure with information about the painting
;-----------------------------------------------------------------------------push
OFFSET hdc
;lpPaint, pointer to PAINTSTRUCT
push
WP1_hWnd
;hwnd, handle of the window
call
BeginPaint
;- API Function mov
hdcDest,eax
;handle, display device (DC)=dest.
;-----------------------------------------------------------------------------; API "BitBlt" performs a bit-block transfer of the color data corresponding
; to a rectangle of pixels from the specified source device context into a
; destination device context.
;-----------------------------------------------------------------------------push
00CC0020h
;dwRop, raster operation code
push
0h
;nYSrc, y=src. rect. up-left corner
push
0h
;nXSrc, x=src. rect. up-left corner
push
handleCDC
;hdcSrc, handle of source device
push
Ymax
;nHeight, height of dest. rect.
push
Xmax
;nWidth, width of dest. rect.
push
0h
;nYDest, y=dest. rect. up-left corner
push
0h
;nXDest, x=dest. rect. up-left corner
push
hdcDest
;hdcDest, handle destination device
call
BitBlt
;- API Function ;-----------------------------------------------------------------------------; API "EndPaint" marks the end of painting in the given window.
; This function is required for each call to the BeginPaint function, but only
; after painting is complete.
;-----------------------------------------------------------------------------push
OFFSET hdc
;lpPaint, pointer PAINTSTRUCT
Page 8

push
call
jmp

WP1_hWnd
EndPaint
WP1_return

td_win32asm_150.asm
;hwnd, handle of the window
;- API Function -

;==============================================================================
; WM_COMMAND (value=111h) message recieved ?
;-----------------------------------------------------------------------------WP1_uMsg_111h:
cmp
eax,111h
;check if WM_COMMAND message recieved
jne
WP1_uMsg_112h
;if not goto label
mov
eax,WP1_wParam
;extra info about the message in ax
cmp
ax,1h
;"Start" clicked ?
jne
WP1_uMsg_111_wParam_02h
;
WP1_uMsg_111_wParam_01h:
mov
Xpos,0h
;reset Xpos
mov
Ypos,0h
;reset Ypos
call
My_FillRect
;- SubRoutine - , clear screen and buffer
;-----------------------------------------------------------------------------; Init some real8 variables using the Floating Point Unit.
; cr=rmin, ci=imax, _dx=(rmax-rmin)/xmax, _dy=(imax-imin)/ymax
;-----------------------------------------------------------------------------ffree
ST(7)
;free ST(7), must be empty for load
fld
rmin
;load rmin into TOS
fstp
cr
;store in cr and POP
fld
imax
;load imax into TOS
fstp
ci
;store in ci and POP
fld
rmax
;load rmax into TOS
fsub
rmin
;sub, TOS-rmin
fidiv
Xmax
;div, TOS/Xmax
fstp
_dx
;store result in _dx and POP
fld
imax
;load imax into TOS
fsub
imin
;sub, TOS-imin
fidiv
Ymax
;div, TOS/Ymax
fstp
_dy
;store result in _dy and POP
Next_Pixel:
;-----------------------------------------------------------------------------; MANDELBROT --> Formula : z=z^2-c
; First reset variables, color=0 (black), it=0, zr=0, zi=0
;-----------------------------------------------------------------------------mov
Color,0h
;set Color to 0 (black), default value
mov
it,0h
;set deep to 0, start value
fldz
;load constant 0.0 into TOS=ST(0)
fst
zr
;store it in zr (real)
fstp
zi
;store in zi (imagin) and POP
Iteration:
;-----------------------------------------------------------------------------; Iteration (itmax) = maximal depth of calculation
;-----------------------------------------------------------------------------mov
eax,itmax
;load iteration max. value into EAX
cmp
it,eax
;compare
Page 9

td_win32asm_150.asm
jae
Set_Pixel
;equal or above, color will be black ...
inc
it
;inc iteration
;-----------------------------------------------------------------------------; Calculate imagin part. zi=2*zi*zr-ci
;-----------------------------------------------------------------------------fld
zr
;load zr into TOS
fmul
zi
;multiplicate, zr*zi, result=ST(0)
fadd
ST(0),ST(0)
;add, ST(0)+(ST0), result=ST(0), it works !
fsub
ci
;sub, ST(0)-ci, result=ST(0), new zi !
;-----------------------------------------------------------------------------; Calculate real part. zr=zr*zr-zi*zi-cr
;-----------------------------------------------------------------------------fld
zi
;load zi into TOS, new zi moves ST(1)
fmul
zi
;multiplicate, zi*zi, result=ST(0)
fld
zr
;load zr into TOS, zi=ST(1), new zi=ST(2)
fmul
zr
;multiplicate, zr*zr
fsub
ST(0),ST(1)
;sub, ST(0)-ST(1), result=ST(0)
fsub
cr
;sub, ST(0)-cr, result=ST(0)
fst
zr
;store result in zr, new zr !
fmul
zr
;multiplicate, zr*zr, for future use
fxch
ST(2)
;exchange ST(0) with ST(2)
fst
zi
;store new zi
fmul
zi
;multiplicate, zi*zi, for future use
;-----------------------------------------------------------------------------; Check if calculated value goes to infinity. (zr*zr+zi*zi)<4
;-----------------------------------------------------------------------------fadd
ST(0),ST(2)
;add, ST(0)+ST(2), result in ST(0)
fcomp
nolimit
;compare ST(0) with variable nolimit + POP
fstsw
ax
;copy FPU flags into ax
sahf
;copy ah of ax into CPU flag register !
ffree
ST(0)
;clear FPU stack
ffree
ST(1)
;
jb
Iteration
;ready to check CPU flags
Set_Color:
;-----------------------------------------------------------------------------; Assign a color to the pixel, depends on current iteration value.
;-----------------------------------------------------------------------------fild
it
;load it into TOS
fimul
cmulti
;yes, we want more color's
fistp
Color
;store value in variable
and
Color,00FFFFFFh
;mask highest byte out for RGB !
Set_Pixel:
;-----------------------------------------------------------------------------; API "SetPixel" sets the pixel at specified coordinates to a specified color.
;-----------------------------------------------------------------------------push
Color
;crColor, pixel color
push
Ypos
;Y, y-coordinate of pixel
push
Xpos
;X, x-coordinate of pixel
push
handleCDC
;hdc, handle of device context, BUFFER !
call
SetPixel
;- API Function cmp
screenFlag,0h
;
Page 10

td_win32asm_150.asm
je
Next_Xpos
;
;-----------------------------------------------------------------------------; API "SetPixel" sets the pixel at specified coordinates to specified color.
;-----------------------------------------------------------------------------push
Color
;crColor, pixel color
push
Ypos
;Y, y-coordinate of pixel
push
Xpos
;X, x-coordinate of pixel
push
handleDC
;hdc, handle of device context, SCREEN !
call
SetPixel
;- API Function Next_Xpos:
;-----------------------------------------------------------------------------; cr=cr+_dx and inc Xpos
;-----------------------------------------------------------------------------fld
cr
;load cr into TOS
fadd
_dx
;add, cr+_dx
fstp
cr
;store result in cr and POP
inc
Xpos
;time to increase Xpos
mov
eax,Xpos
;
cmp
eax,Xmax
;check if right window border reached
jb
Next_Pixel
;
mov
Xpos,0h
;reset Xpos
;-----------------------------------------------------------------------------; API "GetAsyncKeyState" determines whether a key is up or down at the time the
; function is called ...
;-----------------------------------------------------------------------------push
1Bh
;vKey, virtual-key code, VK_ESCAPE=1Bh
call
GetAsyncKeyState
;- API Function shr
eax,1Fh
cmp
eax,1h
je
Force_WM_PAINT
;escape key pressed, stop calc and exit !
Next_Ypos:
;-----------------------------------------------------------------------------; cr=rmin, ci=ci-_dy and inc Ypos
;-----------------------------------------------------------------------------fld
rmin
;load rmin into TOS
fstp
cr
;store value in cr and POP
fld
ci
;load ci into TOS
fsub
_dy
;sub, ci-_dy
fstp
ci
;store result in ci and POP
inc
Ypos
;time to increase Ypos
mov
eax,Ypos
;
cmp
eax,Ymax
;check if bottom window border reached
jb
Next_Pixel
;
Force_WM_PAINT:
;-----------------------------------------------------------------------------; API "InvalidateRect" adds a rectangle to specified window's update region.
; This function performs a WM_PAINT message.
;-----------------------------------------------------------------------------push
0h
;bErase, erase-background flag
Page 11

push
push
call
jmp

0h
WP1_hWnd
InvalidateRect
WP1_return

td_win32asm_150.asm
;lpRect, rect structure, 0h=client area
;hWnd, handle window changed update region
;- API Function -

WP1_uMsg_111_wParam_02h:
cmp
ax,2h
;"Out" clicked ?, zoom out
jne
WP1_uMsg_111_wParam_03h
;
;-----------------------------------------------------------------------------; Zoom out. rmin=rmin-zoom, rmax=rmax+zoom, imin=imin-zoom, imax=imax+zoom
;-----------------------------------------------------------------------------cmp
zoomCounter,0
;limit for zooming out
je
WP1_return
dec
zoomCounter
;
ffree
ST(7)
;free ST(7), must be empty for load
fld
rmin
;load rmin into TOS
fsub
zoom
;sub, TOS-zoom
fstp
rmin
;store result in rmin and POP
fld
rmax
;load rmax into TOS
fadd
zoom
;add, TOS+zoom
fstp
rmax
;store result in rmax and POP
fld
imin
;load imin into TOS
fsub
zoom
;sub, TOS-zoom
fstp
imin
;store result in imin and POP
fld
imax
;load imax into TOS
fadd
zoom
;add, TOS+zoom
fstp
imax
;store result in imax and POP
cmp
autocalcFlag,1h
;
je
WP1_uMsg_111_wParam_01h
;
jmp
WP1_return
WP1_uMsg_111_wParam_03h:
cmp
ax,3h
;"In" clicked ?, zoom in
jne
WP1_uMsg_111_wParam_04h
;
;-----------------------------------------------------------------------------; Zoom in. rmin=rmin+zoom, rmax=rmax-zoom, imin=imin+zoom, imax=imax-zoom
;-----------------------------------------------------------------------------cmp
zoomCounter,62
;limit for zooming in
jae
WP1_return
inc
zoomCounter
;
ffree
ST(7)
;free ST(7), must be empty for load
fld
rmin
;load rmin into TOS
fadd
zoom
;add, TOS+zoom
fstp
rmin
;store result in rmin and POP
fld
rmax
;load rmax into TOS, rmin moves ST(1)
fsub
zoom
;sub, TOS-zoom
fstp
rmax
;store result in rmax and POP
fld
imin
;load imin into TOS, rmin=ST(2),rmax=ST(1)
fadd
zoom
;add, TOS+zoom
fstp
imin
;store result in imin and POP
fld
imax
;load imax into TOS
fsub
zoom
;sub, TOS-zoom
fstp
imax
;store result in imax and POP
Page 12

td_win32asm_150.asm
cmp
je
jmp

autocalcFlag,1h
WP1_uMsg_111_wParam_01h
WP1_return

;
;

WP1_uMsg_111_wParam_04h:
cmp
ax,4h
;"Left" clicked ?, moves left
jne
WP1_uMsg_111_wParam_05h
;
;-----------------------------------------------------------------------------; Changes the viewport to the left, scrolls left
;-----------------------------------------------------------------------------ffree
ST(7)
;free ST(7), must be empty for load
fld
rmin
;load rmin into TOS
fadd
view
;add, TOS-view
fstp
rmin
;store result in rmin and POP
fld
rmax
;load rmax into TOS
fadd
view
;add, TOS-view
fstp
rmax
;store result in rmax and POP
cmp
autocalcFlag,1h
;
je
WP1_uMsg_111_wParam_01h
;
jmp
WP1_return
WP1_uMsg_111_wParam_05h:
cmp
ax,5h
;"Right" clicked ?, moves right
jne
WP1_uMsg_111_wParam_06h
;
;-----------------------------------------------------------------------------; Changes the viewport to the right, scrolls right
;-----------------------------------------------------------------------------ffree
ST(7)
;free ST(7), must be empty for load
fld
rmin
;load rmin into TOS
fsub
view
;sub, TOS-view
fstp
rmin
;store result in rmin and POP
fld
rmax
;load rmax into TOS
fsub
view
;sub, TOS-view
fstp
rmax
;store result in rmax and POP
cmp
autocalcFlag,1h
;
je
WP1_uMsg_111_wParam_01h
;
jmp
WP1_return
WP1_uMsg_111_wParam_06h:
cmp
ax,6h
;"Up" clicked ?, moves up
jne
WP1_uMsg_111_wParam_07h
;
;-----------------------------------------------------------------------------; Changes the viewport up, scrolls up
;-----------------------------------------------------------------------------ffree
ST(7)
;free ST(7), must be empty for load
fld
imin
;load imin into TOS
fsub
view
;sub, TOS-view
fstp
imin
;store result in imin and POP
fld
imax
;load imax into TOS
fsub
view
;sub, TOS-view
fstp
imax
;store result in imax and POP
cmp
autocalcFlag,1h
;
je
WP1_uMsg_111_wParam_01h
;
Page 13

td_win32asm_150.asm
jmp

WP1_return

WP1_uMsg_111_wParam_07h:
cmp
ax,7h
;"Down" clicked ?, moves down
jne
WP1_uMsg_111_wParam_08h
;
;-----------------------------------------------------------------------------; Changes the viewport down, scrolls down
;-----------------------------------------------------------------------------ffree
ST(7)
;free ST(7), must be empty for load
fld
imin
;load imin into TOS
fadd
view
;add, TOS-view
fstp
imin
;store result in imin and POP
fld
imax
;load imax into TOS
fadd
view
;add, TOS-view
fstp
imax
;store result in imax and POP
cmp
autocalcFlag,1h
;
je
WP1_uMsg_111_wParam_01h
;
jmp
WP1_return
WP1_uMsg_111_wParam_08h:
cmp
ax,8h
;"Reset" clicked ?
jne
WP1_uMsg_111_wParam_0Ah
;
;-----------------------------------------------------------------------------; This function loads the default values for calculating the fractal
;-----------------------------------------------------------------------------mov
zoomCounter,0h
;reset zoom counter
ffree
ST(7)
;free ST(7), must be empty for load
fld
org_rmin
;load org_rmin into TOS
fstp
rmin
;store in rmin and POP
fld
org_rmax
;load org_rmax into TOS
fstp
rmax
;store in rmax and POP
fld
org_imin
;load org_imin into TOS
fstp
imin
;store in imin and POP
fld
org_imax
;load org_imax into TOS
fstp
imax
;store in imax and POP
cmp
autocalcFlag,1h
;
je
WP1_uMsg_111_wParam_01h
;
jmp
WP1_return
WP1_uMsg_111_wParam_0Ah:
cmp
ax,0Ah
;"Screen On" clicked ?
jne
WP1_uMsg_111_wParam_0Bh
;
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, menu item flags
;MF_BYCOMMAND=0h | MF_CHECKED=8h
push
0Ah
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, menu item flags
;MF_BYCOMMAND=0h | MF_UNCHECKED=0h
Page 14

push
push
call
mov
jmp

0Bh
handleMenu
CheckMenuItem
screenFlag,1h
WP1_return

td_win32asm_150.asm
;uIDCheckItem, menu item to check/uncheck
;hmenu, handle of menu
;- API Function ;

WP1_uMsg_111_wParam_0Bh:
cmp
ax,0Bh
;"Screen Off" clicked ?
jne
WP1_uMsg_111_wParam_0Ch
;
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, menu item flags
push
0Bh
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, menu item flags
push
0Ah
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function mov
screenFlag,0h
;
jmp
WP1_return
WP1_uMsg_111_wParam_0Ch:
cmp
ax,0Ch
;"Color 1" selected ?
jne
WP1_uMsg_111_wParam_0Dh
;
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, menu item flags
;MF_BYCOMMAND=0h | MF_CHECKED=8h
push
0Ch
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, menu item flags
;MF_BYCOMMAND=0h | MF_UNCHECKED=0h
push
0Dh
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function mov
cmulti,00000F00h
;
jmp
WP1_return
WP1_uMsg_111_wParam_0Dh:
cmp
ax,0Dh
;"Color 2" selected ?
jne
WP1_uMsg_111_wParam_0Eh
;
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, menu item flags
push
0Dh
;uIDCheckItem, menu item to check/uncheck
Page 15

push
call
push
push
push
call
mov
jmp

handleMenu
CheckMenuItem
0h
0Ch
handleMenu
CheckMenuItem
cmulti,00002F3Fh
WP1_return

td_win32asm_150.asm
;hmenu, handle of menu
;- API Function ;uCheck, menu item flags
;uIDCheckItem, menu item to check/uncheck
;hmenu, handle of menu
;- API Function ;

WP1_uMsg_111_wParam_0Eh:
cmp
ax,0Eh
;"Autocalc On" clicked ?
jne
WP1_uMsg_111_wParam_0Fh
;
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, menu item flags
push
0Eh
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, menu item flags
push
0Fh
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function mov
autocalcFlag,1h
;
jmp
WP1_return
WP1_uMsg_111_wParam_0Fh:
cmp
ax,0Fh
;"Autocalc Off" clicked ?
jne
WP1_uMsg_111_wParam_10h
;
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, menu item flags
push
0Fh
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, menu item flags
push
0Eh
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function mov
autocalcFlag,0h
;
jmp
WP1_return
WP1_uMsg_111_wParam_10h:
cmp
ax,10h
;"Iteration 256" clicked ?
jne
WP1_uMsg_111_wParam_11h
;
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, menu item flags
Page 16

push
push
call
push
push
push
call
push
push
push
call
push
push
push
call
mov
jmp

10h
handleMenu
CheckMenuItem
0h
11h
handleMenu
CheckMenuItem
0h
12h
handleMenu
CheckMenuItem
0h
13h
handleMenu
CheckMenuItem
itmax,256
WP1_return

td_win32asm_150.asm
;uIDCheckItem, menu item to check/uncheck
;hmenu, handle of menu
;- API Function ;uCheck, menu item flags
;uIDCheckItem, menu item to check/uncheck
;hmenu, handle of menu
;- API Function ;uCheck, menu item flags
;uIDCheckItem, menu item to check/uncheck
;hmenu, handle of menu
;- API Function ;uCheck, menu item flags
;uIDCheckItem, menu item to check/uncheck
;hmenu, handle of menu
;- API Function ;

WP1_uMsg_111_wParam_11h:
cmp
ax,11h
;"Iteration 128" clicked ?
jne
WP1_uMsg_111_wParam_12h
;
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, menu item flags
push
11h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, menu item flags
push
10h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, menu item flags
push
12h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, menu item flags
push
13h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function mov
itmax,128
;
jmp
WP1_return
WP1_uMsg_111_wParam_12h:
cmp
ax,12h
;"Iteration 064" clicked ?
jne
WP1_uMsg_111_wParam_13h
;
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, menu item flags
push
12h
;uIDCheckItem, menu item to check/uncheck
Page 17

push
call
push
push
push
call
push
push
push
call
push
push
push
call
mov
jmp

handleMenu
CheckMenuItem
0h
10h
handleMenu
CheckMenuItem
0h
11h
handleMenu
CheckMenuItem
0h
13h
handleMenu
CheckMenuItem
itmax,064
WP1_return

td_win32asm_150.asm
;hmenu, handle of menu
;- API Function ;uCheck, menu item flags
;uIDCheckItem, menu item to check/uncheck
;hmenu, handle of menu
;- API Function ;uCheck, menu item flags
;uIDCheckItem, menu item to check/uncheck
;hmenu, handle of menu
;- API Function ;uCheck, menu item flags
;uIDCheckItem, menu item to check/uncheck
;hmenu, handle of menu
;- API Function ;

WP1_uMsg_111_wParam_13h:
cmp
ax,13h
;"Iteration 032" clicked ?
jne
WP1_return
;
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, menu item flags
push
13h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, menu item flags
push
10h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, menu item flags
push
11h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, menu item flags
push
12h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function mov
itmax,032
;
jmp
WP1_return
;==============================================================================
; WM_SYSCOMMAND (value=112h) message recieved ?
;-----------------------------------------------------------------------------WP1_uMsg_112h:
cmp
eax,112h
;check if WM_COMMAND message recieved
jne
WP1_return
;if not goto label
mov
eax,WP1_wParam
;extra info about the message
cmp
eax,0F060h
;SC_CLOSE=0F060h received ?
jne
WP1_return
;
call
My_CleanSystem
;- SubRoutine Page 18

td_win32asm_150.asm
jmp

WP1_return

;==============================================================================
; API "DefWindowProcA" calls the window procedure to provide default processing
; for any window messages that an application does not process.
; This function ensures that every message is processed.
; It is called with the same parameters received by the window procedure.
;-----------------------------------------------------------------------------WP1_return:
popad
;pop all register from stack
push
WP1_lParam
;extra info about the message
push
WP1_wParam
;extra info about the message
push
WP1_uMsg
;the message number
push
WP1_hWnd
;handle of window who receives message
call
DefWindowProcA
;- API Function mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
10h
;return and clear stack
;##############################################################################
;******************************************************************************
; My own subroutine(s) for a compacter code resist here ...
;-----------------------------------------------------------------------------My_CleanSystem:
;-----------------------------------------------------------------------------; API "DeleteObject" deletes a logical pen, brush, font, bitmap, region, or
; palette, freeing all system resources associated with the object.
;-----------------------------------------------------------------------------push
handleBitmap
;hObject, handle compatible graphic object
call
DeleteObject
;- API Function ;-----------------------------------------------------------------------------; API "DeleteDC" deletes the specified device context (DC).
;-----------------------------------------------------------------------------push
handleCDC
;hdc, handle of compatible device context
call
DeleteDC
;- API Function ;-----------------------------------------------------------------------------; API "ReleaseDC" releases a device context (DC), freeing it for use by other.
;-----------------------------------------------------------------------------push
handleDC
;hdc, handle of device context
push
WP1_hWnd
;hwnd, handle of window
call
ReleaseDC
;- API Function ret
My_FillRect:
;-----------------------------------------------------------------------------; API "GetDC" retrieves a handle of a display device context (DC) for the
; client area of the specified window.
;-----------------------------------------------------------------------------push
WP1_hWnd
;hwnd, handle of window
call
GetDC
;- API Function mov
handleDC,eax
;hDC, handle of main device context
;-----------------------------------------------------------------------------; API "FillRect" fills a rectangle using the specified brush. Includes the left
Page 19

td_win32asm_150.asm
; and top borders, but excludes the right and bottom borders of the rectangle.
;-----------------------------------------------------------------------------push
hbrBackground
;hbr, handle of brush
push
OFFSET Xpos
;lprc, address of structure with rectangle
push
handleDC
;hDC, handle of main device context
call
FillRect
;- API Function ;-----------------------------------------------------------------------------; API "FillRect" fills a rectangle using the specified brush. Includes the left
; and top borders, but excludes the right and bottom borders of the rectangle.
;-----------------------------------------------------------------------------push
hbrBackground
;hbr, handle of brush
push
OFFSET Xpos
;lprc, address of structure with rectangle
push
handleCDC
;hDC, handle of compatible device context
call
FillRect
;- API Function ;-----------------------------------------------------------------------------; API "ReleaseDC" releases a device context (DC), freeing it for use by other.
;-----------------------------------------------------------------------------push
handleDC
;hdc, handle of main device context
push
WP1_hWnd
;hwnd, handle of window
call
ReleaseDC
;- API Function ret
;******************************************************************************
;==============================================================================
; end Main
= end of our program code
;-----------------------------------------------------------------------------end Main
;end of our program code, entry point
;==============================================================================
; To create the exe file use this commands with your Microsoft Assembler/Linker
;-----------------------------------------------------------------------------; ml.exe /c /coff td_win32asm_150.asm
;asm command
; rc.exe /v rsrc.rc
;rc command
; cvtres.exe /machine:ix86 rsrc.res
; link.exe /subsystem:windows td_win32asm_150.obj rsrc.obj
;link command
;==============================================================================

Page 20

Вам также может понравиться