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