2020-09-20 21:49:36 +00:00
|
|
|
%import textio
|
|
|
|
%import floats
|
2019-02-12 22:24:47 +00:00
|
|
|
%zeropage basicsafe
|
|
|
|
|
2020-09-21 23:34:05 +00:00
|
|
|
; Note: this program is compatible with C64 and CX16.
|
2020-09-20 21:49:36 +00:00
|
|
|
|
2019-07-29 21:11:13 +00:00
|
|
|
main {
|
2019-01-08 00:27:25 +00:00
|
|
|
const uword width = 30
|
|
|
|
const uword height = 20
|
|
|
|
const ubyte max_iter = 16
|
2018-09-18 21:14:32 +00:00
|
|
|
|
2018-09-30 16:49:58 +00:00
|
|
|
sub start() {
|
2020-08-27 16:10:22 +00:00
|
|
|
txt.print("calculating mandelbrot fractal...")
|
2018-09-18 21:14:32 +00:00
|
|
|
|
2020-09-21 23:34:05 +00:00
|
|
|
%asm {{
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
; reset the jiffy clock
|
|
|
|
ldx #0
|
|
|
|
ldy #0
|
|
|
|
lda #0
|
|
|
|
jsr c64.SETTIM
|
|
|
|
ldx P8ZP_SCRATCH_REG
|
|
|
|
}}
|
2018-09-23 00:42:42 +00:00
|
|
|
|
2019-08-18 01:16:23 +00:00
|
|
|
ubyte pixelx
|
|
|
|
ubyte pixely
|
|
|
|
|
|
|
|
for pixely in 0 to height-1 {
|
2019-01-08 00:27:25 +00:00
|
|
|
float yy = (pixely as float)/0.4/height - 1.0
|
|
|
|
|
2019-08-18 01:16:23 +00:00
|
|
|
for pixelx in 0 to width-1 {
|
2019-01-08 00:27:25 +00:00
|
|
|
float xx = (pixelx as float)/0.3/width - 2.2
|
2018-10-06 22:21:13 +00:00
|
|
|
|
|
|
|
float xsquared = 0.0
|
|
|
|
float ysquared = 0.0
|
|
|
|
float x = 0.0
|
|
|
|
float y = 0.0
|
2018-10-10 07:21:20 +00:00
|
|
|
ubyte iter = 0
|
2018-10-06 22:21:13 +00:00
|
|
|
|
2020-06-17 23:35:24 +00:00
|
|
|
while iter<max_iter and xsquared+ysquared<4.0 {
|
2018-10-05 15:44:29 +00:00
|
|
|
y = x*y*2.0 + yy
|
2018-09-26 23:35:35 +00:00
|
|
|
x = xsquared - ysquared + xx
|
|
|
|
xsquared = x*x
|
|
|
|
ysquared = y*y
|
2018-09-23 00:42:42 +00:00
|
|
|
iter++
|
2018-09-18 21:14:32 +00:00
|
|
|
}
|
2020-08-27 16:10:22 +00:00
|
|
|
txt.setcc(pixelx+4, pixely+1, 160, max_iter-iter)
|
2018-09-18 21:14:32 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-15 20:35:15 +00:00
|
|
|
|
2020-09-21 23:34:05 +00:00
|
|
|
ubyte time_lo
|
|
|
|
ubyte time_mid
|
|
|
|
ubyte time_hi
|
|
|
|
|
|
|
|
%asm {{
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr c64.RDTIM ; A/X/Y
|
|
|
|
sta time_lo
|
|
|
|
stx time_mid
|
|
|
|
sty time_hi
|
|
|
|
ldx P8ZP_SCRATCH_REG
|
|
|
|
}}
|
|
|
|
|
|
|
|
float duration = ((mkword(time_mid, time_lo) as float) + (time_hi as float)*65536.0) / 60
|
2020-08-27 16:10:22 +00:00
|
|
|
txt.plot(0, 21)
|
|
|
|
txt.print("finished in ")
|
2020-09-20 21:49:36 +00:00
|
|
|
floats.print_f(duration)
|
2020-08-27 16:10:22 +00:00
|
|
|
txt.print(" seconds!\n")
|
2018-09-18 21:14:32 +00:00
|
|
|
}
|
|
|
|
}
|