]> git.sur5r.net Git - cc65/blob - libsrc/c64/soft80mono_cputc.s
Add test showing optimizer failure, OptUnusedLoads removes needed loads
[cc65] / libsrc / c64 / soft80mono_cputc.s
1 ;
2 ; Groepaz/Hitmen, 19.10.2015
3 ;
4 ; high level implementation for the monochrome soft80 implementation
5 ;
6 ; void cputcxy (unsigned char x, unsigned char y, char c);
7 ; void cputc (char c);
8 ;
9
10         .export         soft80mono_cputcxy, soft80mono_cputc
11         .export         soft80mono_cputdirect, soft80mono_putchar
12         .export         soft80mono_newline, soft80mono_plot
13
14         .import         gotoxy
15
16         .import         soft80mono_kplot
17         .import         soft80mono_internal_bgcolor, soft80mono_internal_cellcolor
18         .import         soft80mono_internal_cursorxlsb, soft80mono_internal_nibble
19
20         .importzp       tmp4, tmp3, ptr2
21
22         .include        "c64.inc"
23         .include        "soft80.inc"
24
25 soft80mono_cputcxy:
26         pha                     ; Save C
27         jsr     gotoxy          ; Set cursor, drop x and y
28         pla                     ; Restore C
29
30 ; Plot a character - also used as internal function
31
32 soft80mono_cputc:
33         cmp     #$0A            ; CR?
34         bne     L1
35
36         lda     #0
37         sta     CURS_X
38
39         ; Set cursor position, calculate RAM pointers
40 soft80mono_plot:
41         ldx     CURS_Y
42         ldy     CURS_X
43         clc
44         jmp     soft80mono_kplot        ; Set the new cursor
45
46 L1:     cmp     #$0D                    ; LF?
47         beq     soft80mono_newline      ; Recalculate pointers
48
49         ; shortcut for codes < $80 ... codes $20-$7f can be printed directly,
50         ; codes $00-$1f are control codes which are not printable and thus may
51         ; give undefined result.
52         tay
53         bpl     @L10
54
55         ; codes $80-$ff must get converted like this:
56         ; $80-$9f  ->   dont care (control codes)
57         ; $a0-$bf  ->   $00-$1f
58         ; $c0-$df  ->   $60-$7f
59         ; $e0-$ff  ->   $00-$1f
60
61         ora     #%01000000      ; $40
62         clc
63         adc     #%00100000      ; $20
64         and     #%01111111      ; $7f
65 @L10:
66
67         ; entry point for direct output of a character. the value passed in
68         ; akku must match the offset in the charset.
69         ; - the following may not modify tmp1
70 soft80mono_cputdirect:
71         jsr     soft80mono_putchar      ; Write the character to the screen
72
73         ; Advance cursor position
74         iny                             ; contains CURS_X
75         cpy     #charsperline
76         beq     @L3
77
78         sty     CURS_X
79         tya
80         and     #$01
81         sta     soft80mono_internal_cursorxlsb
82         bne     @L4
83
84         lda     SCREEN_PTR
85         clc
86         adc     #8
87         sta     SCREEN_PTR
88         bcc     @L4
89         inc     SCREEN_PTR+1
90 @L4:
91         rts
92 @L3:
93         inc     CURS_Y          ; new line
94         ldy     #0              ; + cr
95         sty     CURS_X
96         jmp     soft80mono_plot
97
98         ; - the following may not modify tmp1
99 soft80mono_newline:
100
101         lda     SCREEN_PTR
102         clc
103         adc     #<(40*8)
104         sta     SCREEN_PTR
105
106         lda     SCREEN_PTR+1
107         adc     #>(40*8)
108         sta     SCREEN_PTR+1
109
110         inc     CURS_Y
111         rts
112
113 ;-------------------------------------------------------------------------------
114 ; output one character in internal encoding without advancing cursor position
115 ; generic entry point
116 ;
117 ; - the following may not modify tmp1
118 ; in:   A: charcode
119 ; out:  Y: CURS_X
120 ;
121 soft80mono_putchar:
122         sta     tmp3            ; save charcode
123
124         sei
125         lda     $01
126         pha
127         lda     #$34
128         sta     $01             ; enable RAM under I/O
129
130         ldy     #$00            ; will be $00 from now on
131
132         ldx     soft80mono_internal_cursorxlsb
133         lda     chardatal,x
134         clc
135         adc     tmp3
136         sta     ptr2
137         lda     chardatah,x
138         adc     #0
139         sta     ptr2+1
140
141         lda     RVS
142         bne     draw_charinvers
143
144         lda     nibble,x
145         sta     tmp3
146
147         ;ldy     #0                      ; is still $00
148 @lp1:
149         lda     (SCREEN_PTR),y
150         and     tmp3
151         ora     (ptr2),y
152         sta     (SCREEN_PTR),y
153         clc
154         lda     ptr2
155         adc     #$7f
156         sta     ptr2
157         bcc     @sk1
158         inc     ptr2+1
159 @sk1:
160         iny
161         cpy     #8
162         bne     @lp1
163
164 draw_back:
165         pla
166         sta     $01
167         cli
168
169         ldy     CURS_X
170         rts
171
172 ; output inverted character
173 draw_charinvers:
174         lda     soft80mono_internal_nibble,x
175         sta     tmp3
176
177         ;ldy     #0                      ; is still $00
178 @lp1:
179         lda     (SCREEN_PTR),y
180         ora     tmp3
181         eor     (ptr2),y
182         sta     (SCREEN_PTR),y
183         clc
184         lda     ptr2
185         adc     #$7f
186         sta     ptr2
187         bcc     @sk1
188         inc     ptr2+1
189 @sk1:
190         iny
191         cpy     #8
192         bne     @lp1
193         jmp     draw_back
194
195         .rodata
196 chardatal:
197         .byte <soft80_hi_charset
198         .byte <soft80_lo_charset
199 chardatah:
200         .byte >soft80_hi_charset
201         .byte >soft80_lo_charset
202 nibble:
203         .byte $0f, $f0
204