/[projet1]/public/oric/routines/rasterization/polybench/filler.s
Defence Force logotype

Contents of /public/oric/routines/rasterization/polybench/filler.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1246 - (show annotations)
Sat Dec 13 15:59:17 2014 UTC (5 years, 3 months ago) by dbug
File size: 13090 byte(s)
Used the direction test to compute the width        | 76.9%|2977 2577 2708 2706 2856 2878 2806
1
2 /*
3 *= $50
4
5 ap .dsb 2
6 fp .dsb 2
7 sp .dsb 2
8 tmp0 .dsb 2
9 tmp1 .dsb 2
10 tmp2 .dsb 2
11 tmp3 .dsb 2
12 tmp4 .dsb 2
13 tmp5 .dsb 2
14 tmp6 .dsb 2
15 tmp7 .dsb 2
16 op1 .dsb 2
17 op2 .dsb 2
18 tmp .dsb 2
19 reg0 .dsb 2
20 reg1 .dsb 2
21 reg2 .dsb 2
22 reg3 .dsb 2
23 reg4 .dsb 2
24 reg5 .dsb 2
25 reg6 .dsb 2
26 reg7 .dsb 2
27 */
28
29 .zero
30
31 *= tmp1
32
33 _DY .dsb 1 ; tmp1
34 _DX .dsb 1 ; tmp2
35 _E .dsb 2 ; tmp3
36
37 *= tmp1
38
39 StartOffset .dsb 1 ; tmp1
40 _S1 .dsb 1
41 LeftByte .dsb 1 ; tmp2
42 RightByte .dsb 1
43 _NEW .dsb 1 ; tmp3
44 LinePattern .dsb 1
45
46 *= tmp4
47
48 _X0 .dsb 1
49 _Y0 .dsb 1
50 _X1 .dsb 1
51 _Y1 .dsb 1
52 _FlagFirst .dsb 1
53 _OddEvenFlag .dsb 1
54 _PolyY0 .dsb 1
55 _PolyY1 .dsb 1
56
57 .text
58
59
60 #define COLOR_PAPER 4
61 #define COLOR_INK 3
62
63
64 .dsb 256-(*&255)
65
66
67
68
69 _FillTablesASM
70 ;
71 ; Patch the code that detects odd or even lines
72 ;
73 .(
74 ldx #$F0 ; BEQ
75 lda _OddEvenFlag
76 bne skip
77 ldx #$D0 ; BNE
78 skip
79 stx __patch_oddevenflag
80 .)
81
82 ;
83 ; Compute the adress of the pattern
84 ; No need to compute the highbyte since we have less than 256 bytes of patterns and the table is alligned on a page boundary
85 ;
86 lda _CurrentPattern
87 sta patch_pattern+1
88
89 ;
90 ; Compute the screen start adress
91 ;
92 ldy _PolyY0
93 lda _ScreenPtrLow,y
94 sta tmp0+0
95 lda _ScreenPtrHigh,y
96 sta tmp0+1
97
98 ldy _PolyY0
99 draw_loop_y
100 ;
101 ; Start Y
102 ;
103 tya
104 and #1
105 __patch_oddevenflag
106 bne draw_end ; bne=$D0 beq=$F0
107
108 ;
109 ; Compute the pattern value
110 ;
111 tya
112 and #7
113 tax
114 patch_pattern
115 lda _Pattern,x
116 sta LinePattern
117
118 ;
119 ; Compute the position in the line
120 ;
121 ldx _MinX,y ; Get X0
122 lda _Mod6Left,x ; X offset 0
123 sta LeftByte
124 lda _Div6,x ; X byte 0
125 sta StartOffset
126
127 ldx _MaxX,y ; Get X1
128 ldy StartOffset ; Start offset
129 lda _Mod6Right,x ; X offset 1
130 sta RightByte
131
132 sec
133 lda _Div6,x ; X byte 1
134 sbc StartOffset
135 beq draw_one
136
137 draw_multiple
138 ;
139 ; X=Nb to draw
140 ;
141 tax ; Nb to draw
142 dex
143
144 lda LeftByte
145 eor #255
146 and (tmp0),y
147 sta _NEW
148
149 lda LeftByte
150 and LinePattern
151 ora _NEW
152
153 sta (tmp0),y
154 iny
155
156 ; ----- 40*3=120
157
158 lda UnrolledOffset,x
159 sta __patch_jump+1
160 lda LinePattern
161 __patch_jump
162 jmp UnrolledMultipleDraw
163
164 draw_one
165 lda LeftByte ; compute the mask by intersecting the left and right masks
166 and RightByte
167 tax ; Store the mask
168 eor #255 ; Need to inverse the mask to "keep" the original parts of the screen
169 and (tmp0),y ; Intersect with the scren value
170 sta _NEW ; Save the masked out screen value
171
172 txa ; Get the mask
173 and LinePattern ; Apply the pattern
174 ora _NEW ; Add the original screen value
175
176 sta (tmp0),y ; Write back to screen
177
178 EndMultipleDrawLoop
179 draw_end
180 ;
181 ; End Y
182 ;
183 ;
184 ; Update screen ptr
185 ;
186 .(
187 clc ; 2
188 lda tmp0+0 ; 3
189 adc #40 ; 2
190 sta tmp0+0 ; 3
191 bcc skip ; 2/3
192 inc tmp0+1 ; 5
193 skip
194 ; --------------> 17/18
195 .)
196
197 ;
198 ; Update Y position and local mini/max
199 ;
200 inc _PolyY0
201 ldy _PolyY0
202
203 lda #239
204 sta _MinX-1,y
205
206 lda #0
207 sta _MaxX-1,y
208
209 cpy _PolyY1
210 ;bcs end_draw
211 ;jmp draw_loop_y
212 bcc draw_loop_y
213
214 end_draw
215 ;
216 ; Clear Global Y mini/maxi
217 ;
218 lda #200
219 sta _PolyY0
220 lda #0
221 sta _PolyY1
222 sta _FlagFirst
223 rts
224
225
226 .dsb 256-(*&255)
227
228 UnrolledMultipleDraw
229 ; 40 instructions
230 sta (tmp0),y ; 2 bytes
231 iny ; 1 byte
232 sta (tmp0),y
233 iny
234 sta (tmp0),y
235 iny
236 sta (tmp0),y
237 iny
238 sta (tmp0),y
239 iny
240
241 sta (tmp0),y
242 iny
243 sta (tmp0),y
244 iny
245 sta (tmp0),y
246 iny
247 sta (tmp0),y
248 iny
249 sta (tmp0),y
250 iny
251
252 sta (tmp0),y
253 iny
254 sta (tmp0),y
255 iny
256 sta (tmp0),y
257 iny
258 sta (tmp0),y
259 iny
260 sta (tmp0),y
261 iny
262
263 sta (tmp0),y
264 iny
265 sta (tmp0),y
266 iny
267 sta (tmp0),y
268 iny
269 sta (tmp0),y
270 iny
271 sta (tmp0),y
272 iny
273
274 sta (tmp0),y
275 iny
276 sta (tmp0),y
277 iny
278 sta (tmp0),y
279 iny
280 sta (tmp0),y
281 iny
282 sta (tmp0),y
283 iny
284
285 sta (tmp0),y
286 iny
287 sta (tmp0),y
288 iny
289 sta (tmp0),y
290 iny
291 sta (tmp0),y
292 iny
293 sta (tmp0),y
294 iny
295
296 sta (tmp0),y
297 iny
298 sta (tmp0),y
299 iny
300 sta (tmp0),y
301 iny
302 sta (tmp0),y
303 iny
304 sta (tmp0),y
305 iny
306
307 sta (tmp0),y
308 iny
309 sta (tmp0),y
310 iny
311 sta (tmp0),y
312 iny
313 sta (tmp0),y
314 iny
315 sta (tmp0),y
316 iny
317
318 draw_x_final
319 lda RightByte
320 eor #255
321 and (tmp0),y
322 sta _NEW
323
324 lda RightByte
325 and LinePattern
326 ora _NEW
327
328 sta (tmp0),y
329
330 jmp EndMultipleDrawLoop ; 3 cycles
331
332 UnrolledOffset
333 .byt 3*40
334
335 .byt 3*39
336 .byt 3*38
337 .byt 3*37
338 .byt 3*36
339 .byt 3*35
340 .byt 3*34
341 .byt 3*33
342 .byt 3*32
343 .byt 3*31
344 .byt 3*30
345
346 .byt 3*29
347 .byt 3*28
348 .byt 3*27
349 .byt 3*26
350 .byt 3*25
351 .byt 3*24
352 .byt 3*23
353 .byt 3*22
354 .byt 3*21
355 .byt 3*20
356
357 .byt 3*19
358 .byt 3*18
359 .byt 3*17
360 .byt 3*16
361 .byt 3*15
362 .byt 3*14
363 .byt 3*13
364 .byt 3*12
365 .byt 3*11
366 .byt 3*10
367
368 .byt 3*9
369 .byt 3*8
370 .byt 3*7
371 .byt 3*6
372 .byt 3*5
373 .byt 3*4
374 .byt 3*3
375 .byt 3*2
376 .byt 3*1
377 .byt 3*0
378
379
380
381 .dsb 256-(*&255)
382
383
384
385
386 _AddLineASM
387 lda _Y0
388 cmp _Y1
389 bcc no_swap_values
390 bne swap_values
391
392 ; Null height, so, we leave
393 rts
394
395 swap_values
396
397 ; Swap X's
398 ldx _X0
399 ldy _X1
400 stx _X1
401 sty _X0
402
403 ; Swap Y's
404 ldx _Y0
405 ldy _Y1
406 stx _Y1
407 sty _Y0
408
409 no_swap_values
410 ; Store height
411 lda _Y1
412 cmp _PolyY1
413 bcc no_bottom
414 sta _PolyY1
415 no_bottom
416 sec
417 sbc _Y0
418 sta _DY
419
420 lda _Y0
421 cmp _PolyY0
422 bcs no_top
423 sta _PolyY0
424 no_top
425
426 ; Init E
427 lda #0
428 sta _E
429 sta _E+1
430
431 ;
432 ; Common inits
433 ;
434 ldy _Y0
435 ldx _X0
436
437 txa
438 sec
439 sbc _X1 ; Compute line width
440 bcs main_to_left
441
442 ; Negate to get the positive value
443 eor #$ff
444 adc #1
445 sta _DX
446
447 main_to_right
448 .(
449 lda _FlagFirst
450 beq loop_first_to_right
451
452 loop_to_right
453 txa
454
455 cmp _MinX,y
456 bcs no_min_1
457 sta _MinX,y
458 no_min_1
459
460 cmp _MaxX,y
461 bcc no_max_1
462 sta _MaxX,y
463 clc
464 no_max_1
465
466 lda _E
467 adc _DX
468 sta _E
469 lda _E+1
470 adc #0
471 sta _E+1
472 bmi end_loop_e_left
473 loop_e_left
474 inx
475
476 .(
477 ;sec
478 lda _E
479 sbc _DY
480 sta _E
481 lda _E+1
482 sbc #0
483 sta _E+1
484 .)
485 bpl loop_e_left
486
487 end_loop_e_left
488 iny
489 cpy _Y1
490 bcc loop_to_right
491 rts
492 .)
493
494 main_to_left
495 .(
496 ; Init width
497 sta _DX
498
499 lda _FlagFirst
500 beq loop_first_to_left
501
502 loop_to_left
503 txa
504
505 cmp _MinX,y
506 bcs no_min_2
507 sta _MinX,y
508 clc
509 no_min_2
510
511 cmp _MaxX,y
512 bcc no_max_2
513 sta _MaxX,y
514 no_max_2
515
516 lda _E
517 adc _DX
518 sta _E
519 lda _E+1
520 adc #0
521 sta _E+1
522 bmi end_loop_e_right
523 loop_e_right
524 dex
525 .(
526 ;sec
527 lda _E
528 sbc _DY
529 sta _E
530 lda _E+1
531 sbc #0
532 sta _E+1
533 .)
534 bpl loop_e_right
535
536 end_loop_e_right
537 iny
538 cpy _Y1
539 bcc loop_to_left
540 rts
541 .)
542
543 loop_first_to_right
544 .(
545 lda #1
546 sta _FlagFirst
547 clc
548 loop_y_leftto_right
549 txa ; NZ, not C
550 sta _MinX,y
551 sta _MaxX,y
552
553 lda _E
554 adc _DX
555 sta _E
556 lda _E+1
557 adc #0
558 sta _E+1
559 bmi end_loop_e_left_first
560 loop_e_left_first
561 inx
562 .(
563 ;sec
564 lda _E
565 sbc _DY
566 sta _E
567 lda _E+1
568 sbc #0
569 sta _E+1
570 .)
571 bpl loop_e_left_first
572
573 end_loop_e_left_first
574 iny
575 cpy _Y1
576 bcc loop_y_leftto_right
577 rts
578 .)
579
580
581
582 loop_first_to_left
583 .(
584 lda #1
585 sta _FlagFirst
586
587 clc
588 loop_to_left
589 txa
590 sta _MinX,y
591 sta _MaxX,y
592
593 lda _E
594 adc _DX
595 sta _E
596 lda _E+1
597 adc #0
598 sta _E+1
599 bmi end_loop_e_right_first
600 loop_e_right_first
601 dex
602 .(
603 ;sec
604 lda _E
605 sbc _DY
606 sta _E
607 lda _E+1
608 sbc #0
609 sta _E+1
610 .)
611 bpl loop_e_right_first
612
613 end_loop_e_right_first
614 iny
615 cpy _Y1
616 bcc loop_to_left
617 rts
618 .)
619
620
621
622
623
624 _ClearAndSwapFlag
625 lda _OddEvenFlag
626 eor #1
627 sta _OddEvenFlag
628 bne clear_odd
629
630 ;
631 ; Run the generated code (path 1)
632 ;
633 clear_even
634 ldx #COLOR_PAPER
635 ldy #COLOR_INK
636
637 lda #1
638 sta __patch_loop_clear_scanline_start+1
639 lda #39
640 sta __patch_loop_clear_scanline_end+1
641 jmp clear_patch
642
643 ;
644 ; Run the generated code (path 2)
645 ;
646 clear_odd
647 ldx #COLOR_INK
648 ldy #COLOR_PAPER
649
650 lda #1+40
651 sta __patch_loop_clear_scanline_start+1
652 lda #39+40
653 sta __patch_loop_clear_scanline_end+1
654
655 clear_patch
656 ;
657 ; Contains 200 lines of "STX adr"/"STY adr"
658 ;
659 .dsb 100*6
660
661 ;
662 ; Erase the scan lines
663 ;
664 lda #64
665 __patch_loop_clear_scanline_start
666 ldy #1
667 loop_clear_scanline
668 ; Contains 100 lines of "STA adr,y"
669 .dsb 100*3
670 iny
671 __patch_loop_clear_scanline_end
672 cpy #40
673 beq end_loop_clear_scanline
674 jmp loop_clear_scanline
675 end_loop_clear_scanline
676
677 rts
678
679
680
681
682 ; y=offset from "tmp0"
683 ; a=increment
684 IncrementPointer
685 .(
686 clc
687 adc tmp0+0,y
688 sta tmp0+0,y
689 lda tmp0+1,y
690 adc #0
691 sta tmp0+1,y
692 rts
693 .)
694
695
696 InitClearPatch
697 .(
698 lda #<($a000+1)
699 sta tmp0
700 lda #>($a000+1)
701 sta tmp0+1
702
703 lda #<(clear_patch)
704 sta tmp1
705 lda #>(clear_patch)
706 sta tmp1+1
707
708 lda #<(loop_clear_scanline)
709 sta tmp2
710 lda #>(loop_clear_scanline)
711 sta tmp2+1
712
713 ldx #100
714 init_clear_loop
715 ;
716 ; Scan line eraser
717 ;
718 ldy #0
719 lda #$99 ; "STA adr,y" opcode
720 sta (tmp2),y
721
722 iny
723 lda tmp0
724 sta (tmp2),y ; LOW adr
725
726 iny
727 lda tmp0+1
728 sta (tmp2),y ; HIGH adr
729
730 lda #3
731 ldy #tmp2-tmp0
732 jsr IncrementPointer
733
734 ;
735 ; Even lines
736 ;
737 ldy #0
738 lda #$8e ; "STX adr" opcode
739 sta (tmp1),y
740
741 iny
742 lda tmp0
743 sta (tmp1),y ; LOW adr
744
745 iny
746 lda tmp0+1
747 sta (tmp1),y ; HIGH adr
748
749 lda #3
750 ldy #tmp1-tmp0
751 jsr IncrementPointer
752
753 lda #40
754 ldy #tmp0-tmp0
755 jsr IncrementPointer
756
757 ;
758 ; Odd lines
759 ;
760 ldy #0
761 lda #$8c ; "STY adr" opcode
762 sta (tmp1),y
763
764 iny
765 lda tmp0
766 sta (tmp1),y ; LOW adr
767
768 iny
769 lda tmp0+1
770 sta (tmp1),y ; HIGH adr
771
772 lda #3
773 ldy #tmp1-tmp0
774 jsr IncrementPointer
775
776 lda #40
777 ldy #tmp0-tmp0
778 jsr IncrementPointer
779
780 dex
781 bne init_clear_loop
782 rts
783 .)
784
785
786
787
788
789
790
791
792 _InitTables
793 .(
794 lda #200
795 sta _PolyY0
796 lda #0
797 sta _PolyY1
798 sta _FlagFirst
799 sta _OddEvenFlag
800
801 lda #239
802 ldx #200
803 loop_init_min
804 dex
805 sta _MinX,x
806 bne loop_init_min
807
808 lda #0
809 ldx #200
810 loop_init_max
811 dex
812 sta _MaxX,x
813 bne loop_init_max
814 rts
815 .)
816
817
818
819
820 _DIV6 .byt 0
821 _MOD6 .byt 0
822
823
824 _ComputeDivMod
825 .(
826 ;sei
827
828 lda #0
829 sta _Y0
830
831 ldx #0
832 loop_div
833 ;
834 ; Store Div6
835 ;
836 lda _DIV6
837 ldy _Y0
838 sta _Div6,y
839
840 ;
841 ; Store Mod6
842 ;
843 ldy _MOD6
844 lda _LeftPattern,y
845 ldy _Y0
846 sta _Mod6Left,y
847
848 ldy _MOD6
849 lda _RightPattern,y
850 ldy _Y0
851 sta _Mod6Right,y
852
853
854 ;
855 ; Update Div/Mod
856 ;
857 inc _MOD6
858 lda _MOD6
859 cmp #6
860 bne no_update
861 lda #0
862 sta _MOD6
863 inc _DIV6
864 no_update
865
866 ;
867 ; Inc Y
868 ;
869 inc _Y0
870 ldy _Y0
871 bne loop_div
872
873 ldx #200
874 loop_screen_offset
875 src_1
876 lda #$00
877 dst_1
878 sta _ScreenPtrLow
879 src_2
880 lda #$a0
881 dst_2
882 sta _ScreenPtrHigh
883
884 .(
885 clc
886 lda src_1+1
887 adc #40
888 sta src_1+1
889 bcc skip
890 inc src_2+1
891 skip
892 .)
893
894 inc dst_1+1
895 inc dst_2+1
896
897 dex
898 bne loop_screen_offset
899
900
901 jsr InitClearPatch
902 rts
903 .)
904
905
906
907
908
909
910
911
912
913
914 ; Calculate some RANDOM values
915 ; Not accurate at all, but who cares ?
916 ; For what I need it's enough.
917
918 _RandomValueLow
919 .byt 23
920 _RandomValue
921 _RandomValueHigh
922 .byt 35
923
924
925 _GetRand
926 lda _RandomValueHigh
927 sta tmp1
928 lda _RandomValueLow
929 asl
930 rol tmp1
931 asl
932 rol tmp1
933 ; asl
934 ; rol temp1
935 ; asl
936 ; rol temp1
937 clc
938 adc _RandomValueLow
939 pha
940 lda tmp1
941 adc _RandomValueHigh
942 sta _RandomValueHigh
943 pla
944 adc #$11
945 sta _RandomValueLow
946 lda _RandomValueHigh
947 adc #$36
948 sta _RandomValueHigh
949 jmp *+3
950 rts
951
952
953
954 .dsb 256-(*&255)
955
956 _Div6 .dsb 256
957 _Mod6Left .dsb 256
958 _Mod6Right .dsb 256
959 _ScreenPtrLow .dsb 256
960 _ScreenPtrHigh .dsb 256
961
962 _MinX .dsb 256 ; 200
963 _MaxX .dsb 256 ; 200
964
965 _Pattern
966 ; Solid
967 .byt 64+ 1+ 2+ 4+ 8+16+32
968 .byt 64+ 1+ 2+ 4+ 8+16+32
969 .byt 64+ 1+ 2+ 4+ 8+16+32
970 .byt 64+ 1+ 2+ 4+ 8+16+32
971 .byt 64+ 1+ 2+ 4+ 8+16+32
972 .byt 64+ 1+ 2+ 4+ 8+16+32
973 .byt 64+ 1+ 2+ 4+ 8+16+32
974 .byt 64+ 1+ 2+ 4+ 8+16+32
975
976 ; Vertical lines
977 .byt 64+ 1+ 4+ 16
978 .byt 64+ 1+ 4+ 16
979 .byt 64+ 1+ 4+ 16
980 .byt 64+ 1+ 4+ 16
981 .byt 64+ 1+ 4+ 16
982 .byt 64+ 1+ 4+ 16
983 .byt 64+ 1+ 4+ 16
984 .byt 64+ 1+ 4+ 16
985
986 ; Diagonals
987 .byt 64+ 1+ 16
988 .byt 64+ 8
989 .byt 64+ 4
990 .byt 64+ 2+ 32
991 .byt 64+ 1+ 16
992 .byt 64+ 8
993 .byt 64+ 4
994 .byt 64+ 2+ 32
995
996 ; Dithered
997 .byt 64+ 1+ 4+ 16
998 .byt 64+ 2+ 8+ 32
999 .byt 64+ 1+ 4+ 16
1000 .byt 64+ 2+ 8+ 32
1001 .byt 64+ 1+ 4+ 16
1002 .byt 64+ 2+ 8+ 32
1003 .byt 64+ 1+ 4+ 16
1004 .byt 64+ 2+ 8+ 32
1005
1006 ; Diagonals 2
1007 .byt 64+ 1+ 16
1008 .byt 64+ 2+ 32
1009 .byt 64+ 4
1010 .byt 64+ 8
1011 .byt 64+ 1+ 16
1012 .byt 64+ 2+ 32
1013 .byt 64+ 4
1014 .byt 64+ 8
1015
1016 ; Crossings
1017 .byt 64+ 1+ 4+ 16
1018 .byt 64
1019 .byt 64+ 1+ 4+ 16
1020 .byt 64
1021 .byt 64+ 1+ 4+ 16
1022 .byt 64
1023 .byt 64+ 1+ 4+ 16
1024 .byt 64
1025
1026 _LeftPattern
1027 .byt 64+1+2+4+8+16+32
1028 .byt 64+1+2+4+8+16
1029 .byt 64+1+2+4+8
1030 .byt 64+1+2+4
1031 .byt 64+1+2
1032 .byt 64+1
1033
1034 _RightPattern
1035 .byt 64+63-(1+2+4+8+16+32)
1036 .byt 64+63-(1+2+4+8+16)
1037 .byt 64+63-(1+2+4+8)
1038 .byt 64+63-(1+2+4)
1039 .byt 64+63-(1+2)
1040 .byt 64+63-(1)
1041
1042

  ViewVC Help
Powered by ViewVC 1.1.26