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

  ViewVC Help
Powered by ViewVC 1.1.26