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