News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

AOW32

Started by avcaballero, September 11, 2015, 04:39:05 AM

Previous topic - Next topic

Mikl__

The revised text of the program FernCM1.asm. The size of executable file is reduced from 856 bytes to 473 bytes.; masm dos com #
.286
.model tiny
.code
  ClipX2    EQU  640
  ClipY2    EQU  480
org 100h
start:
;Semilla---------------------------------------------------------
mov ah, 0           ; CLOCK - GET TIME OF DAY
int 1Ah ; Return: CX:DX = clock count
; AL = 00h if clock was read or written (via AH=0,1) since the previous
; midnight
; Otherwise, AL > 0
mov word_101CA, dx
mov cx,37h
push cs
pop es
mov si,offset word_101CA
lea di,[si+1]
                mov bx,3DCDh
@@: lodsw
mul bx
inc ax
stosw
loop @b
mov word ptr [si],2Ah
mov ax,12h
int 10h ; - VIDEO - SET VIDEO MODE
finit
DrawFern:
    ; Propуsito : Dibuja una hoja de helecho
    ; Entrada   : Ninguna
    ; Salida    : Ninguna
    ; Destruye  : Ninguna
;Randomization--------------------------------------------
mov bx,word_10238
inc bx
cmp bx,37h
jnz @f
xor bx,bx
@@: mov word_10238,bx
lea ax,[bx+17h]
mov dl,37h
div dl
shr ax,8
mov si,ax
mov cx,word_101CA[si]
lea ax,[bx+36h]
div dl
shr ax,8
mov si,ax
add cx,word_101CA[si]
mov word_101CA[bx], cx
mov ax,10000    ; Rango
mul cx
;--------------------------------------------------------------------
mov bx,7*2*3             ; Suponemos AX < 100
cmp dx,9300
jb Siguiente1
mov bx,7*2*0
jmp Final
Siguiente1: cmp dx,8600
jb Siguiente2
mov bx,7*2*1
jmp Final
Siguiente2: cmp dx,100
jb Final
mov bx,7*2*2
Final: mov si,offset ParamFern+2
add si,bx
mov di,offset x0
mov cx,6
rep movsw
                ; Xn = x0 + ((xu - x0)*x + (xv - x0)*y)/400
fild xu         ; ST(0)=xu
fisub x0         ; ST(0)=xu-x0
fmul X          ; ST(0)=(xu-x0)*x
fild xv         ; ST(0)=xv
fisub x0         ; ST(0)=xv-x0
fmul Y          ; ST(0)=(xv-x)*y
faddp st(1),st   ; ST(0)=((xu - x0)*x + (xv - x0)*y) y Liberamos ST(1)
fidiv const400
fiadd x0
                ; Yn = y0 + ((yu - y0)*x + (yv - y0)*y)/400
fild yu
fisub y0
fmul X
fild Yv
fisub y0
fmul Y
faddp st(1), st
fidiv const400
fiadd y0
                ; x = Xn: y = Yn
fst Y
fchs    ;st(0)=-Y
fistp R2Tmp
mov dx,R2Tmp
                fst X
add dx,440 ; dx = 440 - Y
fistp R2Tmp
mov cx,R2Tmp
add cx,10  ; cx = x + 10
ClipPixel: ; PSET (x + 10, 440 - y)
    ;  Propуsito: Dibujamos un punto con recorte en (BX,DX)
    ;  Entrada  : BX, eje X; DX, eje Y; AL, color
    ;  Salida   : Ninguna
    ;  Destruye : Ninguna
;IF (BX>0) && (BX<ClipX2) && (DX>0) && (DX<ClipY2)
cmp cx, ClipX2    ; CX = column
jnb @f
cmp dx, ClipY2    ; DX = row
jnb @f            ; BH = 0 display page
mov ax, 0C0Ah     ; AH = 0Ch WRITE DOT ON SCREEN
int 10h ; AL = color of dot
@@: dec i
jnz DrawFern
xor ah,ah ; їQueremos salir?
int 16h                 ; Si no pulsamos ninguna tecla
mov ax,3
int 10h ; - VIDEO - SET VIDEO MODE
ret
;--------------------------------------------------------------
i dw ClipX2*ClipY2
word_101CA dw 37h dup(?)
word_10238 dw ?
x0 dw ?
y0 dw ?
xu dw ?
yu dw ?
xv dw ?
Yv dw ?
const400 dw 400
X dd 200.0
Y dd 200.0
R2Tmp dw ?
ParamFern dw 2, 184, 0,  124, 64,  333, 82    ; Primer valor es el color
                DW 2, 128, 34, 208, 103, 0,   122   ; Primer valor es el color
                DW 2, 24,  57, 364, 45,  45,  397   ; Primer valor es el color
                DW 2, 160, 0,  160, 0,   160, 64    ; Primer valor es el color
end start

avcaballero

Let's see, Mikl__. What you are doing is ripping my codes and posting the resulting codes here. What is the effort? I asked you to help me on continue working with the Desktop Window Manager, because I don't have enough time, but you omised it and working on what you want (nothig to say, you can do whatever you want). But, tell me where is the effort? doing what I have already done?

Mikl__

Hola, Alonso! En cuanto a la Desktop Window Manager escucho por primera vez, me tienes con alguien confundido. Conmigo usted habló de la AOW32 traducción al ruso

avcaballero

I did, it was in our mails. Are you translating it to russian? Where you are working on is in AOWG, not in AOW32. AOWG has all the libraries available to download for all the examples, it is just that I had no time to make everything also in asm, that is what is missed, everything was coded in c, you can compile everything. This last fern is from AOE in MS-DOS. Nevertheless, you can keep doing what you want.

Mikl__

asm-file part #1
; masm windows gui #
.686
.model flat, stdcall
option casemap :none
includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\gdi32.lib
includelib c:\masm32\lib\msvcrt.lib
include c:\masm32\include\windows.inc
extern _imp__RegisterClassA@4:dword
extern _imp__BeginPaint@8:dword
extern _imp__BitBlt@36:dword
extern _imp__CreateWindowExA@48:dword
extern _imp__CreateCompatibleDC@4:dword
extern _imp__CreateDIBSection@24:dword
extern _imp__DeleteObject@4:dword
extern _imp__DeleteDC@4:dword
extern _imp__DestroyWindow@4:dword
extern _imp__DefWindowProcA@16:dword
extern _imp__DispatchMessageA@4:dword
extern _imp__EndPaint@8:dword
extern _imp__ExitProcess@4:dword
extern _imp__GetMessageA@16:dword
extern _imp__GetDC@4:dword
extern _imp__InvalidateRect@12:dword
extern _imp__KillTimer@8:dword
extern _imp__rand:dword
extern _imp__ReleaseDC@8:dword
extern _imp__SetTimer@16:dword
extern _imp__SelectObject@8:dword
.code
cdXPos          equ 131
cdYPos          equ 217
ScreenHeight equ 400
ScreenWidth     equ 640 ;ScreenHeight*1.6
cdIdTimer       equ 1
DIB_RGB_COLORS  equ 0
stPaleta struct
  Azul db ?
  Verde db ?
  Rojo db ?
  Alfa db ?
stPaleta ends
start:          xor ebx,ebx
mov edi,offset wTitle
mov esi,400000h
push edi
push ebx
push BLACK_PEN
push 10011h
push ebx
push esi
push ebx
push ebx
push offset WinProc
push ebx
push esp ; lpWndClass
call _imp__RegisterClassA@4
push ebx    
push esi
push ebx
push ebx
push ScreenHeight+25
push ScreenWidth
push cdYPos
push cdXPos
push WS_VISIBLE
push edi; szWinTitle
push edi; lpszClassName
push ebx ; dwExStyle
call _imp__CreateWindowExA@48
mov ebp,esp

message_loop: push ebx  ;                       
push ebx
push ebx
push ebp
call _imp__GetMessageA@16
        cmp [ebp+MSG.wParam],1Bh ;press "Esc"?
jz wmDESTROY
push ebp
call _imp__DispatchMessageA@4       
jmp message_loop

sub_4010DD proc arg_0:dword,arg_4:dword

mov eax, arg_0
mov edx, [eax]
mov eax, arg_0
mov ecx, arg_4
mov ecx, [ecx]
mov [eax], ecx
mov eax, arg_4
mov [eax], edx
ret
sub_4010DD endp

sub_401421 proc X1:dword,Y1:dword,X2:dword

mov eax, X1
cmp eax, X2
jbe @f
lea eax, X2
push eax
lea eax, X1
push eax
call sub_4010DD
@@: imul eax, Y1,ScreenWidth
add eax, X1
mov edx, eax ; edx = Y1 * ScreenWidth + X1
xor ecx, ecx
@@: mov eax, X2
sub eax, X1
cmp ecx, eax
ja @f
mov buffer1[ecx+edx], 5 ; color = 5
inc ecx
jmp @b
@@: ret
sub_401421 endp


sub_4014A3 proc X1:dword,Y1:dword,Y2:dword

mov eax, Y1
cmp eax, Y2
jbe @f
lea eax, Y2
push eax
lea eax, Y1
push eax
call sub_4010DD
@@: imul    eax, Y1,ScreenWidth
add eax, X1
mov edx, eax ;edx = Y1 * ScreenWidth + X1
xor ecx, ecx
@@: mov eax, Y2
sub eax, Y1
cmp ecx, eax
ja @f
mov buffer1[edx], 5;color
add edx, ScreenWidth
inc ecx
jmp @b
@@: ret
sub_4014A3 endp





BresLine proc X1:dword,Y1:dword,X2:dword,Y2:dword
local var_4:dword
local var_8:dword
local var_C:dword
local var_10:dword
local var_14:dword
local var_18:dword


mov eax, Y1
cmp eax, Y2
jnz @f
push X2
push Y1
push X1
call sub_401421
jmp fin

@@: mov eax, X1
cmp eax, X2
jnz @f
push Y2
push Y1
push X1
call sub_4014A3
jmp fin

@@: mov eax, X2
sub eax, X1
mov var_4, eax
cmp eax, 0
jge @f
neg var_4

@@: mov eax, Y2
sub eax, Y1
mov var_8, eax
cmp eax, 0
jge @f
neg var_8

@@: mov eax, X1
cmp eax, X2
jge @f
mov var_C, 1
jmp loc_401601


@@: or var_C, -1

loc_401601: mov eax, Y1
cmp eax, Y2
jge @f
mov var_10, 1
jmp loc_401624


@@: or var_10, -1

loc_401624: mov eax, var_4
sub eax, var_8
mov var_14, eax

loc_40162F: imul eax, Y1,ScreenWidth
add eax, X1      ; eax = Y1 * ScreenWidth + X1
mov buffer1[eax], 5;color
mov eax, X1
cmp eax, X2
jnz @f
mov eax, Y1
cmp eax, Y2
jz fin


