]> git.sur5r.net Git - cc65/blob - libsrc/c64/cputc.s
New EMD driver for the ISEPIC cartridge written and contributed by
[cc65] / libsrc / c64 / cputc.s
1 ;
2 ; Ullrich von Bassewitz, 1998-08-06, 2009-09-26
3 ;
4 ; void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c);
5 ; void __fastcall__ cputc (char c);
6 ;
7
8         .export         _cputcxy, _cputc, cputdirect, putchar
9         .export         newline, plot
10         .import         popa, _gotoxy
11         .import         PLOT
12
13         .include        "c64.inc"
14
15
16 _cputcxy:
17         pha                     ; Save C
18         jsr     popa            ; Get Y
19         jsr     _gotoxy         ; Set cursor, drop x
20         pla                     ; Restore C
21
22 ; Plot a character - also used as internal function
23
24 _cputc: cmp     #$0A            ; CR?
25         bne     L1
26         lda     #0
27         sta     CURS_X
28         beq     plot            ; Recalculate pointers
29
30 L1:     cmp     #$0D            ; LF?
31         beq     newline         ; Recalculate pointers
32
33 ; Printable char of some sort
34
35         cmp     #' '
36         bcc     cputdirect      ; Other control char
37         tay
38         bmi     L10
39         cmp     #$60
40         bcc     L2
41         and     #$DF
42         bne     cputdirect      ; Branch always
43 L2:     and     #$3F
44
45 cputdirect:
46         jsr     putchar         ; Write the character to the screen
47
48 ; Advance cursor position
49
50 advance:
51         iny
52         cpy     #XSIZE
53         bne     L3
54         jsr     newline         ; new line
55         ldy     #0              ; + cr
56 L3:     sty     CURS_X
57         rts
58
59 newline:
60         clc
61         lda     #XSIZE
62         adc     SCREEN_PTR
63         sta     SCREEN_PTR
64         bcc     L4
65         inc     SCREEN_PTR+1
66         clc
67 L4:     lda     #XSIZE
68         adc     CRAM_PTR
69         sta     CRAM_PTR
70         bcc     L5
71         inc     CRAM_PTR+1
72 L5:     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
84
85
86
87 ; Set cursor position, calculate RAM pointers.
88
89 plot:   ldy     CURS_X
90         ldx     CURS_Y
91         clc
92         jmp     PLOT            ; Set the new cursor
93
94
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         lda     CHARCOLOR
104         sta     (CRAM_PTR),y    ; Set color
105         rts