]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/cputc.s
e0c0e78374aeea20265d70f52549d2a51915e679
[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         PLOT
12         .import         popa, _gotoxy
13         .import         xsize
14
15         .include        "cbm510.inc"
16
17 ; ------------------------------------------------------------------------
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     SCREEN_PTR
67         sta     SCREEN_PTR
68         bcc     L4
69         inc     SCREEN_PTR+1
70         clc
71 L4:     lda     xsize
72         adc     CRAM_PTR
73         sta     CRAM_PTR
74         bcc     L5
75         inc     CRAM_PTR+1
76 L5:     inc     CURS_Y
77         rts
78
79 ; Handle character if high bit set
80
81 L10:    and     #$7F
82         cmp     #$7E            ; PI?
83         bne     L11
84         lda     #$5E            ; Load screen code for PI
85         bne     cputdirect
86 L11:    ora     #$40
87         bne     cputdirect
88
89 ; Set cursor position, calculate RAM pointers
90
91 plot:   ldy     CURS_X
92         ldx     CURS_Y
93         clc
94         jmp     PLOT            ; Set the new cursor
95
96 ; Write one character to the screen without doing anything else, return X
97 ; position in Y
98
99 putchar:
100         ora     RVS             ; Set revers bit
101         ldy     CURS_X
102         sta     (SCREEN_PTR),y  ; Set char
103         ldx     IndReg
104         lda     #$0F
105         sta     IndReg
106         lda     CHARCOLOR
107         sta     (CRAM_PTR),y    ; Set color
108         stx     IndReg
109         rts
110