@@: mov eax, var_14
shl eax, 1
mov var_18, eax
mov eax, 0
sub eax, var_8
cmp var_18, eax
jle @f
mov eax, var_14
sub eax, var_8
mov var_14, eax
mov eax, X1
add eax, var_C
mov X1, eax

@@: mov eax, X1
cmp eax, X2
jnz @f
mov eax, Y1
cmp eax, Y2
jnz @f
imul eax, Y1,ScreenWidth
add eax, X1 ; eax = Y1 * ScreenWidth + X1
mov buffer1[eax], 5;color=5
jmp fin


@@: mov eax, var_18
cmp eax, var_4
jge loc_40162F
mov eax, var_14
add eax, var_4
mov var_14, eax
mov eax, Y1
add eax, var_10
mov Y1, eax
jmp loc_40162F
fin: ret
BresLine endp


WinProc proc hWnd:dword,Msg:dword,wParam:dword,lParam:dword
local hdc:dword
local ps:PAINTSTRUCT

mov eax, Msg
dec eax;cmp eax,WM_CREATE
jz wmCREATE
        dec eax;cmp eax,WM_DESTROY
jz wmDESTROY
sub eax,WM_PAINT-WM_DESTROY
jz wmPAINT
                sub eax,WM_TIMER-WM_PAINT
jz wmTIMER
        leave
jmp _imp__DefWindowProcA@16

wmDESTROY:: push cdIdTimer ; uIDEvent
push hWnd
call _imp__KillTimer@8
push hOldBmp
push hBackDC
call _imp__SelectObject@8
mov hGDITmp, eax
push bufBMP ; HGDIOBJ
call _imp__DeleteObject@4
push hBackDC ; HDC
call _imp__DeleteDC@4
push hOldDIB ; HGDIOBJ
push bufDIBDC ; HDC
call _imp__SelectObject@8
mov hGDITmp, eax
push bufDIBDC ; HDC
call _imp__DeleteDC@4
push hMainDIB ; HGDIOBJ
call _imp__DeleteObject@4
push hWnd
call _imp__DestroyWindow@4
push ebx ; nExitCode
call _imp__ExitProcess@4


wmCREATE: push hWnd
call _imp__GetDC@4
mov hdc, eax
push eax ; HDC
call _imp__CreateCompatibleDC@4
mov bufDIBDC, eax
push ebx ; DWORD
push ebx ; HANDLE
push offset pMainDIB
push ebx ; UINT
push offset bi       ; BITMAPINFO *
push hdc ; HDC
call _imp__CreateDIBSection@24
mov hMainDIB, eax
push eax ; HGDIOBJ
push bufDIBDC ; HDC
call _imp__SelectObject@8
mov hOldDIB, eax
push hdc
push hWnd
call _imp__ReleaseDC@8
call Init
push ebx ; lpTimerFunc
push 40 ; uElapse
push cdIdTimer ; nIDEvent
push hWnd
call _imp__SetTimer@16
jmp wmBYE

wmTIMER: push ebx ; bErase
push ebx ; lpRect
push hWnd
call _imp__InvalidateRect@12
jmp wmBYE


wmPAINT: lea eax,ps
push eax ; lpPaint
push hWnd
call _imp__BeginPaint@8
mov hdc, eax
call PintaObjeto
push SRCCOPY
push ebx ; int
push ebx ; int
push bufDIBDC ; HDC
push 190h ; int
push ScreenWidth ; int
push ebx ; int
push ebx ; int
push hdc ; HDC
call _imp__BitBlt@36
lea eax,ps
push eax ; lpPaint
push hWnd
call _imp__EndPaint@8
wmBYE: ret
WinProc endp


sub_401BC7 proc arg_0:dword
local i:dword

mov i,ScreenWidth*ScreenHeight-1
@@: mov eax, arg_0
add eax, i
mov cl, byte ptr [eax]
test cl, cl
jz loc_401C6D
mov edx, i
shl edx, 2
add edx, pMainDIB

movzx eax, cl
shl eax, 2
add eax, offset miPaleta
assume eax: ptr stPaleta
                movzx ecx, byte ptr [eax].Rojo
shl ecx, 10h
                mov ch, byte ptr [eax].Verde
                mov cl, byte ptr [eax].Azul
assume eax: nothing
mov [edx], ecx

loc_401C6D: dec i
jns @b

ret
sub_401BC7 endp


KochTree proc X1:qword,Y1:qword,X2:qword,Y2:qword,Nivel:qword

local XX1:qword
local YY1:qword
local XX2:qword
local YY2:qword
local XX3:qword
local YY3:qword
local XX4:qword
local YY4:qword
local XVector:qword
local YVector:qword
local var_54:dword
local var_58:dword
local XVector2:qword
local YVector2:qword
local Temp:qword

fld Nivel
fldz            ;Nivel > 0 ?
fucompp
fnstsw ax
test ah, 5
jnz @@KOCH_ELSE
fld X1
push eax
fistp dword ptr [esp]
pop var_54
fld Y1
push ecx
fistp dword ptr [esp]
pop var_58
fld X2
push edx
fistp dword ptr [esp]
pop edx
fld Y2
push eax
fistp dword ptr [esp]
pop eax
push offset buffer1
push 5
push eax    ;=Y2
push edx    ;=X2
push var_58 ;=Y1
push var_54 ;=X1
call BresLine
jmp @@KOCH_FIN


@@KOCH_ELSE: fld X2     ;st(0)=X2
fsub X1     ;st(0)=X2-X1
fst XVector;XVector=X2-X1
                fadd st,st 
fstp XVector2;st(0)=2*XVector

fld Y2     ;st(0)=Y2
fsub Y1     ;st(0)=Y2-Y1
fst YVector;YVector=Y2-Y1
                fadd st,st
fstp YVector2 ;st(0)=2*YVector

fld const3
fdivr XVector;st(0)=XVector/3
fadd X1     ;st(0)=X1+XVector/3
fstp XX1    ;XX1=X1+XVector/3
fld const3
fdivr YVector;st(0)=YVector/3
fadd Y1     ;st(0)=Y1+YVector/3
fstp YY1    ;YY1=Y1+YVector/3
fld const2
fdivr XVector;st(0)=XVector/2
fadd X1     ;st(0)=X1+XVector/2
fstp XX2    ;XX2=X1+XVector/2
fld const2
fdivr YVector;st(0)=YVector/2
fadd Y1     ;st(0)=Y1+YVector/2
fstp YY2    ;YY2=Y1+YVector/2

fld const3
fdivr XVector2 ;st(0)=2*XVector/3
fadd X1     ;st(0)=X1+2*XVector/3
fstp XX3    ;XX3=X1+2*XVector/3

fld const3
fdivr YVector2;st(0)=2*YVector/3
fadd Y1    ;st(0)=Y1+2*YVector/3
fstp YY3   ;YY3=Y1+2*YVector/3
fld constSQRT3x2
fdivr YVector;st(0)=YVector/(2*SQRT(3))
fsubr XX2    ;st(0)=XX2-YVector/(2*SQRT(3))
fstp XX4    ;XX4=XX2-YVector/(2*SQRT(3))
fld constSQRT3x2
fdivr XVector;st(0)=XVector/(2*SQRT(3))
fsubr YY2    ;st(0)=YY2-XVector/(2*SQRT(3))
fstp YY4    ;YY4=YY2-XVector/(2*SQRT(3))
fld1
fsubr Nivel
fstp    Temp
push dword ptr Temp+4
                push dword ptr Temp
push dword ptr YY1+4
push dword ptr YY1
push dword ptr XX1+4
push dword ptr XX1
push dword ptr Y1+4
push dword ptr Y1
push dword ptr X1+4
push dword ptr X1
call KochTree
push dword ptr Temp+4
                push dword ptr Temp
push dword ptr YY4+4
push dword ptr YY4
push dword ptr XX4+4
push dword ptr XX4
push dword ptr YY1+4
push dword ptr YY1
push dword ptr XX1+4
push dword ptr XX1
call KochTree
push dword ptr Temp+4
                push dword ptr Temp
push dword ptr YY3+4
push dword ptr YY3
push dword ptr XX3+4
push dword ptr XX3
push dword ptr YY4+4
push dword ptr YY4
push dword ptr XX4+4
push dword ptr XX4
call KochTree
push dword ptr Temp+4
                push dword ptr Temp
push dword ptr Y2+4
push dword ptr Y2
push dword ptr X2+4
push dword ptr X2
push dword ptr YY3+4
push dword ptr YY3
push dword ptr XX3+4
push dword ptr XX3
call KochTree

@@KOCH_FIN: ret
KochTree endp


sub_401FE0 proc arg_0:dword 
local var_4:dword
local var_8:dword
local var_C:dword

mov var_4, 0
mov eax, arg_0
imul eax, 10
add eax, offset buffer3+2
movsx eax, word ptr [eax]
add eax, 1
shl eax, 9
mov ecx, arg_0
imul ecx, 10
add ecx, offset buffer3+2
movsx ecx, word ptr [ecx]
add ecx, 1
shl ecx, 7
add eax, ecx
mov ecx, arg_0
imul ecx, 10
add ecx, offset buffer3
movsx ecx, word ptr [ecx]
add eax, ecx
mov var_C, eax
mov eax, arg_0
imul eax, 10
add eax, offset buffer3+2
movsx eax, word ptr [eax]
add eax, 1
mov var_8, eax

loc_402068: mov eax, offset buffer1
add eax, var_C
movzx ecx, byte ptr [eax]
cmp ecx, 5
jz loc_4020B7
mov eax, offset buffer1
add eax, var_C
movzx ecx, byte ptr [eax]
cmp ecx, 5
jnz loc_4020C2


loc_4020B7: mov eax, var_8
mov var_4, eax
jmp loc_4020D0


loc_4020C2: sub var_C, ScreenWidth
dec var_8
jnz   loc_402068


loc_4020D0: mov eax, var_4

leave
retn 4
sub_401FE0 endp

Mikl__

asm-file part #2
sub_4020DA proc arg_0:dword 
local var_4:dword
local var_8:dword

mov eax, arg_0
imul eax, 10
add eax, offset buffer3+6
mov var_4, eax
call _imp__rand
and eax,0Fh
shl eax, 1
add eax, offset word_404004
movsx ecx, word ptr [eax]
mov eax, var_4
mov [eax], cx
mov eax, arg_0
imul eax, 10
add eax, offset buffer3+8
mov var_8, eax
call _imp__rand
and eax,0Fh
shl eax, 1
add eax, offset word_404024
movsx ecx, word ptr [eax]
mov eax, var_8
mov [eax], cx
leave
retn 4
sub_4020DA endp


sub_402156 proc arg_0:dword,arg_4:dword
local var_4:dword
local var_8:dword
local var_C:dword

