;Chris Twardzicki ;Mandelbrot Set, MC160 Project ;twardzic@bc.edu ;****************************************************************** ;The Mandelbrot set is defined as: For each complex number C, ;a sequence of iterations Zn is defined as: ; z0=(0+0i) ; zn=(zn-1^2) + C ;If the sequence remains within a distance of 2 of the origin ;forever, then z0 is said to be in the mandelbrot set. ;****************************************************************** .model small .stack 200h .386 ;Screen corners (-2,-2),(2,2) ;Transformation between real and integer coordinates: ;x=(u-320)/160, y = (240-v)/120 .data u dw ? v dw ? dist dd ? color dw ? y dd ? x dd ? loopvar dd 0 previousx dd 0.0 previousy dd 0.0 newX dd 0.0 newY dd 0.0 variable dd 0.0 variable2 dd 0.0 CCXL dd 240.0 CCCXX dd 320.0 VIII dd 8.0 TWO dd 2 TOO dd 2.0 junk dd ? status dw ? ONETWENTY dd 120.0 ONESIXTY dd 160.0 .code .startup mov ah,0 ;set color video mode mov al,12h int 10h mov bh,0 finit mov v, 0 a_loop: mov u, 0 b_loop: mov loopvar, 0 mov previousx, 0 mov previousy, 0 fild u ;u is placed onto the copro stack fld CCCXX ;320 is placed onto the copro stack fsub ;u-320 is placed onto the stack fdiv ONESIXTY ;(u-320)/160 is placed onto the stack fstp x ;stores (u-320)/160 in x and popped ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; fld CCXL ;240 is placed onto the copro stack fild v ;v is placed onto the copro stack fsub ;(240-v) on top of the stack fdiv ONETWENTY ;(240-v)/120 on top of stack fstp y ;(120-v)/120 is stored into y and popped ;intially z0 = (0+0i), so we move 0 into previousx and previousy mov previousx, 0 mov previousy, 0 iterate: fld previousx ;pushes previousx onto stack fmul previousx ;previousx^2 fld previousy ;pushes previousy onto stack fmul previousy ;previousy^2 fsub ;(previousx^2)-(previousy^2) on stack fld x fadd ;(previousx^2)-(previousy^2)+x on stack fstp newX ;stores above equation into newX and pops ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; fld previousy ;pushes previousy onto stack fld previousx ; fmul ;previousx*previousy on stack fld TOO fmul ;previousx*previousy*2 on stack fld y fadd ;previousx*previousy*2+y fstp newY ;stores above equation into newY and pops ;this simply does previousx = newX and previousy = newY fld newX ;load newX onto stack fstp previousx ;store newX into previousx and pop fld newY ;load newY onto stack fstp previousy ;store newY into previousy and pop inc loopvar ;loop counter is incremented cmp loopvar, 1000 ;the incremented loop counter,which is on top of the stack, ;is compared to 1000, and pops it off the stack jl iterate ;jump if loop counter is less than one hundred to iterate again. ;finally applying the full distance equation fld newX ;pushes newX onto stack fmul newX ;newX^2 fld newY ;pushes newY onto stack fmul newY ;newY^2 fadd ;adds (newX^2)+(newY^2) onto the stack fsqrt ;sqrt((newX^2)+(newY^2)) on the stack fst dist ;stores the top of the stack, the distance, into dist, just in case! fcomp TWO ;compares the distance equation of the iterated points to 2, & pops it fstsw status ;save the status register fstp junk ;get rid of top of stack fld dist ;and put dist back and status,4500h ;mask three bits jz plotwhite ;if it is less than 2, it is in the set, so we jump to ;plotwhite, else it isn't in the set, and we write the pixel in green ;Now get ready to write pixel in green, a point in the not in the mandelbrot set mov ax,10 mov ah,0ch mov cx,u mov dx,v int 10h jmp increment plotwhite: ;Now get ready to write pixel in white, a point in the set mov ax,15 mov ah,0ch mov cx,u mov dx,v int 10h increment: inc u cmp u,640 jl b_loop inc v cmp v,480 jl a_loop ;Here's a delay that requests keyboard input and ;waits for key pressed mov ah,10h int 16h ;Now set back to text mode mov ah,0 mov al,3 int 10h .exit end