]> git.sur5r.net Git - cc65/blob - libsrc/gamate/cputc.s
Move Atari-specific PIA reg vals to atari.h
[cc65] / libsrc / gamate / cputc.s
1 ;
2 ; void cputcxy (unsigned char x, unsigned char y, char c);
3 ; void cputc (char c);
4 ;
5
6         .export         _cputcxy, _cputc, cputdirect, putchar
7         .export         newline, plot
8         .import         gotoxy
9         .import         PLOT
10         .import         xsize
11         .import         fontdata
12         .import         _plotlo
13
14         .importzp       tmp3,tmp4
15         .importzp       ptr3
16
17         .include        "gamate.inc"
18         .include        "extzp.inc"
19
20 _cputcxy:
21         pha                     ; Save C
22         jsr     gotoxy          ; Set cursor, drop x and y
23         pla                     ; Restore C
24
25 ; Plot a character - also used as internal function
26
27 _cputc: cmp     #$0d            ; CR?
28         bne     L1
29         lda     #0
30         sta     CURS_X
31         beq     plot            ; Recalculate pointers
32
33 L1:     cmp     #$0a            ; LF?
34         beq     newline         ; Recalculate pointers
35
36 ; Printable char of some sort
37
38 cputdirect:
39         jsr     putchar         ; Write the character to the screen
40
41 ; Advance cursor position
42
43 advance:
44         ldy     CURS_X
45         iny
46         cpy     xsize
47         bne     L3
48         jsr     newline         ; new line
49         ldy     #0              ; + cr
50 L3:     sty     CURS_X
51         jmp     plot
52
53 newline:
54         inc     CURS_Y
55
56 ; Set cursor position, calculate RAM pointers
57
58 plot:   ldy     CURS_X
59         ldx     CURS_Y
60         clc
61         jmp     PLOT            ; Set the new cursor
62
63 ; Write one character to the screen without doing anything else, return X
64 ; position in Y
65
66 putchar:
67         sta     ptr3
68
69         txa
70         pha
71
72         lda     #0
73         sta     ptr3+1
74
75         ; char index * 8
76         asl     ptr3
77         rol     ptr3+1
78         asl     ptr3
79         rol     ptr3+1
80         asl     ptr3
81         rol     ptr3+1
82
83         ; plus fontdata base address
84         lda     ptr3
85         clc
86         adc     #<(fontdata-$f8)
87         sta     ptr3
88         lda     ptr3+1
89         adc     #>(fontdata-$f8)
90         sta     ptr3+1
91
92         lda     CHARCOLOR
93         and     #1
94         beq     @skip_plane1
95
96         lda     #LCD_XPOS_PLANE1
97         clc
98         adc     CURS_X
99         sta     LCD_X
100
101         ldy     #$f8
102 @copylp1:
103         lda     (ptr3),y
104         eor     RVS
105         sta     LCD_DATA
106         iny
107         bne     @copylp1
108
109 @skip_plane1:
110
111         lda     CHARCOLOR
112         and     #2
113         beq     @skip_plane2
114
115         lda     #LCD_XPOS_PLANE2
116         clc
117         adc     CURS_X
118         sta     LCD_X
119
120         ldx     CURS_Y
121         lda     _plotlo,x
122         sta     LCD_Y
123
124         ldy     #$f8
125 @copylp2:
126         lda     (ptr3),y
127         eor     RVS
128         sta     LCD_DATA
129         iny
130         bne     @copylp2
131
132 @skip_plane2:
133         pla
134         tax
135         ldy     CURS_X
136         rts
137
138 ;-------------------------------------------------------------------------------
139 ; force the init constructor to be imported
140
141         .import initconio
142 conio_init      = initconio