.386p
.model flat,c
.code

                public  julia2
julia2:
		mov	edi,[esp+4]
		mov	ebp,edi
MainLoop:       mov     Xedi,0
		mov	ZImag,-5171		; #72: ZIm = 0FFFFEBCDh
		mov	YCnt,0			; #73: YCnt = 0
NewLine:	mov	XCnt,0			; #74: XCnt = 0
		mov	ZReal,-8192		; #75: ZRe = 0FFFFE000h
		add	ZImag,103		; #76: ZIm = ZIm + 132 (delta Y)
NextPoint:	mov	eax,ZReal		; #77: eax = ZRe
		mov	ebx,ZImag		; #78: ebx = ZIm
                add     ZReal,103               ; #79: ZRe = ZRe + 102 (delta X)
                mov     Iter,24                 ; #80: Iter = 30 ones
		mov	ecx,eax 		; #81: ecx = #77
		mov	edx,ebx 		; #82: edx = #78
		imul	ecx,ecx 		; #01: ecx = ZReý
		sar	ecx,0Ch 		; #02: ecx = #01 / 4096 (ZReý)
		imul	edx,edx 		; #03: edx = ZImý
		sar	edx,0Ch 		; #04: edx = #03 / 4096 (ZImý)
NextIter:       imul    ebx,eax                 ; #05: ebx = ZIm * ZRe
                sar     ebx,0bh                 ; #06: ebx = #05 / 2048
                add     ebx,CImag               ; #07: ebx = #06 + CIm  (ZIm*ZRe+CIm) = ZIm n+1
		sub	ecx,edx 		; #08: ecx = #02 - #04
		add	ecx,CReal		; #09: ecx = #08 + CRe	(ZReý-ZImý+CRe) = ZRe n+1
		mov	eax,ecx 		; #10: eax = #09
		imul	ecx,ecx 		; #11: ecx = #09ý
                sar     ecx,0ch                 ; #12: ecx = #11 / 4096
                mov     edx,ebx                 ; #13: edx = #07
		imul	edx,edx 		; #14: edx = #13ý = #07ý
		sar	edx,0Ch 		; #15: edx = #14 / 4096
		mov	esi,ecx 		; #16: esi = #12
		add	esi,edx 		; #17: esi = #16 + #15
		cmp	esi,4000h		; #18: esi ? 16k	(#09ý+#07ý) modul
		jge	BailOut 		; Jump if > or = 16k
		dec	Iter			; #19: Iter = Iter - 1
                jnz     NextIter                ; Make next iteration
                add     Xedi,2
                inc     XCnt                    ; #25: XCnt = XCnt + 1
                cmp     XCnt,0A0h               ; #26: XCnt ? 160
                je      NextLine                ; Jump if XCnt = 160 NextLine
                jmp     NextPoint               ; One point means one word

BailOut:	xor	cx,cx			; #27: cx = 0
                mov     ebx,64000-322           ; #28: bx = 6182h (Scr End)
		sub	ebx,Xedi		; #29: bx = #28 - di
                cmp     ebx,64000               ; #30: bx ? 6180h (is Last)
		jb	PixPosOk		; if not last then PixPosOk
		mov	cx,1			; #31: cx = 1 if Last one
PixPosOk:       mov     al,Iter                 ; #32: al = Iter
                shl     al,2
		mov	ah,al			; #33: ah = #32  (color)
		cmp	cx,1			; #34: cx ? 1
		je	NoMirror		; if Last one then NoMirror
                add     [ebp+ebx],ax            ; #35: es:[bx] = ax = #32#32 Draw Bottom in color of itaration
                add     [ebp+ebx+320],ax
NoMirror:	mov	edx,Xedi
                add     word ptr [ebp+edx],ax  ; #36: es:[di] = ax = #32#32 Draw Top in color as above
                add     word ptr [ebp+edx+320],ax

                add     Xedi,2
                inc     XCnt
                cmp     XCnt,0A0h
		jne	NextPoint
NextLine:       inc     YCnt
		inc	YCnt
		add	Xedi,320
                cmp     byte ptr YCnt,100
		jne	NewLine

IniNewFrame:    add     CReal,46h
                add     CImag,46h
                mov     ax,FrameCnt
                cmp     ax,0A5h
		jb	Modify1
                sub     CImag,64h
Modify1:        mov     ax,FrameCnt
                cmp     ax,0FFh
		jb	Modify2
                sub     CReal,64h
Modify2:        mov     ax,FrameCnt
                cmp     ax,14Fh
		jb	Modify3
                add     CImag,64h
Modify3:        mov     eax,04040404h
                add     [ebp+32000],eax
                inc     FrameCnt
		cmp	FrameCnt,760
		jne	exitus
		mov	FrameCnt,0
                mov     ZImag,-5171
                mov     ZReal,-8192
                mov     CReal,-12950
                mov     CImag,-8500
exitus: 	ret

;------------------------------------------------------------  data   ----

ZReal		dd	00000h
ZImag		dd	00000h
CReal		dd	-12950			; 0FFFFCD6Ah
CImag		dd	-8500			; 0FFFFDECCh
XCnt		dw	0
YCnt		db	0
Iter		db	0
Xedi		dd	0
FrameCnt	dw	0

		end
