]> git.sur5r.net Git - cc65/blob - libsrc/c64/soft80_cputc.s
prepend soft80_ to some more internally used functions
[cc65] / libsrc / c64 / soft80_cputc.s
1 ;
2 ; void cputcxy (unsigned char x, unsigned char y, char c);
3 ; void cputc (char c);
4 ;
5
6         .export         soft80_cputcxy, soft80_cputc
7         .export         soft80_cputdirect, soft80_putchar
8         .export         soft80_putcolor
9         .export         soft80_newline, soft80_plot
10
11         .import         popa, _gotoxy
12         .import         xsize
13         .import         soft80_kplot
14         .import         __bgcolor               ; FIX/CHECK
15
16         .importzp       tmp4,tmp3
17
18         .macpack        longbranch
19
20         .include        "c64.inc"
21         .include        "soft80.inc"
22
23 soft80_cputcxy:
24         pha                     ; Save C
25         jsr     popa            ; Get Y
26         jsr     _gotoxy         ; Set cursor, drop x
27         pla                     ; Restore C
28
29 ; Plot a character - also used as internal function
30
31 soft80_cputc:
32         cmp     #$0A            ; CR?
33         bne     L1
34
35         lda     #0
36         sta     CURS_X
37
38         ; Set cursor position, calculate RAM pointers
39 soft80_plot:
40         ldx     CURS_Y
41         ldy     CURS_X
42         clc
43         jmp     soft80_kplot            ; Set the new cursor
44
45 L1:     cmp     #$0D            ; LF?
46         beq     soft80_newline         ; Recalculate pointers
47
48         ; Printable char of some sort
49
50         tay
51         bpl     L10
52
53         clc
54         adc     #$20
55         and     #$7F
56 L10:
57
58 soft80_cputdirect:
59         jsr     soft80_putchar         ; Write the character to the screen
60
61 ; Advance cursor position
62
63 advance:
64         iny
65         cpy     #charsperline
66         beq     L3
67
68         sty     CURS_X
69         tya
70         and     #$01
71         bne     @L5
72
73         lda     SCREEN_PTR
74         clc
75         adc     #8
76         sta     SCREEN_PTR
77         bcc     @L4
78         inc     SCREEN_PTR+1
79 @L4:
80         inc     CRAM_PTR
81         bne     @L5
82         inc     CRAM_PTR+1
83 @L5:
84         rts
85 L3:
86         inc     CURS_Y          ; new line
87         ldy     #0              ; + cr
88         sty     CURS_X
89         jmp     soft80_plot
90
91 soft80_newline:
92
93         lda     SCREEN_PTR
94         clc
95         adc     #<(40*8)
96         sta     SCREEN_PTR
97
98         lda     SCREEN_PTR+1
99         adc     #>(40*8)
100         sta     SCREEN_PTR+1
101
102         lda     CRAM_PTR
103         clc
104         adc     #40
105         sta     CRAM_PTR
106         bcc     L5
107         inc     CRAM_PTR+1
108 L5:
109         inc     CURS_Y
110         rts
111
112 ; Write one character to the screen without doing anything else
113 ; in:         A:  character
114 ; returns:    Y:  cursor X position
115 ; this function is going to be used a lot so we unroll it a bit for speed
116
117 ;--- start color vodoo
118
119 ; remove color from cell
120 ; y unmodified
121 remcolor:
122
123         ;ldy     #$00            ; is still $00
124
125         lda     (CRAM_PTR),y    ; vram
126         and     #$0f
127         cmp     __bgcolor
128         jeq     @l2b            ; vram==bgcolor
129
130         inc     $01
131         lda     (CRAM_PTR),y    ; colram
132         stx     $01             ;$34
133         and     #$0f
134         cmp     __bgcolor
135         beq     @l2s            ; colram==bgcolor
136
137         ; vram = colram
138         ;inc     $01
139         ;lda     (CRAM_PTR),y    ; colram
140         ;stx     $01             ;$34
141         ;and     #$0f
142
143         sta     tmp3
144         lda     (CRAM_PTR),y    ; vram
145         and     #$f0
146         ora     tmp3
147         sta     (CRAM_PTR),y    ; vram
148
149         ; colram = bgcolor
150         lda     __bgcolor
151         inc     $01
152         sta     (CRAM_PTR),y    ; colram
153         stx     $01 ;$34
154
155         jmp     @l2b
156
157 @l2s:
158         ; colram is bgcolor
159         ; => only one char in cell used
160
161         jsr     soft80_checkchar
162         bcc     @l2b            ; space at current position
163
164         ; vram = bgcolor
165         lda     (CRAM_PTR),y    ; vram
166         and     #$f0
167         ora     __bgcolor
168         sta     (CRAM_PTR),y    ; vram
169 @l2b:
170         rts
171
172 ; put color to cell
173 ; y unmodified
174 soft80_putcolor:
175
176         ;ldy     #$00            ; is still $00
177
178         lda     (CRAM_PTR),y    ; vram
179         and     #$0f
180         cmp     __bgcolor
181         beq     @l2s            ; vram==bgcolor => first char in cell
182
183         ; vram!=bgcolor => second char in cell
184
185         inc     $01             ;$35
186         lda     (CRAM_PTR),y    ; colram
187         stx     $01             ;$34
188         and     #$0f
189         cmp     __bgcolor
190         bne     @l2s            ; colram!=bgcolor
191
192         ; colram==bgcolor => second char in cell or overwrite 1st char
193
194         jsr     soft80_checkchar
195         bcs     @l2a            ; char at current position => overwrite 1st
196
197         ; colram=vram
198         lda     (CRAM_PTR),y    ; vram
199         inc     $01
200         sta     (CRAM_PTR),y    ; colram
201         stx     $01 ;$34
202
203         ;jmp     @l2a
204
205 @l2s:
206         ; colram!=bgcolor => alread 2 chars in cell
207 @l2a:
208
209         ; Set color
210         lda     CHARCOLOR
211         sta     (CRAM_PTR),y    ; vram
212
213         rts
214
215
216 ;--- end color vodoo
217
218         .export soft80_checkchar
219
220 ; test if there is a space or a character at current position
221 ; CLC: space        SEC: character
222 soft80_checkchar:
223
224         ;ldy     #$00            ; is still $00
225
226         lda     CURS_X
227         and     #$01
228         jne     @l1a
229
230         .repeat 8,line
231         lda     (SCREEN_PTR),y
232         and     #$f0
233         cmp     #$f0
234         bne     @l2b
235         .if (line < 7)
236         iny
237         .endif
238         .endrepeat
239
240         ldy     #$00
241         clc
242         rts
243 @l2b:
244         ldy     #$00
245         sec
246         rts
247 @l1a:
248         .repeat 8,line
249         lda     (SCREEN_PTR),y
250         and     #$0f
251         cmp     #$0f
252         bne     @l2bb
253         .if line < 7
254         iny
255         .endif
256         .endrepeat
257         ldy     #$00
258         clc
259         rts
260 @l2bb:
261         ldy     #$00
262         sec
263         rts
264
265 ; output space
266
267 _space:
268
269         lda     RVS
270         jne     _spaceinvers
271
272         jsr     remcolor
273
274         ;ldy     #$00            ; is still $00
275
276         lda     CURS_X
277         and     #$01
278         bne     @l1
279
280         .repeat 8,line
281         lda     (SCREEN_PTR),y
282         ora     #$f0
283         sta     (SCREEN_PTR),y
284         .if (line < 7)
285         iny
286         .endif
287         .endrepeat
288         jmp     _back
289 @l1:
290         .repeat 8,line
291         lda     (SCREEN_PTR),y
292         ora     #$0f
293         sta     (SCREEN_PTR),y
294         .if line < 7
295         iny
296         .endif
297         .endrepeat
298 @l2:
299         jmp     _back
300
301 ; output inverted space
302
303 _spaceinvers:
304
305         jsr     soft80_putcolor
306
307         lda     CURS_X
308         and     #$01
309         bne     @l1
310
311         .repeat 8,line
312         lda     (SCREEN_PTR),y
313         and     #$0f
314         sta     (SCREEN_PTR),y
315         .if line < 7
316         iny
317         .endif
318         .endrepeat
319         jmp     _back
320 @l1:
321         .repeat 8,line
322         lda     (SCREEN_PTR),y
323         and     #$f0
324         sta     (SCREEN_PTR),y
325         .if line < 7
326         iny
327         .endif
328         .endrepeat
329
330         jmp     _back
331
332 ; output a character
333
334 soft80_putchar:
335         sta     tmp3
336
337         sei
338         ldx     $01
339         stx     tmp4
340         ldx     #$34
341
342         stx     $01             ; will stay $34 for space
343         ldy     #$00            ; will be $00 from now on
344
345         cmp     #' '            ; space is a special (optimized) case
346         jeq     _space
347
348         jsr     soft80_putcolor
349
350 ; output character
351 char:
352         ldx     tmp3
353
354         lda     RVS
355         jne     _invers
356
357         lda     CURS_X
358         and     #$01
359         bne     @l1
360
361         .repeat 8,line
362         lda     (SCREEN_PTR),y
363         and     #$0f
364         ora     soft80_hi_charset+(line*$80),x
365         sta     (SCREEN_PTR),y
366         .if line < 7
367         iny
368         .endif
369         .endrepeat
370         jmp     @l2
371 @l1:
372
373         .repeat 8,line
374         lda     (SCREEN_PTR),y
375         and     #$f0
376         ora     soft80_lo_charset+(line*$80),x
377         sta     (SCREEN_PTR),y
378         .if line < 7
379         iny
380         .endif
381         .endrepeat
382
383 @l2:
384
385 _back:
386         lda     tmp4
387         sta     $01
388         cli
389
390         ldy     CURS_X
391         rts
392
393 ; output inverted character
394 _invers:
395
396         lda     CURS_X
397         and     #$01
398         bne     @l1
399
400         .repeat 8,line
401         lda     (SCREEN_PTR),y
402         ora     #$f0
403         eor     soft80_hi_charset+(line*$80),x
404         sta     (SCREEN_PTR),y
405         .if line < 7
406         iny
407         .endif
408         .endrepeat
409         jmp     _back
410 @l1:
411         .repeat 8,line
412         lda     (SCREEN_PTR),y
413         ora     #$0f
414         eor     soft80_lo_charset+(line*$80),x
415         sta     (SCREEN_PTR),y
416         .if line < 7
417         iny
418         .endif
419         .endrepeat
420         jmp     _back