/[projet1]/public/oric/routines/rasterization/linebench/clip.s
Defence Force logotype

Annotation of /public/oric/routines/rasterization/linebench/clip.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 46 - (hide annotations)
Wed Mar 25 21:32:32 2009 UTC (10 years, 8 months ago) by dbug
Original Path: users/dbug/rasterization/linebench/clip.s
File size: 10043 byte(s)
Added PolyBench and LineBench
1 dbug 46
2     #include "params.h"
3    
4    
5     .zero
6    
7     _LargeX0 .dsb 2
8     _LargeY0 .dsb 2
9     _LargeX1 .dsb 2
10     _LargeY1 .dsb 2
11    
12     _LargeX .dsb 2
13     _LargeY .dsb 2
14     _ClipCode .dsb 1
15     _ClipCode0 .dsb 1
16     _ClipCode1 .dsb 1
17    
18     #ifdef USE_ACCURATE_CLIPPING
19     .dsb 1
20     #endif
21     _ClipX0 .dsb 2
22     #ifdef USE_ACCURATE_CLIPPING
23     .dsb 1
24     #endif
25     _ClipY0 .dsb 2
26     #ifdef USE_ACCURATE_CLIPPING
27     .dsb 1
28     #endif
29     _ClipX1 .dsb 2
30     #ifdef USE_ACCURATE_CLIPPING
31     .dsb 1
32     #endif
33     _ClipY1 .dsb 2
34     #ifdef USE_ACCURATE_CLIPPING
35     .dsb 1
36     #endif
37     _ClipXc .dsb 2
38     #ifdef USE_ACCURATE_CLIPPING
39     .dsb 1
40     #endif
41     _ClipYc .dsb 2
42    
43     .text
44    
45    
46     _Break
47     jmp _Break
48     rts
49    
50    
51    
52     _ClipComputeMidPoint
53     .(
54     ; xc=(x0+x1)>>1;
55     clc
56     #ifdef USE_ACCURATE_CLIPPING
57     lda _ClipX0-1
58     adc _ClipX1-1
59     sta _ClipXc-1
60     #endif
61     lda _ClipX0+0
62     adc _ClipX1+0
63     sta _ClipXc+0
64    
65     lda _ClipX0+1
66     adc _ClipX1+1
67     sta _ClipXc+1
68    
69     lda _ClipXc+1
70     cmp #$80
71     ror _ClipXc+1
72     ror _ClipXc+0
73     #ifdef USE_ACCURATE_CLIPPING
74     ror _ClipXc-1
75     #endif
76    
77     ; yc=(y0+y1)>>1;
78     clc
79     #ifdef USE_ACCURATE_CLIPPING
80     lda _ClipY0-1
81     adc _ClipY1-1
82     sta _ClipYc-1
83     #endif
84     lda _ClipY0+0
85     adc _ClipY1+0
86     sta _ClipYc+0
87    
88     lda _ClipY0+1
89     adc _ClipY1+1
90     sta _ClipYc+1
91    
92     lda _ClipYc+1
93     cmp #$80
94     ror _ClipYc+1
95     ror _ClipYc+0
96     #ifdef USE_ACCURATE_CLIPPING
97     ror _ClipYc-1
98     #endif
99     rts
100     .)
101    
102     _ClipMoveP1
103     .(
104     ; x1=xc;
105     lda _ClipXc+0
106     sta _ClipX1+0
107     lda _ClipXc+1
108     sta _ClipX1+1
109     #ifdef USE_ACCURATE_CLIPPING
110     lda _ClipXc-1
111     sta _ClipX1-1
112     #endif
113    
114     ; y1=yc;
115     lda _ClipYc+0
116     sta _ClipY1+0
117     lda _ClipYc+1
118     sta _ClipY1+1
119     #ifdef USE_ACCURATE_CLIPPING
120     lda _ClipYc-1
121     sta _ClipY1-1
122     #endif
123     rts
124     .)
125    
126     _ClipMoveP0
127     .(
128     ; x0=xc;
129     lda _ClipXc+0
130     sta _ClipX0+0
131     lda _ClipXc+1
132     sta _ClipX0+1
133     #ifdef USE_ACCURATE_CLIPPING
134     lda _ClipXc-1
135     sta _ClipX0-1
136     #endif
137    
138     ; y0=yc;
139     lda _ClipYc+0
140     sta _ClipY0+0
141     lda _ClipYc+1
142     sta _ClipY0+1
143     #ifdef USE_ACCURATE_CLIPPING
144     lda _ClipYc-1
145     sta _ClipY0-1
146     #endif
147     rts
148     .)
149    
150    
151     _ClipReturnPc
152     .(
153     ; LargeX=ClipXc;
154     lda _ClipXc+0
155     sta _LargeX+0
156     lda _ClipXc+1
157     sta _LargeX+1
158    
159     ; LargeY=ClipYc;
160     lda _ClipYc+0
161     sta _LargeY+0
162     lda _ClipYc+1
163     sta _LargeY+1
164    
165     rts
166     .)
167    
168     _ClipReturnP0
169     .(
170     ; LargeX=LargeX0;
171     lda _LargeX0+0
172     sta _LargeX+0
173     lda _LargeX0+1
174     sta _LargeX+1
175    
176     ; LargeY=LargeY0;
177     lda _LargeY0+0
178     sta _LargeY+0
179     lda _LargeY0+1
180     sta _LargeY+1
181    
182     rts
183     .)
184    
185     _ClipReturnP1
186     .(
187     ; LargeX=LargeX1;
188     lda _LargeX1+0
189     sta _LargeX+0
190     lda _LargeX1+1
191     sta _LargeX+1
192    
193     ; LargeY=LargeY1;
194     lda _LargeY1+0
195     sta _LargeY+0
196     lda _LargeY1+1
197     sta _LargeY+1
198    
199     rts
200     .)
201    
202     _ClipSetNormalStartPoints
203     .(
204     ; x0=LargeX0;
205     ; y0=LargeY0;
206     lda _LargeX0+0
207     sta _ClipX0+0
208     lda _LargeX0+1
209     sta _ClipX0+1
210    
211     lda _LargeY0+0
212     sta _ClipY0+0
213     lda _LargeY0+1
214     sta _ClipY0+1
215    
216     ; x1=LargeX1;
217     ; y1=LargeY1;
218     lda _LargeX1+0
219     sta _ClipX1+0
220     lda _LargeX1+1
221     sta _ClipX1+1
222    
223     lda _LargeY1+0
224     sta _ClipY1+0
225     lda _LargeY1+1
226     sta _ClipY1+1
227    
228     rts
229     .)
230    
231     _ClipSetInvertedStartPoints
232     .(
233     ; x0=LargeX1;
234     ; y0=LargeY1;
235     lda _LargeX1+0
236     sta _ClipX0+0
237     lda _LargeX1+1
238     sta _ClipX0+1
239    
240     lda _LargeY1+0
241     sta _ClipY0+0
242     lda _LargeY1+1
243     sta _ClipY0+1
244    
245     ; x1=LargeX0;
246     ; y1=LargeY0;
247     lda _LargeX0+0
248     sta _ClipX1+0
249     lda _LargeX0+1
250     sta _ClipX1+1
251    
252     lda _LargeY0+0
253     sta _ClipY1+0
254     lda _LargeY0+1
255     sta _ClipY1+1
256    
257     rts
258     .)
259    
260    
261     _ClipDichoTopBottom
262     .(
263     .(
264     ; if (LargeY0==CLIP_TOP)
265     cpx _LargeY0+0
266     bne skip
267     lda _LargeY0+1
268     bne skip
269     jmp _ClipReturnP0
270     skip
271     .)
272    
273     .(
274     ; if (LargeY1==CLIP_TOP)
275     cpx _LargeY1+0
276     bne skip
277     lda _LargeY1+1
278     bne skip
279     jmp _ClipReturnP1
280     skip
281     .)
282    
283     sec
284     lda _LargeY0+0
285     sbc _LargeY1+0
286     lda _LargeY0+1
287     sbc _LargeY1+1
288     bmi label4
289    
290     label3
291     ; (LargeY0>=LargeY1)
292     jsr _ClipSetInvertedStartPoints
293     jmp end_swap
294    
295     label4
296     ; (LargeY0<LargeY1)
297     jsr _ClipSetNormalStartPoints
298    
299     end_swap
300    
301     #ifdef USE_ACCURATE_CLIPPING
302     lda #0
303     sta _ClipX0-1
304     sta _ClipY0-1
305     sta _ClipX1-1
306     sta _ClipY1-1
307     #endif
308    
309     loop
310     jsr _ClipComputeMidPoint
311    
312     ; if (yc==CLIP_TOP)
313     cpx _ClipYc+0
314     bne not_done
315     lda _ClipYc+1
316     beq done
317    
318     not_done
319    
320     sec
321     txa
322     sbc _ClipYc+0
323     lda #0
324     sbc _ClipYc+1
325     bmi replace_first
326    
327     replace_second
328     ; if (yc<CLIP_TOP)
329     jsr _ClipMoveP0
330     jmp loop
331    
332     replace_first
333     ; if (yc>CLIP_TOP)
334     jsr _ClipMoveP1
335     jmp loop
336    
337     done
338     ; Finished !
339     jmp _ClipReturnPc
340     .)
341    
342    
343     _ClipDichoLeftRight
344     .(
345     .(
346     ; if (LargeX0==CLIP_LEFT/RIGHT)
347     cpx _LargeX0+0
348     bne skip
349     lda _LargeX0+1
350     bne skip
351     jmp _ClipReturnP0
352     skip
353     .)
354    
355     .(
356     ; if (LargeX1==CLIP_LEFT/RIGHT)
357     cpx _LargeX1+0
358     bne skip
359     lda _LargeX1+1
360     bne skip
361     jmp _ClipReturnP1
362     skip
363     .)
364    
365     sec
366     lda _LargeX0+0
367     sbc _LargeX1+0
368     lda _LargeX0+1
369     sbc _LargeX1+1
370     bmi label4
371    
372     label3
373     ; (LargeX0>=LargeX1)
374     jsr _ClipSetInvertedStartPoints
375     jmp end_swap
376    
377     label4
378     ; (LargeX0<LargeX1)
379     jsr _ClipSetNormalStartPoints
380    
381     end_swap
382    
383     #ifdef USE_ACCURATE_CLIPPING
384     lda #0
385     sta _ClipX0-1
386     sta _ClipY0-1
387     sta _ClipX1-1
388     sta _ClipY1-1
389     #endif
390    
391     loop
392     jsr _ClipComputeMidPoint
393    
394     ; if (xc==CLIP_LEFT/RIGHT)
395     cpx _ClipXc+0
396     bne not_done
397     lda _ClipXc+1
398     beq done
399    
400     not_done
401    
402     sec
403     txa
404     sbc _ClipXc+0
405     lda #0
406     sbc _ClipXc+1
407     bmi replace_first
408    
409     replace_second
410     ; if (xc<CLIP_LEFT/RIGHT)
411     jsr _ClipMoveP0
412     jmp loop
413    
414     replace_first
415     ; if (xc>CLIP_LEFT/RIGHT)
416     jsr _ClipMoveP1
417     jmp loop
418    
419     done
420     ; Finished !
421     jmp _ClipReturnPc
422     .)
423    
424    
425    
426    
427     ;
428     ; In this code, we assume that the CLIP_ values are fitting
429     ; the resolution of an Oric screen, so they will never be out
430     ; of a 240x200 screen resolution, fit in an unsigned byte.
431     ;
432     _ClipFindRegion
433     .(
434     ; Initialize with 'not clipped'
435     lda #0
436    
437     ;
438     ; Bottom test
439     ;
440     .(
441     ldy _LargeY+1
442     bmi end_bottom ; If the high byte of Y is negative, it's certainly not clipped
443     bne clip_bottom ; If it's not negative, then it needs to be clipped for sure
444    
445     ldy _LargeY+0
446     cpy #(CLIP_BOTTOM+1) ; 194
447     bcc end_bottom
448    
449     clip_bottom
450     ora #1 ; Means (y >= CLIP_BOTTOM)
451    
452     jmp end_top ; If the end point is clipped on the bottom, it cannot be on the top side as well
453     .)
454     end_bottom
455    
456     ;
457     ; Top test
458     ;
459     .(
460     ldy _LargeY+1
461     bmi clip_top ; If the high byte of Y is negative, it certainly needs to be clipped
462     bne end_top ; If it's not negative, then it's too large to be clipped on top
463    
464     ldy _LargeY+0
465     cpy #CLIP_TOP ; 5
466     bcs end_top
467    
468     clip_top
469     ora #2 ; Means (y < CLIP_TOP)
470     .)
471     end_top
472    
473     ;
474     ; Righttest
475     ;
476     .(
477     ldy _LargeX+1
478     bmi end_right ; If the high byte of X is negative, it's certainly not clipped
479     bne clip_right ; If it's not negative, then it needs to be clipped for sure
480    
481     ldy _LargeX+0
482     cpy #(CLIP_RIGHT+1)
483     bcc end_right
484    
485     clip_right
486     ora #4 ; Means (x >= CLIP_RIGHT)
487    
488     jmp end_left ; If the end point is clipped on the right, it cannot be on the left side as well
489     .)
490     end_right
491    
492     ;
493     ; Left test
494     ;
495     .(
496     ldy _LargeX+1
497     bmi clip_left ; If the high byte of X is negative, it certainly needs to be clipped
498     bne end_left ; If it's not negative, then it's too large to be clipped on left
499    
500     ldy _LargeX+0
501     cpy #CLIP_LEFT
502     bcs end_left
503    
504     clip_left
505     ora #8 ; Means (x < CLIP_LEFT)
506     .)
507     end_left
508    
509     ; Save the result
510     sta _ClipCode
511     rts
512     .)
513    
514    
515     ; Compute the outcode for the first point
516     _ClipComputeCode0
517     .(
518     lda _LargeX0+0
519     sta _LargeX+0
520     lda _LargeX0+1
521     sta _LargeX+1
522    
523     lda _LargeY0+0
524     sta _LargeY+0
525     lda _LargeY0+1
526     sta _LargeY+1
527    
528     jsr _ClipFindRegion
529    
530     lda _ClipCode
531     sta _ClipCode0
532    
533     rts
534     .)
535    
536     ; Compute the outcode for the second point
537     _ClipComputeCode1
538     .(
539     lda _LargeX1+0
540     sta _LargeX+0
541     lda _LargeX1+1
542     sta _LargeX+1
543    
544     lda _LargeY1+0
545     sta _LargeY+0
546     lda _LargeY1+1
547     sta _LargeY+1
548    
549     jsr _ClipFindRegion
550    
551     lda _ClipCode
552     sta _ClipCode1
553    
554     rts
555     .)
556    
557     _DrawClippedLine
558     .(
559    
560     ; The region outcodes for the the endpoints
561     jsr _ClipComputeCode0
562     jsr _ClipComputeCode1
563    
564     ; In theory, this can never end up in an infinite loop, it'll always come in one of the trivial cases eventually
565     clip_loop
566    
567     lda _ClipCode0
568     ora _ClipCode1
569     bne end_trivial_draw
570     .(
571     ; /accept because both endpoints are in screen or on the border, trivial accept
572     lda _LargeX0
573     sta _CurrentPixelX
574     lda _LargeY0
575     sta _CurrentPixelY
576     lda _LargeX1
577     sta _OtherPixelX
578     lda _LargeY1
579     sta _OtherPixelY
580    
581     jsr _DrawLine
582     rts
583     .)
584     end_trivial_draw
585    
586     lda _ClipCode0
587     and _ClipCode1
588     beq end_invisible_line
589     .(
590     ; The line isn't visible on screen, trivial reject
591     rts
592     .)
593     end_invisible_line
594    
595     .(
596     ; if no trivial reject or accept, continue the loop
597     .(
598     lda _ClipCode0
599     bne skip
600     lda _ClipCode1
601     skip
602     .)
603    
604     lsr
605     bcc end_clip_bottom
606     ; Clip bottom
607     ldx #CLIP_BOTTOM
608     jsr _ClipDichoTopBottom
609     jmp end_clip_switch
610     end_clip_bottom
611    
612     lsr
613     bcc end_clip_top
614     ; Clip top
615     ldx #CLIP_TOP
616     jsr _ClipDichoTopBottom
617     jmp end_clip_switch
618     end_clip_top
619    
620     lsr
621     bcc end_clip_right
622     ; Clip right
623     ldx #CLIP_RIGHT
624     jsr _ClipDichoLeftRight
625     jmp end_clip_switch
626     end_clip_right
627    
628     lsr
629     bcc end_clip_left
630     ; Clip left
631     ldx #CLIP_LEFT
632     jsr _ClipDichoLeftRight
633     jmp end_clip_switch
634     end_clip_left
635    
636     end_clip_switch
637    
638     lda _ClipCode0
639     beq clip_second_point
640    
641     clip_first_point
642     ; First endpoint was clipped
643     lda _LargeX+0
644     sta _LargeX0+0
645     lda _LargeX+1
646     sta _LargeX0+1
647    
648     lda _LargeY+0
649     sta _LargeY0+0
650     lda _LargeY+1
651     sta _LargeY0+1
652    
653     jsr _ClipComputeCode0
654    
655     jmp clip_loop
656    
657     clip_second_point
658     ; Second endpoint was clipped
659     lda _LargeX+0
660     sta _LargeX1+0
661     lda _LargeX+1
662     sta _LargeX1+1
663    
664     lda _LargeY+0
665     sta _LargeY1+0
666     lda _LargeY+1
667     sta _LargeY1+1
668    
669     jsr _ClipComputeCode1
670    
671     jmp clip_loop
672    
673     .)
674    
675     ; Not supposed to arrive here :p
676     rts
677     .)
678    

  ViewVC Help
Powered by ViewVC 1.1.26