]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/cputc.s
c7d694042c5d505864ec8a41fcc8a8caa72c8bb4
[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         .import         popa, _gotoxy
11         .import         xsize, revers
12
13         .include        "zeropage.inc"
14         .include        "../cbm/cbm.inc"
15
16 ; ------------------------------------------------------------------------
17 ;
18
19 _cputcxy:
20         pha                     ; Save C
21         jsr     popa            ; Get Y
22         jsr     _gotoxy         ; Set cursor, drop x
23         pla                     ; Restore C
24
25 ; Plot a character - also used as internal function
26
27 _cputc: cmp     #$0A            ; CR?
28         bne     L1
29         lda     #0
30         sta     CURS_X
31         beq     plot            ; Recalculate pointers
32
33 L1:     cmp     #$0D            ; LF?
34         beq     newline         ; Recalculate pointers
35
36 ; Printable char of some sort
37
38         cmp     #' '
39         bcc     cputdirect      ; Other control char
40         tay
41         bmi     L10
42         cmp     #$60
43         bcc     L2
44         and     #$DF
45         bne     cputdirect      ; Branch always
46 L2:     and     #$3F
47
48 cputdirect:
49         jsr     putchar         ; Write the character to the screen
50
51 ; Advance cursor position
52
53 advance:
54         iny
55         cpy     xsize
56         bne     L3
57         jsr     newline         ; new line
58         ldy     #0              ; + cr
59 L3:     sty     CURS_X
60         rts
61
62 newline:
63         clc              
64         lda     xsize
65         adc     SCREEN_PTR
66         sta     SCREEN_PTR
67         bcc     L4
68         inc     SCREEN_PTR+1
69         clc
70 L4:     lda     xsize
71         adc     CRAM_PTR
72         sta     CRAM_PTR
73         bcc     L5
74         inc     CRAM_PTR+1
75 L5:     inc     CURS_Y
76         rts
77
78 ; Handle character if high bit set
79
80 L10:    and     #$7F
81         cmp     #$7E            ; PI?
82         bne     L11
83         lda     #$5E            ; Load screen code for PI
84         bne     cputdirect
85 L11:    ora     #$40
86         bne     cputdirect
87
88 ; Set cursor position, calculate RAM pointers
89
90 plot:   ldy     CURS_X
91         ldx     CURS_Y
92         clc
93         jmp     PLOT            ; Set the new cursor
94
95 ; Write one character to the screen without doing anything else, return X
96 ; position in Y
97
98 putchar:
99         ora     revers          ; Set revers bit
100         ldy     CURS_X
101         sta     (SCREEN_PTR),y  ; Set char
102         ldx     IndReg
103         lda     #$0F
104         sta     IndReg
105         lda     CHARCOLOR
106         sta     (CRAM_PTR),y    ; Set color
107         stx     IndReg
108         rts
109