]> git.sur5r.net Git - cc65/blob - libsrc/c64/soft80_color.s
fe2be71d50d647581c140b7c53536c6bb5312a79
[cc65] / libsrc / c64 / soft80_color.s
1 ;
2 ; Groepaz/Hitmen, 12.10.2015
3 ;
4 ; unsigned char __fastcall__ textcolor (unsigned char color);
5 ; unsigned char __fastcall__ bgcolor (unsigned char color);
6 ;
7
8         .export         soft80_textcolor, soft80_bgcolor
9         .import         soft80_internal_textcolor, soft80_internal_bgcolor
10
11         .importzp       tmp1, tmp2
12
13         .include        "c64.inc"
14         .include        "soft80.inc"
15
16 soft80_textcolor:
17         ldx     soft80_internal_textcolor       ; get old value
18         sta     soft80_internal_textcolor       ; set new value
19
20         jsr     mkcharcolor
21
22         txa                                     ; get old value
23         rts
24
25 soft80_bgcolor:
26         ldx     soft80_internal_bgcolor         ; get old value
27         stx     tmp2                            ; save old value
28         sta     soft80_internal_bgcolor         ; set new value
29
30         jsr     mkcharcolor
31
32 .if SOFT80COLORVOODOO = 1
33         ; if the old bg color is equal to color ram of that cell, then also
34         ; update the color ram to the new value.
35         ; FIXME: perhaps we must also check if the non visible character is not
36         ;        a space, and NOT update the color ram in that case.
37         ldx     #$00
38 lp1:
39         .repeat $4,page
40         .scope
41         lda     soft80_colram+(page*250),x
42         and     #$0f
43         cmp     tmp2                            ; old bg color
44         bne     @sk1
45         lda     soft80_internal_bgcolor         ; new bg color
46         sta     soft80_colram+(page*250),x
47 @sk1:
48         .endscope
49         .endrepeat
50
51         inx
52         bne     lp1
53 .endif
54
55         sei
56         ldy     $01
57         lda     #$34                            ; disable I/O
58         sta     $01
59
60         ; if the old bg color is equal to text color in this cell, then also
61         ; update the text color to the new value.
62         ; FIXME: perhaps we need to check for space, see note above
63         ldx     #$00
64 lp2:
65         .repeat $4,page
66         .scope
67         lda     soft80_vram+(page*250),x
68         and     #$0f
69         cmp     tmp2                            ; old bg color
70         bne     @sk2
71         lda     soft80_internal_bgcolor         ; new bg color
72 @sk2:
73         ora     tmp1                            ; new bg color (high nibble)
74         sta     soft80_vram+(page*250),x
75         .endscope
76         .endrepeat
77
78         inx
79         bne     lp2
80
81         sty     $01                             ; enable I/O
82         cli
83
84         lda     tmp2                            ; get old value
85         rts
86
87 mkcharcolor:
88         lda     soft80_internal_bgcolor
89         asl     a
90         asl     a
91         asl     a
92         asl     a
93         sta     tmp1                            ; remember new bg color (high nibble)
94         ora     soft80_internal_textcolor
95         sta     CHARCOLOR                       ; text/bg combo for new chars
96         rts
97
98 ;-------------------------------------------------------------------------------
99 ; force the init constructor to be imported
100
101         .import soft80_init
102 conio_init      = soft80_init