]> git.sur5r.net Git - cc65/blob - libsrc/c128/cputc.s
d69170bce07af10d6b75d056bf53535bd36e292b
[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         ldx     SCROLL
53         stx     ScrollSave      ; Save scroll flag
54         ldx     #$C0
55         stx     SCROLL          ; Disable scrolling
56         jsr     PRINT           ; Call kernal entry point
57         ldx     ScrollSave
58         stx     SCROLL          ; Restore old scroll flag
59         rts
60
61 ; Handle character if high bit set
62
63 L5:     and     #$7F
64         cmp     #$7E            ; PI?
65         bne     L6
66         lda     #$5E            ; Load screen code for PI
67         bne     cputdirect
68 L6:     ora     #$40
69         bne     cputdirect      ; Branch always
70
71 ; Carriage return
72
73 cr:     lda     #0
74         sta     CURS_X
75
76 ; Set cursor position, calculate RAM pointers
77
78 plot:   ldy     CURS_X
79         ldx     CURS_Y
80         clc
81         jmp     PLOT            ; Set the new cursor
82
83 ; Write one character to the screen without doing anything else, return X
84 ; position in Y
85
86 putchar = $CC2F
87
88 ;--------------------------------------------------------------------------
89 ; Data
90 .bss
91
92 ScrollSave:     .res    1       ; Save location for scroll byte
93
94