]> git.sur5r.net Git - cc65/blob - libsrc/cbm610/cputc.s
Removed (pretty inconsistently used) tab chars from source code base.
[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         .destructor     setsyscursor
11
12         .import         _gotoxy
13         .import         popa
14         .import         PLOT
15
16         .import         ktmp: zp, crtc: zp, CURS_X: zp, CURS_Y: zp, RVS: zp
17         .import         CharPtr: zp
18
19         .include        "cbm610.inc"
20
21
22 _cputcxy:
23         pha                     ; Save C
24         jsr     popa            ; Get Y
25         jsr     _gotoxy         ; Set cursor, drop x
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 newline:
66         clc
67         lda     #XSIZE
68         adc     CharPtr
69         sta     CharPtr
70         bcc     L4
71         inc     CharPtr+1
72 L4:     inc     CURS_Y
73         rts
74
75 ; Handle character if high bit set
76
77 L10:    and     #$7F
78         cmp     #$7E            ; PI?
79         bne     L11
80         lda     #$5E            ; Load screen code for PI
81         bne     cputdirect
82 L11:    ora     #$40
83         bne     cputdirect      ; Branch always
84
85 ; Write one character to the screen without doing anything else, return X
86 ; position in Y
87
88 putchar:
89         ldx     IndReg
90         ldy     #$0F
91         sty     IndReg
92         ora     RVS             ; Set revers bit
93         ldy     CURS_X
94         sta     (CharPtr),y     ; Set char
95         stx     IndReg
96         rts
97
98 ; Set cursor position, calculate RAM pointers
99
100 plot:   ldx     CURS_Y
101         lda     LineLSBTab,x
102         sta     CharPtr
103         lda     LineMSBTab,x
104         sta     CharPtr+1
105
106         lda     IndReg
107         pha
108         lda     #$0F
109         sta     IndReg
110
111         ldy     #$00
112         clc
113         sei
114         sta     (crtc),y
115         lda     CharPtr
116         adc     CURS_X
117         iny
118         sta     (crtc),y
119         dey
120         lda     #$0E
121         sta     (crtc),y
122         iny
123         lda     (crtc),y
124         and     #$F8
125         sta     ktmp
126         lda     CharPtr+1
127         adc     #$00
128         and     #$07
129         ora     ktmp
130         sta     (crtc),y
131         cli
132
133         pla
134         sta     IndReg
135         rts
136
137 ; -------------------------------------------------------------------------
138 ; Cleanup routine that sets the kernal cursor position to ours
139
140 .segment        "PAGE2"
141
142 setsyscursor:
143         ldy     CURS_X
144         ldx     CURS_Y
145         clc
146         jmp     PLOT            ; Set the new cursor
147
148 ; -------------------------------------------------------------------------
149 ; Low bytes of the start address of the screen lines
150
151 .rodata
152
153 LineLSBTab:
154         .byte   $00,$50,$A0,$F0,$40,$90,$E0,$30
155         .byte   $80,$D0,$20,$70,$C0,$10,$60,$B0
156         .byte   $00,$50,$A0,$F0,$40,$90,$E0,$30
157         .byte   $80
158 ; -------------------------------------------------------------------------
159 ; High bytes of the start address of the screen lines
160
161 LineMSBTab:
162         .byte   $D0,$D0,$D0,$D0,$D1,$D1,$D1,$D2
163         .byte   $D2,$D2,$D3,$D3,$D3,$D4,$D4,$D4
164         .byte   $D5,$D5,$D5,$D5,$D6,$D6,$D6,$D7
165         .byte   $D7
166