]> git.sur5r.net Git - cc65/blob - libsrc/apple2/cputc.s
Made Apple II CONIO more flexible.
[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         cputdirect, newline, putchar, putchardirect
13         .import         gotoxy, VTABZ
14
15         .include        "apple2.inc"
16
17         .segment        "ONCE"
18
19         .ifdef  __APPLE2ENH__
20 initconio:
21         sta     SETALTCHAR      ; Switch in alternate charset
22         bit     LORES           ; Limit SET80COL-HISCR to text
23         rts
24         .endif
25
26         .code
27
28 ; Plot a character - also used as internal function
29
30 _cputcxy:
31         pha                     ; Save C
32         jsr     gotoxy          ; Call this one, will pop params
33         pla                     ; Restore C and run into _cputc
34
35 _cputc:
36         cmp     #$0D            ; Test for \r = carrage return
37         beq     left
38         cmp     #$0A            ; Test for \n = line feed
39         beq     newline
40         eor     #$80            ; Invert high bit
41         .ifndef __APPLE2ENH__
42         cmp     #$E0            ; Test for lowercase
43         bcc     cputdirect
44         and     #$DF            ; Convert to uppercase
45         .endif
46
47 cputdirect:
48         jsr     putchar
49         inc     CH              ; Bump to next column
50         lda     CH
51         cmp     WNDWDTH
52         bcc     :+
53 left:   lda     #$00            ; Goto left edge of screen
54         sta     CH
55 :       rts
56
57 newline:
58         inc     CV              ; Bump to next line
59         lda     CV
60         cmp     WNDBTM
61         bcc     :+
62         lda     WNDTOP          ; Goto top of screen
63         sta     CV
64 :       jmp     VTABZ
65
66 putchar:
67         .ifdef  __APPLE2ENH__
68         ldy     INVFLG
69         cpy     #$FF            ; Normal character display mode?
70         beq     putchardirect
71         cmp     #$E0            ; Lowercase?
72         bcc     mask
73         and     #$7F            ; Inverse lowercase
74         bra     putchardirect
75         .endif
76 mask:   and     INVFLG          ; Apply normal, inverse, flash
77
78 putchardirect:
79         pha
80         ldy     CH
81         .ifdef  __APPLE2ENH__
82         bit     RD80VID         ; In 80 column mode?
83         bpl     put             ; No, just go ahead
84         tya
85         lsr                     ; Div by 2
86         tay
87         bcs     put             ; Odd cols go in main memory
88         bit     HISCR           ; Assume SET80COL
89         .endif
90 put:    lda     (BASL),Y        ; Get current character
91         tax                     ; Return old character for _cgetc
92         pla
93         sta     (BASL),Y
94         .ifdef  __APPLE2ENH__
95         bit     LOWSCR          ; Doesn't hurt in 40 column mode
96         .endif
97         rts