/[projet1]/public/oric/games/Space 1999/Sources/game source/NOISE/clipping.s
Defence Force logotype

Contents of /public/oric/games/Space 1999/Sources/game source/NOISE/clipping.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 76 - (show annotations)
Tue May 26 07:45:25 2009 UTC (10 years, 6 months ago) by Chema
File size: 11468 byte(s)


1
2
3
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5 adjust_clip
6 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 ; Helper function
8 ; Adjust pointer, #lines, #scans and x,y position
9 ; of sprite so it clips to the clipping region
10 ; Parametres:
11 ; op1 x position
12 ; op2 y position
13 ; tmp3 lines
14 ; tmp3+1 scans
15 ; tmp4 *image
16 ; tmp5 *mask
17 ; scans_to_draw
18 ; scan_to_start
19
20 ; Adjust lines and pointers...
21
22 lda op2 ; if(y_sprite > y_clip)
23 sec
24 sbc _clip_rgn+1
25 bmi ac_donothingy
26 beq ac_donothingy ;{
27 ac_doy
28 sta tmp
29
30 #define TEST
31 #ifdef TEST
32 ldy tmp3+1
33
34 ac_loop1
35 lda tmp4 ; p_image-=(y_sprite-y_clip)*scans
36 sec
37 sbc tmp
38 sta tmp4
39 bcs ac_nocarry1
40 dec tmp4+1
41 ac_nocarry1
42 lda tmp5 ; p_mask-=(y_sprite-y_clip)*scans
43 sec
44 sbc tmp
45 sta tmp5
46 bcs ac_nocarry2
47 dec tmp5+1
48 ac_nocarry2
49 dey
50 bne ac_loop1
51
52 #else
53 tay
54 ac_loop1
55 lda tmp4 ; p_image-=(y_sprite-y_clip)*scans
56 sec
57 sbc tmp3+1
58 sta tmp4
59 bcs ac_nocarry1
60 dec tmp4+1
61 ac_nocarry1
62 lda tmp5 ; p_mask-=(y_sprite-y_clip)*scans
63 sec
64 sbc tmp3+1
65 sta tmp5
66 bcs ac_nocarry2
67 dec tmp5+1
68 ac_nocarry2
69 dey
70 bne ac_loop1
71 #endif
72 lda tmp3 ; lines-=(y_sprite-y_clip)
73 sec
74 sbc tmp
75 sta tmp3
76
77 lda _clip_rgn+1 ; y_sprite=y_clip
78 sta op2
79 ac_donothingy ;}
80
81 lda op2 ;b=y_sprite-lines
82 sec
83 sbc tmp3
84 sta tmp7
85
86 lda _clip_rgn+1 ;a=y_clip-lines_clip
87 sec
88 sbc _clip_rgn+3
89 ;sta tmp6
90
91 sec
92 sbc tmp7 ;if(a>b) ;// SIGNED COMPARISON!
93 sta tmp
94 bmi ac_donothingy2
95 beq ac_donothingy2
96 lda tmp3 ; lines-=(a-b)
97 sec
98 sbc tmp
99 sta tmp3
100 ac_donothingy2 ;}
101
102 ; Adjust scans...
103 lda _clip_rgn ; if(x_clip > x_sprite)
104 sec
105 sbc op1
106 bmi ac_donothingx
107 beq ac_donothingx ;{
108 ac_dox
109
110 jsr do_div6 ; calculate (x_clip-x_sprite) div 6
111 tax
112 inx
113 stx scan_to_start ; start drawing in scan (x_clip-x_sprite) div 6 + 1
114
115
116 ac_donothingx ;}
117
118
119 lda _clip_rgn ;a=x_clip div 6+scans_clip
120 jsr do_div6
121 clc
122 adc _clip_rgn+2
123 sta tmp6
124
125 lda op1 ;b=x_sprite div 6+scans_to_draw
126 jsr do_div6
127 clc
128 adc scans_to_draw
129 sta tmp7
130
131 sec
132 sbc tmp6 ;if(a<b)
133 bmi ac_donothingx2
134 beq ac_donothingx2 ;{
135 ac_dox2
136 sta tmp ; scans_to_draw-=(a-b)
137
138 lda scans_to_draw
139 sec
140 sbc tmp
141 sta scans_to_draw
142 ac_donothingx2 ;}
143
144 rts ;We're done!
145
146 ;; End of adjust_clip
147
148
149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
150 intersect_rect
151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
152 ;; Helper function. Calculates if a rectangle intersects
153 ;; with clipping region
154 ;; Needs:
155 ;; op1 X coord of R1
156 ;; op2 Y coord of R1
157 ;; tmp3+1 Width of R1 (in scans)
158 ;; tmp3 Height of R1
159 ;; Returns Z=0 if overlap occurs, else Z=1
160
161 ;; The formula is !((X1>X2+W2)||(X2>X1+W1)||(Y1>Y2+H2)||(Y2>Y1+H1))
162 ;; or else (X2+W2>=X1)&&(X1+W1>=X2)&&(Y2+H2>=Y1)&&(Y1+H1>=Y2)
163
164 ;lda op2 ;; Y1+H1
165 ;tay
166 ldy op2
167 iny
168 tya
169 sec
170 sbc tmp3 ;; Y1
171 bcs ir_notneg1 ; clip up!
172 lda #0
173 ir_notneg1
174
175 sta tmp
176 lda _clip_rgn+1 ;; Y2+H2
177 cmp tmp ;; >=Y1
178 bcc irfalse ;; FALSE
179
180
181 ;lda _clip_rgn+1 ;; Y2+H2
182 ;tay
183 ;iny
184 ;tya
185 ;sec
186 ;sbc _clip_rgn+3 ;; Y2
187 ; bpl ir_notneg2
188 ; cmp _clip_rgn+1
189 ; bcs ir_notneg2
190 ; lda #0
191 ;ir_notneg2
192 ;sta tmp
193 ;lda op2 ;; Y1+H1
194 ;cmp tmp ;; >= Y2
195
196 sec
197 ldy _clip_rgn+1 ;; Y2+H2
198 iny
199 tya
200 sbc _clip_rgn+3 ;; Y2
201 sta tmp
202 lda op2 ;; Y1+H1
203 cmp tmp ;; >= Y2
204 bcc irfalse ;; FALSE
205
206 lda _clip_rgn+2
207 asl
208 sta tmp ;; W2*2
209 asl
210 clc
211 adc tmp ;; + W2*4
212 sta tmp
213 dec tmp
214
215 lda _clip_rgn ;; X2
216 clc
217 adc tmp ;; X2+W2
218 cmp op1 ;; >=X1
219 bcc irfalse ;; FALSE
220
221 lda tmp3+1
222 asl
223 sta tmp ;; W1*2
224 asl
225 clc
226 adc tmp ;; + W1*4
227 sta tmp
228 dec tmp
229
230 lda op1 ;; X1
231 clc
232 adc tmp ;; X1+W1
233 cmp _clip_rgn ;; >=X2
234 bcc irfalse ;; FALSE
235
236 lda #0
237 rts
238 irfalse
239 lda #1
240 rts ; We're done!
241
242 ;; End of intersect_rect
243
244 #ifdef CLEARCLIPFN
245
246 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
247 ; void clear_clip_rgn();
248 ; Clears the clipping region
249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
250
251 +_clear_clip_rgn
252 lda _clip_rgn
253 sta op1
254 lda _clip_rgn+1
255 sta op2
256 jsr pixel_address
257
258 ;; Pointer in tmp0
259 ldx _clip_rgn+3 ; get lines
260
261 ccr_looplines
262 lda #$40
263 ldy _clip_rgn+2 ; get scans
264 dey
265 ccr_loopscans
266 sta (tmp0),y
267 dey
268 bpl ccr_loopscans
269
270 lda tmp0
271 sec
272 sbc #40 ; Point to previous line
273 bcs ccr_no_carry
274 dec tmp0+1
275 ccr_no_carry
276 sta tmp0
277 dex
278 bne ccr_looplines
279
280 rts ; We're done
281
282 #endif ;CLEARCLIPFN
283
284 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
285 ; void clear_buff();
286 ; Clears the buffer
287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
288 +_clear_buff
289 lda #HI(scr_buffer)
290 sta tmp0+1
291 lda #LO(scr_buffer)
292 sta tmp0
293
294 lda #0
295 sta tmp
296 ;clc
297 ldx _clip_rgn+3
298 dex
299 txa
300 #ifdef EIGTHSCANS
301 asl
302 rol tmp
303 asl
304 rol tmp
305 asl
306 rol tmp
307
308 adc tmp0
309 sta tmp0
310 lda tmp
311 adc tmp0+1
312 sta tmp0+1
313
314 #else
315 asl
316 sta tmp
317 asl
318 clc
319 adc tmp
320 adc tmp0
321 bcc nocarryt1
322 inc tmp0+1
323 nocarryt1
324 sta tmp0
325 #endif
326
327 ;; Pointer in tmp0
328 ldx _clip_rgn+3 ; get lines
329
330 cb_looplines
331 lda #$40
332 ldy _clip_rgn+2 ; get scans
333 dey
334 cb_loopscans
335 sta (tmp0),y
336 dey
337 bpl cb_loopscans
338
339 lda tmp0
340 sec
341 ; sbc #8 ; Point to previous line
342 sbc #SCANSINBUFF ; Point to previous line
343 bcs cb_no_carry
344 dec tmp0+1
345 cb_no_carry
346 sta tmp0
347 dex
348 bne cb_looplines
349
350 rts ; We're done
351
352
353 ;; End of clear_buff
354
355 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
356 ; void set_doublebuff(char status)
357 ; Sets the double buffering on (status<>1) or off (status == 0)
358 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
359 +_set_doublebuff
360 ldy #0
361 lda (sp),y
362 beq sdb_off
363 lda #1
364 sta double_buff
365 ;lda #8
366 lda #SCANSINBUFF
367 sta sps_dbl+1
368 sta sps2_dbl+1
369 jmp sdb_end
370 sdb_off
371 lda #0
372 sta double_buff
373 lda #40
374 sta sps_dbl+1
375 sta sps2_dbl+1
376 sdb_end
377 rts ; We're done
378
379
380 ;; End of set_doublebuff
381
382 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
383 ; void paint_buff()
384 ; paints the double buffer on screen
385 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
386 +_paint_buff
387
388 lda double_buff
389 pha
390 lda #0
391 sta double_buff
392
393 lda _clip_rgn
394 sta op1
395 lda _clip_rgn+1
396 sta op2
397 jsr pixel_address
398
399 ;; Pointer in tmp1
400 lda #LO(scr_buffer)
401 sta tmp1
402 lda #HI(scr_buffer)
403 sta tmp1+1
404
405 lda #0
406 sta tmp
407 ldx _clip_rgn+3
408 dex
409 txa
410 #ifdef EIGTHSCANS
411 asl
412 rol tmp
413 asl
414 rol tmp
415 asl
416 rol tmp
417
418 adc tmp1
419 sta tmp1
420 lda tmp
421 adc tmp1+1
422 sta tmp1+1
423
424 #else
425 asl
426 sta tmp
427 asl
428 clc
429 adc tmp
430 adc tmp1
431 bcc nocarryt2
432 inc tmp1+1
433 nocarryt2
434 sta tmp1
435 #endif
436
437 ldx _clip_rgn+3 ; get lines
438 ldy _clip_rgn+2 ; get scans
439 dey
440 sty tmp
441
442 pb_looplines
443 ldy tmp
444 pb_loopscans
445 lda (tmp1),y
446 sta (tmp0),y
447 dey
448 bpl pb_loopscans
449
450 lda tmp0
451 sec
452 sbc #40 ; Point to previous line
453 bcs pb_no_carry
454 dec tmp0+1
455 pb_no_carry
456 sta tmp0
457
458 lda tmp1
459 sec
460 ;sbc #8 ; Point to previous line
461 sbc #SCANSINBUFF ; Point to previous line
462 bcs pb_no_carry2
463 dec tmp1+1
464 pb_no_carry2
465 sta tmp1
466
467 dex
468 bne pb_looplines
469
470 pla
471 sta double_buff
472
473 rts ; We're done
474
475 ;; End of paint_buff
476
477
478
479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
480 ; void recalc_clip(char who)
481 ; Recalculates the clipping region for a given character
482 ; after movement
483 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
484 aux2 .db $00
485 tempx .db $00
486 tempy .db $00
487 +_recalc_clip
488 ldy #0
489 lda (sp),y ; grab id of character moving
490 sta aux2
491 asl ; Multiply by 4 (sizeof(moving_object_t))
492 asl
493 tay
494
495
496 ; Get coordinates
497 lda _characters,y ; .fine_coord_i
498 sta who_i
499 iny
500 lda _characters,y ; .fine_coord_j
501 sta who_j
502 iny
503 lda _characters,y ; .fine_coord_k
504 sta who_k
505
506 ; Get size of object
507 iny
508 lda _characters,y ; .type
509 and #%00111111 ; get size
510 sta sizecode
511
512 lda who_i
513 jsr do_div6
514 sta _orig_i
515
516 lda who_j
517 jsr do_div6
518 sta _orig_j
519
520 ; Prepare for calling ij2xy
521 lda _orig_i
522 sta op1
523 lda _orig_j
524 sta op2
525 jsr ij2xy
526 stx tempx
527 sty tempy
528
529 ; xo=(who_i-((i<<1)+(i<<2))); yo=(who_j-((j<<1)+(j<<2)));
530
531 lda _orig_i
532 asl
533 asl
534 sta tmp
535 lda _orig_i
536 asl
537 clc
538 adc tmp
539 sta tmp
540
541 lda who_i
542 sec
543 sbc tmp
544
545 sta tmp1
546
547 lda _orig_j
548 asl
549 asl
550 sta tmp
551 lda _orig_j
552 asl
553 clc
554 adc tmp
555 sta tmp
556
557 lda who_j
558 sec
559 sbc tmp
560
561 sta tmp1+1
562
563 ; xo2=(xo-yo)<<1;
564
565 lda tmp1
566 sec
567 sbc tmp1+1
568 asl
569 sta tmp2
570
571 ;yo2=(xo+yo);
572 lda tmp1
573 clc
574 adc tmp1+1
575 sta tmp2+1
576
577 ;y=y-who_k;
578 lda tempy
579 sec
580 sbc who_k
581 sta tempy
582
583 ; clip_rgn.x_clip=dodiv6(x+xo2);
584 lda tempx
585 clc
586 adc tmp2
587
588 ;Adjust sprite size (now x+xo2+(#ancho_tile/2-(size_i*2)))
589 adc #ancho_tile/2
590 tay
591 lda aux2
592 asl ; Multiply by 6 (sizeof(sprite_t))
593 asl
594 sta tmp
595 lda aux2
596 asl
597 clc
598 adc tmp
599 sta aux2
600 tax
601 inx
602 lda _char_pics,x ; Get number of scans
603
604 sta tmp
605 asl
606 clc
607 adc tmp ; Multiply by 3 (6 pix per scan /2)
608 sta tmp
609
610 ;tay
611 ;ldx sizecode
612 ;lda _sizes_i,x
613 ;asl
614 ;sta tmp
615
616 tya
617 ;sec
618 clc ; ON PURPOSE... SUBSTRACT 1
619 sbc tmp
620 pha
621
622 jsr do_div6
623 sta tmp+1
624
625 ;clip_rgn.x_clip=(clip_rgn.x_clip<<1)+(clip_rgn.x_clip<<2); /* *6 */
626 asl
627 asl
628 sta tmp
629 lda tmp+1
630 asl
631 clc
632 adc tmp
633 sta _clip_rgn
634
635 ;clip_rgn.y_clip=y+yo2+3;
636 lda tempy
637 clc
638 adc tmp2+1
639 ; adc #3
640 adc #2
641 ldx #1
642 sta _clip_rgn,x
643
644 ;clip_rgn.height_clip=char_pics[who].lines+2;
645 ldx aux2
646 lda _char_pics,x
647 ; clc
648 ; adc #2
649 ldx #3
650 sta _clip_rgn,x
651
652
653 ;clip_rgn.width_clip=char_pics[who].scans+1;
654 ldx aux2
655 inx
656 lda _char_pics,x
657 ; clc
658 ; adc #1
659 ldx #2
660 sta _clip_rgn,x
661
662 ; if x mod 6 = 5, then add 1 scan more
663 pla
664 sec
665 sbc _clip_rgn
666
667 ; clc
668 beq rc_end
669
670 ; cmp #0
671 ; bne rc_not1
672 ; lda _clip_rgn
673 ; sec
674 ; sbc #6
675 ; sta _clip_rgn
676 ; jmp rc_onemorescan
677 ;rc_not1
678 ; cmp #5
679 ; bne rc_end
680 ;rc_onemorescan
681
682 inc _clip_rgn,x
683 ; sec
684 rc_end
685 rts ; We're done
686
687 ; End of recalc_clip

  ViewVC Help
Powered by ViewVC 1.1.26