]> git.sur5r.net Git - cc65/blob - libsrc/atari/cputc.s
New module fileio-test.c
[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
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         ; update cursor position pointer
49         ldy     #0
50         lda     OLDCHR
51         sta     (OLDADR),y
52         inc     OLDADR
53         bne     L1
54         inc     OLDADR+1
55 L1:     lda     (OLDADR),y
56         sta     OLDCHR
57         ora     _revflag
58         sta     (OLDADR),y
59         
60 ; advance cursor
61         inc     COLCRS
62         lda     COLCRS
63         cmp     #40
64         bcc     plot
65         lda     #0
66         sta     COLCRS
67
68         .export newline
69 newline:
70         inc     ROWCRS
71         lda     ROWCRS
72         cmp     #24
73         bne     plot
74         lda     #0
75         sta     ROWCRS
76 plot:   ldy     COLCRS
77         ldx     ROWCRS
78         rts
79
80 ; turn off cursor, update screen, turn on cursor
81 putchar:
82         pha                     ; save char
83
84         ldy     #0
85         lda     OLDCHR
86         sta     (OLDADR),y
87
88         lda     ROWCRS
89         jsr     mul40
90 L3:     clc
91         adc     SAVMSC          ; add start of screen memory
92         sta     ptr4
93         lda     tmp4
94         adc     SAVMSC+1
95         sta     ptr4+1
96         pla                     ; get char again
97
98         sta     OLDCHR
99
100         ora     _revflag
101         ldy     COLCRS
102         sta     (ptr4),y
103
104         ; update OLDADR (maybe ROWCRS and COLCRS were changed)
105         sty     tmp4
106         lda     ptr4
107         clc
108         adc     tmp4
109         sta     OLDADR
110         lda     ptr4+1
111         adc     #0
112         sta     OLDADR+1
113         rts
114
115         .rodata
116 ataint: .byte   64,0,32,96
117