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

  ViewVC Help
Powered by ViewVC 1.1.26