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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 279 - (show annotations)
Sat Feb 13 21:20:38 2010 UTC (9 years, 10 months ago) by thrust26
File size: 10555 byte(s)
some optimizations to the trivial rejection, overhead from +15 down to +8
1 ; without, trivial, -1, 7331 clipping
2 ; 451, 466, 636 (initial version)
3 ; 451, 459, 624, 424
4
5 #include "params.h"
6
7
8 .zero
9
10 _LargeX0 .dsb 2
11 _LargeY0 .dsb 2
12 _LargeX1 .dsb 2
13 _LargeY1 .dsb 2
14
15 _LargeX .dsb 2
16 _LargeY .dsb 2
17 ;_ClipCode .dsb 1
18 _ClipCode0 .dsb 1
19 _ClipCode1 .dsb 1
20
21 #ifdef USE_ACCURATE_CLIPPING
22 .dsb 1
23 #endif
24 _ClipX0 .dsb 2
25 #ifdef USE_ACCURATE_CLIPPING
26 .dsb 1
27 #endif
28 _ClipY0 .dsb 2
29 #ifdef USE_ACCURATE_CLIPPING
30 .dsb 1
31 #endif
32 _ClipX1 .dsb 2
33 #ifdef USE_ACCURATE_CLIPPING
34 .dsb 1
35 #endif
36 _ClipY1 .dsb 2
37 #ifdef USE_ACCURATE_CLIPPING
38 .dsb 1
39 #endif
40 _ClipXc .dsb 2
41 #ifdef USE_ACCURATE_CLIPPING
42 .dsb 1
43 #endif
44 _ClipYc .dsb 2
45
46 .text
47
48
49 _Break
50 jmp _Break
51 rts
52
53
54
55 _ClipComputeMidPoint
56 .(
57 ; xc=(x0+x1)>>1;
58 clc
59 #ifdef USE_ACCURATE_CLIPPING
60 lda _ClipX0-1
61 adc _ClipX1-1
62 sta _ClipXc-1
63 #endif
64 lda _ClipX0+0
65 adc _ClipX1+0
66 sta _ClipXc+0
67
68 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 #ifdef USE_ACCURATE_CLIPPING
77 ror _ClipXc-1
78 #endif
79
80 ; yc=(y0+y1)>>1;
81 clc
82 #ifdef USE_ACCURATE_CLIPPING
83 lda _ClipY0-1
84 adc _ClipY1-1
85 sta _ClipYc-1
86 #endif
87 lda _ClipY0+0
88 adc _ClipY1+0
89 sta _ClipYc+0
90
91 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 #ifdef USE_ACCURATE_CLIPPING
100 ror _ClipYc-1
101 #endif
102 rts
103 .)
104
105 _ClipMoveP1
106 .(
107 ; x1=xc;
108 lda _ClipXc+0
109 sta _ClipX1+0
110 lda _ClipXc+1
111 sta _ClipX1+1
112 #ifdef USE_ACCURATE_CLIPPING
113 lda _ClipXc-1
114 sta _ClipX1-1
115 #endif
116
117 ; y1=yc;
118 lda _ClipYc+0
119 sta _ClipY1+0
120 lda _ClipYc+1
121 sta _ClipY1+1
122 #ifdef USE_ACCURATE_CLIPPING
123 lda _ClipYc-1
124 sta _ClipY1-1
125 #endif
126 rts
127 .)
128
129 _ClipMoveP0
130 .(
131 ; x0=xc;
132 lda _ClipXc+0
133 sta _ClipX0+0
134 lda _ClipXc+1
135 sta _ClipX0+1
136 #ifdef USE_ACCURATE_CLIPPING
137 lda _ClipXc-1
138 sta _ClipX0-1
139 #endif
140
141 ; y0=yc;
142 lda _ClipYc+0
143 sta _ClipY0+0
144 lda _ClipYc+1
145 sta _ClipY0+1
146 #ifdef USE_ACCURATE_CLIPPING
147 lda _ClipYc-1
148 sta _ClipY0-1
149 #endif
150 rts
151 .)
152
153
154 _ClipReturnPc
155 .(
156 ; LargeX=ClipXc;
157 lda _ClipXc+0
158 sta _LargeX+0
159 lda _ClipXc+1
160 sta _LargeX+1
161
162 ; LargeY=ClipYc;
163 lda _ClipYc+0
164 sta _LargeY+0
165 lda _ClipYc+1
166 sta _LargeY+1
167
168 rts
169 .)
170
171 _ClipReturnP0
172 .(
173 ; LargeX=LargeX0;
174 lda _LargeX0+0
175 sta _LargeX+0
176 lda _LargeX0+1
177 sta _LargeX+1
178
179 ; LargeY=LargeY0;
180 lda _LargeY0+0
181 sta _LargeY+0
182 lda _LargeY0+1
183 sta _LargeY+1
184
185 rts
186 .)
187
188 _ClipReturnP1
189 .(
190 ; LargeX=LargeX1;
191 lda _LargeX1+0
192 sta _LargeX+0
193 lda _LargeX1+1
194 sta _LargeX+1
195
196 ; LargeY=LargeY1;
197 lda _LargeY1+0
198 sta _LargeY+0
199 lda _LargeY1+1
200 sta _LargeY+1
201
202 rts
203 .)
204
205 _ClipSetNormalStartPoints
206 .(
207 ; x0=LargeX0;
208 ; y0=LargeY0;
209 lda _LargeX0+0
210 sta _ClipX0+0
211 lda _LargeX0+1
212 sta _ClipX0+1
213
214 lda _LargeY0+0
215 sta _ClipY0+0
216 lda _LargeY0+1
217 sta _ClipY0+1
218
219 ; x1=LargeX1;
220 ; y1=LargeY1;
221 lda _LargeX1+0
222 sta _ClipX1+0
223 lda _LargeX1+1
224 sta _ClipX1+1
225
226 lda _LargeY1+0
227 sta _ClipY1+0
228 lda _LargeY1+1
229 sta _ClipY1+1
230
231 rts
232 .)
233
234 _ClipSetInvertedStartPoints
235 .(
236 ; x0=LargeX1;
237 ; y0=LargeY1;
238 lda _LargeX1+0
239 sta _ClipX0+0
240 lda _LargeX1+1
241 sta _ClipX0+1
242
243 lda _LargeY1+0
244 sta _ClipY0+0
245 lda _LargeY1+1
246 sta _ClipY0+1
247
248 ; 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 .)
262
263
264 _ClipDichoTopBottom
265 .(
266 .(
267 ; if (LargeY0==CLIP_TOP)
268 cpx _LargeY0+0
269 bne skip
270 lda _LargeY0+1
271 bne skip
272 jmp _ClipReturnP0
273 skip
274 .)
275
276 .(
277 ; if (LargeY1==CLIP_TOP)
278 cpx _LargeY1+0
279 bne skip
280 lda _LargeY1+1
281 bne skip
282 jmp _ClipReturnP1
283 skip
284 .)
285
286 sec
287 lda _LargeY0+0
288 sbc _LargeY1+0
289 lda _LargeY0+1
290 sbc _LargeY1+1
291 bmi label4
292
293 label3
294 ; (LargeY0>=LargeY1)
295 jsr _ClipSetInvertedStartPoints
296 jmp end_swap
297
298 label4
299 ; (LargeY0<LargeY1)
300 jsr _ClipSetNormalStartPoints
301
302 end_swap
303
304 #ifdef USE_ACCURATE_CLIPPING
305 lda #0
306 sta _ClipX0-1
307 sta _ClipY0-1
308 sta _ClipX1-1
309 sta _ClipY1-1
310 #endif
311
312 loop
313 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 not_done
322
323 sec
324 txa
325 sbc _ClipYc+0
326 lda #0
327 sbc _ClipYc+1
328 bmi replace_first
329
330 replace_second
331 ; 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 done
341 ; Finished !
342 jmp _ClipReturnPc
343 .)
344
345
346 _ClipDichoLeftRight
347 .(
348 .(
349 ; if (LargeX0==CLIP_LEFT/RIGHT)
350 cpx _LargeX0+0
351 bne skip
352 lda _LargeX0+1
353 bne skip
354 jmp _ClipReturnP0
355 skip
356 .)
357
358 .(
359 ; if (LargeX1==CLIP_LEFT/RIGHT)
360 cpx _LargeX1+0
361 bne skip
362 lda _LargeX1+1
363 bne skip
364 jmp _ClipReturnP1
365 skip
366 .)
367
368 sec
369 lda _LargeX0+0
370 sbc _LargeX1+0
371 lda _LargeX0+1
372 sbc _LargeX1+1
373 bmi label4
374
375 label3
376 ; (LargeX0>=LargeX1)
377 jsr _ClipSetInvertedStartPoints
378 jmp end_swap
379
380 label4
381 ; (LargeX0<LargeX1)
382 jsr _ClipSetNormalStartPoints
383
384 end_swap
385
386 #ifdef USE_ACCURATE_CLIPPING
387 lda #0
388 sta _ClipX0-1
389 sta _ClipY0-1
390 sta _ClipX1-1
391 sta _ClipY1-1
392 #endif
393
394 loop
395 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 not_done
404
405 sec
406 txa
407 sbc _ClipXc+0
408 lda #0
409 sbc _ClipXc+1
410 bmi replace_first
411
412 replace_second
413 ; 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 done
423 ; Finished !
424 jmp _ClipReturnPc
425 .)
426
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 ; yHi >= $01 -> clip_bottom
438 ; yHi == $00 -> check
439 ; yHi <= $ff -> clip_top
440
441 ; 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
446 ; 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 clip_top
461 lda #2 ; means (y < CLIP_TOP)
462 end_top_bottom
463
464 ; xHi >= $01 -> clip_right
465 ; xHi == $00 -> check
466 ; xHi <= $ff -> clip_left
467
468 ; 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
473 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
484 clip_left
485 ora #8 ; means (x < CLIP_LEFT)
486 end_left_right
487 rts
488 .)
489
490 _DrawClippedLine
491 .(
492 ; The region outcodes for the the endpoints
493 ; Compute the outcode for the first point
494 ldx #0 ; XY0
495 jsr _ClipFindRegion
496 sta _ClipCode0
497 ; Compute the outcode for the second point
498 clip_loop1
499 ldx #_LargeY1-_LargeY0 ; XY1
500 jsr _ClipFindRegion
501 sta _ClipCode1
502
503 ; In theory, this can never end up in an infinite loop, it'll always come in one of the trivial cases eventually
504 clip_loop
505
506 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
520 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 end_invisible_line
532
533 .(
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 end_clip_bottom
549
550 lsr
551 bcc end_clip_top
552 ; Clip top
553 ldx #CLIP_TOP
554 jsr _ClipDichoTopBottom
555 jmp end_clip_switch
556 end_clip_top
557
558 lsr
559 bcc end_clip_right
560 ; Clip right
561 ldx #CLIP_RIGHT
562 jsr _ClipDichoLeftRight
563 jmp end_clip_switch
564 end_clip_right
565
566 lsr
567 bcc end_clip_left
568 ; Clip left
569 ldx #CLIP_LEFT
570 jsr _ClipDichoLeftRight
571 jmp end_clip_switch
572 end_clip_left
573
574 end_clip_switch
575
576 lda _ClipCode0
577 beq clip_second_point
578
579 clip_first_point
580 ; First endpoint was clipped
581 lda _LargeX+0
582 sta _LargeX0+0
583 lda _LargeX+1
584 sta _LargeX0+1
585
586 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 .)
620

  ViewVC Help
Powered by ViewVC 1.1.26