]> git.sur5r.net Git - cc65/blob - libsrc/c64/soft80_color.s
Merge pull request #627 from jedeoric/master
[cc65] / libsrc / c64 / soft80_color.s
1 ;
2 ; Groepaz/Hitmen, 12.10.2015
3 ;
4 ; high level implementation for the soft80 implementation
5 ;
6 ; unsigned char __fastcall__ textcolor (unsigned char color);
7 ; unsigned char __fastcall__ bgcolor (unsigned char color);
8 ;
9
10         .export         soft80_textcolor, soft80_bgcolor
11         .import         soft80_internal_cellcolor, soft80_internal_bgcolor
12         .import         soft80_internal_cursorxlsb
13         .import         soft80_kplot, soft80_checkchar
14
15         .importzp       tmp1, tmp2
16
17         .include        "c64.inc"
18         .include        "soft80.inc"
19
20 soft80_textcolor:
21         ldx     CHARCOLOR                       ; get old value
22         sta     CHARCOLOR                       ; set new value
23
24 mkcharcolor:
25         lda     soft80_internal_bgcolor
26         asl     a
27         asl     a
28         asl     a
29         asl     a
30         sta     tmp1                            ; remember new bg color (high nibble)
31         ora     CHARCOLOR
32         sta     soft80_internal_cellcolor       ; text/bg combo for new chars
33
34         txa                                     ; get old value
35         rts
36
37 soft80_bgcolor:
38         ldx     soft80_internal_bgcolor         ; get old value
39         stx     tmp2                            ; save old value
40         sta     soft80_internal_bgcolor         ; set new value
41
42         jsr     mkcharcolor
43
44         lda     CURS_X
45         pha
46         lda     CURS_Y
47         pha
48
49         ldy     #0
50         ldx     #0
51         clc
52         jsr     soft80_kplot
53
54         sei
55         lda     $01
56         pha
57         ldx     #$34
58         stx     $01                             ; $34
59
60         ;ldy     #0                              ; is still 0
61
62         lda     #24
63         sta     CURS_Y
64 lpy:
65         lda     #39
66         sta     CURS_X
67 lpx:
68
69 .if SOFT80COLORVOODOO = 1
70         ; if the old bg color is equal to color ram of that cell, then also
71         ; update the color ram to the new value.
72
73         inc     $01                             ; $35
74         lda     (CRAM_PTR),y                    ; colram
75         stx     $01                             ; $34
76
77         and     #$0f
78         cmp     tmp2                            ; old bg color
79         bne     @sk1
80
81         ; if the left character in the cell is not a space, then dont update
82         ; the color ram
83         lda     #1
84         sta     soft80_internal_cursorxlsb
85         jsr     soft80_checkchar
86         bcc     @sk1
87         lda     soft80_internal_bgcolor         ; new bg color
88
89         inc     $01                             ; $35
90         sta     (CRAM_PTR),y                    ; colram
91         stx     $01                             ; $34
92 @sk1:
93 .endif
94         ; if the old bg color is equal to text color in this cell, then also
95         ; update the text color to the new value.
96
97         lda     (CRAM_PTR),y                    ; vram
98         and     #$0f
99         cmp     tmp2                            ; old bg color
100         bne     @sk2
101
102         ; if there are non space characters in the cell, do not update the
103         ; color ram
104         pha
105         lda     #0
106         sta     soft80_internal_cursorxlsb
107         jsr     soft80_checkchar
108         pla
109         bcc     @sk2
110
111         pha
112         inc     soft80_internal_cursorxlsb
113         jsr     soft80_checkchar
114         pla
115         bcc     @sk2
116
117         lda     soft80_internal_bgcolor         ; new bg color
118 @sk2:
119         ora     tmp1                            ; new bg color (high nibble)
120         sta     (CRAM_PTR),y                    ; vram
121
122         inc     CRAM_PTR
123         bne     @sk3
124         inc     CRAM_PTR+1
125 @sk3:
126
127         lda     SCREEN_PTR
128         clc
129         adc     #8
130         sta     SCREEN_PTR
131         bcc     @sk4
132         inc     SCREEN_PTR+1
133 @sk4:
134
135         dec     CURS_X
136         bpl     lpx
137
138         dec     CURS_Y
139         bpl     lpy
140
141         pla
142         sta     $01                             ; enable I/O
143         cli
144
145         pla     ; CURS_Y
146         tax
147         pla     ; CURS_X
148         tay
149         clc
150         jsr     soft80_kplot
151
152         lda     tmp2                            ; get old value
153         rts
154
155 ;-------------------------------------------------------------------------------
156 ; force the init constructor to be imported
157
158         .import soft80_init
159 conio_init      = soft80_init