Created
March 6, 2015 12:58
-
-
Save dgryski/fccd39279e8127fe5382 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[org 100h] | |
; uses fixed point: 1 bit sign, 4 bits int, 11 bits frac | |
xstart equ -3584 ; -1.75 | |
xend equ 1536 ; 0.75 | |
ystart equ -2048 ; -1.0 | |
yend equ 2048 ; 1.0 | |
xincr equ 16 ; (xend-xstart) div 320 | |
yincr equ 20 ; 20.48 = (yend-ystart) div 200 | |
niters equ 100 ; | |
fixed4 equ 8192 ; 4 * 2048 | |
; set vga mode | |
mov ax, 13h | |
int 10h | |
; initialize regs for pixel access | |
mov ax, 0a000h | |
mov es, ax | |
xor di, di | |
mov si, 320*199 | |
; mov word [y], ystart | |
; initialized in data section | |
mov cx, 100 | |
yloop: | |
push cx | |
mov word [x], xstart | |
mov cx, 320 | |
xloop: | |
push cx | |
mov ax, [y] | |
mov [zi], ax | |
mov bx, [x] | |
mov [zr], bx | |
mov cx, niters | |
while_loop: | |
; compute zrsqr | |
; bx holds zr | |
mov ax, bx | |
mov dx, ax | |
call fixedmul | |
mov bx, ax | |
; compute zisqr | |
mov ax, [zi] | |
mov dx, ax | |
call fixedmul | |
mov dx, ax | |
; if zisqr+zrsqr > 4, exit while | |
add ax, bx | |
cmp ax, fixed4 | |
jge done_while | |
; t := zrsqr - zisqr + x; | |
sub bx, dx | |
add bx, [x] | |
; zi := 2*zi*zr + y | |
mov ax, [zi] | |
mov dx, [zr] | |
call fixedmul | |
shl ax, 1 | |
add ax, [y] | |
mov [zi], ax | |
; zr := t; | |
mov [zr], bx | |
loop while_loop | |
done_while: | |
mov ax, cx | |
; draw the pixels | |
stosb | |
xchg si, di | |
stosb | |
xchg si, di | |
add word [x], xincr | |
pop cx | |
loop xloop | |
; adjust si (since it needs to move up the screen) | |
sub si, 640 | |
; use 1bit of yloop iter | |
; this is how we handle yincr = 20.48 | |
pop cx | |
mov ax, cx | |
and ax, 1 | |
add ax, yincr | |
add [y], ax | |
loop yloop | |
done: | |
; wait for keypress | |
xor ax, ax | |
int 16h | |
; restore text screen | |
mov ax, 3h | |
int 10h | |
; exit | |
mov ax, 4c00h | |
int 21h | |
fixedmul: | |
; multiply ax,dx as fixed point, return value in ax | |
imul dx | |
shl dx, 5 | |
shr ax, 11 | |
or ax, dx | |
ret | |
.data | |
x: dw xstart | |
y: dw ystart | |
zr: dw 0 | |
zi: dw 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment