/[projet1]/users/chema/TINE/oobj3d/circle.s
Defence Force logotype

Contents of /users/chema/TINE/oobj3d/circle.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 223 - (show annotations)
Mon Feb 1 22:31:07 2010 UTC (10 years, 3 months ago) by Chema
File size: 12874 byte(s)
Some more minor changes. Totally removed the TRANSPORTER ship, as it was too complex. Added new version of LineDraw.s, with still minor glitches.

Scratched some cycles from the circle routine.
1 #include "params.h"
2
3 #define cypy tmp0
4 #define cymy cypy+1
5 #define cypx cypy+2
6 #define cymx cypy+3
7 #define cxpy cypy+4
8 #define cxmy cypy+5
9 #define cxpx cypy+6
10 #define cxmx cypy+7
11
12 /*.zero
13 clipme .byt 0
14 */
15
16 #define clipme plotpoint+1
17
18 /*
19 .zero
20 cypy .byt 0
21 cymy .byt 0
22 cypx .byt 0
23 cymx .byt 0
24 cxpy .byt 0
25 cxmy .byt 0
26 cxpx .byt 0
27 cxmx .byt 0
28 */
29
30
31 .zero
32
33 ; Circle centre and radius
34 cy .word 0
35 cx .word 0
36 rad .word 0
37
38 .text
39
40
41 #ifdef FILLEDPOLYS
42
43 _circlePoints
44 .(
45
46 ; Calculate cy+y
47
48 lda cy
49 clc
50 adc sy
51 sta op1
52 lda cy+1
53 adc sy+1
54 sta op1+1
55
56 jsr clipbt
57 sta cypy
58
59
60 ; Calculate cy-y
61
62 lda cy
63 sec
64 sbc sy
65 sta op1
66 lda cy+1
67 sbc sy+1
68 sta op1+1
69
70 jsr clipbt
71 sta cymy
72
73 ; Calculate cy+x
74
75 lda cy
76 clc
77 adc sx
78 sta op1
79 lda cy+1
80 adc sx+1
81 sta op1+1
82
83 jsr clipbt
84 sta cypx
85
86 ; Calculate cy-x
87
88 lda cy
89 sec
90 sbc sx
91 sta op1
92 lda cy+1
93 sbc sx+1
94 sta op1+1
95
96 jsr clipbt
97 sta cymx
98
99
100
101 ; Calculate cx+y
102
103 lda cx
104 clc
105 adc sy
106 sta op1
107 lda cx+1
108 adc sy+1
109 sta op1+1
110
111 jsr cliplr
112 sta cxpy
113
114
115 ; Calculate cx-y
116
117 lda cx
118 sec
119 sbc sy
120 sta op1
121 lda cx+1
122 sbc sy+1
123 sta op1+1
124
125 jsr cliplr
126 sta cxmy
127
128 ; Calculate cx+x
129
130 lda cx
131 clc
132 adc sx
133 sta op1
134 lda cx+1
135 adc sx+1
136 sta op1+1
137
138 jsr cliplr
139 sta cxpx
140
141 ; Calculate cx-x
142
143 lda cx
144 sec
145 sbc sx
146 sta op1
147 lda cx+1
148 sbc sx+1
149 sta op1+1
150
151 jsr cliplr
152 sta cxmx
153
154 ; Now fill the MaxMin array
155
156 ;MaxX[cy+y]=(cx+x>CLIP_RIGHT?CLIP_RIGHT:cx+x);
157 ;MinX[cy+y]=(cx-x<CLIP_LEFT?CLIP_LEFT:cx-x);
158 ;MaxX[cy-y]=(cx+x>CLIP_RIGHT?CLIP_RIGHT:cx+x);
159 ;MinX[cy-y]=(cx-x<CLIP_LEFT?CLIP_LEFT:cx-x);
160 ;MaxX[cy+x]=(cx+y>CLIP_RIGHT?CLIP_RIGHT:cx+y);
161 ;MinX[cy+x]=(cx-y<CLIP_LEFT?CLIP_LEFT:cx-y);
162 ;MaxX[cy-x]=(cx+y>CLIP_RIGHT?CLIP_RIGHT:cx+y);
163 ;MinX[cy-x]=(cx-y<CLIP_LEFT?CLIP_LEFT:cx-y);
164
165 ldx cypy
166 lda cxpx
167 sta _MaxX,x
168 lda cxmx
169 sta _MinX,x
170
171 ldx cymy
172 lda cxpx
173 sta _MaxX,x
174 lda cxmx
175 sta _MinX,x
176
177 ldx cypx
178 lda cxpy
179 sta _MaxX,x
180 lda cxmy
181 sta _MinX,x
182
183 ldx cymx
184 lda cxpy
185 sta _MaxX,x
186 lda cxmy
187 sta _MinX,x
188
189
190 rts
191
192
193 .)
194
195
196 clipbt
197 .(
198 ; Compare with CLIP_BOTTOM and CLIP_TOP
199 lda #(CLIP_BOTTOM)
200 sta op2
201 lda #0
202 sta op2+1
203
204 jsr cmp16
205
206 bmi cont1
207 lda #(CLIP_BOTTOM)
208 rts
209
210 cont1
211 lda #(CLIP_TOP)
212 sta op2
213 jsr cmp16
214 bpl cont2
215 lda #(CLIP_TOP)
216 rts
217 cont2
218 lda op1
219 rts
220 .)
221
222 cliplr
223 .(
224 ; Compare with CLIP_LEFT and CLIP_RIGHT
225 lda #(CLIP_RIGHT)
226 sta op2
227 lda #0
228 sta op2+1
229
230 jsr cmp16
231
232 bmi cont1
233 lda #(CLIP_RIGHT)
234 rts
235
236 cont1
237 lda #(CLIP_LEFT)
238 sta op2
239 jsr cmp16
240 bpl cont2
241 lda #(CLIP_LEFT)
242 rts
243
244 cont2
245 lda op1
246 rts
247 .)
248
249
250
251 ; Variables for circlepoints
252 sy .word 0
253 sx .word 0
254
255
256 _circleMidpoint
257 .(
258 ; Check if circle is visible
259 ;; cx + rad < lhs of screen fails
260 lda #CLIP_LEFT
261 sta op2
262 lda #0
263 sta op2+1
264 lda cx
265 clc
266 adc rad
267 sta op1
268 lda cx+1
269 adc rad+1
270 sta op1+1
271 jsr cmp16
272 bpl next1
273 rts
274 next1
275 ;; x - size > rhs of screen fails
276 lda #CLIP_RIGHT-1
277 sta op2
278 lda #0
279 sta op2+1
280 lda cx
281 sec
282 sbc rad
283 sta op1
284 lda cx+1
285 sbc rad+1
286 sta op1+1
287 jsr cmp16
288 bmi next2
289 rts
290 next2
291 ;; y + size < top of screen fails
292 lda #CLIP_TOP
293 sta op2
294 lda #0
295 sta op2+1
296 lda cy
297 clc
298 adc rad
299 sta op1
300 lda cy+1
301 adc rad+1
302 sta op1+1
303 jsr cmp16
304 bpl next3
305 rts
306 next3
307 ;; y - size > bot of screen fails
308 lda #CLIP_BOTTOM-1
309 sta op2
310 lda #0
311 sta op2+1
312 lda cy
313 sec
314 sbc rad
315 sta op1
316 lda cy+1
317 sbc rad+1
318 sta op1+1
319 jsr cmp16
320 bmi next4
321 rts
322 next4
323
324 ;x=0;y=radius
325 lda #0
326 sta sx
327 sta sx+1
328 lda rad
329 sta sy
330 lda rad+1
331 sta sy+1
332
333 ; p=1-radius
334 lda #1
335 sec
336 sbc rad
337 sta p
338 lda #0
339 sbc rad+1
340 sta p+1
341
342 ; PolyY0=yCenter-radius
343 lda cy
344 sec
345 sbc rad
346 sta op1
347 lda cy+1
348 sbc rad+1
349 sta op1+1
350 jsr clipbt
351 sta _PolyY0
352
353 ; PolyY1=yCenter+radius+1
354
355 lda cy
356 sec
357 adc rad
358 sta op1
359 lda cy+1
360 adc rad+1
361 sta op1+1
362 jsr clipbt
363 sta _PolyY1
364
365 ; If outside, then end
366
367 lda _PolyY0
368 cmp _PolyY1
369 bcc draw
370 lda #0
371 sta _PolyY0
372 sta _PolyY1
373 rts
374 draw
375 ; circlePoints (xCenter, yCenter, x, y);
376 jsr _circlePoints
377
378
379 ;while (x < y) {
380 ; x++;
381 ; if (p < 0)
382 ; p += 2 * x + 1;
383 ; else {
384 ; y--;
385 ; p += 2 * (x - y) + 1;
386 ; }
387 ; circlePoints (xCenter, yCenter, x, y);
388 ; }
389
390 loop
391 lda sx
392 sta op1
393 lda sx+1
394 sta op1+1
395 lda sy
396 sta op2
397 lda sy+1
398 sta op2+1
399 jsr cmp16
400 bpl end
401
402
403 inc sx
404 bne noinc
405 inc sx+1
406 noinc
407
408 lda p+1
409 bpl positivep
410
411 lda sx
412 asl
413 sta tmp
414 lda sx+1
415 rol
416 sta tmp+1
417
418 inc tmp
419 bne noinc2
420 inc tmp+1
421 noinc2
422 lda p
423 clc
424 adc tmp
425 sta p
426 lda p+1
427 adc tmp+1
428 sta p+1
429
430 jsr _circlePoints
431 jmp loop
432
433 positivep
434
435 lda sy
436 bne nodec
437 dec sy+1
438 nodec
439 dec sy
440
441 lda sx
442 sec
443 sbc sy
444 sta tmp
445 lda sx+1
446 sbc sy+1
447 sta tmp+1
448
449 asl tmp
450 rol tmp+1
451
452 inc tmp
453 bne noinc3
454 inc tmp+1
455 noinc3
456
457 lda p
458 clc
459 adc tmp
460 sta p
461 lda p+1
462 adc tmp+1
463 sta p+1
464
465 jsr _circlePoints
466 jmp loop
467
468 end
469
470 jsr _FillTablesASM
471 rts
472
473
474 p .word 0
475
476 .)
477
478
479 #else
480 _circlePoints
481 .(
482 ; Calculate cy+y
483
484 lda cy
485 clc
486 adc sy
487 sta Y1
488 lda cy+1
489 adc sy+1
490 ;bne skip2
491 sta Y1+1
492
493 ; Calculate cx+x
494
495 lda cx
496 clc
497 adc sx
498 sta X1
499 lda cx+1
500 adc sx+1
501 ;bne skip1
502 sta X1+1
503
504 jsr plotpoint ; cx+x,cy+y
505 skip1
506
507 ; Calculate cx-x
508
509 lda cx
510 sec
511 sbc sx
512 sta X1
513 lda cx+1
514 sbc sx+1
515 ;bne skip3
516 sta X1+1
517
518 jsr plotpoint ; cx-x,cy+y
519 skip2
520 ; Calculate cy-y
521
522 lda cy
523 sec
524 sbc sy
525 sta Y1
526 lda cy+1
527 sbc sy+1
528 ;bne skip4
529 sta Y1+1
530
531 jsr plotpoint ; cx-x,cy-y
532 skip3
533 ; Calculate cx+x
534
535 lda cx
536 clc
537 adc sx
538 sta X1
539 lda cx+1
540 adc sx+1
541 ;bne skip4
542 sta X1+1
543
544 jsr plotpoint ; cx+x,cy-y
545 skip4
546
547 ; Calculate cy+x
548
549 lda cy
550 clc
551 adc sx
552 sta Y1
553 lda cy+1
554 adc sx+1
555 ;bne skip6
556 sta Y1+1
557
558 ; Calculate cx+y
559
560 lda cx
561 clc
562 adc sy
563 sta X1
564 lda cx+1
565 adc sy+1
566 ;bne skip5
567 sta X1+1
568
569 jsr plotpoint ; cx+y,cy+x
570 skip5
571 ; Calculate cx-y
572
573 lda cx
574 sec
575 sbc sy
576 sta X1
577 lda cx+1
578 sbc sy+1
579 ;bne skip7
580 sta X1+1
581
582 jsr plotpoint ; cx-y,cy+x
583 skip6
584
585 ; Calculate cy-x
586
587 lda cy
588 sec
589 sbc sx
590 sta Y1
591 lda cy+1
592 sbc sx+1
593 ;bne skip8
594 sta Y1+1
595
596 jsr plotpoint ; cx-y,cy-x
597 skip7
598 ; Calculate cx+y
599
600 lda cx
601 clc
602 adc sy
603 sta X1
604 lda cx+1
605 adc sy+1
606 ;bne skip8
607 sta X1+1
608
609 jmp plotpoint ; cx+y,cy-x
610 skip8
611 rts
612 .)
613
614 #ifdef 0
615 plotpoint
616 .(
617 lda #0 ;SMC
618 bne plot
619 .(
620 lda X1
621 cmp #(CLIP_RIGHT)
622 lda X1+1
623 sbc #0
624 bvc ret ; N eor V
625 eor #$80
626 ret
627 .)
628 bpl end
629 .(
630 lda X1
631 cmp #(CLIP_LEFT)
632 lda X1+1
633 sbc #0
634 bvc ret ; N eor V
635 eor #$80
636 ret
637 .)
638 bmi end
639 .(
640 lda Y1
641 +patch_circleclip
642 cmp #(CLIP_BOTTOM)
643 lda Y1+1
644 sbc #0
645 bvc ret ; N eor V
646 eor #$80
647 ret
648 .)
649 bpl end
650 .(
651 lda Y1
652 cmp #(CLIP_TOP)
653 lda Y1+1
654 sbc #0
655 bvc ret ; N eor V
656 eor #$80
657 ret
658 .)
659 bmi end
660 plot
661 ldx X1
662 ldy Y1
663
664 ;jsr pixel_address
665
666 lda _HiresAddrLow,y ; 4
667 sta tmp0+0 ; 3
668 lda _HiresAddrHigh,y ; 4
669 sta tmp0+1 ; 3 => Total 14 cycles
670
671 ldy _TableDiv6,x
672 lda _TableBit6Reverse,x ; 4
673
674
675 ora (tmp0),y
676 sta (tmp0),y
677
678 end
679 rts
680
681 .)
682 #endif
683
684 plotpoint
685 .(
686 lda #0 ;SMC
687 bne plot
688
689 lda X1+1
690 ora Y1+1
691 bne end
692
693 lda X1
694 cmp #(CLIP_RIGHT)
695 bcs end
696 cmp #(CLIP_LEFT)
697 bcc end
698
699 lda Y1
700 +patch_circleclip
701 cmp #(CLIP_BOTTOM)
702 bcs end
703 cmp #(CLIP_TOP)
704 bcc end
705 plot
706 ldx X1
707 ldy Y1
708
709 ;jsr pixel_address
710
711 lda _HiresAddrLow,y ; 4
712 sta tmp0+0 ; 3
713 lda _HiresAddrHigh,y ; 4
714 sta tmp0+1 ; 3 => Total 14 cycles
715
716 ldy _TableDiv6,x
717 lda _TableBit6Reverse,x ; 4
718
719
720 ora (tmp0),y
721 sta (tmp0),y
722
723 end
724 rts
725
726 .)
727
728
729
730
731 .zero
732 ; Variables for circlepoints
733 sy .word 0
734 sx .word 0
735
736
737 xpr .word 0
738 xmr .word 0
739 ypr .word 0
740 ymr .word 0
741 p .word 0
742
743 .text
744
745 _circleMidpoint
746 .(
747
748 ; Check if circle is visible
749 ;; cx + rad < lhs of screen fails
750 lda cx
751 clc
752 adc rad
753 sta xpr
754 lda cx+1
755 adc rad+1
756 sta xpr+1
757 .(
758 lda xpr
759 cmp #(CLIP_LEFT)
760 lda xpr+1
761 sbc #0
762 bvc ret ; N eor V
763 eor #$80
764 ret
765 .)
766 bpl next1
767 rts
768 next1
769 ;; x - size > rhs of screen fails
770 lda cx
771 sec
772 sbc rad
773 sta xmr
774 lda cx+1
775 sbc rad+1
776 sta xmr+1
777 .(
778 lda xmr
779 cmp #(CLIP_RIGHT-1)
780 lda xmr+1
781 sbc #0
782 bvc ret ; N eor V
783 eor #$80
784 ret
785 .)
786 bmi next2
787 rts
788 next2
789 ;; y + size < top of screen fails
790 lda cy
791 clc
792 adc rad
793 sta ypr
794 lda cy+1
795 adc rad+1
796 sta ypr+1
797 .(
798 lda ypr
799 cmp #(CLIP_TOP)
800 lda ypr+1
801 sbc #0
802 bvc ret ; N eor V
803 eor #$80
804 ret
805 .)
806
807 bpl next3
808 rts
809 next3
810 ;; y - size > bot of screen fails
811 lda cy
812 sec
813 sbc rad
814 sta ymr
815 lda cy+1
816 sbc rad+1
817 sta ymr+1
818 .(
819 lda ymr
820 cmp #(CLIP_BOTTOM-1)
821 lda ymr+1
822 sbc #0
823 bvc ret ; N eor V
824 eor #$80
825 ret
826 .)
827 bmi next4
828 rts
829 next4
830
831 ; Check if clipping is needed
832 lda #1
833 sta clipme
834
835 ;cx+r<CLIP_RIGHT
836 .(
837 lda xpr
838 cmp #(CLIP_RIGHT-1)
839 lda xpr+1
840 sbc #0
841 bvc ret ; N eor V
842 eor #$80
843 ret
844 .)
845 bmi nextb1
846 lda #0
847 sta clipme
848 beq drawit
849 nextb1
850
851 ;cx-r>CLIP_LEFT
852 .(
853 lda xmr
854 cmp #(CLIP_LEFT)
855 lda xmr+1
856 sbc #0
857 bvc ret ; N eor V
858 eor #$80
859 ret
860 .)
861 bpl nextb2
862 lda #0
863 sta clipme
864 beq drawit
865 nextb2
866
867
868 ;cy+r<CLIP_BOTTOM
869 .(
870 lda ypr
871 cmp #(CLIP_BOTTOM-1)
872 lda ypr+1
873 sbc #0
874 bvc ret ; N eor V
875 eor #$80
876 ret
877 .)
878 bmi nextb3
879 lda #0
880 sta clipme
881 beq drawit
882 nextb3
883
884 ;cy-r>CLIP_TOP
885 .(
886 lda ymr
887 cmp #(CLIP_TOP)
888 lda ymr+1
889 sbc #0
890 bvc ret ; N eor V
891 eor #$80
892 ret
893 .)
894 bpl drawit
895 lda #0
896 sta clipme
897
898 drawit
899 ;x=0;y=radius
900 lda #0
901 sta sx
902 sta sx+1
903 lda rad
904 sta sy
905 lda rad+1
906 sta sy+1
907
908 ; p=1-radius
909 lda #1
910 sec
911 sbc rad
912 sta p
913 lda #0
914 sbc rad+1
915 sta p+1
916
917 draw
918 ; circlePoints (xCenter, yCenter, x, y);
919 jsr _circlePoints
920
921
922 ;while (x < y) {
923 ; x++;
924 ; if (p < 0)
925 ; p += 2 * x + 1;
926 ; else {
927 ; y--;
928 ; p += 2 * (x - y) + 1;
929 ; }
930 ; circlePoints (xCenter, yCenter, x, y);
931 ; }
932
933 loop
934 .(
935 lda sx
936 cmp sy
937 lda sx+1
938 sbc sy+1
939 bvc ret ; N eor V
940 eor #$80
941 ret
942 .)
943 bpl end
944
945 inc sx
946 bne noinc
947 inc sx+1
948 noinc
949
950 lda p+1
951 bpl positivep
952
953 lda sx
954 asl
955 sta tmp
956 lda sx+1
957 rol
958 sta tmp+1
959
960 inc tmp
961 bne noinc2
962 inc tmp+1
963 noinc2
964 lda p
965 clc
966 adc tmp
967 sta p
968 lda p+1
969 adc tmp+1
970 sta p+1
971
972 jsr _circlePoints
973 jmp loop
974
975 positivep
976
977 lda sy
978 bne nodec
979 dec sy+1
980 nodec
981 dec sy
982
983 lda sx
984 sec
985 sbc sy
986 sta tmp
987 lda sx+1
988 sbc sy+1
989 sta tmp+1
990
991 asl tmp
992 rol tmp+1
993
994 inc tmp
995 bne noinc3
996 inc tmp+1
997 noinc3
998
999 lda p
1000 clc
1001 adc tmp
1002 sta p
1003 lda p+1
1004 adc tmp+1
1005 sta p+1
1006
1007 jsr _circlePoints
1008 jmp loop
1009
1010 end
1011 rts
1012 .)
1013
1014
1015
1016
1017
1018
1019 #endif //FILLEDPOLYS
1020
1021
1022
1023
1024

  ViewVC Help
Powered by ViewVC 1.1.26