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