]> git.sur5r.net Git - cc65/blob - libsrc/atmos/cputc.s
Added SER_ prefix. Whitespace cleanup
[cc65] / libsrc / atmos / cputc.s
1 ;
2 ; 2003-04-13, Ullrich von Bassewitz
3 ; 2013-07-16, Greg King
4 ;
5 ; void cputcxy (unsigned char x, unsigned char y, char c);
6 ; void cputc (char c);
7 ;
8
9         .export         _cputcxy, _cputc
10         .export         setscrptr, putchar
11         .constructor    initcputc
12         .import         rvs
13         .import         popax
14         .importzp       ptr2
15
16         .include        "atmos.inc"
17
18
19 _cputcxy:
20         pha                     ; Save C
21         jsr     popax           ; Get X and Y
22         sta     CURS_Y          ; Store Y
23         stx     CURS_X          ; Store 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          ; Carriage return
32         rts
33
34 L1:     cmp     #$0A            ; LF?
35         bne     output
36         inc     CURS_Y          ; Newline
37         rts
38
39 ; Output the character, then advance the cursor position
40
41 output:
42         jsr     putchar
43
44 advance:
45         iny
46         cpy     #SCREEN_XSIZE
47         bne     L3
48         inc     CURS_Y          ; new line
49         ldy     #0              ; + cr
50 L3:     sty     CURS_X
51         rts
52
53 ; ------------------------------------------------------------------------
54 ; Set ptr2 to the screen, load the X offset into Y
55
56 .code
57 .proc   setscrptr
58
59         ldy     CURS_Y          ; Get line number into Y
60         lda     ScrTabLo,y      ; Get low byte of line address
61         sta     ptr2
62         lda     ScrTabHi,y      ; Get high byte of line address
63         sta     ptr2+1
64         ldy     CURS_X          ; Get X offset
65         rts
66
67 .endproc
68
69 ; ------------------------------------------------------------------------
70 ; Write one character to the screen without doing anything else, return X
71 ; position in Y
72
73 .code
74 .proc   putchar
75
76         ora     rvs             ; Set revers bit
77         pha                     ; And save
78         jsr     setscrptr       ; Set ptr2 to the screen
79         pla                     ; Restore the character
80         sta     (ptr2),y        ; Set char
81         rts
82
83 .endproc
84
85 ; ------------------------------------------------------------------------
86 ; Screen address table
87
88 .rodata
89 ScrTabLo:
90         .repeat SCREEN_YSIZE, Line
91                 .byte   <(SCREEN + Line * SCREEN_XSIZE)
92         .endrep
93
94 ScrTabHi:
95         .repeat SCREEN_YSIZE, Line
96                 .byte   >(SCREEN + Line * SCREEN_XSIZE)
97         .endrep
98
99 ; ------------------------------------------------------------------------
100 ; Switch the cursor off. Code goes into the ONCE segment,
101 ; which will be reused after it is run.
102
103 .segment        "ONCE"
104
105 initcputc:
106         lsr     STATUS
107         asl     STATUS          ; Clear bit zero
108         rts