]> git.sur5r.net Git - cc65/blob - libsrc/c128/cputc.s
TGI drivers updated for current API (INIT call has changed)
[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 _cputcxy:
23         pha                     ; Save C
24         jsr     popa            ; Get Y
25         jsr     _gotoxy         ; Set cursor, drop x
26         pla                     ; Restore C
27
28 ; Plot a character - also used as internal function
29
30 _cputc: cmp     #$0A            ; CR?
31         beq     cr              ; Output a cr
32
33         cmp     #$0D            ; LF?
34         bne     L2
35         jmp     NEWLINE         ; Update cursor position
36
37 ; Printable char of some sort
38
39 L2:     cmp     #' '
40         bcc     L4              ; Other control char
41         tay
42         bmi     L5
43         cmp     #$60
44         bcc     L3
45         and     #$DF
46         bne     L4              ; Branch always
47 L3:     and     #$3F
48 L4:     jmp     PRINT           ; Output character
49
50 ; Handle character if high bit set
51
52 L5:     and     #$7F
53         cmp     #$7E            ; PI?
54         bne     L6
55         lda     #$5E            ; Load screen code for PI
56         bne     L4
57 L6:     ora     #$40
58         bne     L4              ; Branch always
59
60 ; Carriage return
61
62 cr:     lda     #0
63         sta     CURS_X
64
65 ; Set cursor position, calculate RAM pointers
66
67 plot:   ldy     CURS_X
68         ldx     CURS_Y
69         clc
70         jmp     PLOT            ; Set the new cursor
71
72 ; Write one character to the screen without doing anything else, return X
73 ; position in Y
74
75 putchar = $CC2F
76
77 ;--------------------------------------------------------------------------
78 ; Module constructor/destructor
79
80 initcputc:
81         lda     #$C0
82         .byte   $2C
83 donecputc:
84         lda     #$00
85         sta     SCROLL
86         rts
87