corrupt! but it produces pixels

This commit is contained in:
Brooke Vibber 2023-01-22 10:42:37 -08:00
parent b4721ae46b
commit ae9dd0674d

View file

@ -168,7 +168,7 @@ color_map:
.endmacro
.macro add32 dest, arg1, arg2
add 2, dest, arg2, dest
add 4, dest, arg2, dest
.endmacro
; 2 + 9 * byte cycles
@ -422,6 +422,13 @@ next:
.endmacro
.macro shift_round_16 arg, shift
.repeat shift
shl32 arg
.endrepeat
round16 arg
.endmacro
.proc mandelbrot
; input:
; cx: position scaled to 4.12 fixed point - -8..+7.9
@ -445,64 +452,48 @@ initloop:
bne initloop
loop:
; 1939 - 3007 cyc
; iter++ & max-iters break = 7 cyc
inc iter ; 5 cyc
bne keep_going ; 2 cyc
; iter++ & max-iters break
inc iter
bne keep_going
rts
keep_going:
; 4.12: (-8 .. +7.9)
; zx = zx_2 - zy_2 + cx = 3 * 20 = 60 cyc
sub16 zx, zx_2, zy_2
; zx = zx_2 - zy_2 + cx
sub16 zx, zx_2 + 2, zy_2 + 2
add16 zx, zx, cx
; zy = zx_zy + zx_zy + cy = 3 * 20 = 60 cyc
sub16 zy, zx_zy, zx_zy
; zy = zx_zy + zx_zy + cy
add16 zy, zx_zy + 2, zx_zy + 2
add16 zy, zy, cy
; 8.24: (-128 .. +127.9)
; zx_2 = zx * zx = 518 - 828 cyc
; zx_2 = zx * zx
imul16 zx_2, zx, zx
; zy_2 = zy * zy = 518 - 828 cyc
; zy_2 = zy * zy
imul16 zy_2, zy, zy
; zx_zy = zx * zy = 518 - 828 cyc
; zx_zy = zx * zy
imul16 zx_zy, zx, zy
; dist = zx_2 + zy_2 = 38 cyc
; dist = zx_2 + zy_2
add32 dist, zx_2, zy_2
; if dist >= 4 break, else continue iterating = 7 cyc
lda dist + 3 ; 3 cyc
cmp #4 ; 2 cyc
bmi still_in ; 2 cyc
; if dist >= 4 break, else continue iterating
lda dist + 3
cmp #4
bmi still_in
rts
still_in:
; shift and round zx_2 to 4.12 = (60 + 5) - (60 + 28) = 65 - 88 cyc
.repeat 4 ; 60 cyc
shl24 zx_2 ; 15 cyc
.endrepeat
round16 zx_2 ; 5-28 cycles
; shift and round zy_2 to 4.12 = (20 + 5) - (20 + 28) = 65 - 88 cyc
.repeat 4 ; 60 cyc
shl24 zy_2 ; 15 cyc
.endrepeat
round16 zy_2 ; 5-28 cycles
; shift and round zx_zy to 4.12 = (20 + 5) - (20 + 28) = 65 - 88 cyc
.repeat 4 ; 60 cyc
shl24 zx_zy ; 15 cyc
.endrepeat
round16 zx_zy ; 5-28 cycles
shift_round_16 zx_2, 4
shift_round_16 zy_2, 4
shift_round_16 zx_zy, 4
; if may be in the lake, look for looping output with a small buffer
; as an optimization vs running to max iters
jmp loop ; 3 cycles
jmp loop
.endproc
@ -708,7 +699,6 @@ loop_sx:
zoom_factor cx, sx, zoom, aspect_x
zoom_factor cy, sy, zoom, aspect_y
jsr mandelbrot
inc iter
jsr pset
clc