mov eax, arg_0
imul eax, 10
add eax, offset buffer3
mov var_4, eax
call _imp__rand
mov ecx, 27Fh
cdq
idiv ecx
mov eax, var_4
mov [eax], dx
mov eax, arg_0
imul eax, 10
add eax, offset buffer3+2
mov var_8, eax
mov eax, arg_4
cmp eax, 0
mov eax, 0
setz al
test eax, eax
jnz loc_4021CE


loc_4021BB: call _imp__rand
mov ecx, arg_4
sub ecx, 1
cdq
idiv ecx
jmp loc_4021D5


loc_4021CE: xor eax, eax
cdq ;edx=0

loc_4021D5: mov eax, var_8
mov [eax], dx
mov eax, arg_0
imul eax, 10
add eax, offset buffer3+4
mov var_C, eax
call _imp__rand
and eax, 3
inc eax
mov ecx, var_C
mov [ecx], ax
push arg_0
call sub_4020DA
ret
sub_402156 endp

sub_402217 proc arg_0:dword 
local var_4:dword
local var_8:dword
local var_C:dword
local var_10:dword

mov eax, arg_0
imul eax, 10
add eax, offset buffer3+2
movsx eax, word ptr [eax]
shl eax, 9
mov ecx, arg_0
imul ecx, 10
add ecx, offset buffer3+2
movsx ecx, word ptr [ecx]
shl ecx, 7
add eax, ecx
mov ecx, arg_0
imul ecx, 10
add ecx, offset buffer3
movsx ecx, word ptr [ecx]
add eax, ecx
mov var_4, eax
mov eax, offset buffer2
add eax, var_4
mov ecx, var_4
add ecx, 1
mov edx, offset buffer2
add edx, ecx
mov ecx, var_4
add ecx, ScreenWidth
mov var_8, eax
mov eax, offset buffer2
add eax, ecx
mov ecx, var_4
add ecx, 281h
mov var_C, edx
mov edx, offset buffer2
add edx, ecx
mov ecx, arg_0
mov var_10, eax
imul ecx, 10;eax
add ecx, offset buffer3+4
movsx ecx, word ptr [ecx]
mov [edx], cl
mov eax, var_10
mov [eax], cl
mov eax, var_C
mov [eax], cl
mov eax, var_8
mov [eax], cl
leave
retn 4
sub_402217 endp

sub_4022ED proc
local var_4:dword
local var_8:dword
local var_10:dword

mov var_4, 0
loc_4022FF: push 390
push var_4
call sub_402156
push var_4
call sub_401FE0
mov var_8, eax
cmp eax, 0
jle loc_402379
mov eax, var_4
imul eax, 10
add eax, offset buffer3+2
mov var_10, eax
call _imp__rand
mov ecx, var_8
sar ecx, 2
cdq
idiv ecx
mov eax, var_10
mov [eax], dx

loc_402379: push var_4
call sub_402217
inc var_4
                cmp var_4,1000
jl loc_4022FF

locret_402387: leave
retn
sub_4022ED endp

Init proc
push dword ptr CNivel+4
push dword ptr CNivel
push dword ptr CY2+4
push dword ptr CY2
push dword ptr CX2+4
push dword ptr CX2
push dword ptr CY1+4
push dword ptr CY1
push dword ptr CX1+4
push dword ptr CX1
call KochTree
call sub_4022ED
retn
Init endp






sub_4023F7 proc arg_0:dword
local var_4:dword
local var_8:dword

mov var_4, 0
mov var_8, 0
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
add ecx, 6
movsx eax, word ptr [ecx]
cmp eax, 0
jle loc_4024AF
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
movsx eax, word ptr [ecx]
add eax, 1
cmp eax, ScreenWidth
jge loc_402498
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
movsx eax, word ptr [ecx]
mov edx, eax
add eax, 1
mov [ecx], ax
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
add ecx, 6
movsx eax, word ptr [ecx]
mov edx, eax
dec eax
mov [ecx], ax
jmp loc_4024AA


loc_402498: mov eax, 0
push eax
mov eax, arg_0
push eax
call sub_402156
loc_4024AA: jmp loc_40254F


loc_4024AF: mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
add ecx, 6
movsx eax, word ptr [ecx]
cmp eax, 0
jge loc_402547
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
movsx eax, word ptr [ecx]
cmp eax, 0
jle loc_402530
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
movsx eax, word ptr [ecx]
mov edx, eax
dec eax
mov [ecx], ax
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
add ecx, 6
movsx eax, word ptr [ecx]
mov edx, eax
add eax, 1
mov [ecx], ax
jmp loc_402542


loc_402530: mov eax, 0
push eax
mov eax, arg_0
push eax
call sub_402156
loc_402542: jmp loc_40254F


loc_402547: mov eax, 1
mov var_4, eax

loc_40254F: mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
add ecx, 8
movsx eax, word ptr [ecx]
cmp eax, 0
jle loc_4025F3
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
add ecx, 2
movsx eax, word ptr [ecx]
add eax, 1
cmp eax, 186h
jge loc_4025DC
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
add ecx, 2
movsx eax, word ptr [ecx]
mov edx, eax
add eax, 1
mov [ecx], ax
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
add ecx, 8
movsx eax, word ptr [ecx]
mov edx, eax
dec eax
mov [ecx], ax
jmp loc_4025EE


loc_4025DC: mov eax, 0
push eax
mov eax, arg_0
push eax
call sub_402156
loc_4025EE: jmp loc_402699


loc_4025F3: mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
add ecx, 8
movsx eax, word ptr [ecx]
cmp eax, 0
jge loc_402691
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
add ecx, 2
movsx eax, word ptr [ecx]
cmp eax, 0
jle loc_40267A
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
add ecx, 2
movsx eax, word ptr [ecx]
mov edx, eax
dec eax
mov [ecx], ax
mov eax, arg_0
mov ecx, 0Ah
imul eax, ecx
mov ecx, offset buffer3
add ecx, eax
add ecx, 8
movsx eax, word ptr [ecx]
mov edx, eax
inc eax
mov [ecx], ax
jmp loc_40268C


loc_40267A: push ebx
push arg_0
call sub_402156
loc_40268C: jmp loc_402699


loc_402691: mov var_8, 1

loc_402699: cmp var_4, 1
jnz locret_4026BD
cmp var_8, 1
jnz locret_4026BD
push arg_0
call sub_4020DA

locret_4026BD: leave
retn 4
sub_4023F7 endp


sub_4026BF proc

local var_4:dword

mov ecx,ScreenHeight*ScreenWidth/4
xor eax,eax
mov edi,offset buffer2
rep stosd
mov var_4, 0
loc_4026EB: push var_4
call sub_4023F7
push var_4
call sub_401FE0
cmp eax, 0
jle loc_40273F
push ebx
push var_4
call sub_402156
loc_40273F: push var_4
call sub_402217
inc var_4
cmp var_4,3E8h
jl loc_4026EB

locret_40274D: leave
retn
sub_4026BF endp

PintaObjeto proc
mov ecx,ScreenHeight*ScreenWidth*4/4
xor eax,eax
mov edi,pMainDIB
rep stosd
call sub_4026BF
push offset buffer2
call sub_401BC7
push offset buffer1
call sub_401BC7
retn
PintaObjeto endp

sub_402E27 proc arg_0:dword,arg_4:dword,arg_8:dword
local var_4:dword
local var_8:dword
local var_C:dword

mov eax, arg_0
mov ecx, arg_4
mov var_8, eax
mov var_4, ecx
cmp arg_8, 20h
jl loc_402E6C
mov eax, arg_8
sub eax, 20h
mov ecx, var_8
mov var_C, ecx
mov ecx, eax
mov eax, var_C
shl eax, cl
mov var_4, eax
mov var_8, 0
jmp loc_402E9F


loc_402E6C: cmp arg_8, 0
jz loc_402E9F
mov eax, var_4
mov ecx, arg_8
shl eax, cl
mov ecx, 20h
sub ecx, arg_8
mov edx, var_8
shr edx, cl
or eax, edx
mov var_4, eax
mov eax, var_8
mov ecx, arg_8
shl eax, cl
mov var_8, eax

loc_402E9F: mov eax, var_8
mov edx, var_4

leave
retn
sub_402E27 endp
;-----------------------------------------------------------------
.data
word_404004 dw 7, 0FFF9h, 6, 0FFFAh, 5, 0FFFBh, 4, 0FFFCh, 3, 0FFFDh
dw 2, 0FFFEh, 1, 0FFFFh, 0, 1
word_404024 dw 4, 2, 3, 1, 2, 0, 1, 2, 2 dup(3), 2, 4, 1, 0FFFFh, 2 dup(0)
wTitle db 'Nevada - (c) abreojosensamblador.net',0
const3 dq 3.0
const2 dq 2.0
constSQRT3x2 dq 3.464101615137754;sqrt(3)=1,7320508075688772935274463415059*2
CNivel dq 5.0
CY2 dq 390.0
CX2 dq 639.0
CY1 dq 390.0
CX1 dq 0.0
db 8 dup(0)
db 1Ah dup(0)
byte_404180 db 10h dup(0), 98h, 42h, 0Eh dup(0), 0F4h, 41h, 2 dup(0)
db 0F4h, 42h, 0Eh dup(0), 50h, 42h, 2 dup(0), 4, 43h, 0Eh dup(0)
db 60h, 42h, 2 dup(0), 20h, 43h, 0Eh dup(0), 7Ch, 42h
db 16h dup(0)

dd 4347h, 435Ah, 4369h, 4375h, 4383h, 4394h, 43A2h, 43B4h
dd 43C1h, 43D0h, 43DEh, 43F1h, 4404h, 4410h, 4422h, 442Ah
dd 4436h, 4441h, 4452h, 445Fh, 446Ah, 447Ah, 0, 4498h
dd 44ABh, 44BDh, 0, 44D9h, 44E8h, 44F7h, 4502h, 4517h
dd 452Ah, 0, 453Eh, 4547h, 454Eh, 455Fh, 456Ch, 4573h
dd 92h dup(0)
bi BITMAPINFOHEADER <sizeof BITMAPINFOHEADER,ScreenWidth,-ScreenHeight,1,32,0>
miPaleta stPaleta <0>,<43,43,43>,<85,85,85>,<128,128,128>,<171,171,171>,<255,255,255>
.data?
buffer3 db 10000 dup(?)
buffer1 db ScreenHeight*ScreenWidth dup(?)
buffer2 db ScreenHeight*ScreenWidth dup(?)
bufDIBDC dd ?
hBackDC dd ?
hMainDIB dd ?
bufBMP dd ?
hOldBmp dd ?
hGDITmp dd ?
hOldDIB dd ?
pMainDIB dd ?
end start
bat-filecls
set filename=%1
set masm_path=c:\masm32
if exist %filename%.exe del %filename%.exe
%masm_path%\bin\ml /c /Cp /Gz /I%masm_path%\include /coff /nologo %filename%.asm  || exit
%masm_path%\bin\link /SUBSYSTEM:WINDOWS /LIBPATH:%masm_path%\lib /NOLOGO %filename%.obj
del %filename%.obj

