UrForth: it is now possible to use relative disp in branches (compile-time toggle...
[urasm.git] / samples / koch.zas
bloba44b1becfbc74978365d8fca249a5661a07a0a80
1 ; http://www.retroprogramming.com/2013/08/zx-spectrum-koch-levy-c-curve.html
3   org #8000
5   ld    a,6
6   include <cls_ei.zas>
8   call  MAIN
9   include <waitkey.zas>
10   ret
12 MAIN:
13   ld    de,49023 ; d = position on x axis
14                  ; e = position on y axis
15   ld    bc,3840  ; b = number of iterations
16                  ; c = initial direction
17 RECURSE:
18   djnz  DOWN
20   ld    a,6      ; check direction
21   and   c        ; c=0, left
22   rrca           ; c=2, up
23   rrca           ; c=4, right
24   add   a,a      ; c=6, down
25   dec   a
26   jr    nc,XMOVE
28   add   a,e      ; adjust y position +/-1
30   ld    e,a      ; calculate high byte of screen pos
31   rrca
32   scf
33   rra
34   rrca
35   xor   e
36   and   88
37   xor   e
38   and   95
39   ld    h,a
40   sub   h
42 XMOVE:
43   add   a,d      ; adjust x position +/-1
45   ld    d,a      ; calculate low byte of screen pos
46   rlca
47   rlca
48   rlca
49   xor   e
50   and   199
51   xor   e
52   rlca
53   rlca
54   ld    l,a
56   ld    a,7      ; calculate bit position of pixel
57   and   d
58   ld    b,a
59   inc   b
60   ld    a,1
61 SHIFTBIT:
62   rrca
63   djnz  SHIFTBIT
65   xor   (hl)     ; plot
66   ld    (hl),a
67   ret
69 DOWN:
70   inc   c        ; turn 45 clockwise
71   call  RECURSE
72   inc   b
73   dec   c        ; turn 90 anti-clockwise
74   dec   c
75   call  RECURSE
76   inc   b
77   inc   c        ; turn 45 clockwise
78   ret