]> git.sur5r.net Git - cc65/blob - libsrc/apple2/cgetc.s
b1bda8b9170e354ce518ff2e9bd4fafde6e70686
[cc65] / libsrc / apple2 / cgetc.s
1 ;
2 ; Kevin Ruland
3 ;
4 ; char cgetc (void);
5 ;
6 ; If open_apple key is pressed then the high-bit of the key is set.
7 ;
8
9         .export         _cgetc
10         .import         cursor, putchardirect
11
12         .include        "apple2.inc"
13
14 _cgetc:
15         ; Cursor on ?
16         lda     cursor
17         beq     :+
18
19         ; Show caret.
20         .ifdef  __APPLE2ENH__
21         lda     #$7F | $80      ; Checkerboard, screen code
22         .else
23         lda     #' ' | $40      ; Blank, flashing
24         .endif
25         jsr     putchardirect   ; Returns old character in X
26
27         ; Wait for keyboard strobe.
28 :       lda     KBD
29         bpl     :-              ; If < 128, no key pressed
30
31         ; Cursor on ?
32         ldy     cursor
33         beq     :+
34
35         ; Restore old character.
36         pha
37         txa
38         jsr     putchardirect
39         pla
40
41         ; At this time, the high bit of the key pressed is set.
42 :       bit     KBDSTRB         ; Clear keyboard strobe
43         .ifdef __APPLE2ENH__
44         bit     BUTN0           ; Check if OpenApple is down
45         bmi     done
46         .endif
47         and     #$7F            ; If not down, then clear high bit
48 done:   ldx     #>$0000
49         rts