update examples to use the new const eval syntax

coroutines
Ondřej Hruška 4 years ago
parent 66b3674f81
commit 4e67ac291f
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 23
      examples/life.csn
  2. 47
      examples/mandelbrot/mandelbrot-full.csn
  3. 49
      examples/mandelbrot/mandelbrot-interactive.csn
  4. 52
      examples/mandelbrot/mandelbrot-lowres.csn

@ -10,23 +10,22 @@
(def GENERATION_MS 200) (def GENERATION_MS 200)
; Real pixel size ; Number of pixels
(sc-init 400 400)
; Upscaling factor (bug pixels)
(sc-opt SCREEN_UPSCALE 10)
; Number of big pixels
(def W 40) (def W 40)
(def H 40) (def H 40)
(def UPSCALE 10)
; --- end of config ---
; !!! If you change size, also update the following constants. ; Real pixel size
; Compile-time math is not implemented yet. (sc-init (=mul UPSCALE W) (=mul UPSCALE H))
; Upscaling factor (bug pixels)
(sc-opt SCREEN_UPSCALE UPSCALE)
(def XMAX 39) ; W-1 (def XMAX (=sub W 1))
(def YMAX 39) ; H-1 (def YMAX (=sub H 1))
(def NCELLS 1600) ; W*H (def NCELLS (=mul W H))
; --- end of config ---
(sc-opt SCREEN_AUTO_BLIT 0) (sc-opt SCREEN_AUTO_BLIT 0)
(sc-erase 0) ; all black (sc-erase 0) ; all black

