|
8 | 8 | ; Draws a circle at X, Y of radius R |
9 | 9 | ; X, Y on the Stack, R in accumulator (Byte) |
10 | 10 |
|
11 | | - PROC |
12 | | - LOCAL __CIRCLE_ERROR |
13 | | - LOCAL __CIRCLE_LOOP |
14 | | - LOCAL __CIRCLE_NEXT |
| 11 | + PROC |
| 12 | + LOCAL __CIRCLE_ERROR |
| 13 | + LOCAL __CIRCLE_LOOP |
| 14 | + LOCAL __CIRCLE_NEXT |
15 | 15 |
|
16 | 16 | __CIRCLE_ERROR: |
17 | 17 | jp __OUT_OF_SCREEN_ERR |
18 | | -;; __CIRCLE_ERROR EQU __OUT_OF_SCREEN_ERR |
19 | | -;; __CIRCLE_ERROR: |
20 | | -;; ; Jumps here if out of screen |
21 | | -;; scf ; Always sets carry Flag |
22 | | -;; |
23 | | -;; ld a, ERROR_OutOfScreen |
24 | | -;; ld (ERR_NR), a |
25 | | -;; ret |
26 | 18 | CIRCLE: |
27 | 19 | ;; Entry point |
28 | | - pop hl ; Return Address |
29 | | - pop de ; D = Y |
30 | | - ex (sp), hl ; __CALLEE__ convention |
31 | | - ld e, h ; E = X |
32 | | - |
33 | | - |
34 | | - ld h, a ; H = R |
35 | | - add a, d |
36 | | - sub 192 |
37 | | - jr nc, __CIRCLE_ERROR |
38 | | - |
39 | | - ld a, d |
40 | | - sub h |
41 | | - jr c, __CIRCLE_ERROR |
42 | | - |
43 | | - ld a, e |
44 | | - sub h |
45 | | - jr c, __CIRCLE_ERROR |
46 | | - |
47 | | - ld a, h |
48 | | - add a, e |
49 | | - jr c, __CIRCLE_ERROR |
| 20 | + pop hl ; Return Address |
| 21 | + pop de ; D = Y |
| 22 | + ex (sp), hl ; __CALLEE__ convention |
| 23 | + ld e, h ; E = X |
| 24 | + ld h, a ; H = R |
| 25 | + |
| 26 | +#ifdef SCREEN_Y_OFFSET |
| 27 | + ld a, SCREEN_Y_OFFSET |
| 28 | + add a, d |
| 29 | + ld d, a |
| 30 | +#endif |
| 31 | + |
| 32 | +#ifdef SCREEN_X_OFFSET |
| 33 | + ld a, SCREEN_X_OFFSET |
| 34 | + add a, e |
| 35 | + ld e, a |
| 36 | +#endif |
| 37 | + |
| 38 | + ld a, h |
| 39 | + add a, d |
| 40 | + sub 192 |
| 41 | + jr nc, __CIRCLE_ERROR |
| 42 | + |
| 43 | + ld a, d |
| 44 | + sub h |
| 45 | + jr c, __CIRCLE_ERROR |
| 46 | + |
| 47 | + ld a, e |
| 48 | + sub h |
| 49 | + jr c, __CIRCLE_ERROR |
| 50 | + |
| 51 | + ld a, h |
| 52 | + add a, e |
| 53 | + jr c, __CIRCLE_ERROR |
50 | 54 |
|
51 | 55 |
|
52 | 56 | ; __FASTCALL__ Entry: D, E = Y, X point of the center |
53 | 57 | ; A = Radious |
54 | 58 | __CIRCLE: |
55 | | - push de |
56 | | - ld a, h |
57 | | - exx |
58 | | - pop de ; D'E' = x0, y0 |
59 | | - ld h, a ; H' = r |
60 | | - |
61 | | - ld c, e |
62 | | - ld a, h |
63 | | - add a, d |
64 | | - ld b, a |
65 | | - call __CIRCLE_PLOT ; PLOT (x0, y0 + r) |
66 | | - |
67 | | - ld b, d |
68 | | - ld a, h |
69 | | - add a, e |
70 | | - ld c, a |
71 | | - call __CIRCLE_PLOT ; PLOT (x0 + r, y0) |
72 | | - |
73 | | - ld c, e |
74 | | - ld a, d |
75 | | - sub h |
76 | | - ld b, a |
77 | | - call __CIRCLE_PLOT ; PLOT (x0, y0 - r) |
78 | | - |
79 | | - ld b, d |
80 | | - ld a, e |
81 | | - sub h |
82 | | - ld c, a |
83 | | - call __CIRCLE_PLOT ; PLOT (x0 - r, y0) |
84 | | - |
85 | | - exx |
86 | | - ld b, 0 ; B = x = 0 |
87 | | - ld c, h ; C = y = Radius |
88 | | - ld hl, 1 |
89 | | - or a |
90 | | - sbc hl, bc ; HL = f = 1 - radius |
91 | | - |
92 | | - ex de, hl |
93 | | - ld hl, 0 |
94 | | - or a |
95 | | - sbc hl, bc ; HL = -radius |
96 | | - add hl, hl ; HL = -2 * radius |
97 | | - ex de, hl ; DE = -2 * radius = ddF_y, HL = f |
98 | | - |
99 | | - xor a ; A = ddF_x = 0 |
100 | | - ex af, af' ; Saves it |
| 59 | + push de |
| 60 | + ld a, h |
| 61 | + exx |
| 62 | + pop de ; D'E' = x0, y0 |
| 63 | + ld h, a ; H' = r |
| 64 | + |
| 65 | + ld c, e |
| 66 | + ld a, h |
| 67 | + add a, d |
| 68 | + ld b, a |
| 69 | + call __CIRCLE_PLOT ; PLOT (x0, y0 + r) |
| 70 | + |
| 71 | + ld b, d |
| 72 | + ld a, h |
| 73 | + add a, e |
| 74 | + ld c, a |
| 75 | + call __CIRCLE_PLOT ; PLOT (x0 + r, y0) |
| 76 | + |
| 77 | + ld c, e |
| 78 | + ld a, d |
| 79 | + sub h |
| 80 | + ld b, a |
| 81 | + call __CIRCLE_PLOT ; PLOT (x0, y0 - r) |
| 82 | + |
| 83 | + ld b, d |
| 84 | + ld a, e |
| 85 | + sub h |
| 86 | + ld c, a |
| 87 | + call __CIRCLE_PLOT ; PLOT (x0 - r, y0) |
| 88 | + |
| 89 | + exx |
| 90 | + ld b, 0 ; B = x = 0 |
| 91 | + ld c, h ; C = y = Radius |
| 92 | + ld hl, 1 |
| 93 | + or a |
| 94 | + sbc hl, bc ; HL = f = 1 - radius |
| 95 | + |
| 96 | + ex de, hl |
| 97 | + ld hl, 0 |
| 98 | + or a |
| 99 | + sbc hl, bc ; HL = -radius |
| 100 | + add hl, hl ; HL = -2 * radius |
| 101 | + ex de, hl ; DE = -2 * radius = ddF_y, HL = f |
| 102 | + |
| 103 | + xor a ; A = ddF_x = 0 |
| 104 | + ex af, af' ; Saves it |
101 | 105 |
|
102 | 106 | __CIRCLE_LOOP: |
103 | | - ld a, b |
104 | | - cp c |
105 | | - ret nc ; Returns when x >= y |
| 107 | + ld a, b |
| 108 | + cp c |
| 109 | + ret nc ; Returns when x >= y |
106 | 110 |
|
107 | | - bit 7, h ; HL >= 0? : if (f >= 0)... |
108 | | - jp nz, __CIRCLE_NEXT |
| 111 | + bit 7, h ; HL >= 0? : if (f >= 0)... |
| 112 | + jp nz, __CIRCLE_NEXT |
109 | 113 |
|
110 | | - dec c ; y-- |
111 | | - inc de |
112 | | - inc de ; ddF_y += 2 |
| 114 | + dec c ; y-- |
| 115 | + inc de |
| 116 | + inc de ; ddF_y += 2 |
113 | 117 |
|
114 | | - add hl, de ; f += ddF_y |
| 118 | + add hl, de ; f += ddF_y |
115 | 119 |
|
116 | 120 | __CIRCLE_NEXT: |
117 | | - inc b ; x++ |
118 | | - ex af, af' |
119 | | - add a, 2 ; 1 Cycle faster than inc a, inc a |
120 | | - |
121 | | - inc hl ; f++ |
122 | | - push af |
123 | | - add a, l |
124 | | - ld l, a |
125 | | - ld a, h |
126 | | - adc a, 0 ; f = f + ddF_x |
127 | | - ld h, a |
128 | | - pop af |
129 | | - ex af, af' |
130 | | - |
131 | | - push bc |
132 | | - exx |
133 | | - pop hl ; H'L' = Y, X |
134 | | - |
135 | | - ld a, d |
136 | | - add a, h |
137 | | - ld b, a ; B = y0 + y |
138 | | - ld a, e |
139 | | - add a, l |
140 | | - ld c, a ; C = x0 + x |
141 | | - call __CIRCLE_PLOT ; plot(x0 + x, y0 + y) |
142 | | - |
143 | | - ld a, d |
144 | | - add a, h |
145 | | - ld b, a ; B = y0 + y |
146 | | - ld a, e |
147 | | - sub l |
148 | | - ld c, a ; C = x0 - x |
149 | | - call __CIRCLE_PLOT ; plot(x0 - x, y0 + y) |
150 | | - |
151 | | - ld a, d |
152 | | - sub h |
153 | | - ld b, a ; B = y0 - y |
154 | | - ld a, e |
155 | | - add a, l |
156 | | - ld c, a ; C = x0 + x |
157 | | - call __CIRCLE_PLOT ; plot(x0 + x, y0 - y) |
158 | | - |
159 | | - ld a, d |
160 | | - sub h |
161 | | - ld b, a ; B = y0 - y |
162 | | - ld a, e |
163 | | - sub l |
164 | | - ld c, a ; C = x0 - x |
165 | | - call __CIRCLE_PLOT ; plot(x0 - x, y0 - y) |
166 | | - |
167 | | - ld a, d |
168 | | - add a, l |
169 | | - ld b, a ; B = y0 + x |
170 | | - ld a, e |
171 | | - add a, h |
172 | | - ld c, a ; C = x0 + y |
173 | | - call __CIRCLE_PLOT ; plot(x0 + y, y0 + x) |
174 | | - |
175 | | - ld a, d |
176 | | - add a, l |
177 | | - ld b, a ; B = y0 + x |
178 | | - ld a, e |
179 | | - sub h |
180 | | - ld c, a ; C = x0 - y |
181 | | - call __CIRCLE_PLOT ; plot(x0 - y, y0 + x) |
182 | | - |
183 | | - ld a, d |
184 | | - sub l |
185 | | - ld b, a ; B = y0 - x |
186 | | - ld a, e |
187 | | - add a, h |
188 | | - ld c, a ; C = x0 + y |
189 | | - call __CIRCLE_PLOT ; plot(x0 + y, y0 - x) |
190 | | - |
191 | | - ld a, d |
192 | | - sub l |
193 | | - ld b, a ; B = y0 - x |
194 | | - ld a, e |
195 | | - sub h |
196 | | - ld c, a ; C = x0 + y |
197 | | - call __CIRCLE_PLOT ; plot(x0 - y, y0 - x) |
198 | | - |
199 | | - exx |
200 | | - jp __CIRCLE_LOOP |
| 121 | + inc b ; x++ |
| 122 | + ex af, af' |
| 123 | + add a, 2 ; 1 Cycle faster than inc a, inc a |
| 124 | + |
| 125 | + inc hl ; f++ |
| 126 | + push af |
| 127 | + add a, l |
| 128 | + ld l, a |
| 129 | + ld a, h |
| 130 | + adc a, 0 ; f = f + ddF_x |
| 131 | + ld h, a |
| 132 | + pop af |
| 133 | + ex af, af' |
| 134 | + |
| 135 | + push bc |
| 136 | + exx |
| 137 | + pop hl ; H'L' = Y, X |
| 138 | + |
| 139 | + ld a, d |
| 140 | + add a, h |
| 141 | + ld b, a ; B = y0 + y |
| 142 | + ld a, e |
| 143 | + add a, l |
| 144 | + ld c, a ; C = x0 + x |
| 145 | + call __CIRCLE_PLOT ; plot(x0 + x, y0 + y) |
| 146 | + |
| 147 | + ld a, d |
| 148 | + add a, h |
| 149 | + ld b, a ; B = y0 + y |
| 150 | + ld a, e |
| 151 | + sub l |
| 152 | + ld c, a ; C = x0 - x |
| 153 | + call __CIRCLE_PLOT ; plot(x0 - x, y0 + y) |
| 154 | + |
| 155 | + ld a, d |
| 156 | + sub h |
| 157 | + ld b, a ; B = y0 - y |
| 158 | + ld a, e |
| 159 | + add a, l |
| 160 | + ld c, a ; C = x0 + x |
| 161 | + call __CIRCLE_PLOT ; plot(x0 + x, y0 - y) |
| 162 | + |
| 163 | + ld a, d |
| 164 | + sub h |
| 165 | + ld b, a ; B = y0 - y |
| 166 | + ld a, e |
| 167 | + sub l |
| 168 | + ld c, a ; C = x0 - x |
| 169 | + call __CIRCLE_PLOT ; plot(x0 - x, y0 - y) |
| 170 | + |
| 171 | + ld a, d |
| 172 | + add a, l |
| 173 | + ld b, a ; B = y0 + x |
| 174 | + ld a, e |
| 175 | + add a, h |
| 176 | + ld c, a ; C = x0 + y |
| 177 | + call __CIRCLE_PLOT ; plot(x0 + y, y0 + x) |
| 178 | + |
| 179 | + ld a, d |
| 180 | + add a, l |
| 181 | + ld b, a ; B = y0 + x |
| 182 | + ld a, e |
| 183 | + sub h |
| 184 | + ld c, a ; C = x0 - y |
| 185 | + call __CIRCLE_PLOT ; plot(x0 - y, y0 + x) |
| 186 | + |
| 187 | + ld a, d |
| 188 | + sub l |
| 189 | + ld b, a ; B = y0 - x |
| 190 | + ld a, e |
| 191 | + add a, h |
| 192 | + ld c, a ; C = x0 + y |
| 193 | + call __CIRCLE_PLOT ; plot(x0 + y, y0 - x) |
| 194 | + |
| 195 | + ld a, d |
| 196 | + sub l |
| 197 | + ld b, a ; B = y0 - x |
| 198 | + ld a, e |
| 199 | + sub h |
| 200 | + ld c, a ; C = x0 + y |
| 201 | + call __CIRCLE_PLOT ; plot(x0 - y, y0 - x) |
| 202 | + |
| 203 | + exx |
| 204 | + jp __CIRCLE_LOOP |
201 | 205 |
|
202 | 206 |
|
203 | 207 |
|
204 | 208 | __CIRCLE_PLOT: |
205 | | - ; Plots a point of the circle, preserving HL and DE |
206 | | - push hl |
207 | | - push de |
208 | | - call __PLOT |
209 | | - pop de |
210 | | - pop hl |
211 | | - ret |
212 | | - |
213 | | - ENDP |
| 209 | + ; Plots a point of the circle, preserving HL and DE |
| 210 | + push hl |
| 211 | + push de |
| 212 | + call __PLOT |
| 213 | + pop de |
| 214 | + pop hl |
| 215 | + ret |
| 216 | + |
| 217 | + ENDP |
0 commit comments