/[projet1]/public/oric/routines/rasterization/CircleBench/circle.s
Defence Force logotype

Contents of /public/oric/routines/rasterization/CircleBench/circle.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 225 - (show annotations)
Tue Feb 2 20:25:29 2010 UTC (9 years, 7 months ago) by Chema
File size: 8424 byte(s)
Circle routine. Performs clipping and handles 16-bit coordinates for center and radius.
1 ;1186
2 ;1136
3 ;993
4 ;949
5 ;874
6 ;840
7
8
9 #include "params.h"
10
11 #define cypy tmp0
12 #define cymy cypy+1
13 #define cypx cypy+2
14 #define cymx cypy+3
15 #define cxpy cypy+4
16 #define cxmy cypy+5
17 #define cxpx cypy+6
18 #define cxmx cypy+7
19
20
21 /*
22 .zero
23 cypy .byt 0
24 cymy .byt 0
25 cypx .byt 0
26 cymx .byt 0
27 cxpy .byt 0
28 cxmy .byt 0
29 cxpx .byt 0
30 cxmx .byt 0
31 */
32
33
34 .zero
35
36 X1 .byt 0
37 Y1 .byt 0
38
39 ; Circle centre and radius
40 _CentreY .word 0
41 _CentreX .word 0
42 _Radius .word 0
43
44 ; Variables for circlepoints
45 sy .word 0
46 sx .word 0
47
48
49 xpr .word 0
50 xmr .word 0
51 ypr .word 0
52 ymr .word 0
53 p .word 0
54
55
56 .text
57
58 _circleMidpoint
59 .(
60
61 ; Check if circle is visible
62 ;; _CentreX + _Radius < lhs of screen fails
63 lda _CentreX
64 clc
65 adc _Radius
66 sta xpr
67 lda _CentreX+1
68 adc _Radius+1
69 sta xpr+1
70 .(
71 lda xpr
72 cmp #(CLIP_LEFT)
73 lda xpr+1
74 sbc #0
75 bvc ret ; N eor V
76 eor #$80
77 ret
78 .)
79 bpl next1
80 rts
81 next1
82 ;; x - size > rhs of screen fails
83 lda _CentreX
84 sec
85 sbc _Radius
86 sta xmr
87 lda _CentreX+1
88 sbc _Radius+1
89 sta xmr+1
90 .(
91 lda xmr
92 cmp #(CLIP_RIGHT-1)
93 lda xmr+1
94 sbc #0
95 bvc ret ; N eor V
96 eor #$80
97 ret
98 .)
99 bmi next2
100 rts
101 next2
102 ;; y + size < top of screen fails
103 lda _CentreY
104 clc
105 adc _Radius
106 sta ypr
107 lda _CentreY+1
108 adc _Radius+1
109 sta ypr+1
110 .(
111 lda ypr
112 cmp #(CLIP_TOP)
113 lda ypr+1
114 sbc #0
115 bvc ret ; N eor V
116 eor #$80
117 ret
118 .)
119
120 bpl next3
121 rts
122 next3
123 ;; y - size > bot of screen fails
124 lda _CentreY
125 sec
126 sbc _Radius
127 sta ymr
128 lda _CentreY+1
129 sbc _Radius+1
130 sta ymr+1
131 .(
132 lda ymr
133 cmp #(CLIP_BOTTOM-1)
134 lda ymr+1
135 sbc #0
136 bvc ret ; N eor V
137 eor #$80
138 ret
139 .)
140 bmi next4
141 rts
142 next4
143
144 drawit
145 ;x=0;y=radius
146 lda #0
147 sta sx
148 sta sx+1
149 lda _Radius
150 sta sy
151 lda _Radius+1
152 sta sy+1
153
154 ; p=1-radius
155 lda #1
156 sec
157 sbc _Radius
158 sta p
159 lda #0
160 sbc _Radius+1
161 sta p+1
162
163 draw
164 ; circlePoints (xCenter, yCenter, x, y);
165 jsr _circlePoints
166
167
168 ;while (x < y) {
169 ; x++;
170 ; if (p < 0)
171 ; p += 2 * x + 1;
172 ; else {
173 ; y--;
174 ; p += 2 * (x - y) + 1;
175 ; }
176 ; circlePoints (xCenter, yCenter, x, y);
177 ; }
178
179 loop
180 .(
181 lda sx
182 cmp sy
183 lda sx+1
184 sbc sy+1
185 bvc ret ; N eor V
186 eor #$80
187 ret
188 .)
189 bpl end
190
191 inc sx
192 bne noinc
193 inc sx+1
194 noinc
195
196 lda p+1
197 bpl positivep
198
199 lda sx
200 asl
201 sta tmp
202 lda sx+1
203 rol
204 sta tmp+1
205
206 inc tmp
207 bne noinc2
208 inc tmp+1
209 noinc2
210 lda p
211 clc
212 adc tmp
213 sta p
214 lda p+1
215 adc tmp+1
216 sta p+1
217
218 jsr _circlePoints
219 jmp loop
220
221 positivep
222
223 lda sy
224 bne nodec
225 dec sy+1
226 nodec
227 dec sy
228
229 lda sx
230 sec
231 sbc sy
232 sta tmp
233 lda sx+1
234 sbc sy+1
235 sta tmp+1
236
237 asl tmp
238 rol tmp+1
239
240 inc tmp
241 bne noinc3
242 inc tmp+1
243 noinc3
244
245 lda p
246 clc
247 adc tmp
248 sta p
249 lda p+1
250 adc tmp+1
251 sta p+1
252
253 jsr _circlePoints
254 jmp loop
255
256 end
257 rts
258 .)
259
260
261
262 _circlePoints
263 .(
264 ; Calculate _CentreY+y
265
266 lda _CentreY
267 clc
268 adc sy
269 tay
270 lda _CentreY+1
271 adc sy+1
272 sta Y1
273
274 ; Calculate _CentreX+x
275
276 lda _CentreX
277 clc
278 adc sx
279 tax
280 lda _CentreX+1
281 adc sx+1
282 sta X1
283 ora Y1
284 bne skip1
285 ;jsr plotpoint ; _CentreX+x,_CentreY+y
286
287 .(
288 cpx #(CLIP_RIGHT)
289 bcs end
290 cpx #(CLIP_LEFT)
291 bcc end
292 cpy #(CLIP_BOTTOM)
293 bcs end
294 cpy #(CLIP_TOP)
295 bcc end
296
297 plot
298 lda _HiresAddrLow,y ; 4
299 sta tmp0+0 ; 3
300 lda _HiresAddrHigh,y ; 4
301 sta tmp0+1 ; 3 => Total 14 cycles
302
303 sty _savy+1
304 ldy _TableDiv6,x
305 lda _TableBit6Reverse,x ; 4
306
307 ora (tmp0),y
308 sta (tmp0),y
309 _savy
310 ldy #0 ;SMC
311 end
312
313 .)
314
315
316 skip1
317
318 ; Calculate _CentreX-x
319
320 lda _CentreX
321 sec
322 sbc sx
323 tax
324 lda _CentreX+1
325 sbc sx+1
326 sta X1
327 ora Y1
328 bne skip2
329
330 ; jsr plotpoint ; _CentreX-x,_CentreY+y
331 .(
332 cpx #(CLIP_RIGHT)
333 bcs end
334 cpx #(CLIP_LEFT)
335 bcc end
336 cpy #(CLIP_BOTTOM)
337 bcs end
338 cpy #(CLIP_TOP)
339 bcc end
340
341 plot
342 lda _HiresAddrLow,y ; 4
343 sta tmp0+0 ; 3
344 lda _HiresAddrHigh,y ; 4
345 sta tmp0+1 ; 3 => Total 14 cycles
346
347 sty _savy+1
348 ldy _TableDiv6,x
349 lda _TableBit6Reverse,x ; 4
350
351 ora (tmp0),y
352 sta (tmp0),y
353 _savy
354 ldy #0 ;SMC
355 end
356
357 .)
358
359 skip2
360 ; Calculate _CentreY-y
361
362 lda _CentreY
363 sec
364 sbc sy
365 tay
366 lda _CentreY+1
367 sbc sy+1
368 sta Y1
369 ora X1
370 bne skip3
371
372 ; jsr plotpoint ; _CentreX-x,_CentreY-y
373 .(
374 cpx #(CLIP_RIGHT)
375 bcs end
376 cpx #(CLIP_LEFT)
377 bcc end
378 cpy #(CLIP_BOTTOM)
379 bcs end
380 cpy #(CLIP_TOP)
381 bcc end
382
383 plot
384 lda _HiresAddrLow,y ; 4
385 sta tmp0+0 ; 3
386 lda _HiresAddrHigh,y ; 4
387 sta tmp0+1 ; 3 => Total 14 cycles
388
389 sty _savy+1
390 ldy _TableDiv6,x
391 lda _TableBit6Reverse,x ; 4
392
393 ora (tmp0),y
394 sta (tmp0),y
395 _savy
396 ldy #0 ;SMC
397 end
398
399 .)
400
401 skip3
402 ; Calculate _CentreX+x
403
404 lda _CentreX
405 clc
406 adc sx
407 tax
408 lda _CentreX+1
409 adc sx+1
410 sta X1
411 ora Y1
412 bne skip4
413
414 ; jsr plotpoint ; _CentreX+x,_CentreY-y
415 .(
416 cpx #(CLIP_RIGHT)
417 bcs end
418 cpx #(CLIP_LEFT)
419 bcc end
420 cpy #(CLIP_BOTTOM)
421 bcs end
422 cpy #(CLIP_TOP)
423 bcc end
424
425 plot
426 lda _HiresAddrLow,y ; 4
427 sta tmp0+0 ; 3
428 lda _HiresAddrHigh,y ; 4
429 sta tmp0+1 ; 3 => Total 14 cycles
430
431 sty _savy+1
432 ldy _TableDiv6,x
433 lda _TableBit6Reverse,x ; 4
434
435 ora (tmp0),y
436 sta (tmp0),y
437 _savy
438 ldy #0 ;SMC
439 end
440
441 .)
442
443 skip4
444
445 ; Calculate _CentreY+x
446
447 lda _CentreY
448 clc
449 adc sx
450 tay
451 lda _CentreY+1
452 adc sx+1
453 sta Y1
454
455 ; Calculate _CentreX+y
456
457 lda _CentreX
458 clc
459 adc sy
460 tax
461 lda _CentreX+1
462 adc sy+1
463 sta X1
464 ora Y1
465 bne skip5
466
467 ; jsr plotpoint ; _CentreX+y,_CentreY+x
468 .(
469 cpx #(CLIP_RIGHT)
470 bcs end
471 cpx #(CLIP_LEFT)
472 bcc end
473 cpy #(CLIP_BOTTOM)
474 bcs end
475 cpy #(CLIP_TOP)
476 bcc end
477
478 plot
479 lda _HiresAddrLow,y ; 4
480 sta tmp0+0 ; 3
481 lda _HiresAddrHigh,y ; 4
482 sta tmp0+1 ; 3 => Total 14 cycles
483
484 sty _savy+1
485 ldy _TableDiv6,x
486 lda _TableBit6Reverse,x ; 4
487
488 ora (tmp0),y
489 sta (tmp0),y
490 _savy
491 ldy #0 ;SMC
492 end
493
494 .)
495
496 skip5
497 ; Calculate _CentreX-y
498 lda _CentreX
499 sec
500 sbc sy
501 tax
502 lda _CentreX+1
503 sbc sy+1
504 sta X1
505 ora Y1
506 bne skip6
507
508 ; jsr plotpoint ; _CentreX-y,_CentreY+x
509 .(
510 cpx #(CLIP_RIGHT)
511 bcs end
512 cpx #(CLIP_LEFT)
513 bcc end
514 cpy #(CLIP_BOTTOM)
515 bcs end
516 cpy #(CLIP_TOP)
517 bcc end
518
519 plot
520 lda _HiresAddrLow,y ; 4
521 sta tmp0+0 ; 3
522 lda _HiresAddrHigh,y ; 4
523 sta tmp0+1 ; 3 => Total 14 cycles
524
525 sty _savy+1
526 ldy _TableDiv6,x
527 lda _TableBit6Reverse,x ; 4
528
529 ora (tmp0),y
530 sta (tmp0),y
531 _savy
532 ldy #0 ;SMC
533 end
534
535 .)
536
537 skip6
538
539 ; Calculate _CentreY-x
540
541 lda _CentreY
542 sec
543 sbc sx
544 tay
545 lda _CentreY+1
546 sbc sx+1
547 sta Y1
548 ora X1
549 bne skip7
550
551 ; jsr plotpoint ; _CentreX-y,_CentreY-x
552 .(
553 cpx #(CLIP_RIGHT)
554 bcs end
555 cpx #(CLIP_LEFT)
556 bcc end
557 cpy #(CLIP_BOTTOM)
558 bcs end
559 cpy #(CLIP_TOP)
560 bcc end
561
562 plot
563 lda _HiresAddrLow,y ; 4
564 sta tmp0+0 ; 3
565 lda _HiresAddrHigh,y ; 4
566 sta tmp0+1 ; 3 => Total 14 cycles
567
568 sty _savy+1
569 ldy _TableDiv6,x
570 lda _TableBit6Reverse,x ; 4
571
572 ora (tmp0),y
573 sta (tmp0),y
574 _savy
575 ldy #0 ;SMC
576 end
577
578 .)
579
580 skip7
581 ; Calculate _CentreX+y
582
583 lda _CentreX
584 clc
585 adc sy
586 tax
587 lda _CentreX+1
588 adc sy+1
589 sta X1
590 ora Y1
591 bne skip8
592
593 ; jmp plotpoint ; _CentreX+y,_CentreY-x
594 .(
595 cpx #(CLIP_RIGHT)
596 bcs end
597 cpx #(CLIP_LEFT)
598 bcc end
599 cpy #(CLIP_BOTTOM)
600 bcs end
601 cpy #(CLIP_TOP)
602 bcc end
603
604 plot
605 lda _HiresAddrLow,y ; 4
606 sta tmp0+0 ; 3
607 lda _HiresAddrHigh,y ; 4
608 sta tmp0+1 ; 3 => Total 14 cycles
609
610 sty _savy+1
611 ldy _TableDiv6,x
612 lda _TableBit6Reverse,x ; 4
613
614 ora (tmp0),y
615 sta (tmp0),y
616 _savy
617 ldy #0 ;SMC
618 end
619
620 .)
621
622 skip8
623 rts
624 .)
625
626
627
628
629
630
631
632
633

  ViewVC Help
Powered by ViewVC 1.1.26