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