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