]> git.sur5r.net Git - cc65/blob - libsrc/c128/cputc.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / c128 / 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         advance, newline, plot
10         .import         popa, _gotoxy
11         .import         xsize, revers
12
13         .include        "c128.inc"
14         .include        "../cbm/cbm.inc"
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     #$0D            ; CR?
25         bne     L1
26         lda     #0
27         sta     CURS_X
28         beq     plot            ; Recalculate pointers
29
30 L1:     cmp     #$0A            ; LF?
31         bne     L2
32         ldy     CURS_Y
33         iny
34         bne     newline         ; Recalculate pointers
35
36 ; Printable char of some sort
37
38 L2:     cmp     #' '
39         bcc     cputdirect      ; Other control char
40         tay
41         bmi     L10
42         cmp     #$60
43         bcc     L3
44         and     #$DF
45         bne     cputdirect      ; Branch always
46 L3:     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     L9
57         ldy     #0              ; new line
58 newline:
59         clc
60         lda     xsize
61         adc     SCREEN_PTR
62         sta     SCREEN_PTR
63         bcc     L4
64         inc     SCREEN_PTR+1
65 L4:     clc
66         lda     xsize
67         adc     CRAM_PTR
68         sta     CRAM_PTR
69         bcc     L5
70         inc     CRAM_PTR+1
71 L5:     inc     CURS_Y
72 L9:     sty     CURS_X
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     revers          ; 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