Mikl__

#21
Program was made slightly smaller and were added meaningful names for procedures and for labels. There is original program in attachment NevadaWC01.zip
asm-file; masm windows gui #
.686
.model flat, stdcall
option casemap :none
includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\gdi32.lib
includelib c:\masm32\lib\msvcrt.lib
include c:\masm32\include\windows.inc
extern _imp__RegisterClassA@4:dword
extern _imp__BeginPaint@8:dword
extern _imp__BitBlt@36:dword
extern _imp__CreateWindowExA@48:dword
extern _imp__CreateCompatibleDC@4:dword
extern _imp__CreateDIBSection@24:dword
extern _imp__DeleteObject@4:dword
extern _imp__DeleteDC@4:dword
extern _imp__DestroyWindow@4:dword
extern _imp__DefWindowProcA@16:dword
extern _imp__DispatchMessageA@4:dword
extern _imp__EndPaint@8:dword
extern _imp__ExitProcess@4:dword
extern _imp__GetMessageA@16:dword
extern _imp__GetDC@4:dword
extern _imp__InvalidateRect@12:dword
extern _imp__KillTimer@8:dword
extern _imp__rand:dword
extern _imp__ReleaseDC@8:dword
extern _imp__SetTimer@16:dword
extern _imp__SelectObject@8:dword
.code
cdXPos          equ 131
cdYPos          equ 217
ScreenHeight equ 400;+50
ScreenWidth     equ 640 ;ScreenHeight*1.6
cdIdTimer       equ 1
DIB_RGB_COLORS  equ 0
SnowLevel       equ ScreenHeight-10
stPaleta struct
  Azul db ?
  Verde db ?
  Rojo db ?
  Alfa db ?
stPaleta ends
start:          xor ebx,ebx
mov edi,offset wTitle
mov esi,400000h
push edi
push ebx
push BLACK_PEN
push 10011h
push ebx
push esi
push ebx
push ebx
push offset WinProc
push ebx
push esp ; lpWndClass
call _imp__RegisterClassA@4
push ebx    
push esi
push ebx
push ebx
push ScreenHeight+25
push ScreenWidth
push cdYPos
push cdXPos
push WS_VISIBLE
push edi; szWinTitle
push edi; lpszClassName
push ebx ; dwExStyle
call _imp__CreateWindowExA@48
mov ebp,esp

message_loop: push ebx  ;                       
push ebx
push ebx
push ebp
call _imp__GetMessageA@16
        cmp [ebp+MSG.wParam],VK_ESCAPE ;press "Esc"? without TranslateMessage
jz wmDESTROY
push ebp
call _imp__DispatchMessageA@4       
jmp message_loop

CopyPoint proc arg_0:dword,arg_4:dword

mov esi, arg_0
                mov edi, arg_4
movsd
ret
CopyPoint endp

sub_401421 proc X1:dword,Y1:dword,X2:dword

mov eax, X1
cmp eax, X2
jbe @f
lea eax, X2
push eax
lea eax, X1
push eax
call CopyPoint
@@: imul eax, Y1,ScreenWidth
add eax, X1
mov edx, eax ; edx = Y1 * ScreenWidth + X1
xor ecx, ecx
@@: mov eax, X2
sub eax, X1
cmp ecx, eax
ja fin
mov buffer1[ecx+edx], 5 ; color = 5
inc ecx
jmp @b
fin: ret
sub_401421 endp


sub_4014A3 proc X1:dword,Y1:dword,Y2:dword

mov eax, Y1
cmp eax, Y2
jbe @f
lea eax, Y2
push eax
lea eax, Y1
push eax
call CopyPoint
@@: imul    eax, Y1,ScreenWidth
add eax, X1
mov edx, eax ;edx = Y1 * ScreenWidth + X1
xor ecx, ecx
@@: mov eax, Y2
sub eax, Y1
cmp ecx, eax
ja fin
mov buffer1[edx], 5;color
add edx, ScreenWidth
inc ecx
jmp @b
fin: ret
sub_4014A3 endp





BresLine proc X1:dword,Y1:dword,X2:dword,Y2:dword
local DeltaX:dword
local DeltaY:dword
local Xinc:dword
local Yinc:dword
local Error:dword


mov eax, Y1
cmp eax, Y2
jnz @f
push X2
push Y1
push X1
call sub_401421
jmp fin

@@: mov eax, X1
cmp eax, X2
jnz @f
push Y2
push Y1
push X1
call sub_4014A3
jmp fin

@@: mov eax, X2
sub eax, X1
cdq
xor eax,edx
sub eax,edx
mov DeltaX, eax  ; DeltaX = |X2 - X1|
or edx,1
mov Xinc, edx    ; if X2 - X1 >= 0  Xinc=1 else Xinc= -1

mov eax, Y2
sub eax, Y1
cdq
xor eax,edx      ; if edx = -1 not(eax)
sub eax,edx      ; if edx = -1 neg(eax) = not(eax)-(-1)
mov DeltaY, eax  ; DeltaY = |Y2 - Y1|
or edx,1
                mov Yinc, edx    ; if Y2 - Y1 >= 0  Yinc=1 else Yinc= -1

mov eax, DeltaX
sub eax, DeltaY
mov Error, eax

bucle: imul eax, Y1,ScreenWidth
add eax, X1      ; eax = Y1 * ScreenWidth + X1
mov buffer1[eax], 5;color
mov eax, X1
cmp eax, X2
jnz @f
mov eax, Y1
cmp eax, Y2
jz fin

@@: mov eax, Error
shl eax, 1
add eax,DeltaY
jle @f
mov eax, Error
sub eax, DeltaY
mov Error, eax
mov eax, X1
add eax, Xinc
mov X1, eax

@@: mov eax, X1
cmp eax, X2
jnz @f
mov eax, Y1
cmp eax, Y2
jnz @f
imul eax, Y1,ScreenWidth
add eax, X1 ; eax = Y1 * ScreenWidth + X1
mov buffer1[eax], 5;color=5
jmp fin


@@: mov eax, Error
shl eax,1
cmp eax, DeltaX
jge bucle
mov eax, Error
add eax, DeltaX
mov Error, eax
mov eax, Y1
add eax, Yinc
mov Y1, eax
jmp bucle
fin: ret
BresLine endp


WinProc proc hWnd:dword,Msg:dword,wParam:dword,lParam:dword
local hdc:dword
local ps:PAINTSTRUCT

mov eax, Msg
dec eax;cmp eax,WM_CREATE
jz wmCREATE
        dec eax;cmp eax,WM_DESTROY
jz wmDESTROY
sub eax,WM_PAINT-WM_DESTROY
jz wmPAINT
            sub eax,WM_TIMER-WM_PAINT
jz wmTIMER
        leave
jmp _imp__DefWindowProcA@16

wmDESTROY:: push cdIdTimer ; uIDEvent
push hWnd
call _imp__KillTimer@8
push hOldBmp
push hBackDC
call _imp__SelectObject@8
mov hGDITmp, eax
push bufBMP ; HGDIOBJ
call _imp__DeleteObject@4
push hBackDC ; HDC
call _imp__DeleteDC@4
push hOldDIB ; HGDIOBJ
push bufDIBDC ; HDC
call _imp__SelectObject@8
mov hGDITmp, eax
push bufDIBDC ; HDC
call _imp__DeleteDC@4
push hMainDIB ; HGDIOBJ
call _imp__DeleteObject@4
push hWnd
call _imp__DestroyWindow@4
push ebx ; nExitCode
call _imp__ExitProcess@4


wmCREATE: push hWnd
call _imp__GetDC@4
mov hdc, eax
push eax ; HDC
call _imp__CreateCompatibleDC@4
mov bufDIBDC, eax
push ebx ; DWORD
push ebx ; HANDLE
push offset pMainDIB
push ebx ; UINT
push offset bi       ; BITMAPINFO *
push hdc ; HDC
call _imp__CreateDIBSection@24
mov hMainDIB, eax
push eax ; HGDIOBJ
push bufDIBDC ; HDC
call _imp__SelectObject@8
mov hOldDIB, eax
push hdc
push hWnd
call _imp__ReleaseDC@8
call Init
push ebx ; lpTimerFunc
push 40 ; uElapse
push cdIdTimer ; nIDEvent
push hWnd
call _imp__SetTimer@16
jmp wmBYE

wmTIMER: push ebx ; bErase
push ebx ; lpRect
push hWnd
call _imp__InvalidateRect@12
jmp wmBYE


wmPAINT: lea eax,ps
push eax ; lpPaint
push hWnd
call _imp__BeginPaint@8
mov hdc, eax
call PintaObjeto
push SRCCOPY
push ebx ; int
push ebx ; int
push bufDIBDC ; HDC
push ScreenHeight ; int
push ScreenWidth ; int
push ebx ; int
push ebx ; int
push hdc ; HDC
call _imp__BitBlt@36
lea eax,ps
push eax ; lpPaint
push hWnd
call _imp__EndPaint@8
wmBYE: ret
WinProc endp


sub_401BC7 proc arg_0:dword

mov edx,ScreenWidth*ScreenHeight-1
bucle: mov eax, arg_0
movzx ecx, byte ptr [eax+edx]
test ecx, ecx
jz @f
lea eax, miPaleta[ecx*4]
assume eax: ptr stPaleta
                movzx ecx, byte ptr [eax].Rojo
shl ecx, 10h
                mov ch, byte ptr [eax].Verde
                mov cl, byte ptr [eax].Azul
assume eax: nothing
mov eax, pMainDIB
mov [eax+edx*4], ecx

@@: dec edx
jns bucle

ret
sub_401BC7 endp


KochTree proc X1:qword,Y1:qword,X2:qword,Y2:qword,Nivel:dword

local XX1:qword
local YY1:qword
local XX2:qword
local YY2:qword
local XX3:qword
local YY3:qword
local XX4:qword
local YY4:qword
local XVector:qword
local YVector:qword
local XVector2:qword
local YVector2:qword
local Temp:dword

cmp Nivel,0
jnz @@KOCH_ELSE
fld Y2
push eax
fistp dword ptr [esp]
fld X2
push eax
fistp dword ptr [esp]
fld Y1
push eax
fistp dword ptr [esp]
fld X1
push eax
fistp dword ptr [esp]
call BresLine
jmp @@KOCH_FIN


@@KOCH_ELSE: fld X2     ;st(0)=X2
fsub X1     ;st(0)=X2-X1
fst XVector;XVector=X2-X1
                fadd st,st 
