]> git.sur5r.net Git - cc65/blob - libsrc/atari/cputc.s
added PAL/NTSC check for 1200xl + XL/XE systems
[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
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     ROWCRS
74         jsr     mul40
75 L3:     clc
76         adc     SAVMSC          ; add start of screen memory
77         sta     ptr4
78         lda     tmp4
79         adc     SAVMSC+1
80         sta     ptr4+1
81         pla                     ; get char again
82         ora     _revflag
83         ldy     COLCRS
84         sta     (ptr4),y
85         rts
86
87         .rodata
88 ataint: .byte   64,0,32,96
89
90 ;****************************************************************
91 .else   ;***** above DIRECT_SCREEN, below thru OS ***************
92 ;****************************************************************
93
94         .import         __do_oserror,cursor,__oserror
95
96
97 ; Plot a character - also used as internal function
98
99 _cputc: cmp     #$0D            ; CR?
100         bne     L1
101         lda     #0
102         sta     COLCRS
103         beq     plot            ; Recalculate pointers
104
105 ; don't know whether this is needed. the compiler generates
106 ; already ATEOL chars for \n
107
108 L1:     cmp     #$0A            ; LF?
109         bne     L2
110         lda     #ATEOL
111
112 ; Printable char of some sort
113
114 L2:
115 cputdirect:
116         pha
117         and     #$7f
118         cmp     #32             ; control char?
119         bcs     goon
120         lda     #$1b
121         jsr     putchar
122 goon:   pla
123         jsr     putchar         ; Write the character to the screen
124
125 plot:   ldy     COLCRS
126         ldx     ROWCRS
127         rts
128
129 ; Write one character to the screen without doing anything else, return X
130 ; position in Y
131
132 putchar:
133 .if 0
134         tax
135         lda     #>(retr-1)
136         pha
137         lda     #<(retr-1)
138         pha
139         lda     ICPTH
140         pha
141         lda     ICPTL
142         pha
143         lda     #0
144         sta     LOGCOL
145         txa
146         rts
147 retr:
148 .endif
149 .if 1
150         pha
151         ldx     #0              ; iocb #0 (screen editor)
152         txa
153         sta     ICBLL,x
154         sta     ICBLH,x
155         sta     ICBAL,x
156         sta     ICBAH,x
157         lda     #PUTCHR
158         sta     ICCOM,x
159         lda     cursor
160         beq     putc7
161         lda     #0
162         beq     putc8
163 putc7:  lda     #1
164 putc8:  sta     CRSINH
165         pla
166         jsr     CIOV
167         bpl     putc9
168         jmp     __do_oserror    ; update system specific error code
169
170 putc9:  tya
171         ldx     #0
172         stx     __oserror
173         ldy     COLCRS
174 .endif
175         rts
176
177 .endif  ; not defined DIRECT_SCREEN