@ -1,17 +1,20 @@
( (
(sc-init 800 600) ; High resolution mandelbrot
(sc-opt SCREEN_AUTOBLIT 0)
(def W 800) (def W 800)
(def H 600) (def H 600)
(def MAXITER 50) (def MAXITER 50) ; Increase for more detail but slower render
(sc-init W H)
(sc-opt SCREEN_AUTOBLIT 0)
(sym gradient r9) (sym gradient r9)
(sym asciigr r10) (sym asciigr r10)
(mkbf gradient ( (mkbf gradient (
0x421e0f 0x19071a 0x09012f 0x040449 0x000764 0x0c2c8a 0x1852b1 0x397dd1 0x421e0f 0x19071a 0x09012f 0x040449 0x000764 0x0c2c8a 0x1852b1 0x397dd1
0x86b5e5 0xd3ecf8 0xf1e9bf 0xf8c95f 0xffaa00 0xcc8000 0x995700 0x6a3403)) 0x86b5e5 0xd3ecf8 0xf1e9bf 0xf8c95f 0xffaa00 0xcc8000 0x995700 0x6a3403))
(sym x r7) (sym x r7)
(sym y r8) (sym y r8)
(:row) (:row)
@ -34,38 +37,38 @@
(sc-blit) ; Render after every row (sc-blit) ; Render after every row
(cmp y H) (cmp y H)
(j.ne :row) (j.ne :row)
;(sc-blit) ;(sc-blit)
(:slp) (:slp)
(sc-poll) (sc-poll)
(mslp 10) (mslp 10)
(j :slp) (j :slp)
(proc pixel xi yi (proc pixel xi yi
(sym x0 r7) (sym x0 r7)
(sym y0 r8) (sym y0 r8)
(itf x0 xi) (itf x0 xi)
(itf y0 yi) (itf y0 yi)
; Scale to the interesting range x -2.5..1 and y -1..1 ; Scale to the interesting range x -2.5..1 and y -1..1
(itf r0 W) (itf r0 W)
(itf r1 H) (itf r1 H)
(fdiv x0 r0) (fdiv x0 r0)
(fmul x0 3.5) (fmul x0 3.5)
(fsub x0 2.5) (fsub x0 2.5)
(fdiv y0 r1) (fdiv y0 r1)
(fmul y0 2.4) (fmul y0 2.4)
(fsub y0 1.2) (fsub y0 1.2)
(sym x r5) (sym x r5)
(sym y r6) (sym y r6)
(ld x 0.0) (ld x 0.0)
(ld y 0.0) (ld y 0.0)
(sym iter r4) (sym iter r4)
(:iter) (:iter)
(cmp iter MAXITER) (cmp iter MAXITER)
(j.eq :end) (j.eq :end)
@ -74,18 +77,18 @@
(fadd r2 r1) (fadd r2 r1)
(fcmp r2 4.0) (fcmp r2 4.0)
(j.gt :end) (j.gt :end)
(fsub r2 r0 r1) (fsub r2 r0 r1)
(fadd r2 x0) (fadd r2 x0)
(fmul r0 x y) (fmul r0 x y)
(fmul r0 2.0) (fmul r0 2.0)
(fadd r0 y0) (fadd r0 y0)
(ld y r0) (ld y r0)
(ld x r2) (ld x r2)
(inc iter) (inc iter)
(j :iter) (j :iter)
(:end) (:end)
(ret iter) (ret iter)
) )

@ -1,10 +1,15 @@
( (
(sc-init 1024 768)
(sc-opt SCREEN_AUTOBLIT 0)
(def W 1024) (def W 1024)
(def H 768) (def H 768)
(sym MAXITER g0) (def DEF_MAXITER 50)
(ld MAXITER 50)
; ---
(sc-init W H)
(sc-opt SCREEN_AUTOBLIT 0)
(sym maxiter g0)
(ld maxiter DEF_MAXITER)
(lds @cout "Interactive Mandelbrot\n") (lds @cout "Interactive Mandelbrot\n")
(lds @cout "----------------------\n") (lds @cout "----------------------\n")
@ -18,7 +23,7 @@
; index into the skip/size table ; index into the skip/size table
(sym mb_skip_index r11) (sym mb_skip_index r11)
; Interactive movement speed ; Interactive movement speed
(def ZOOM_STEP 0.1) (def ZOOM_STEP 0.1)
(def PAN_STEP 0.3) (def PAN_STEP 0.3)
@ -66,10 +71,10 @@
(sym did_change r15) (sym did_change r15)
(sym is_first_render r6) (sym is_first_render r6)
(ld is_first_render 1) (ld is_first_render 1)
(sym GRADIENT g1) (sym GRADIENT g1)
(mkbf GRADIENT ( (mkbf GRADIENT (
0x421e0f 0x19071a 0x09012f 0x040449 0x000764 0x0c2c8a 0x1852b1 0x397dd1 0x421e0f 0x19071a 0x09012f 0x040449 0x000764 0x0c2c8a 0x1852b1 0x397dd1
0x86b5e5 0xd3ecf8 0xf1e9bf 0xf8c95f 0xffaa00 0xcc8000 0x995700 0x6a3403)) 0x86b5e5 0xd3ecf8 0xf1e9bf 0xf8c95f 0xffaa00 0xcc8000 0x995700 0x6a3403))
; render row ; render row
@ -86,7 +91,7 @@
(ld x col) (ld x col)
(:col) (:col)
(call pixel x y px py scale) (call pixel x y px py scale)
(sub r0 MAXITER 1) (sub r0 maxiter 1)
(rcmp res0 1 r0 (rcmp res0 1 r0
(eq? (eq?
(mod r0 res0 16) (mod r0 res0 16)
@ -106,7 +111,7 @@
(sc-poll) (sc-poll)
; did_change -- did the user interact during this frame? ; did_change -- did the user interact during this frame?
(ld did_change 0) (ld did_change 0)
(sym pstep r2) (sym pstep r2)
(sym zstep r3) (sym zstep r3)
(ld pstep PAN_STEP) (ld pstep PAN_STEP)
@ -117,10 +122,10 @@
(fmul zstep 5.0) (fmul zstep 5.0)
)) ))
(fadd zstep 1.0) (fadd zstep 1.0)
; scaled movement speed ; scaled movement speed
(fdiv pstep mb_s) (fdiv pstep mb_s)
(tst is_first_render (z? (tst is_first_render (z?
; A < ; A <
(sc-key _ KEY_A (nz? (sc-key _ KEY_A (nz?
@ -154,7 +159,7 @@
(sc-key r0 KEY_Q (nz? (sc-key r0 KEY_Q (nz?
(fmul mb_s zstep) (fmul mb_s zstep)
(ld did_change 1) (ld did_change 1)
(lds @cout "Zoom in\n") (lds @cout "Zoom in\n")
)) ))
; E - ; E -
@ -166,16 +171,16 @@
; R iter+ ; R iter+
(sc-key r0 KEY_R (nz? (sc-key r0 KEY_R (nz?
(add MAXITER 50) (add maxiter 50)
(lds @cout "ITER=") (call printnum MAXITER) (ld @cout '\n') (lds @cout "ITER=") (call printnum maxiter) (ld @cout '\n')
(mslp 200) ; Avoid unexpected rapid change (mslp 200) ; Avoid unexpected rapid change
)) ))
; F iter- ; F iter-
(sc-key r0 KEY_F (nz? (sc-key r0 KEY_F (nz?
(cmp MAXITER 50) (cmp maxiter 50)
(sub.gt MAXITER 50) (sub.gt maxiter 50)
(lds @cout "ITER=") (call printnum MAXITER) (ld @cout '\n') (lds @cout "ITER=") (call printnum maxiter) (ld @cout '\n')
(mslp 200) ; Avoid unexpected rapid change (mslp 200) ; Avoid unexpected rapid change
)) ))
@ -209,7 +214,7 @@
(unsym mb_col_skip) (unsym mb_col_skip)
(unsym mb_row_skip) (unsym mb_row_skip)
(cmp mb_row H (cmp mb_row H
(lt? (lt?
; if mb_row < H ; if mb_row < H
(add mb_row ROW_SKIP) (add mb_row ROW_SKIP)
@ -220,7 +225,7 @@
(add mb_skip_index 1) (add mb_skip_index 1)
(ld is_first_render 0) (ld is_first_render 0)
(cmp mb_skip_index MB_SKIP_TABLE_SIZE (ge? (cmp mb_skip_index MB_SKIP_TABLE_SIZE (ge?
; if skip index is out of bounds, go back to repeating area ; if skip index is out of bounds, go back to repeating area
(ld mb_skip_index MB_SKIP_REPEAT_INDEX) (ld mb_skip_index MB_SKIP_REPEAT_INDEX)
)) ))
@ -229,7 +234,7 @@
(j :loop) (j :loop)
(proc pixel xi yi off_x off_y scale (proc pixel xi yi off_x off_y scale
(sym x0 r7) (sym x0 r7)
(sym y0 r8) (sym y0 r8)
(itf x0 xi) (itf x0 xi)
(itf y0 yi) (itf y0 yi)
@ -258,7 +263,7 @@
(sym iter r4) (sym iter r4)
(:iter) (:iter)
(cmp iter MAXITER) (cmp iter maxiter)
(j.eq :end) (j.eq :end)
(fmul r0 x x) (fmul r0 x x)
(fmul r1 y y) (fmul r1 y y)
@ -280,7 +285,7 @@
(:end) (:end)
(ret iter) (ret iter)
) )
(proc printnum num (proc printnum num
(mkbf r15) (mkbf r15)
(ld r1 num) (ld r1 num)

@ -1,18 +1,22 @@
( (
(sc-init 1024 768) (def PX_W 1024)
(sc-opt SCREEN_AUTOBLIT 0) (def PX_H 768)
(sc-opt SCREEN_UPSCALE 8) (def UPSCALE 8)
(def W 128)
(def H 96)
(def MAXITER 50) (def MAXITER 50)
(sc-init PX_W PX_H)
(sc-opt SCREEN_AUTOBLIT 0)
(sc-opt SCREEN_UPSCALE UPSCALE)
(def W (=div PX_W UPSCALE))
(def H (=div PX_H UPSCALE))
(sym gradient r9) (sym gradient r9)
(sym asciigr r10) (sym asciigr r10)
(mkbf gradient ( (mkbf gradient (
0x421e0f 0x19071a 0x09012f 0x040449 0x000764 0x0c2c8a 0x1852b1 0x397dd1 0x421e0f 0x19071a 0x09012f 0x040449 0x000764 0x0c2c8a 0x1852b1 0x397dd1
0x86b5e5 0xd3ecf8 0xf1e9bf 0xf8c95f 0xffaa00 0xcc8000 0x995700 0x6a3403)) 0x86b5e5 0xd3ecf8 0xf1e9bf 0xf8c95f 0xffaa00 0xcc8000 0x995700 0x6a3403))
(sym x r7) (sym x r7)
(sym y r8) (sym y r8)
(:row) (:row)
@ -35,38 +39,38 @@
(sc-blit) ; Render after every row (sc-blit) ; Render after every row
(cmp y H) (cmp y H)
(j.ne :row) (j.ne :row)
;(sc-blit) ;(sc-blit)
(:slp) (:slp)
(sc-poll) (sc-poll)
(mslp 10) (mslp 10)
(j :slp) (j :slp)
(proc pixel xi yi (proc pixel xi yi
(sym x0 r7) (sym x0 r7)
(sym y0 r8) (sym y0 r8)
(itf x0 xi) (itf x0 xi)
(itf y0 yi) (itf y0 yi)
; Scale to the interesting range x -2.5..1 and y -1..1 ; Scale to the interesting range x -2.5..1 and y -1..1
(itf r0 W) (itf r0 W)
(itf r1 H) (itf r1 H)
(fdiv x0 r0) (fdiv x0 r0)
(fmul x0 3.5) (fmul x0 3.5)
(fsub x0 2.5) (fsub x0 2.5)
(fdiv y0 r1) (fdiv y0 r1)
(fmul y0 2.4) (fmul y0 2.4)
(fsub y0 1.2) (fsub y0 1.2)
(sym x r5) (sym x r5)
(sym y r6) (sym y r6)
(ld x 0.0) (ld x 0.0)
(ld y 0.0) (ld y 0.0)
(sym iter r4) (sym iter r4)
(:iter) (:iter)
(cmp iter MAXITER) (cmp iter MAXITER)
(j.eq :end) (j.eq :end)
@ -75,18 +79,18 @@
(fadd r2 r1) (fadd r2 r1)
(fcmp r2 4.0) (fcmp r2 4.0)
(j.gt :end) (j.gt :end)
(fsub r2 r0 r1) (fsub r2 r0 r1)
(fadd r2 x0) (fadd r2 x0)
(fmul r0 x y) (fmul r0 x y)
(fmul r0 2.0) (fmul r0 2.0)
(fadd r0 y0) (fadd r0 y0)
(ld y r0) (ld y r0)
(ld x r2) (ld x r2)
(inc iter) (inc iter)
(j :iter) (j :iter)
(:end) (:end)
(ret iter) (ret iter)
) )

Loading…
Cancel
Save