fstp XVector2;st(0)=2*XVector

fld Y2     ;st(0)=Y2
fsub Y1     ;st(0)=Y2-Y1
fst YVector;YVector=Y2-Y1
                fadd st,st
fstp YVector2 ;st(0)=2*YVector

fld const3
fdivr XVector;st(0)=XVector/3
fadd X1     ;st(0)=X1+XVector/3
fstp XX1    ;XX1=X1+XVector/3
fld const3
fdivr YVector;st(0)=YVector/3
fadd Y1     ;st(0)=Y1+YVector/3
fstp YY1    ;YY1=Y1+YVector/3
fld1
fadd st,st  ;st(0)=2
fdivr XVector;st(0)=XVector/2
fadd X1     ;st(0)=X1+XVector/2
fstp XX2    ;XX2=X1+XVector/2
fld1
fadd st,st  ;st(0)=2
fdivr YVector;st(0)=YVector/2
fadd Y1     ;st(0)=Y1+YVector/2
fstp YY2    ;YY2=Y1+YVector/2

fld const3
fdivr XVector2 ;st(0)=2*XVector/3
fadd X1     ;st(0)=X1+2*XVector/3
fstp XX3    ;XX3=X1+2*XVector/3

fld const3
fdivr YVector2;st(0)=2*YVector/3
fadd Y1     ;st(0)=Y1+2*YVector/3
fstp YY3    ;YY3=Y1+2*YVector/3
fld constSQRT3x2
fdivr YVector;st(0)=YVector/(2*SQRT(3))
fsubr XX2    ;st(0)=XX2-YVector/(2*SQRT(3))
fstp XX4    ;XX4=XX2-YVector/(2*SQRT(3))
fld constSQRT3x2
fdivr XVector;st(0)=XVector/(2*SQRT(3))
fsubr YY2    ;st(0)=YY2-XVector/(2*SQRT(3))
fstp YY4    ;YY4=YY2-XVector/(2*SQRT(3))
mov eax,Nivel
            dec eax
            mov Temp,eax
            push eax
push dword ptr YY1+4
push dword ptr YY1
push dword ptr XX1+4
push dword ptr XX1
push dword ptr Y1+4
push dword ptr Y1
push dword ptr X1+4
push dword ptr X1
call KochTree
push Temp
push dword ptr YY4+4
push dword ptr YY4
push dword ptr XX4+4
push dword ptr XX4
push dword ptr YY1+4
push dword ptr YY1
push dword ptr XX1+4
push dword ptr XX1
call KochTree
push Temp
push dword ptr YY3+4
push dword ptr YY3
push dword ptr XX3+4
push dword ptr XX3
push dword ptr YY4+4
push dword ptr YY4
push dword ptr XX4+4
push dword ptr XX4
call KochTree
push Temp
push dword ptr Y2+4
push dword ptr Y2
push dword ptr X2+4
push dword ptr X2
push dword ptr YY3+4
push dword ptr YY3
push dword ptr XX3+4
push dword ptr XX3
call KochTree

@@KOCH_FIN: ret
KochTree endp


sub_401FE0 proc arg_0:dword 

mov eax, arg_0
imul eax, 10
movsx ecx, word ptr buffer3[eax]
movsx eax, word ptr buffer3[eax+2]
inc eax
                mov edx, eax
imul eax, ScreenWidth
add eax, ecx

bucle: cmp byte ptr buffer1[eax],5
jz @f
sub eax, ScreenWidth
dec edx
jnz    bucle
@@: mov eax,edx
ret
sub_401FE0 endp

sub_4020DA proc arg_0:dword 
local var_4:dword

mov eax, arg_0
imul eax, 10
add eax, offset buffer3+6
mov var_4, eax
call _imp__rand
and eax,0Fh
mov cx, word_404004[eax*2]
mov eax, var_4
mov [eax], cx
call _imp__rand
and eax,0Fh
mov cx, word_404024[eax*2]
mov eax, var_4
mov [eax+2], cx
ret
sub_4020DA endp


sub_402156 proc arg_0:dword,arg_4:dword
local var_4:dword

mov eax, arg_0
imul eax, 10
add eax, offset buffer3
mov var_4, eax
call _imp__rand
mov ecx, ScreenWidth-1
cdq
idiv ecx
mov eax, var_4
mov [eax], dx
or eax,eax ;eax = 0 ?
mov eax, 0
setz al
test eax, eax
jnz @f
call _imp__rand
mov ecx, arg_4
dec ecx
cdq
idiv ecx
jmp loc_4021D5


@@: xor eax, eax
cdq ;edx=0

loc_4021D5: mov eax, var_4
mov [eax+2], dx
call _imp__rand
and eax, 3
inc eax
mov ecx, var_4
mov [ecx+4], ax
push arg_0
call sub_4020DA
ret
sub_402156 endp

sub_402217 proc arg_0:dword 

mov eax, arg_0
imul eax, 10
                mov dl, buffer3[eax+4]
                movsx ecx, word ptr buffer3[eax]
movsx eax, word ptr buffer3[eax+2]
inc eax
imul eax,ScreenWidth    ;eax=(y+1)*ScreenWidth
add eax, ecx           ;eax=(y+1)*ScreenWidth+x
add eax, offset buffer2
mov [eax+1], dl
mov [eax], dl
mov [eax-ScreenWidth+1], dl
mov [eax-ScreenWidth], dl
ret
sub_402217 endp

sub_4022ED proc
local var_4:dword
local var_8:dword
local var_10:dword

mov var_4,999
bucle: push SnowLevel
push var_4
call sub_402156
push var_4
call sub_401FE0
mov var_8, eax
or eax, eax
jz @f
mov eax, var_4
imul eax, 10
add eax, offset buffer3+2
mov var_10, eax
call _imp__rand
mov ecx, var_8
sar ecx, 2
cdq
idiv ecx
mov eax, var_10
mov [eax], dx

@@: push var_4
call sub_402217
dec var_4
jns bucle

ret
sub_4022ED endp

Init proc
push 5; nesting level = 5
push dword ptr CY2+4
push dword ptr CY2
push dword ptr CX2+4
push dword ptr CX2
push dword ptr CY1+4
push dword ptr CY1
push dword ptr CX1+4
push dword ptr CX1
call KochTree
call sub_4022ED
retn
Init endp


sub_4023F7 proc arg_0:dword
local var_4:dword
local var_8:dword
local var_C:dword

mov var_4, 0
mov var_8, 0
mov eax, arg_0
imul eax, 10
add eax, offset buffer3
mov var_C,eax
movsx ecx, word ptr [eax+6]
cmp ecx, 0
jle loc_4024AF
movsx ecx, word ptr [eax]
inc ecx
cmp ecx, ScreenWidth
jge loc_402498
mov [eax], cx
movsx ecx, word ptr [eax+6]
dec ecx
mov [eax+6], cx
jmp @f

loc_402498: push ebx
push arg_0
call sub_402156
jmp @f

loc_4024AF: mov ecx, var_C
movsx eax, word ptr [ecx+6]
cmp eax, 0
jge loc_402547
movsx eax, word ptr [ecx]
cmp eax, 0
jle loc_402530
dec eax
mov [ecx], ax
movsx eax, word ptr [ecx+6]
mov edx, eax
inc eax
mov [ecx+6], ax
jmp @f

loc_402530: push ebx
push arg_0
call sub_402156
jmp @f

loc_402547: mov eax, 1
mov var_4, eax

@@: mov ecx, var_C
movsx eax, word ptr [ecx+8]
cmp eax, 0
jle loc_4025F3
movsx eax, word ptr [ecx+2]
inc eax
cmp eax, SnowLevel
jge loc_4025DC
movsx eax, word ptr [ecx+2]
inc eax
mov [ecx+2], ax
movsx eax, word ptr [ecx+8]
dec eax
mov [ecx+8], ax
jmp @f

loc_4025DC: push ebx
push arg_0
call sub_402156
jmp @f

loc_4025F3: mov ecx, var_C
movsx eax, word ptr [ecx+8]
cmp eax, 0
jge loc_402691
movsx eax, word ptr [ecx+2]
cmp eax, 0
jle loc_40267A
movsx eax, word ptr [ecx+2]
dec eax
mov [ecx+2], ax
movsx eax, word ptr [ecx+8]
inc eax
mov [ecx+8], ax
jmp @f

loc_40267A: push ebx
push arg_0
call sub_402156
jmp @f

loc_402691: mov var_8, 1

@@: cmp var_4, 1
jnz fin
cmp var_8, 1
jnz fin
push arg_0
call sub_4020DA
fin: ret
sub_4023F7 endp


sub_4026BF proc

local var_4:dword

mov ecx,ScreenHeight*ScreenWidth/4
xor eax,eax
mov edi,offset buffer2
rep stosd
mov var_4, 999
bucle: push var_4
call sub_4023F7
push var_4
call sub_401FE0
or eax, eax
jz @f
push ebx
push var_4
call sub_402156
@@:       push var_4
call sub_402217
dec var_4
jns bucle
            ret
sub_4026BF endp

PintaObjeto proc
mov ecx,ScreenHeight*ScreenWidth*4/4
xor eax,eax
mov edi,pMainDIB
rep stosd
call sub_4026BF
push offset buffer2
call sub_401BC7
push offset buffer1
call sub_401BC7
retn
PintaObjeto endp
;-----------------------------------------------------------------
.data
word_404004 dw 7, 0FFF9h, 6, 0FFFAh, 5, 0FFFBh, 4, 0FFFCh, 3, 0FFFDh
dw 2, 0FFFEh, 1, 0FFFFh, 0, 1
word_404024 dw 4, 2, 3, 1, 2, 0, 1, 2, 2 dup(3), 2, 4, 1, 0FFFFh, 2 dup(0)
wTitle db 'Nevada - (c) abreojosensamblador.net',0
const3 dq 3.0
constSQRT3x2 dq 3.464101615137754;sqrt(3)=1,7320508075688772935274463415059*2
CY2 dq 390.0 ;SnowLevel
CX2 dq 639.0 ;ScreenWidth-1
CY1 dq 390.0 ;SnowLevel
CX1 dq 0.0
db 8 dup(0)
db 1Ah dup(0)
byte_404180 db 10h dup(0), 98h, 42h, 0Eh dup(0), 0F4h, 41h, 2 dup(0)
db 0F4h, 42h, 0Eh dup(0), 50h, 42h, 2 dup(0), 4, 43h, 0Eh dup(0)
db 60h, 42h, 2 dup(0), 20h, 43h, 0Eh dup(0), 7Ch, 42h
db 16h dup(0)

