]> git.sur5r.net Git - cc65/blob - libsrc/atari/cputc.s
088e2bbf15d2e07fb8250d301a5b3bd9f0df78e8
[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
11
12         .include        "atari.inc"
13
14 _cputcxy:
15         pha                     ; Save C
16         jsr     popa            ; Get Y
17         jsr     _gotoxy         ; Set cursor, drop x
18         pla                     ; Restore C
19
20 .ifdef DIRECT_SCREEN
21
22         .importzp tmp4,ptr4
23         .import _revflag
24
25 _cputc:
26         cmp     #$0D            ; CR
27         bne     L4
28         lda     #0
29         sta     COLCRS
30         beq     plot            ; return
31         
32 L4:     cmp     #$0A            ; LF
33         beq     newline
34         cmp     #ATEOL          ; Atari-EOL?
35         beq     newline
36
37         tay
38         rol     a
39         rol     a
40         rol     a
41         rol     a
42         and     #3
43         tax
44         tya
45         and     #$9f
46         ora     ataint,x
47
48 cputdirect:                     ; accepts screen code
49         jsr     putchar
50         
51 ; advance cursor
52         inc     COLCRS
53         lda     COLCRS
54         cmp     #40
55         bcc     plot
56         lda     #0
57         sta     COLCRS
58
59         .export newline
60 newline:
61         inc     ROWCRS
62         lda     ROWCRS
63         cmp     #24
64         bne     plot
65         lda     #0
66         sta     ROWCRS
67 plot:   ldy     COLCRS
68         ldx     ROWCRS
69         rts
70
71 putchar:
72         pha                     ; save char
73         lda     #0
74         sta     tmp4
75         lda     ROWCRS
76         asl     a
77         rol     tmp4
78         asl     a
79         rol     tmp4            ; row * 4
80         adc     ROWCRS
81         bcc     L1
82         inc     tmp4            ; row * 5
83 L1:     asl     a
84         rol     tmp4            ; row * 10
85         asl     a
86         rol     tmp4
87         asl     a
88         rol     tmp4            ; row * 40
89 L3:     clc
90         adc     SAVMSC          ; add start of screen memory
91         sta     ptr4
92         lda     tmp4
93         adc     SAVMSC+1
94         sta     ptr4+1
95         pla                     ; get char again
96         ora     _revflag
97         ldy     COLCRS
98         sta     (ptr4),y
99         rts
100
101         .rodata
102 ataint: .byte   64,0,32,96
103
104 ;****************************************************************
105 .else   ;***** above DIRECT_SCREEN, below thru OS ***************
106 ;****************************************************************
107
108         .import         __do_oserror,cursor,__oserror
109
110
111 ; Plot a character - also used as internal function
112
113 _cputc: cmp     #$0D            ; CR?
114         bne     L1
115         lda     #0
116         sta     COLCRS
117         beq     plot            ; Recalculate pointers
118
119 ; don't know whether this is needed. the compiler generates
120 ; already ATEOL chars for \n
121
122 L1:     cmp     #$0A            ; LF?
123         bne     L2
124         lda     #ATEOL
125
126 ; Printable char of some sort
127
128 L2:
129 cputdirect:
130         pha
131         and     #$7f
132         cmp     #32             ; control char?
133         bcs     goon
134         lda     #$1b
135         jsr     putchar
136 goon:   pla
137         jsr     putchar         ; Write the character to the screen
138
139 plot:   ldy     COLCRS
140         ldx     ROWCRS
141         rts
142
143 ; Write one character to the screen without doing anything else, return X
144 ; position in Y
145
146 putchar:
147 .if 0
148         tax
149         lda     #>(retr-1)
150         pha
151         lda     #<(retr-1)
152         pha
153         lda     ICPTH
154         pha
155         lda     ICPTL
156         pha
157         lda     #0
158         sta     LOGCOL
159         txa
160         rts
161 retr:
162 .endif
163 .if 1
164         pha
165         ldx     #0              ; iocb #0 (screen editor)
166         txa
167         sta     ICBLL,x
168         sta     ICBLH,x
169         sta     ICBAL,x
170         sta     ICBAH,x
171         lda     #PUTCHR
172         sta     ICCOM,x
173         lda     cursor
174         beq     putc7
175         lda     #0
176         beq     putc8
177 putc7:  lda     #1
178 putc8:  sta     CRSINH
179         pla
180         jsr     CIOV
181         bpl     putc9
182         jmp     __do_oserror    ; update system specific error code
183
184 putc9:  tya
185         ldx     #0
186         stx     __oserror
187         ldy     COLCRS
188 .endif
189         rts
190
191 .endif  ; not defined DIRECT_SCREEN