]> git.sur5r.net Git - cc65/blob - libsrc/c128/cputc.s
Added more info about internal (builtin) functions
[cc65] / libsrc / c128 / cputc.s
1 ;
2 ; Ullrich von Bassewitz, 2000-08-06, 2002-12-21
3 ; Using lots of code from MagerValp, MagerValp@cling.gu.se
4 ;
5 ; void cputcxy (unsigned char x, unsigned char y, char c);
6 ; void cputc (char c);
7 ;
8
9         .export         _cputcxy, _cputc, cputdirect, putchar
10         .export         newline, plot
11         .constructor    initcputc
12         .destructor     donecputc
13         .import         popa, _gotoxy
14         .import         PLOT
15
16         .include        "c128.inc"
17
18 cputdirect      = PRINT
19 newline         = NEWLINE
20
21 ;--------------------------------------------------------------------------
22
23 .code
24
25 _cputcxy:
26         pha                     ; Save C
27         jsr     popa            ; Get Y
28         jsr     _gotoxy         ; Set cursor, drop x
29         pla                     ; Restore C
30
31 ; Plot a character - also used as internal function
32
33 _cputc: cmp     #$0A            ; CR?
34         beq     cr              ; Output a cr
35
36         cmp     #$0D            ; LF?
37         bne     L2
38         jmp     NEWLINE         ; Update cursor position
39
40 ; Printable char of some sort
41
42 L2:     cmp     #' '
43         bcc     L4              ; Other control char
44         tay
45         bmi     L5
46         cmp     #$60
47         bcc     L3
48         and     #$DF
49         bne     L4              ; Branch always
50 L3:     and     #$3F
51 L4:     jmp     PRINT           ; Output character
52
53 ; Handle character if high bit set
54
55 L5:     and     #$7F
56         cmp     #$7E            ; PI?
57         bne     L6
58         lda     #$5E            ; Load screen code for PI
59         bne     L4
60 L6:     ora     #$40
61         bne     L4              ; Branch always
62
63 ; Carriage return
64
65 cr:     lda     #0
66         sta     CURS_X
67
68 ; Set cursor position, calculate RAM pointers
69
70 plot:   ldy     CURS_X
71         ldx     CURS_Y
72         clc
73         jmp     PLOT            ; Set the new cursor
74
75 ; Write one character to the screen without doing anything else, return X
76 ; position in Y
77
78 putchar = $CC2F
79
80 ;--------------------------------------------------------------------------
81 ; Module constructor/destructor. Don't move the constructor into the INIT
82 ; segment, because it shares most of the code with the destructor.
83
84 initcputc:
85         lda     #$C0
86         .byte   $2C
87 donecputc:
88         lda     #$00
89         sta     SCROLL
90         rts
91