dd 4347h, 435Ah, 4369h, 4375h, 4383h, 4394h, 43A2h, 43B4h
dd 43C1h, 43D0h, 43DEh, 43F1h, 4404h, 4410h, 4422h, 442Ah
dd 4436h, 4441h, 4452h, 445Fh, 446Ah, 447Ah, 0, 4498h
dd 44ABh, 44BDh, 0, 44D9h, 44E8h, 44F7h, 4502h, 4517h
dd 452Ah, 0, 453Eh, 4547h, 454Eh, 455Fh, 456Ch, 4573h
dd 92h dup(0)
bi BITMAPINFOHEADER <sizeof BITMAPINFOHEADER,ScreenWidth,-ScreenHeight,1,32,0>
miPaleta stPaleta <0>,<43,43,43>,<85,85,85>,<128,128,128>,<171,171,171>,<255,255,255>
.data?
buffer3 db 10000 dup(?)
buffer1 db ScreenHeight*ScreenWidth dup(?)
buffer2 db ScreenHeight*ScreenWidth dup(?)
bufDIBDC dd ?
hBackDC dd ?
hMainDIB dd ?
bufBMP dd ?
hOldBmp dd ?
hGDITmp dd ?
hOldDIB dd ?
pMainDIB dd ?
end start

Mikl__

; masm windows gui #
.686
.model flat, stdcall
option casemap :none
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\msvcrt.lib
extern _imp__RegisterClassA@4:dword
extern _imp__BeginPaint@8:dword
extern _imp__BitBlt@36:dword
extern _imp__CreateWindowExA@48:dword
extern _imp__CreateCompatibleDC@4:dword
extern _imp__CreateDIBSection@24:dword
extern _imp__DeleteObject@4:dword
extern _imp__DeleteDC@4:dword
extern _imp__DestroyWindow@4:dword
extern _imp__DefWindowProcA@16:dword
extern _imp__DispatchMessageA@4:dword
extern _imp__EndPaint@8:dword
extern _imp__ExitProcess@4:dword
extern _imp__GetMessageA@16:dword
extern _imp__GetDC@4:dword
extern _imp__InvalidateRect@12:dword
extern _imp__KillTimer@8:dword
extern _imp__rand:dword
extern _imp__ReleaseDC@8:dword
extern _imp__SetTimer@16:dword
extern _imp__SelectObject@8:dword
.code
cdXPos          equ 131
cdYPos          equ 217
ScreenHeight equ 400;+50
ScreenWidth     equ 640 ;ScreenHeight*1.6
cdIdTimer       equ 1
DIB_RGB_COLORS  equ 0
SnowLevel       equ ScreenHeight-10
stPaleta struct
  Azul db ?
  Verde db ?
  Rojo db ?
  Alfa db ?
stPaleta ends
RECT STRUCT
  left    dd      ?
  top     dd      ?
  right   dd      ?
  bottom  dd      ?
RECT ENDS
POINT STRUCT
  x  DWORD ?
  y  DWORD ?
POINT ENDS
PAINTSTRUCT STRUCT
  hdc           DWORD      ?
  fErase        DWORD      ?
  rcPaint       RECT       <>
  fRestore      DWORD      ?
  fIncUpdate    DWORD      ?
  rgbReserved   BYTE 32 dup(?)
PAINTSTRUCT ENDS
MSG STRUCT
  hwnd      DWORD      ?
  message   DWORD      ?
  wParam    DWORD      ?
  lParam    DWORD      ?
  time      DWORD      ?
  pt        POINT      <>
MSG ENDS
BITMAPINFOHEADER STRUCT
  biSize            DWORD      ?
  biWidth           DWORD      ?
  biHeight          DWORD      ?
  biPlanes          WORD       ?
  biBitCount        WORD       ?
  biCompression     DWORD      ?
  biSizeImage       DWORD      ?
  biXPelsPerMeter   DWORD      ?
  biYPelsPerMeter   DWORD      ?
  biClrUsed         DWORD      ?
  biClrImportant    DWORD      ?
BITMAPINFOHEADER ENDS
BLACK_PEN                            equ 7
WS_VISIBLE                           equ 10000000h
WM_DESTROY                           equ 2
WM_PAINT                             equ 0Fh
WM_TIMER                             equ 113h
SRCCOPY                              equ 0CC0020h
VK_ESCAPE                            equ 1Bh

start:          xor ebx,ebx
mov edi,offset wTitle
mov esi,400000h
push edi
push ebx
push BLACK_PEN
push 10011h
push ebx
push esi
push ebx
push ebx
push offset WinProc
push ebx
push esp ; lpWndClass
call _imp__RegisterClassA@4
push ebx    
push esi
push ebx
push ebx
push ScreenHeight+30
push ScreenWidth
push cdYPos
push cdXPos
push WS_VISIBLE
push edi; szWinTitle
push edi; lpszClassName
push ebx ; dwExStyle
call _imp__CreateWindowExA@48
mov ebp,esp

message_loop: push ebx  ;                       
push ebx
push ebx
push ebp
call _imp__GetMessageA@16
        cmp [ebp+MSG.wParam],VK_ESCAPE ;press "Esc"?
jz wmDESTROY
push ebp
call _imp__DispatchMessageA@4       
jmp message_loop


; We construct a line on Bresenham algorithm
BresLine proc X1:dword,Y1:dword,X2:dword,Y2:dword
local DeltaX:dword
local DeltaY:dword
local Xinc:dword
local Yinc:dword
local Error:dword


mov eax, X1
cmp eax, X2   ; X1 = X2 ?
jnz a1
;VertLine---------------------------------------------------
mov ecx, Y2               
cmp ecx, Y1   ; Y2 > Y1 ?
jnbe @f
lea esi, Y1
                lea edi, Y2
movsd
@@: imul    edi, Y1,ScreenWidth
add edi, X1
add edi, offset fir_trees_buffer;edi = Y1 * ScreenWidth + X1 + &fir_trees_buffer
mov al, 5  ;color of fir-tres
                mov ecx, Y2
sub ecx, Y1
inc ecx
@@: stosb          ; Draw a vertical line in fir_tres_buffer
add edi, ScreenWidth-1
loop @b
;-----------------------------------------------------
jmp fin

a1: mov eax, X2
sub eax, X1
cdq
xor eax,edx
sub eax,edx
mov DeltaX, eax  ; DeltaX = |X2 - X1|
or edx,1
mov Xinc, edx    ; if X2 - X1 >= 0  Xinc=1 else Xinc= -1

mov eax, Y2
sub eax, Y1
cdq
xor eax,edx      ; if edx = -1 not(eax)
sub eax,edx      ; if edx = -1 neg(eax) = not(eax)-(-1)
mov DeltaY, eax  ; DeltaY = |Y2 - Y1|
or edx,1
                mov Yinc, edx    ; if Y2 - Y1 >= 0  Yinc=1 else Yinc= -1

mov eax, DeltaX
sub eax, DeltaY
mov Error, eax   ; Error = DeltaX - DeltaY

bucle: imul eax, Y1,ScreenWidth
add eax, X1      ; eax = Y1 * ScreenWidth + X1
mov fir_trees_buffer[eax], 5;color
mov eax, X1
cmp eax, X2      ; X1 = X2 ?
jnz @f
mov eax, Y1
cmp eax, Y2      ; Y1 = Y2 ?
jz fin

@@: mov eax, Error
shl eax, 1
add eax,DeltaY   ;2*Error >= -DeltaY ?
jle @f
mov eax, Error
sub eax, DeltaY
mov Error, eax   ;Error = Error + DeltaY
mov eax, X1
add eax, Xinc
mov X1, eax      ;X1 = X1 + Xinc

@@: mov eax, X1      ;X1 = X2 ?
cmp eax, X2
jnz @f
mov eax, Y1      ;Y1 = Y2 ?
cmp eax, Y2
jnz @f
imul eax, Y1,ScreenWidth
add eax, X1      ;eax = Y1 * ScreenWidth + X1
mov fir_trees_buffer[eax],5 ;fir-tres color=5
jmp fin

@@: mov eax, Error
shl eax,1
cmp eax, DeltaX  ;2*Error >= DeltaX ?
jge bucle
mov eax, Error
add eax, DeltaX
mov Error, eax   ;Error = Error + DeltaX
mov eax, Y1
add eax, Yinc
mov Y1, eax      ;Y1 = Y1 + Yinc
jmp bucle
fin: ret
BresLine endp


WinProc proc hWnd:dword,Msg:dword,wParam:dword,lParam:dword
local ps:PAINTSTRUCT
local i:dword

mov eax, Msg
dec eax;cmp eax,WM_CREATE
jz wmCREATE
        dec eax;cmp eax,WM_DESTROY
jz wmDESTROY
sub eax,WM_PAINT-WM_DESTROY
jz wmPAINT
            sub eax,WM_TIMER-WM_PAINT
jz wmTIMER
        leave
jmp _imp__DefWindowProcA@16

wmDESTROY:: push cdIdTimer ; uIDEvent
push hWnd
call _imp__KillTimer@8
push hOldBmp
push hBackDC
call _imp__SelectObject@8
mov hGDITmp, eax
push bufBMP ; HGDIOBJ
call _imp__DeleteObject@4
push hBackDC ; HDC
call _imp__DeleteDC@4
push hOldDIB ; HGDIOBJ
push bufDIBDC ; HDC
call _imp__SelectObject@8
mov hGDITmp, eax
push bufDIBDC ; HDC
call _imp__DeleteDC@4
push hMainDIB ; HGDIOBJ
call _imp__DeleteObject@4
push hWnd
call _imp__DestroyWindow@4
push ebx ; nExitCode
call _imp__ExitProcess@4

wmCREATE: push hWnd
call _imp__GetDC@4
mov ps.hdc, eax
push eax ; HDC
call _imp__CreateCompatibleDC@4
mov bufDIBDC, eax
push ebx ; DWORD
push ebx ; HANDLE
push offset pMainDIB
push ebx ; UINT
push offset bi       ; BITMAPINFO *
push ps.hdc ; HDC
call _imp__CreateDIBSection@24
mov hMainDIB, eax
push eax ; HGDIOBJ
push bufDIBDC ; HDC
call _imp__SelectObject@8
mov hOldDIB, eax
push ps.hdc
push hWnd
call _imp__ReleaseDC@8
;Init-----------------------------------------------------
push 5; nesting level = 5
push CY2
push CX2
push CY1
push CX1
call KochTree
call sub_4022ED
;---------------------------------------------------------
push ebx ; lpTimerFunc
push 40 ; uElapse
push cdIdTimer ; nIDEvent
push hWnd
call _imp__SetTimer@16
jmp wmBYE

wmTIMER: push ebx ; bErase
push ebx ; lpRect
push hWnd
call _imp__InvalidateRect@12
jmp wmBYE

