        .386
Stacken SEGMENT PARA STACK USE16 'STACK'
        DB      200h DUP (0)
Stacken ENDS

Data1   SEGMENT PARA PUBLIC USE16 'DATA'
zr      DD      ?
zi      DD      ?
cr      DD      -492
ci      DD      -3332
XPoint  DW      ?
YPoint  DB      ?
Count   DB      ?

Colors  DB      0,0,0, 40*3 DUP (0), 0, 20, 50
Data1   ENDS

Code    SEGMENT PARA PUBLIC USE16 'CODE'
        ASSUME  cs:Code, ss:Stacken, ds:Data1
ProgramStart:
; Turn on 320x200x256 screenmode

        mov     ax, 13h
        int     10h

        mov     ax, Data1
        mov     ds, ax
        mov     es, ax

; Set up colors

        mov     di, OFFSET Colors + 3
        mov     cx, 40
        mov     al, 23
CFix1:  inc     di
        stosb
        inc     di
        inc     al
        loop    CFix1

        mov     dx, OFFSET Colors
        sub     bx, bx
        mov     cx, 42
        mov     ax, 1012h
        int     10h

        mov     ax, 0a000h
        mov     es, ax

        sub     di, di
        mov     dword ptr [zi], -5120 - 51
        mov     byte ptr [YPoint], 0

Calc_Ycords:
        mov     word ptr [XPoint], 0
        mov     dword ptr [zr], -8192
        add     dword ptr [zi], 51
Calc_Xcords:
        mov     eax, [zr]
        mov     ebx, [zi]
        add     dword ptr [zr], 51

        mov     byte ptr [Count], 40
        mov     ecx, eax
        mov     edx, ebx
        imul    ecx, ecx
        sar     ecx, 12
        imul    edx, edx
        sar     edx, 12
Calc_Point:
        imul    ebx, eax          ; ebx = zi = 2*zr*zi + ci
        sar     ebx, 11
        add     ebx, [ci]

        sub     ecx, edx          ; eax = zr = zrsqr - zisqr + cr
        add     ecx, [cr]
        mov     eax, ecx

        imul    ecx, ecx          ; ecx = zrsqr
        sar     ecx, 12
        mov     edx, ebx
        imul    edx, edx          ; edx = zisqr
        sar     edx, 12
        mov     esi, ecx
        add     esi, edx
        cmp     esi, 4096*4       ; is zisqr + zrsqr > 4?
        jge     Outside_Set
        dec     byte ptr [Count]
        jne     Calc_Point
        mov     al, 41
        stosb
        inc     word ptr [XPoint]
        cmp     word ptr [XPoint], 320
        je      Line_OK
        jmp     Calc_Xcords
OutSide_Set:
        mov     al, [Count]
        sub     ah, ah
        stosb
        inc     word ptr [XPoint]
        cmp     word ptr [XPoint], 320
        je      Line_OK
        jmp     Calc_Xcords
Line_OK:
        inc     byte ptr [YPoint]
        cmp     byte ptr [YPoint], 200
        je      Quit
        jmp     Calc_Ycords

Quit:   mov     ah, 0
        int     16h
        mov     ax, 3
        int     10h
        mov     ah, 4ch
        int     21h

Code    ENDS
        END     ProgramStart

