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

  ViewVC Help
Powered by ViewVC 1.1.26