wmPAINT: lea eax,ps
push eax ; lpPaint
push hWnd
call _imp__BeginPaint@8
;PintaObjeto--------------------------------------------
mov ecx,ScreenHeight*ScreenWidth
xor eax,eax
mov edi,pMainDIB
rep stosd         ;Clear buffer pMainDIB
;--------------------------------------------------------
mov ecx,ScreenHeight*ScreenWidth/4
xor eax,eax
mov edi,offset snow_buffer
rep stosd      ; Clear snow_buffer
;--------------------------------------------------------
mov i, 999
bucle0: push i
call sub_4023F7
push i
call sub_401FE0
or eax, eax
jz @f
push ebx
push i
call sub_402156
@@:       push i
call sub_402217
dec i
jns bucle0
;draw snowfall--------------------------------------------
mov ecx,ScreenWidth*ScreenHeight
bucle1: movzx edx, snow_buffer[ecx-1]
test edx, edx
jz @f
lea eax, miPaleta[edx*4]
assume eax: ptr stPaleta
                movzx edx, byte ptr [eax].Rojo
shl edx, 10h
                mov dh, byte ptr [eax].Verde
                mov dl, byte ptr [eax].Azul
;color = miPaleta[i].Azul + (miPaleta[i].Verde<<8) + (miPaleta[i].Rojo<<16)
assume eax: nothing
mov eax, pMainDIB
mov [eax+ecx*4-4], edx
@@: loop bucle1
;draw fir-trees-------------------------------------------
mov ecx,ScreenWidth*ScreenHeight
mov eax, pMainDIB
bucle2: cmp fir_trees_buffer[ecx-1],0
jz @f
mov dword ptr [eax+ecx*4-4],0FFFFFFh
@@: loop bucle2
;--------------------------------------------------
push SRCCOPY
push ebx ; int
push ebx ; int
push bufDIBDC ; HDC
push ScreenHeight ; int
push ScreenWidth ; int
push ebx ; int
push ebx ; int
push ps.hdc ; HDC
call _imp__BitBlt@36
lea eax,ps
push eax ; lpPaint
push hWnd
call _imp__EndPaint@8
wmBYE: ret
WinProc endp


KochTree proc X1:dword,Y1:dword,X2:dword,Y2:dword,Nivel:dword

local XX1:dword
local YY1:dword
local XX2:dword
local YY2:dword
local XX3:dword
local YY3:dword
local XX4:dword
local YY4:dword
local XVector:dword
local YVector:dword
local XVector2:dword
local YVector2:dword
local Temp:dword

cmp Nivel,0
jnz @@KOCH_ELSE
push Y2
push X2
push Y1
push X1
call BresLine
jmp @@KOCH_FIN


@@KOCH_ELSE: fild X2     ;st(0)=X2
fisub X1     ;st(0)=X2-X1
fst XVector;XVector=X2-X1
                fadd st,st 
fstp XVector2;st(0)=2*XVector

fild Y2     ;st(0)=Y2
fisub Y1     ;st(0)=Y2-Y1
fst YVector;YVector=Y2-Y1
                fadd st,st
fstp YVector2 ;st(0)=2*YVector

fld const3
fld st     ;st(0)=st(1)=3
fld st     ;st(0)=st(1)=st(2)=3
fld st     ;st(0)=st(1)=st(2)=st(3)=3
fdivr XVector;st(0)=XVector/3
fiadd X1     ;st(0)=X1+XVector/3
fistp XX1    ;XX1=X1+XVector/3
               ;st(0)=3
fdivr YVector;st(0)=YVector/3
fiadd Y1     ;st(0)=Y1+YVector/3
fistp YY1    ;YY1=Y1+YVector/3
fld1
fadd st,st  ;st(0)=2
fdivr XVector;st(0)=XVector/2
fiadd X1     ;st(0)=X1+XVector/2
fstp XX2    ;XX2=X1+XVector/2
fld1
fadd st,st  ;st(0)=2
fdivr YVector;st(0)=YVector/2
fiadd Y1     ;st(0)=Y1+YVector/2
fstp YY2    ;YY2=Y1+YVector/2
               ;st(0)=3
fdivr XVector2 ;st(0)=2*XVector/3
fiadd X1     ;st(0)=X1+2*XVector/3
fistp XX3    ;XX3=X1+2*XVector/3
               ;st(0)=3
fdivr YVector2;st(0)=2*YVector/3
fiadd Y1     ;st(0)=Y1+2*YVector/3
fistp YY3    ;YY3=Y1+2*YVector/3
fld constSQRT3x2
fld st     ;st(0)=st(1)=2*SQRT(3)
fdivr YVector;st(0)=YVector/(2*SQRT(3))
fsubr XX2    ;st(0)=XX2-YVector/(2*SQRT(3))
fistp XX4    ;XX4=XX2-YVector/(2*SQRT(3))
               ;st(0)=2*SQRT(3)
fdivr XVector;st(0)=XVector/(2*SQRT(3))
fsubr YY2    ;st(0)=YY2-XVector/(2*SQRT(3))
fistp YY4    ;YY4=YY2-XVector/(2*SQRT(3))
mov eax,Nivel
            dec eax
            mov Temp,eax
            push eax
push YY1
push XX1
push Y1
push X1
call KochTree
push Temp
push YY4
push XX4
push YY1
push XX1
call KochTree
push Temp
push YY3
push XX3
push YY4
push XX4
call KochTree
push Temp
push Y2
push X2
push YY3
push XX3
call KochTree

@@KOCH_FIN: ret
KochTree endp


sub_401FE0 proc arg_0:dword 

mov eax, arg_0
imul eax, 10
movsx edx, word ptr buffer3[eax]
movsx eax, word ptr buffer3[eax+2]
inc eax
                mov ecx, eax
imul eax, ScreenWidth
add eax, edx
bucle: cmp byte ptr fir_trees_buffer[eax],5
jz @f
sub eax, ScreenWidth
loop bucle
@@: mov eax,ecx
ret
sub_401FE0 endp

sub_4020DA proc arg_0:dword 
local var_4:dword

mov eax, arg_0
imul eax, 10
add eax, offset buffer3+6
mov var_4, eax
call _imp__rand
and eax,0Fh
mov cx, word_404004[eax*2]
mov eax, var_4
mov [eax], cx
call _imp__rand
and eax,0Fh
mov cx, word_404024[eax*2]
mov eax, var_4
mov [eax+2], cx
ret
sub_4020DA endp


sub_402156 proc arg_0:dword,arg_4:dword
local var_4:dword

mov eax, arg_0
imul eax, 10
add eax, offset buffer3
mov var_4, eax
call _imp__rand
mov ecx, ScreenWidth-1
cdq
idiv ecx
mov eax, var_4
mov [eax], dx
or eax,eax ;eax = 0 ?
jz @f
call _imp__rand
mov ecx, arg_4
dec ecx
cdq
idiv ecx
jmp loc_4021D5

@@: xor eax, eax
cdq ;edx=0

loc_4021D5: mov eax, var_4
mov [eax+2], dx
call _imp__rand
and eax, 3
inc eax
mov ecx, var_4
mov [ecx+4], ax
push arg_0
call sub_4020DA
ret
sub_402156 endp

sub_402217 proc arg_0:dword 

mov eax, arg_0
imul eax, 10
                mov dl, buffer3[eax+4]
                movsx ecx, word ptr buffer3[eax]
movsx eax, word ptr buffer3[eax+2]
inc eax
imul eax,ScreenWidth    ;eax=(y+1)*ScreenWidth
add eax, ecx           ;eax=(y+1)*ScreenWidth+x
add eax, offset snow_buffer
mov [eax+1], dl
mov [eax], dl
mov [eax-ScreenWidth+1], dl
mov [eax-ScreenWidth], dl
ret
sub_402217 endp

sub_4022ED proc
local var_4:dword
local var_8:dword
local var_10:dword

mov var_4,999
bucle: push SnowLevel
push var_4
call sub_402156
push var_4
call sub_401FE0
mov var_8, eax
or eax, eax
jz @f
mov eax, var_4
imul eax, 10
add eax, offset buffer3+2
mov var_10, eax
call _imp__rand
mov ecx, var_8
sar ecx, 2
cdq
idiv ecx
mov eax, var_10
mov [eax], dx

@@: push var_4
call sub_402217
dec var_4
jns bucle

ret
sub_4022ED endp


sub_4023F7 proc arg_0:dword
local var_4:dword
local var_8:dword
local var_C:dword

mov var_4, 0
mov var_8, 0
mov eax, arg_0
imul eax, 10
add eax, offset buffer3
mov var_C,eax
cmp word ptr [eax+6], 0
jle loc_4024AF
movsx ecx, word ptr [eax]
inc ecx
cmp ecx, ScreenWidth
jge loc_402498
mov [eax], cx
movsx ecx, word ptr [eax+6]
dec ecx
mov [eax+6], cx
jmp @f

loc_402498: push ebx
push arg_0
call sub_402156
jmp @f

loc_4024AF: mov ecx, var_C
cmp word ptr [ecx+6], 0
jge loc_402547
movsx eax, word ptr [ecx]
cmp eax, 0
jle loc_402530
dec eax
mov [ecx], ax
movsx eax, word ptr [ecx+6]
mov edx, eax
inc eax
mov [ecx+6], ax
jmp @f

loc_402530: push ebx
push arg_0
call sub_402156
jmp @f

loc_402547: mov var_4, 1

@@: mov ecx, var_C
cmp word ptr [ecx+8], 0
jle loc_4025F3
movsx eax, word ptr [ecx+2]
inc eax
cmp eax, SnowLevel
jge loc_4025DC
movsx eax, word ptr [ecx+2]
inc eax
mov [ecx+2], ax
movsx eax, word ptr [ecx+8]
dec eax
mov [ecx+8], ax
jmp @f

loc_4025DC: push ebx
push arg_0
call sub_402156
jmp @f

loc_4025F3: mov ecx, var_C
cmp word ptr [ecx+8], 0
jge loc_402691
cmp word ptr [ecx+2], 0
jle loc_40267A
movsx eax, word ptr [ecx+2]
dec eax
mov [ecx+2], ax
movsx eax, word ptr [ecx+8]
inc eax
mov [ecx+8], ax
jmp @f

loc_40267A: push ebx
push arg_0
call sub_402156
jmp @f

loc_402691: mov var_8, 1

