dsforth: it is now possible to compile it with relative or absolute branches (absolut...
[urasm.git] / dsforth / ext_gfxhi.zas
blob6336d0ac4ef83406e7b5d3488ad2d6db69062439
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; "high-level" graphics
3 ;; mostly by Ketmar
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6 $FORTH_VAR (DRAWLINE-DX)  0
7 $FORTH_VAR (DRAWLINE-DY)  0
8 $FORTH_VAR (DRAWLINE-SX)  0
9 $FORTH_VAR (DRAWLINE-SY)  0
12 $FORTH_WORD DRAWLINE
13 ;;k8
14 ;;( x0 y0 x1 y1 -- )
15   ROT         ;;( x0 x1 y1 y0 )
16   2DUP -      ;;( x0 x1 y1 y0 dy )
17   DUP ISGN (DRAWLINE-SY) !
18   ABS (DRAWLINE-DY) !  ;;( x0 x1 y1 y0 )
19   >R DROP      ;;( x0 x1 | y0 )
20   SWAP DUP >R  ;;( x1 x0 | y0 x0 )
21   -
22   DUP ISGN (DRAWLINE-SX) !
23   ABS (DRAWLINE-DX) !  ;;( -- | y0 x0 )
24   R> R> 0  ;;( x0 y0 err )
26   (DRAWLINE-DX) @  (DRAWLINE-DY) @  MAX 1+
27   0 (DO)
28 drawline_loop:
29     ;;( x y err )
30     >R 2DUP PLOT  ;;( x y | err )
31     R@ DUP (DRAWLINE-DX) @ NEGATE > 0BRANCH drawline_l0
32       (DRAWLINE-DY) @ -  ;;( x y err | olderr )
33       ROT (DRAWLINE-SX) @ + NROT
34 drawline_l0:
35     ;;( x y err | olderr )
36     R> (DRAWLINE-DY) @ < 0BRANCH drawline_l1
37       (DRAWLINE-DX) @ +
38       SWAP (DRAWLINE-SY) @ + SWAP
39 drawline_l1:
40   (LOOP) drawline_loop
41   2DROP DROP
42   ;S
43 $FORTH_END_WORD DRAWLINE