]> git.sur5r.net Git - cc65/blob - libsrc/cbm610/cputc.s
Make screensize() fetch the values dynamically instead of using variables
[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         .exportzp       CURS_X, CURS_Y
11
12         .import         PLOT
13         .import         _gotoxy
14         .import         popa
15
16         .include        "cbm610.inc"
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     CharPtr
66         sta     CharPtr
67         bcc     L4
68         inc     CharPtr+1
69 L4:     inc     CURS_Y
70         rts
71
72 ; Handle character if high bit set
73
74 L10:    and     #$7F
75         cmp     #$7E            ; PI?
76         bne     L11
77         lda     #$5E            ; Load screen code for PI
78         bne     cputdirect
79 L11:    ora     #$40
80         bne     cputdirect      ; Branch always
81
82 ; Set cursor position, calculate RAM pointers
83
84 plot:   ldy     CURS_X
85         ldx     CURS_Y
86         clc
87         jmp     PLOT
88
89 ; Write one character to the screen without doing anything else, return X
90 ; position in Y
91
92 putchar:
93         ldx     IndReg
94         ldy     #$0F
95         sty     IndReg
96         ora     RVS             ; Set revers bit
97         ldy     CURS_X
98         sta     (CharPtr),y     ; Set char
99         stx     IndReg
100         rts
101
102