@@: cmp var_4, 1
jnz fin
cmp var_8, 1
jnz fin
push arg_0
call sub_4020DA
fin: ret
sub_4023F7 endp
;-----------------------------------------------------------------
.data
word_404004 dw 7,-7, 6,-6, 5,-5, 4,-4, 3,-3, 2,-2, 1,-1, 0, 1
word_404024 dw 4, 2, 3, 1, 2, 0, 1, 2, 3, 3, 2, 4, 1,-1, 0, 0
wTitle db 'Nevada - (c) abreojosensamblador.net',0
const3 dq 3.0
constSQRT3x2 dq 3.464101615137754;sqrt(3)=1,7320508075688772935274463415059*2
CY2 dd SnowLevel
CX2 dd ScreenWidth-1
CY1 dd SnowLevel
CX1 dd 0
bi BITMAPINFOHEADER <sizeof BITMAPINFOHEADER,ScreenWidth,-ScreenHeight,1,32,0>
miPaleta stPaleta <0>,<43,43,43>,<85,85,85>,<128,128,128>,<171,171,171>,<255,255,255>
.data?
buffer3 db 10000 dup(?)
fir_trees_buffer db ScreenHeight*ScreenWidth dup(?)
snow_buffer db ScreenHeight*ScreenWidth dup(?)
bufDIBDC dd ?
hBackDC dd ?
hMainDIB dd ?
bufBMP dd ?
hOldBmp dd ?
hGDITmp dd ?
hOldDIB dd ?
pMainDIB dd ?
end start

Mikl__

#23
asm-file; masm windows gui #
.686
.model flat, stdcall
option casemap :none
includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\gdi32.lib
extern _imp__BeginPaint@8:dword
extern _imp__BitBlt@36:dword
extern _imp__CreateWindowExA@48:dword
extern _imp__CreateCompatibleDC@4:dword
extern _imp__CreateDIBSection@24:dword
extern _imp__DefWindowProcA@16:dword
extern _imp__DispatchMessageA@4:dword
extern _imp__DeleteObject@4:dword
extern _imp__DeleteDC@4:dword
extern _imp__DestroyWindow@4:dword
extern _imp__EndPaint@8:dword
extern _imp__ExitProcess@4:dword
extern _imp__GetDC@4:dword
extern _imp__GetMessageA@16:dword
extern _imp__InvalidateRect@12:dword
extern _imp__RegisterClassA@4:dword
extern _imp__ReleaseDC@8:dword
extern _imp__SelectObject@8:dword

cdXPos          equ 128
cdYPos          equ 128
cdYSize         equ 400
cdXSize         equ 640
cdNumColores    equ 256
cdNMax          equ 100
stPaleta struct
  Azul db ?
  Verde db ?
  Rojo db ?
  Alfa db ?
stPaleta ends
RECT STRUCT
  left    dd      ?
  top     dd      ?
  right   dd      ?
  bottom  dd      ?
RECT ENDS
POINT STRUCT
  x  DWORD ?
  y  DWORD ?
POINT ENDS
PAINTSTRUCT STRUCT
  hdc           DWORD      ?
  fErase        DWORD      ?
  rcPaint       RECT       <>
  fRestore      DWORD      ?
  fIncUpdate    DWORD      ?
  rgbReserved   BYTE 32 dup(?)
PAINTSTRUCT ENDS
MSG STRUCT
  hwnd      DWORD      ?
  message   DWORD      ?
  wParam    DWORD      ?
  lParam    DWORD      ?
  time      DWORD      ?
  pt        POINT      <>
MSG ENDS
BITMAPINFOHEADER STRUCT
  biSize            DWORD      ?
  biWidth           DWORD      ?
  biHeight          DWORD      ?
  biPlanes          WORD       ?
  biBitCount        WORD       ?
  biCompression     DWORD      ?
  biSizeImage       DWORD      ?
  biXPelsPerMeter   DWORD      ?
  biYPelsPerMeter   DWORD      ?
  biClrUsed         DWORD      ?
  biClrImportant    DWORD      ?
BITMAPINFOHEADER ENDS
BLACK_PEN                            equ 7
WS_VISIBLE                           equ 10000000h
WM_DESTROY                           equ 2
WM_PAINT                             equ 0Fh
WM_TIMER                             equ 113h
SRCCOPY                              equ 0CC0020h
VK_ESCAPE                            equ 1Bh
.code
start: xor ebx, ebx
mov edi, offset wTitle
mov esi, 400000h
push edi
push ebx
push BLACK_PEN
push 10011h
push ebx
push esi
push ebx
push ebx
push offset WndProc
push ebx
push esp ; lpWndClass
call _imp__RegisterClassA@4
push ebx ; lpParam
push esi ; hInstance
push ebx ; hMenu
push ebx ; hWndParent
push cdYSize+35
push cdXSize+5
push cdYPos
push cdXPos ; X
push WS_VISIBLE ; dwStyle
push edi ; lpWindowName
push edi ; lpClassName
push ebx ; dwExStyle
call _imp__CreateWindowExA@48
mov ebp, esp

message_loop: push ebx ; wMsgFilterMax
push ebx ; wMsgFilterMin
push ebx ; hWnd
push ebp ; lpMsg
call _imp__GetMessageA@16
cmp [ebp+MSG.wParam], VK_ESCAPE
jz wmDESTROY
push ebp ; lpMsg
call _imp__DispatchMessageA@4
jmp message_loop


WndProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD

local ps:PAINTSTRUCT

mov eax, uMsg
dec eax
jz wmCREATE
dec eax
jz wmDESTROY
sub eax,WM_PAINT-WM_DESTROY
jz wmPAINT
leave
jmp _imp__DefWindowProcA@16

wmDESTROY:: push hOldDIB ; HGDIOBJ
push bufDIBDC ; HDC
call _imp__SelectObject@8
push bufDIBDC ; HDC
call _imp__DeleteDC@4
push hMainDIB ; HGDIOBJ
call _imp__DeleteObject@4
push hWnd
call _imp__DestroyWindow@4
push ebx ; uExitCode
call _imp__ExitProcess@4

wmCREATE: push hWnd
call _imp__GetDC@4
mov ps.hdc, eax
push eax ; HDC
call _imp__CreateCompatibleDC@4
mov bufDIBDC, eax
push ebx ; DWORD
push ebx ; HANDLE
push offset pMainDIB ; void **
push ebx ; UINT
push offset bi ; BITMAPINFO *
push ps.hdc
call _imp__CreateDIBSection@24
mov hMainDIB, eax
push eax ; HGDIOBJ
push bufDIBDC ; HDC
call _imp__SelectObject@8
mov hOldDIB, eax
push ps.hdc
push hWnd
call _imp__ReleaseDC@8
mov edi, offset miPaleta
mov ecx, cdNumColores
xor eax, eax
rep stosd
mov cl,16
sub edi,16*4
Bucle: assume edi: ptr stPaleta
mov [edi+ecx*4-68].Verde,al
mov [edi+ecx*4-68].Rojo, 0FCh
mov [edi+ecx*4-4].Rojo, al
assume edi: nothing
add al,16
loop Bucle
call CreaFractal
jmp wmBYE


wmPAINT: push esp ; lpPaint
push hWnd
call _imp__BeginPaint@8
push SRCCOPY ; DWORD
push ebx ; int
push ebx ; int
push bufDIBDC ; HDC
push cdYSize ; int
push cdXSize ; int
push ebx ; int
push ebx ; int
push eax ; HDC
call _imp__BitBlt@36
push esp ; lpPaint
push hWnd
call _imp__EndPaint@8

wmBYE: ret
WndProc endp


CreaFractal proc
local y:dword 
local x:dword 
local v:dword 
local u:dword 
local CurrY:dword 
local CurrX:dword 
local Color:dword 


mov ecx,cdYSize     ;y-Contador
                fld const4          ;st(0)=4
Bucle_Y: push ecx
fild dword ptr [esp] ;st(0) = yCont
push cdYSize
fidiv dword ptr [esp] ;st(0) = yCont/cdYSize
add esp, 8
fadd st,st ;st(0) = YRDif*yCont/cdYSize
fadd cfYRMin         ;st(0) = YRDif*yCont/cdYSize +cfYRMin
fstp CurrY ;CurrY = YRDif*yCont/cdYSize +cfYRMin
mov edx,cdXSize     ; x-Contador

Bucle_X: push edx
fild dword ptr [esp] ;st(0) = xCont
push cdXSize
fidiv dword ptr [esp] ;st(0) = xCont/cdXSize
add esp, 8
fmul XRDif ;st(0) = XRDif*xCont/cdXSize
fadd cfXRMin         ;st(0) = XRDif*xCont/cdXSize +cfXRMin
fstp CurrX           ;CurrX = XRDif*xCont/cdXSize +cfXRMin
mov x, 0
mov y, 0            ; x = y = 0
mov Color, cdNumColores
mov esi, cdNMax               
Bucle_I: fld y               ;st(0)=y
fmul st, st          ;st(0)=y*y
fld x               ;st(0)=x
fmul st, st          ;st(0)=x*x
fsubrp st(1), st       ;st(0)=x*x - y*y
fadd CurrX           ;st(0)=x*x - y*y + CurrX
fst u               ;u=x*x - y*y + CurrX
fmul st, st          ;st(0)=u*u
fld y               ;st(0)=y
fmul x               ;st(0)=y*x
fadd st, st          ;st(0)=2*y*x
fadd CurrY           ;st(0)=2*y*x+CurrY
fst v               ;v=2*y*x+CurrY
fst y               ;y=v
fmul st, st          ;st(0)=v*v
faddp st(1), st       ;st(0)=u*u + v*v
fucomp ;u*u + v*v > 4 ?
fnstsw ax
test ah,45h
jz Exit_BI
mov eax, u
mov x, eax          ;x=u
dec Color
dec esi
jnz Bucle_I

Exit_BI:        mov eax, Color
mov eax, miPaleta[eax*4]
imul esi,ecx,cdXSize
lea esi,[esi+edx-cdXSize-1]               
mov edi, pMainDIB
mov [edi+esi*4], eax
dec edx
jnz Bucle_X
dec ecx
jnz Bucle_Y
leave
retn
CreaFractal endp
;-------------------------------------------------------------------------
.data
wTitle db 'Fractal de Mandelbrot - (c) abreojosensamblador.net',0
bi BITMAPINFOHEADER <sizeof BITMAPINFOHEADER,cdXSize,-cdYSize,1,32,0>   
cfYRMin dd -1.0
cfXRMin dd -2.0
const4 dd 4.0
XRDif dd 2.6
.data?
bufDIBDC dd ?
pMainDIB dd ?
hMainDIB dd ?
hOldBmp dd ?
hOldDIB dd ?
miPaleta stPaleta cdNumColores dup(<?>)
end start

hutch--

This one does look really slick.  :t

dedndave


guga

Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

dedndave

only in america - lol

the mandelbrot does look nice   :t

one of my little christmas presents was a 64-bit laptop
so, when i get some time to play, i can work with 64-bit code   :biggrin:

Siekmanski

Dave, that's a nice little christmas present.  :t
Creative coders use backward thinking techniques as a strategy.

avcaballero

Hello, I have reopened AOW32. There are a lot of new things, but it is heavily in progress, so many things still missing. Almost everything is in Spanish, the English part is quite outdated. Though it is in asm and c, TinyC is the central and many asm versions are still missing, until I have time to complete it.