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

  ViewVC Help
Powered by ViewVC 1.1.26