]> git.sur5r.net Git - cc65/blob - libsrc/c64/soft80_cputc.s
remove some commented out code
[cc65] / libsrc / c64 / soft80_cputc.s
1 ;
2 ; Groepaz/Hitmen, 11.10.2015
3 ;
4 ; void cputcxy (unsigned char x, unsigned char y, char c);
5 ; void cputc (char c);
6 ;
7
8         .export         soft80_cputcxy, soft80_cputc
9         .export         soft80_cputdirect, soft80_putchar
10         .export         soft80_newline, soft80_plot
11
12         .import         popa, _gotoxy
13
14         .import         soft80_kplot
15         .import         soft80_internal_bgcolor, soft80_internal_textcolor
16         .import         soft80_internal_cursorxlsb
17
18         .importzp       tmp4,tmp3
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         ; shortcut for codes < $80 ... codes $20-$7f can be printed directly,
49         ; codes $00-$1f are control codes which are not printable and thus may
50         ; give undefined result.
51         tay
52         bpl     L10
53
54         ; codes $80-$ff must get converted like this:
55         ; $80-$9f  ->   dont care (control codes)
56         ; $a0-$bf  ->   $00-$1f
57         ; $c0-$df  ->   $60-$7f
58         ; $e0-$ff  ->   $00-$1f
59
60         ; extra check for petscii codes 160-191, these have been moved to
61         ; 0-31 in the charset
62         and     #%11100000
63         cmp     #%10100000
64         bne     @sk
65
66         tya
67         and     #%00011111
68         bpl     L10             ; branch always
69 @sk:
70         tya
71         clc
72         adc     #$20
73         and     #$7F
74 L10:
75
76         ; entry point for direct output of a character. the value passed in
77         ; akku must match the offset in the charset.
78         ; - the following may not modify tmp1
79 soft80_cputdirect:
80         jsr     soft80_putchar  ; Write the character to the screen
81
82         ; Advance cursor position
83         iny                     ; contains CURS_X
84         cpy     #charsperline
85         beq     L3
86
87         sty     CURS_X
88         tya
89         and     #$01
90         sta     soft80_internal_cursorxlsb
91         bne     @L5
92
93         lda     SCREEN_PTR
94         clc
95         adc     #8
96         sta     SCREEN_PTR
97         bcc     @L4
98         inc     SCREEN_PTR+1
99 @L4:
100         inc     CRAM_PTR
101         bne     @L5
102         inc     CRAM_PTR+1
103 @L5:
104         rts
105 L3:
106         inc     CURS_Y          ; new line
107         ldy     #0              ; + cr
108         sty     CURS_X
109         jmp     soft80_plot
110
111         ; - the following may not modify tmp1
112 soft80_newline:
113
114         lda     SCREEN_PTR
115         clc
116         adc     #<(40*8)
117         sta     SCREEN_PTR
118
119         lda     SCREEN_PTR+1
120         adc     #>(40*8)
121         sta     SCREEN_PTR+1
122
123         lda     CRAM_PTR
124         clc
125         adc     #40
126         sta     CRAM_PTR
127         bcc     L5
128         inc     CRAM_PTR+1
129 L5:
130         inc     CURS_Y
131         rts
132
133 ;-------------------------------------------------------------------------------
134 ; All following code belongs to the character output to bitmap
135 ;
136 ; this stuff is going to be used a lot so we unroll it a bit for speed
137 ;-------------------------------------------------------------------------------
138
139 .if SOFT80FASTSPACE = 1
140
141 ; output inverted space (odd)
142 draw_spaceinvers_odd:
143         .repeat 8,line
144         lda     (SCREEN_PTR),y
145         and     #$f0
146         sta     (SCREEN_PTR),y
147         .if line < 7
148         iny
149         .endif
150         .endrepeat
151         jmp     draw_back
152
153 ; output inverted space (general entry point)
154 ; in: y must be $00
155 draw_spaceinvers:
156
157 .if SOFT80COLORVOODOO = 1
158         jsr     soft80_putcolor
159 .else
160         lda     CHARCOLOR
161         sta     (CRAM_PTR),y    ; vram
162 .endif
163
164         lda     soft80_internal_cursorxlsb
165         bne     draw_spaceinvers_odd
166
167 ; output inverted space (even)
168         .repeat 8,line
169         lda     (SCREEN_PTR),y
170         and     #$0f
171         sta     (SCREEN_PTR),y
172         .if line < 7
173         iny
174         .endif
175         .endrepeat
176         jmp     draw_back
177
178 ; output space (odd)
179 draw_space_odd:
180         .repeat 8,line
181         lda     (SCREEN_PTR),y
182         ora     #$0f
183         sta     (SCREEN_PTR),y
184         .if line < 7
185         iny
186         .endif
187         .endrepeat
188         jmp     draw_back
189
190 ; output space (general entry point)
191 ; in: y must be $00
192 draw_space:
193
194         lda     RVS
195         bne     draw_spaceinvers
196
197 .if SOFT80COLORVOODOO = 1
198         jsr     remcolor
199 .endif
200         ;ldy     #$00            ; is still $00
201
202         lda     soft80_internal_cursorxlsb
203         bne     draw_space_odd
204
205 ; output space (even)
206         .repeat 8,line
207         lda     (SCREEN_PTR),y
208         ora     #$f0
209         sta     (SCREEN_PTR),y
210         .if (line < 7)
211         iny
212         .endif
213         .endrepeat
214         jmp     draw_back
215 .endif
216
217 ;-------------------------------------------------------------------------------
218 ; output one character in internal encoding without advancing cursor position
219 ; generic entry point
220 ;
221 ; - the following may not modify tmp1
222 ; in:   A: charcode
223 ; out:  Y: CURS_X
224 ;
225 soft80_putchar:
226         sta     tmp3            ; remember charcode
227
228         sei
229         ldx     $01
230         stx     tmp4
231         ldx     #$34
232
233         stx     $01             ; will stay $34 for space
234         ldy     #$00            ; will be $00 from now on
235
236 .if SOFT80FASTSPACE = 1
237         cmp     #' '            ; space is a special (optimized) case
238         beq     draw_space
239 .endif
240
241 .if SOFT80COLORVOODOO = 1
242         jsr     soft80_putcolor
243 .else
244         lda     CHARCOLOR
245         sta     (CRAM_PTR),y    ; vram
246 .endif
247
248 ; output character
249         ldx     tmp3            ; get charcode
250
251         lda     RVS
252         beq     @skp
253         jmp     draw_charinvers
254 @skp:
255         lda     soft80_internal_cursorxlsb
256         bne     draw_char_even
257
258 ; output character (odd)
259         .repeat 8,line
260         lda     (SCREEN_PTR),y
261         and     #$0f
262         ora     soft80_hi_charset+(line*$80),x
263         sta     (SCREEN_PTR),y
264         .if line < 7
265         iny
266         .endif
267         .endrepeat
268         jmp     draw_back
269
270 ; output character (even)
271 draw_char_even:
272         .repeat 8,line
273         lda     (SCREEN_PTR),y
274         and     #$f0
275         ora     soft80_lo_charset+(line*$80),x
276         sta     (SCREEN_PTR),y
277         .if line < 7
278         iny
279         .endif
280         .endrepeat
281
282 draw_back:
283         lda     tmp4
284         sta     $01
285         cli
286
287         ldy     CURS_X
288         rts
289
290 ; output inverted character (odd)
291 draw_charinvers_odd:
292         .repeat 8,line
293         lda     (SCREEN_PTR),y
294         ora     #$0f
295         eor     soft80_lo_charset+(line*$80),x
296         sta     (SCREEN_PTR),y
297         .if line < 7
298         iny
299         .endif
300         .endrepeat
301         jmp     draw_back
302
303 ; output inverted character (generic)
304 draw_charinvers:
305         lda     soft80_internal_cursorxlsb
306         bne     draw_charinvers_odd
307
308         .repeat 8,line
309         lda     (SCREEN_PTR),y
310         ora     #$f0
311         eor     soft80_hi_charset+(line*$80),x
312         sta     (SCREEN_PTR),y
313         .if line < 7
314         iny
315         .endif
316         .endrepeat
317         jmp     draw_back
318
319 ;-------------------------------------------------------------------------------
320 ; optional "color voodoo". the problem is that each 8x8 cell can only contain
321 ; two colors, one of which is used for the background color, so two characters
322 ; have to share the same text color.
323 ;
324 ; - in a cell that contains two spaces, both the color ram and the text color
325 ;   in vram contain the background color
326 ;
327 ; - in a cell that contains one character, its text color goes into vram. the
328 ;   color ram contains the background color.
329 ;
330 ; - in a cell that contains two characters, the color of the left character goes
331 ;   to vram (and is shared by both for display). the "would be" color of the
332 ;   right character goes to color ram as a reminder and can be restored when one
333 ;   of the two characters is cleared by a space.
334
335 .if SOFT80COLORVOODOO = 1
336
337 ; remove color from cell, called before putting a "space" character to the bitmap
338 ;
339 ; __ -> __      -
340 ; _A -> _A      -
341 ; B_ -> B_      -
342 ; _A -> __      vram = bgcol
343 ; B_ -> __      vram = bgcol
344 ; BA -> _A      vram = colram, colram = bgcol
345 ; BA -> B_      colram = bgcol
346 ;
347 ; in:  x must be $34
348 ;      y must be $00
349 ; out: y = $00
350 remcolor:
351
352         ;ldy     #$00            ; is still $00
353
354         ; if the textcolor in vram is equal to the background color, then
355         ; no (visible) character is in the current cell and we can exit
356         ; immediately.
357         lda     (CRAM_PTR),y    ; vram (textcolor)
358         and     #$0f
359         cmp     soft80_internal_bgcolor
360         beq     @sk1            ; yes, vram==bgcolor
361
362         ; now check if the textcolor in color ram is equal the background color,
363         ; if yes then there is only one (visible) character in the current cell
364         inc     $01             ; $35
365         lda     (CRAM_PTR),y    ; colram (2nd textcolor)
366         stx     $01             ; $34
367         and     #$0f
368         cmp     soft80_internal_bgcolor
369         beq     @sk2            ; yes, colram==bgcolor
370
371         ; two characters in the current cell, of which one will get removed
372
373         ; vram = colram
374         ;inc     $01
375         ;lda     (CRAM_PTR),y    ; colram
376         ;stx     $01             ;$34
377         ;and     #$0f
378         sta     tmp3            ; A contains colram
379
380         lda     soft80_internal_cursorxlsb
381         bne     @sk3
382
383         ; vram = colram
384         lda     (CRAM_PTR),y    ; vram
385         and     #$f0
386         ora     tmp3
387         sta     (CRAM_PTR),y    ; vram
388 @sk3:
389         ; colram = bgcolor
390         lda     soft80_internal_bgcolor
391         inc     $01             ; $35
392         sta     (CRAM_PTR),y    ; colram
393         stx     $01             ; $34
394
395         rts
396
397 @sk2:
398         ; colram is bgcolor
399         ; => only one char in cell used
400
401         jsr     soft80_checkchar
402         bcc     @sk1            ; space at current position
403
404         ; vram (textcolor) = bgcolor
405         lda     (CRAM_PTR),y    ; vram
406         and     #$f0
407         ora     soft80_internal_bgcolor
408         sta     (CRAM_PTR),y    ; vram
409 @sk1:
410         rts
411
412 ; put color to cell
413 ;
414 ; __ -> _A      vram = textcol
415 ; __ -> B_      vram = textcol
416 ; _A -> BA      colram = vram, vram = textcol
417 ; B_ -> BA      colram = textcol
418 ;
419 ; _A -> _C      vram = textcol
420 ; B_ -> C_      vram = textcol
421 ; BA -> BC      colram = textcol
422 ; BA -> CA      vram = textcol
423 ;
424 ; in:  $01 is $34 (RAM under I/O) when entering
425 ;      x must be $34
426 ;      y must be $00
427 ; out: x = $34
428 ;      y = $00
429 soft80_putcolor:
430
431         ;ldy     #$00            ; is still $00
432
433         lda     (CRAM_PTR),y    ; vram
434         and     #$0f
435         cmp     soft80_internal_bgcolor
436         beq     @sk1            ; vram==bgcolor => first char in cell
437
438         ; vram!=bgcolor => second char in cell
439
440         inc     $01             ; $35
441         lda     (CRAM_PTR),y    ; colram
442         stx     $01             ; $34
443         and     #$0f
444         cmp     soft80_internal_bgcolor
445         beq     @l2s            ; colram==bgcolor -> second char in cell
446
447         ; botch characters in the cell are used
448
449         lda     soft80_internal_cursorxlsb
450         bne     @sk2            ; jump if odd xpos
451
452         ; vram = textcol
453         lda     CHARCOLOR
454         sta     (CRAM_PTR),y    ; vram
455         rts
456
457 @l2s:
458         ; one character in cell is already used
459         jsr     soft80_checkchar
460         bcs     @sk1            ; char at current position => overwrite 1st
461
462         lda     soft80_internal_cursorxlsb
463         beq     @sk3            ; jump if even xpos
464 @sk2:
465         ; colram = textcol
466         lda     soft80_internal_textcolor
467         inc     $01             ; $35
468         sta     (CRAM_PTR),y    ; colram
469         stx     $01             ; $34
470         rts
471
472 @sk3:
473         ; colram=vram
474         lda     (CRAM_PTR),y    ; vram
475         inc     $01             ; $35
476         sta     (CRAM_PTR),y    ; colram
477         stx     $01             ; $34
478 @sk1:
479         ; vram = textcol
480         lda     CHARCOLOR
481         sta     (CRAM_PTR),y    ; vram
482         rts
483
484 ;
485 ; test if there is a space or a character at current position
486 ;
487 ; in:  x = $34
488 ;      y must be $00
489 ; out: CLC: space        SEC: character
490 ;      x = $34
491 ;      y = $00
492 soft80_checkchar:
493
494         ;ldy     #$00                            ; is still $00
495
496         lda     soft80_internal_cursorxlsb
497         bne     @l1a
498
499         ; check charset data from bottom up, since a lot of eg lowercase chars
500         ; have no data in the top rows, but all of them DO have data in the
501         ; second to bottom row, this will likely be faster in average.
502
503         ldy     #7
504         .repeat 8,line
505         lda     (SCREEN_PTR),y
506         and     #$f0
507         cmp     #$f0
508         bne     @ischar
509         .if (line < 7)
510         dey
511         .endif
512         .endrepeat
513         ;ldy     #$00                            ; is 0
514         clc
515         rts
516 @ischar:
517         ldy     #$00
518         sec
519         rts
520 @l1a:
521         ldy     #$07
522         .repeat 8,line
523         lda     (SCREEN_PTR),y
524         and     #$0f
525         cmp     #$0f
526         bne     @ischar
527         .if line < 7
528         dey
529         .endif
530         .endrepeat
531         ;ldy     #$00                            ; is 0
532         clc
533         rts
534 .endif