]> git.sur5r.net Git - cc65/blob - libsrc/vic20/cgetc.s
d5af9a9f602637bea22cb98993dab47f64f1e743
[cc65] / libsrc / vic20 / 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        "vic20.inc"
11
12 _cgetc: lda     KEY_COUNT       ; Get number of characters
13         bne     L3              ; Jump if there are already chars waiting
14
15 ; Switch on the cursor if needed
16
17         lda     CURS_FLAG
18         pha
19         lda     cursor
20         jsr     setcursor
21 L1:     lda     KEY_COUNT
22         beq     L1
23         ldx     #0
24         pla
25         bne     L2
26         inx
27 L2:     txa
28         jsr     setcursor
29
30 L3:     jsr     KBDREAD         ; Read char and return in A
31         ldx     #0
32         rts
33
34
35 ; Switch the cursor on or off
36
37 .proc   setcursor
38
39         tax                     ; On or off?
40         bne     seton           ; Go set it on
41         lda     CURS_FLAG       ; Is the cursor currently off?
42         bne     crs9            ; Jump if yes
43         inc     CURS_FLAG       ; Mark it as off
44         lda     CURS_STATE      ; Cursor currently displayed?
45         beq     crs8            ; Jump if no
46         ldy     CURS_X          ; Get the character column
47         lda     (SCREEN_PTR),y  ; Get character
48         eor     #$80
49         sta     (SCREEN_PTR),y  ; Store character back
50         lda     CURS_COLOR
51         sta     (CRAM_PTR),y    ; Store color back
52 crs8:   lda     #0
53         sta     CURS_STATE      ; Cursor not displayed
54 crs9:   rts
55
56 seton:  lda     #0
57         sta     CURS_FLAG
58         rts
59
60 .endproc