]> git.sur5r.net Git - cc65/blob - libsrc/atari/cputc.s
always use setcursor to update cursor settings
[cc65] / libsrc / atari / cputc.s
1 ;
2 ; Mark Keates, Christian Groessler
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         popa, _gotoxy, mul40
11         .importzp       tmp4,ptr4
12         .import         _revflag,setcursor
13
14         .include        "atari.inc"
15
16 _cputcxy:
17         pha                     ; Save C
18         jsr     popa            ; Get Y
19         jsr     _gotoxy         ; Set cursor, drop x
20         pla                     ; Restore C
21
22 _cputc:
23         cmp     #$0D            ; CR
24         bne     L4
25         lda     #0
26         sta     COLCRS
27         beq     plot            ; return
28
29 L4:     cmp     #$0A            ; LF
30         beq     newline
31         cmp     #ATEOL          ; Atari-EOL?
32         beq     newline
33
34         tay
35         rol     a
36         rol     a
37         rol     a
38         rol     a
39         and     #3
40         tax
41         tya
42         and     #$9f
43         ora     ataint,x
44
45 cputdirect:                     ; accepts screen code
46         jsr     putchar
47
48 ; advance cursor
49         inc     COLCRS
50         lda     COLCRS
51         cmp     #40
52         bcc     plot
53         lda     #0
54         sta     COLCRS
55
56         .export newline
57 newline:
58         inc     ROWCRS
59         lda     ROWCRS
60         cmp     #24
61         bne     plot
62         lda     #0
63         sta     ROWCRS
64 plot:   jsr     setcursor
65         ldy     COLCRS
66         ldx     ROWCRS
67         rts
68
69 ; turn off cursor, update screen, turn on cursor
70 putchar:
71         pha                     ; save char
72
73         ldy     #0
74         lda     OLDCHR
75         sta     (OLDADR),y
76
77         lda     ROWCRS
78         jsr     mul40           ; destroys tmp4
79         clc
80         adc     SAVMSC          ; add start of screen memory
81         sta     ptr4
82         txa
83         adc     SAVMSC+1
84         sta     ptr4+1
85         pla                     ; get char again
86
87         ora     _revflag
88         sta     OLDCHR
89
90         ldy     COLCRS
91         sta     (ptr4),y
92         jmp     setcursor
93
94         .rodata
95 ataint: .byte   64,0,32,96