]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi_bar.s
Updated to use cbm_kernal.inc. Whitespace cleanups
[cc65] / libsrc / tgi / tgi_bar.s
1 ;
2 ; Ullrich von Bassewitz, 21.06.2002
3 ;
4 ; void __fastcall__ tgi_bar (int x1, int y1, int x2, int y2);
5 ; /* Draw a bar (a filled rectangle) using the current color */
6
7
8         .include        "tgi-kernel.inc"
9
10         .importzp       ptr1, ptr2, ptr3, ptr4
11         .import         popax, popptr1
12
13
14 .proc   _tgi_bar
15
16         sta     ptr4            ; Y2
17         stx     ptr4+1
18
19         jsr     popax
20         sta     ptr3            ; X2
21         stx     ptr3+1
22
23         jsr     popax
24         sta     ptr2            ; Y1
25         stx     ptr2+1
26
27         jsr     popptr1         ; X1
28
29 ; Make sure X1 is less than X2. Swap both if not.
30
31         lda     ptr3
32         cmp     ptr1
33         lda     ptr3+1
34         sbc     ptr1+1
35         bpl     @L1
36         lda     ptr3
37         ldy     ptr1
38         sta     ptr1
39         sty     ptr3
40         lda     ptr3+1
41         ldy     ptr1+1
42         sta     ptr1+1
43         sty     ptr3+1
44
45 ; Make sure Y1 is less than Y2. Swap both if not.
46
47 @L1:    lda     ptr4
48         cmp     ptr2
49         lda     ptr4+1
50         sbc     ptr2+1
51         bpl     @L2
52         lda     ptr4
53         ldy     ptr2
54         sta     ptr2
55         sty     ptr4
56         lda     ptr4+1
57         ldy     ptr2+1
58         sta     ptr2+1
59         sty     ptr4+1
60
61 ; Check if X2 or Y2 are negative. If so, the bar is completely out of screen.
62
63 @L2:    lda     ptr4+1
64         ora     ptr3+1
65         bmi     @L9             ; Bail out
66
67 ; Check if X1 is negative. If so, clip it to the left border (zero).
68
69         bit     ptr1+1
70         bpl     @L3
71         lda     #$00
72         sta     ptr1
73         sta     ptr1+1
74         beq     @L4             ; Branch always, skip following test
75
76 ; Check if X1 is beyond the right border. If so, the bar is invisible.
77
78 @L3:    lda     ptr1
79         cmp     _tgi_xres
80         lda     ptr1+1
81         sbc     _tgi_xres
82         bcs     @L9             ; Bail out if invisible
83
84 ; Check if Y1 is negative. If so, clip it to the top border (zero).
85
86 @L4:    bit     ptr2+1
87         bpl     @L5
88         lda     #$00
89         sta     ptr2
90         sta     ptr2+1
91         beq     @L6             ; Branch always, skip following test
92
93 ; Check if Y1 is beyond the bottom border. If so, the bar is invisible.
94
95 @L5:    lda     ptr2
96         cmp     _tgi_yres
97         lda     ptr2+1
98         sbc     _tgi_yres
99         bcs     @L9             ; Bail out if invisible
100
101 ; Check if X2 is larger than the maximum x coord. If so, clip it.
102
103 @L6:    lda     ptr3
104         cmp     _tgi_xres
105         lda     ptr3+1
106         sbc     _tgi_xres+1
107         bcc     @L7
108         jsr     _tgi_getmaxx
109         sta     ptr3
110         stx     ptr3+1
111
112 ; Check if Y2 is larger than the maximum y coord. If so, clip it.
113
114 @L7:    lda     ptr4
115         cmp     _tgi_yres
116         lda     ptr4+1
117         sbc     _tgi_yres+1
118         bcc     @L8
119         jsr     _tgi_getmaxy
120         sta     ptr4
121         stx     ptr4+1
122
123 ; The coordinates are now valid. Call the driver.
124
125 @L8:    jmp     tgi_bar
126
127 ; Error exit
128
129 @L9:    rts
130
131 .endproc