]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi_outcode.s
Relocate register values outside structs, + more
[cc65] / libsrc / tgi / tgi_outcode.s
1 ;
2 ; Ullrich von Bassewitz, 2009-10-25
3 ;
4 ; Generates clipping outcodes for Cohen Sutherland and others.
5 ;
6
7         .include "tgi-kernel.inc"
8         .include "zeropage.inc"
9
10 ;----------------------------------------------------------------------------
11 ; Data
12
13 .bss
14
15 ; Clipping coordinates. They must be in this order!
16 tgi_clip_x1:    .res    2
17 tgi_clip_y1:    .res    2
18 tgi_clip_x2:    .res    2
19 tgi_clip_y2:    .res    2
20
21 ;----------------------------------------------------------------------------
22 ; Generate a Cohen Sutherland outcode
23 ;
24 ; void outcode ()
25 ; {
26 ;     unsigned char o = 0;
27 ;     if (Y < 0) {
28 ;         o = TGI_CLIP_BOTTOM;
29 ;     } else if (Y >= yres) {
30 ;         o = TGI_CLIP_TOP;
31 ;     }
32 ;     if (X < 0) {
33 ;         o |= TGI_CLIP_LEFT;
34 ;     } else if (X >= xres) {
35 ;         o |= TGI_CLIP_RIGHT;
36 ;     }
37 ;     return o;
38 ; }
39 ;
40 ; The function return the outcode in A and the flags for the outcode are
41 ; correctly set.
42 ;
43
44 .code
45 .proc   tgi_outcode
46
47         lda     #TGI_CLIP_NONE
48         sta     tmp1
49
50 ; Check Y coordinate
51
52         lda     tgi_clip_y1+1,y         ; High byte of Y1
53         bmi     L2                      ; Jump if bottom clip
54
55         ldx     tgi_clip_y1,y           ; Low byte of Y1
56         cpx     _tgi_yres
57         sbc     _tgi_yres+1
58         bvs     L1
59         eor     #$80
60 L1:     bpl     L4
61         lda     #TGI_CLIP_TOP               ; Top clipping necessary
62         bne     L3
63 L2:     lda     #TGI_CLIP_BOTTOM
64 L3:     sta     tmp1                    ; Save temp outcode
65
66
67 ; Check X coordinate
68
69 L4:     lda     tgi_clip_x1+1,y         ; High byte of X1
70         bmi     L7                      ; Jump if left clip
71
72         ldx     tgi_clip_x1,y           ; Low byte of X1
73         cpx     _tgi_xres
74         sbc     _tgi_xres+1
75         bvs     L5
76         eor     #$80
77 L5:     bmi     L6
78
79 ; No right or left clipping necessary
80
81         lda     tmp1
82         rts
83
84 ; Need right clipping
85
86 L6:     lda     #TGI_CLIP_RIGHT
87         ora     tmp1
88         rts
89
90 ; Need left clipping
91
92 L7:     lda     #TGI_CLIP_LEFT
93         ora     tmp1
94         rts
95
96 .endproc
97
98