]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi_bar.s
changes from Fatih
[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
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     popax
28         sta     ptr1            ; X1
29         stx     ptr1+1
30
31 ; Make sure X1 is less than X2. Swap both if not.
32
33         lda     ptr3
34         cmp     ptr1
35         lda     ptr3+1
36         sbc     ptr1+1
37         bpl     @L1
38         lda     ptr3
39         ldy     ptr1
40         sta     ptr1
41         sty     ptr3
42         lda     ptr3+1
43         ldy     ptr1+1
44         sta     ptr1+1
45         sty     ptr3+1
46
47 ; Make sure Y1 is less than Y2. Swap both if not.
48
49 @L1:    lda     ptr4
50         cmp     ptr2
51         lda     ptr4+1
52         sbc     ptr2+1
53         bpl     @L2
54         lda     ptr4
55         ldy     ptr2
56         sta     ptr2
57         sty     ptr4
58         lda     ptr4+1
59         ldy     ptr2+1
60         sta     ptr2+1
61         sty     ptr4+1
62
63 ; Check if X2 or Y2 are negative. If so, the bar is completely out of screen.
64
65 @L2:    lda     ptr4+1
66         ora     ptr3+1
67         bmi     @L9             ; Bail out
68
69 ; Check if X1 is negative. If so, clip it to the left border (zero).
70
71         bit     ptr1+1
72         bpl     @L3
73         lda     #$00
74         sta     ptr1
75         sta     ptr1+1
76         beq     @L4             ; Branch always, skip following test
77
78 ; Check if X1 is beyond the right border. If so, the bar is invisible.
79
80 @L3:    lda     ptr1
81         cmp     _tgi_xres
82         lda     ptr1+1
83         sbc     _tgi_xres
84         bcs     @L9             ; Bail out if invisible
85
86 ; Check if Y1 is negative. If so, clip it to the top border (zero).
87
88 @L4:    bit     ptr2+1
89         bpl     @L5
90         lda     #$00
91         sta     ptr2
92         sta     ptr2+1
93         beq     @L6             ; Branch always, skip following test
94
95 ; Check if Y1 is beyond the bottom border. If so, the bar is invisible.
96
97 @L5:    lda     ptr2
98         cmp     _tgi_yres
99         lda     ptr2+1
100         sbc     _tgi_yres
101         bcs     @L9             ; Bail out if invisible
102
103 ; Check if X2 is larger than the maximum x coord. If so, clip it.
104
105 @L6:    lda     ptr3
106         cmp     _tgi_xres
107         lda     ptr3+1
108         sbc     _tgi_xres+1
109         bcc     @L7
110         jsr     _tgi_getmaxx
111         sta     ptr3
112         stx     ptr3+1
113
114 ; Check if Y2 is larger than the maximum y coord. If so, clip it.
115
116 @L7:    lda     ptr4
117         cmp     _tgi_yres
118         lda     ptr4+1
119         sbc     _tgi_yres+1
120         bcc     @L8
121         jsr     _tgi_getmaxy
122         sta     ptr4
123         stx     ptr4+1
124
125 ; The coordinates are now valid. Call the driver.
126
127 @L8:    jmp     tgi_bar
128
129 ; Error exit
130
131 @L9:    rts
132
133 .endproc