]> git.sur5r.net Git - cc65/blob - libsrc/atmos/cputc.s
Added a comment.
[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         .import         rvs
12         .import         popax
13         .importzp       ptr2
14
15         .include        "atmos.inc"
16
17
18 _cputcxy:
19         pha                     ; Save C
20         jsr     popax           ; Get X and Y
21         sta     CURS_Y          ; Store Y
22         stx     CURS_X          ; Store X
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          ; Carriage return
31         rts
32
33 L1:     cmp     #$0A            ; LF?
34         bne     output
35         inc     CURS_Y          ; Newline
36         rts
37
38 ; Output the character, then advance the cursor position
39
40 output:
41         jsr     putchar
42
43 advance:
44         iny
45         cpy     #SCREEN_XSIZE
46         bne     L3
47         inc     CURS_Y          ; new line
48         ldy     #0              ; + cr
49 L3:     sty     CURS_X
50         rts
51
52 ; ------------------------------------------------------------------------
53 ; Set ptr2 to the screen, load the X offset into Y
54
55 .code
56 .proc   setscrptr
57
58         ldy     CURS_Y          ; Get line number into Y
59         lda     ScrTabLo,y      ; Get low byte of line address
60         sta     ptr2
61         lda     ScrTabHi,y      ; Get high byte of line address
62         sta     ptr2+1
63         ldy     CURS_X          ; Get X offset
64         rts
65
66 .endproc
67
68 ; ------------------------------------------------------------------------
69 ; Write one character to the screen without doing anything else, return X
70 ; position in Y
71
72 .code
73 .proc   putchar
74
75         ora     rvs             ; Set revers bit
76         pha                     ; And save
77         jsr     setscrptr       ; Set ptr2 to the screen
78         pla                     ; Restore the character
79         sta     (ptr2),y        ; Set char
80         rts
81
82 .endproc
83
84 ; ------------------------------------------------------------------------
85 ; Screen address table
86
87 .rodata
88 ScrTabLo:
89         .repeat SCREEN_YSIZE, Line
90                 .byte   <(SCREEN + Line * SCREEN_XSIZE)
91         .endrep
92
93 ScrTabHi:
94         .repeat SCREEN_YSIZE, Line
95                 .byte   >(SCREEN + Line * SCREEN_XSIZE)
96         .endrep
97