]> git.sur5r.net Git - cc65/blob - libsrc/plus4/cgetc.s
493bbf1955f33f97d27fb713c5afae024b9723d5
[cc65] / libsrc / plus4 / cgetc.s
1 ;
2 ; Ullrich von Bassewitz, 06.08.1998
3 ;
4 ; char cgetc (void);
5 ;
6
7         .export         _cgetc
8         .import         cursor
9
10         .include        "plus4.inc"
11
12
13 _cgetc: lda     KEY_COUNT       ; Get number of characters
14         ora     FKEY_COUNT      ; Or with number of function key chars
15         bne     L2              ; Jump if there are already chars waiting
16
17 ; Switch on the cursor if needed
18
19         ldy     CURS_X
20         lda     (CRAM_PTR),y    ; Get current char
21         pha                     ; And save it
22         lda     CHARCOLOR
23         sta     (CRAM_PTR),y
24
25         lda     cursor
26         beq     L1              ; Jump if no cursor
27         tya
28         clc
29         adc     SCREEN_PTR
30         sta     TED_CURSLO
31         lda     SCREEN_PTR+1
32         adc     #$00
33         sbc     #$0B            ; + carry = $C00 (screen address)
34         sta     TED_CURSHI
35
36 L1:     lda     KEY_COUNT
37         ora     FKEY_COUNT
38         beq     L1
39         pla
40         sta     (CRAM_PTR),y
41         lda     #$ff
42         sta     TED_CURSLO      ; Cursor off
43         sta     TED_CURSHI
44
45 L2:     jsr     KBDREAD         ; Read char and return in A
46         ldx     #0
47         rts
48