]> git.sur5r.net Git - cc65/blob - libsrc/apple2/cputc.s
lseek: Return EINVAL if new position is less than 0 or greater than 2^24 - 1.
[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         jsr     newline
54 left:   lda     #$00            ; Goto left edge of screen
55         sta     CH
56 :       rts
57
58 newline:
59         inc     CV              ; Bump to next line
60         lda     CV
61         cmp     WNDBTM
62         bcc     :+
63         lda     WNDTOP          ; Goto top of screen
64         sta     CV
65 :       jmp     VTABZ
66
67 putchar:
68         .ifdef  __APPLE2ENH__
69         ldy     INVFLG
70         cpy     #$FF            ; Normal character display mode?
71         beq     putchardirect
72         cmp     #$E0            ; Lowercase?
73         bcc     mask
74         and     #$7F            ; Inverse lowercase
75         bra     putchardirect
76         .endif
77 mask:   and     INVFLG          ; Apply normal, inverse, flash
78
79 putchardirect:
80         pha
81         ldy     CH
82         .ifdef  __APPLE2ENH__
83         bit     RD80VID         ; In 80 column mode?
84         bpl     put             ; No, just go ahead
85         tya
86         lsr                     ; Div by 2
87         tay
88         bcs     put             ; Odd cols go in main memory
89         bit     HISCR           ; Assume SET80COL
90         .endif
91 put:    lda     (BASL),Y        ; Get current character
92         tax                     ; Return old character for _cgetc
93         pla
94         sta     (BASL),Y
95         .ifdef  __APPLE2ENH__
96         bit     LOWSCR          ; Doesn't hurt in 40 column mode
97         .endif
98         rts