]> git.sur5r.net Git - cc65/blob - libsrc/apple2/cgetc.s
Adds test code for the Atari (xex) linker file format.
[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 :       inc     RNDL            ; Increment random counter low
29         bne     :+
30         inc     RNDH            ; Increment random counter high
31 :       lda     KBD
32         bpl     :--             ; If < 128, no key pressed
33
34         ; Cursor on ?
35         ldy     cursor
36         beq     :+
37
38         ; Restore old character.
39         pha
40         txa
41         jsr     putchardirect
42         pla
43
44         ; At this time, the high bit of the key pressed is set.
45 :       bit     KBDSTRB         ; Clear keyboard strobe
46         .ifdef __APPLE2ENH__
47         bit     BUTN0           ; Check if OpenApple is down
48         bmi     done
49         .endif
50         and     #$7F            ; If not down, then clear high bit
51 done:   ldx     #>$0000
52         rts