]> git.sur5r.net Git - cc65/blob - libsrc/c128/cputc.s
Shortened the code
[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         .import         popa, _gotoxy
12         .import         PLOT
13
14         .include        "c128.inc"
15
16 newline         = NEWLINE
17
18 ;--------------------------------------------------------------------------
19
20 .code
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     cputdirect      ; Other control char
41         tay
42         bmi     L5
43         cmp     #$60
44         bcc     L3
45         and     #$DF
46         bne     cputdirect      ; Branch always
47 L3:     and     #$3F
48
49 ; Output one character to the screen. We will disable scrolling while doing so
50
51 cputdirect:
52         tax                     ; Save output char
53         lda     SCROLL
54         pha                     ; Save scroll flag
55         lda     #$C0
56         sta     SCROLL          ; Disable scrolling
57         txa                     ; Restore output char
58         jsr     PRINT
59         pla
60         sta     SCROLL          ; Restore old scroll flag
61         rts
62
63 ; Handle character if high bit set
64
65 L5:     and     #$7F
66         cmp     #$7E            ; PI?
67         bne     L6
68         lda     #$5E            ; Load screen code for PI
69         bne     cputdirect
70 L6:     ora     #$40
71         bne     cputdirect      ; Branch always
72
73 ; Carriage return
74
75 cr:     lda     #0
76         sta     CURS_X
77
78 ; Set cursor position, calculate RAM pointers
79
80 plot:   ldy     CURS_X
81         ldx     CURS_Y
82         clc
83         jmp     PLOT            ; Set the new cursor
84
85 ; Write one character to the screen without doing anything else, return X
86 ; position in Y
87
88 putchar = $CC2F
89
90 ;--------------------------------------------------------------------------
91 ; Data
92 .bss
93
94 ScrollSave:     .res    1       ; Save location for scroll byte
95
96