]> git.sur5r.net Git - cc65/blob - libsrc/pce/cputc.s
Merge pull request #281 from polluks/sp65
[cc65] / libsrc / pce / 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
12         .importzp       tmp3,tmp4
13
14         .include        "pce.inc"
15         .include        "extzp.inc"
16
17 _cputcxy:
18         pha                     ; Save C
19         jsr     popa            ; Get Y
20         jsr     _gotoxy         ; Set cursor, drop x
21         pla                     ; Restore C
22
23 ; Plot a character - also used as internal function
24
25 _cputc: cmp     #$0d            ; CR?
26         bne     L1
27         lda     #0
28         sta     CURS_X
29         beq     plot            ; Recalculate pointers
30
31 L1:     cmp     #$0a            ; LF?
32         beq     newline         ; Recalculate pointers
33
34 ; Printable char of some sort
35
36 cputdirect:
37         jsr     putchar         ; Write the character to the screen
38
39 ; Advance cursor position
40
41 advance:
42         ldy     CURS_X
43         iny
44         cpy     xsize
45         bne     L3
46         jsr     newline         ; new line
47         ldy     #0              ; + cr
48 L3:     sty     CURS_X
49         jmp     plot
50
51 newline:
52         inc     CURS_Y
53
54 ; Set cursor position, calculate RAM pointers
55
56 plot:   ldy     CURS_X
57         ldx     CURS_Y
58         clc
59         jmp     PLOT            ; Set the new cursor
60
61 ; Write one character to the screen without doing anything else, return X
62 ; position in Y
63
64 putchar:
65
66         ora     RVS             ; Set revers bit
67
68         tax
69
70         st0     #VDC_MAWR       ; Memory Adress Write
71
72         lda     SCREEN_PTR
73         sta     a:VDC_DATA_LO
74
75         lda     SCREEN_PTR + 1
76         sta     a:VDC_DATA_HI
77
78         st0     #VDC_VWR        ; VWR
79
80         txa
81         sta     a:VDC_DATA_LO   ; character
82
83         lda     CHARCOLOR
84
85         asl     a
86         asl     a
87         asl     a
88         asl     a
89
90         ora     #$02
91         sta     a:VDC_DATA_HI
92
93         rts
94
95 ;-------------------------------------------------------------------------------
96 ; force the init constructor to be imported
97
98         .import initconio
99 conio_init      = initconio