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