1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
fn draw-circle screen: (addr screen), cx: int, cy: int, radius: int, color: int {
var x: int
var y: int
var err: int
# x = -r
var tmp/eax: int <- copy radius
tmp <- negate
copy-to x, tmp
# err = 2 - 2*r
tmp <- copy radius
tmp <- shift-left 1
tmp <- negate
tmp <- add 2
copy-to err, tmp
#
var tmpx/ecx: int <- copy 0
var tmpy/edx: int <- copy 0
{
# pixel(cx-x, cy+y)
tmpx <- copy cx
tmpx <- subtract x
tmpy <- copy cy
tmpy <- add y
pixel screen, tmpx, tmpy, color
# pixel(cx-y, cy-x)
tmpx <- copy cx
tmpx <- subtract y
tmpy <- copy cy
tmpy <- subtract x
pixel screen, tmpx, tmpy, color
# pixel(cx+x, cy-y)
tmpx <- copy cx
tmpx <- add x
tmpy <- copy cy
tmpy <- subtract y
pixel screen, tmpx, tmpy, color
# pixel(cx+y, cy+x)
tmpx <- copy cx
tmpx <- add y
tmpy <- copy cy
tmpy <- add x
pixel screen, tmpx, tmpy, color
# r = err
tmp <- copy err
copy-to radius, tmp
# if (r <= y) { ++y; err += (y*2 + 1); }
{
tmpy <- copy y
compare radius, tmpy
break-if->
increment y
tmpy <- copy y
tmpy <- shift-left 1
tmpy <- increment
add-to err, tmpy
}
# if (r > x || err > y) { ++x; err += (x*2 + 1); }
$draw-circle:second-check: {
{
tmpx <- copy x
compare radius, tmpx
break-if->
tmpy <- copy y
compare err, tmpy
break-if->
break $draw-circle:second-check
}
increment x
tmpx <- copy x
tmpx <- shift-left 1
tmpx <- increment
add-to err, tmpx
}
# loop termination condition
compare x, 0
loop-if-<
}
}
fn draw-disc screen: (addr screen), cx: int, cy: int, radius: int, color: int, border-color: int {
var r/eax: int <- copy 0
{
compare r, radius
break-if->=
draw-circle screen, cx cy, r, color
r <- increment
loop
}
draw-circle screen, cx cy, r, border-color
}
|