]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/cputc.s
atari: split color.s into bordercolor.s and bgcolor.s
[cc65] / libsrc / cbm510 / cputc.s
1 ;
2 ; Ullrich von Bassewitz, 14.09.2001
3 ;
4 ; void cputcxy (unsigned char x, unsigned char y, char c);
5 ; void cputc (char c);
6 ;
7
8         .export         _cputcxy, _cputc, cputdirect, putchar
9         .export         newline, plot
10
11         .import         gotoxy
12         .import         __VIDRAM_START__
13         .import         CURS_X: zp, CURS_Y: zp, CHARCOLOR: zp, RVS: zp
14         .import         SCREEN_PTR: zp, CRAM_PTR: zp
15
16         .include        "cbm510.inc"
17
18         .macpack        generic
19
20 ; ------------------------------------------------------------------------
21 ;
22
23 _cputcxy:
24         pha                     ; Save C
25         jsr     gotoxy          ; Set cursor, drop x and y
26         pla                     ; Restore C
27
28 ; Plot a character - also used as internal function
29
30 _cputc: cmp     #$0A            ; CR?
31         bne     L1
32         lda     #0
33         sta     CURS_X
34         beq     plot            ; Recalculate pointers
35
36 L1:     cmp     #$0D            ; LF?
37         beq     newline         ; Recalculate pointers
38
39 ; Printable char of some sort
40
41         cmp     #' '
42         bcc     cputdirect      ; Other control char
43         tay
44         bmi     L10
45         cmp     #$60
46         bcc     L2
47         and     #$DF
48         bne     cputdirect      ; Branch always
49 L2:     and     #$3F
50
51 cputdirect:
52         jsr     putchar         ; Write the character to the screen
53
54 ; Advance cursor position
55
56 advance:
57         iny
58         cpy     #XSIZE
59         bne     L3
60         jsr     newline         ; new line
61         ldy     #0              ; + cr
62 L3:     sty     CURS_X
63         rts
64
65 ; Handle character if high bit set
66
67 L10:    and     #$7F
68         cmp     #$7E            ; PI?
69         bne     L11
70         lda     #$5E            ; Load screen code for PI
71         bne     cputdirect
72 L11:    ora     #$40
73         bne     cputdirect      ; Branch always
74
75 ; Move the cursor into the next line
76
77 newline:
78         inc     CURS_Y
79
80 ; Set cursor position, calculate RAM pointers
81
82 plot:   ldx     CURS_Y
83         lda     LineLSBTab,x
84         sta     SCREEN_PTR
85         sta     CRAM_PTR
86         lda     LineMSBTab,x
87         sta     SCREEN_PTR+1
88         add     #.hibyte(COLOR_RAM - __VIDRAM_START__)
89         sta     CRAM_PTR+1
90         rts
91
92 ; Write one character to the screen without doing anything else, return X
93 ; position in Y
94
95 putchar:
96         ora     RVS             ; Set revers bit
97         ldy     CURS_X
98         sta     (SCREEN_PTR),y  ; Set char
99         ldx     IndReg
100         lda     #$0F
101         sta     IndReg
102         lda     CHARCOLOR
103         sta     (CRAM_PTR),y    ; Set color
104         stx     IndReg
105         rts
106
107 ; -------------------------------------------------------------------------
108 ; Low bytes of the start address of the screen lines
109
110 .rodata
111
112 LineLSBTab:
113         .repeat 25, I
114         .byte   .lobyte(__VIDRAM_START__ + I * 40)
115         .endrep
116
117 ; -------------------------------------------------------------------------
118 ; High bytes of the start address of the screen lines
119
120 LineMSBTab:
121         .repeat 25, I
122         .byte   .hibyte(__VIDRAM_START__ + I * 40)
123         .endrep