]> git.sur5r.net Git - cc65/blob - libsrc/atari/cputc.s
Optimized mul20 & mul40 and extracted to new library.
[cc65] / libsrc / atari / cputc.s
1 ;
2 ; Mark Keates, Christian Groessler, Piotr Fusik
3 ;
4 ; void cputcxy (unsigned char x, unsigned char y, char c);
5 ; void cputc (char c);
6 ;
7
8         .export         _cputcxy, _cputc
9         .export         plot, cputdirect, putchar
10         .import         gotoxy, _mul40
11         .importzp       tmp4,ptr4
12         .import         _revflag,setcursor
13
14         .include        "atari.inc"
15
16 _cputcxy:
17         pha                     ; Save C
18         jsr     gotoxy          ; Set cursor, drop x and y
19         pla                     ; Restore C
20
21 _cputc:
22         cmp     #$0D            ; CR
23         bne     L4
24         lda     #0
25         sta     COLCRS
26         beq     plot            ; return
27
28 L4:     cmp     #$0A            ; LF
29         beq     newline
30         cmp     #ATEOL          ; Atari-EOL?
31         beq     newline
32
33         asl     a               ; shift out the inverse bit
34         adc     #$c0            ; grab the inverse bit; convert ATASCII to screen code
35         bpl     codeok          ; screen code ok?
36         eor     #$40            ; needs correction
37 codeok: lsr     a               ; undo the shift
38         bcc     cputdirect
39         eor     #$80            ; restore the inverse bit
40
41 cputdirect:                     ; accepts screen code
42         jsr     putchar
43
44 ; advance cursor
45         inc     COLCRS
46         lda     COLCRS
47         cmp     #40
48         bcc     plot
49         lda     #0
50         sta     COLCRS
51
52         .export newline
53 newline:
54         inc     ROWCRS
55         lda     ROWCRS
56         cmp     #24
57         bne     plot
58         lda     #0
59         sta     ROWCRS
60 plot:   jsr     setcursor
61         ldy     COLCRS
62         ldx     ROWCRS
63         rts
64
65 ; turn off cursor, update screen, turn on cursor
66 putchar:
67         pha                     ; save char
68
69         ldy     #0
70         lda     OLDCHR
71         sta     (OLDADR),y
72
73         lda     ROWCRS
74         jsr     _mul40          ; destroys tmp4, carry is cleared
75         adc     SAVMSC          ; add start of screen memory
76         sta     ptr4
77         txa
78         adc     SAVMSC+1
79         sta     ptr4+1
80         pla                     ; get char again
81
82         ora     _revflag
83         sta     OLDCHR
84
85         ldy     COLCRS
86         sta     (ptr4),y
87         jmp     setcursor