]> git.sur5r.net Git - cc65/blob - libsrc/cbm610/cputc.s
Minor changes and cleanup
[cc65] / libsrc / cbm610 / cputc.s
1 ;
2 ; Ullrich von Bassewitz, 06.08.1998
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         popa
13
14         .import         ktmp: zp, crtc: zp, CURS_X: zp, CURS_Y: zp, RVS: zp
15         .import         CharPtr: zp
16
17         .include        "cbm610.inc"
18
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     #$0A            ; CR?
29         bne     L1
30         lda     #0
31         sta     CURS_X
32         beq     plot            ; Recalculate pointers
33
34 L1:     cmp     #$0D            ; LF?
35         beq     newline         ; Recalculate pointers
36
37 ; Printable char of some sort
38
39         cmp     #' '
40         bcc     cputdirect      ; Other control char
41         tay
42         bmi     L10
43         cmp     #$60
44         bcc     L2
45         and     #$DF
46         bne     cputdirect      ; Branch always
47 L2:     and     #$3F
48
49 cputdirect:
50         jsr     putchar         ; Write the character to the screen
51
52 ; Advance cursor position
53
54 advance:
55         iny
56         cpy     #XSIZE
57         bne     L3
58         jsr     newline         ; new line
59         ldy     #0              ; + cr
60 L3:     sty     CURS_X
61         rts
62
63 newline:
64         clc
65         lda     #XSIZE
66         adc     CharPtr
67         sta     CharPtr
68         bcc     L4
69         inc     CharPtr+1
70 L4:     inc     CURS_Y
71         rts
72
73 ; Handle character if high bit set
74
75 L10:    and     #$7F
76         cmp     #$7E            ; PI?
77         bne     L11
78         lda     #$5E            ; Load screen code for PI
79         bne     cputdirect
80 L11:    ora     #$40
81         bne     cputdirect      ; Branch always
82
83 ; Write one character to the screen without doing anything else, return X
84 ; position in Y
85
86 putchar:
87         ldx     IndReg
88         ldy     #$0F
89         sty     IndReg
90         ora     RVS             ; Set revers bit
91         ldy     CURS_X
92         sta     (CharPtr),y     ; Set char
93         stx     IndReg
94         rts
95
96 ; Set cursor position, calculate RAM pointers
97
98 plot:   ldx     CURS_Y
99         lda     LineLSBTab,x
100         sta     CharPtr
101         lda     LineMSBTab,x
102         sta     CharPtr+1
103
104         lda     IndReg
105         pha
106         lda     #$0F
107         sta     IndReg
108
109         ldy     #$00
110         clc
111         sei
112         sta     (crtc),y
113         lda     CharPtr
114         adc     CURS_X
115         iny
116         sta     (crtc),y
117         dey
118         lda     #$0E
119         sta     (crtc),y
120         iny
121         lda     (crtc),y
122         and     #$F8
123         sta     ktmp
124         lda     CharPtr+1
125         adc     #$00
126         and     #$07
127         ora     ktmp
128         sta     (crtc),y
129         cli
130
131         pla
132         sta     IndReg
133         rts
134
135 ; -------------------------------------------------------------------------
136 ; Low bytes of the start address of the screen lines
137
138 .rodata
139
140 LineLSBTab:
141         .byte   $00,$50,$A0,$F0,$40,$90,$E0,$30
142         .byte   $80,$D0,$20,$70,$C0,$10,$60,$B0
143         .byte   $00,$50,$A0,$F0,$40,$90,$E0,$30
144         .byte   $80
145 ; -------------------------------------------------------------------------
146 ; High bytes of the start address of the screen lines
147
148 LineMSBTab:
149         .byte   $D0,$D0,$D0,$D0,$D1,$D1,$D1,$D2
150         .byte   $D2,$D2,$D3,$D3,$D3,$D4,$D4,$D4
151         .byte   $D5,$D5,$D5,$D5,$D6,$D6,$D6,$D7
152         .byte   $D7
153