]> git.sur5r.net Git - cc65/blob - libsrc/apple2/cputc.s
Squeezed out a few bytes
[cc65] / libsrc / apple2 / cputc.s
1 ;
2 ; Ullrich von Bassewitz, 06.08.1998
3 ;
4 ; void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c);
5 ; void __fastcall__ cputc (char c);
6 ;
7
8         .ifdef  __APPLE2ENH__
9         .constructor    initconio
10         .endif
11         .export         _cputcxy, _cputc
12         .export         _gotoxy, cputdirect
13         .export         newline, putchar
14
15         .import         popa, VTABZ
16
17         .include        "apple2.inc"
18
19         .segment        "INIT"
20
21         .ifdef  __APPLE2ENH__
22 initconio:
23         sta     SETALTCHAR      ; Switch in alternate charset
24         rts
25         .endif
26
27         .code
28
29 ; Plot a character - also used as internal function
30
31 _cputcxy:
32         pha                     ; Save C
33         jsr     popa            ; Get Y
34         jsr     _gotoxy
35         pla                     ; Restore C
36
37 _cputc:
38         cmp     #$0D            ; Test for \r = carrage return
39         beq     left
40         cmp     #$0A            ; Test for \n = line feed
41         beq     newline
42         ora     #$80            ; Turn on high bit
43         .ifndef __APPLE2ENH__
44         cmp     #$E0            ; Test for lowercase
45         bcc     cputdirect
46         and     #$DF            ; Convert to uppercase
47         .endif
48
49 cputdirect:
50         jsr     putchar
51         inc     CH              ; Bump to next column
52         lda     CH
53         cmp     WNDWDTH
54         bcc     :+
55 left:   lda     #$00            ; Goto left edge of screen
56         sta     CH
57 :       rts
58
59 newline:
60         inc     CV              ; Bump to next line
61         lda     CV
62         cmp     WNDBTM
63         bcc     :+
64         lda     WNDTOP          ; Goto top of screen
65         sta     CV
66 :       jmp     VTABZ
67                 
68 putchar:
69         .ifdef  __APPLE2ENH__
70         ldy     INVFLG
71         cpy     #$FF            ; Normal character display mode?
72         beq     put
73         cmp     #$E0            ; Lowercase?
74         bcc     mask
75         and     #$7F            ; Inverse lowercase
76         bra     put
77         .endif
78 mask:   and     INVFLG          ; Apply normal, inverse, flash
79 put:    ldy     CH
80         .ifdef  __APPLE2ENH__
81         bit     RD80VID         ; In 80 column mode?
82         bpl     col40           ; No, in 40 cols
83         pha
84         tya
85         lsr                     ; Div by 2
86         tay
87         pla
88         bcs     col40           ; Odd cols go in 40 col memory
89         bit     HISCR
90         sta     (BASL),Y
91         bit     LOWSCR
92         rts
93         .endif
94 col40:  sta     (BASL),Y
95         rts
96
97 _gotoxy:
98         clc
99         adc     WNDTOP
100         sta     CV              ; Store Y
101         jsr     VTABZ
102         jsr     popa            ; Get X
103         sta     CH              ; Store X
104         rts