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